/* ── MailerApp — Clean Professional Theme ── */
@import url('https://fonts.googleapis.com/css2?family=Instrument+Serif:ital@0;1&family=DM+Sans:wght@300;400;500;600&family=DM+Mono:wght@400;500&display=swap');

:root {
    --white: #ffffff;
    --bg: #f5f6fa;
    --bg2: #eef0f6;
    --card: #ffffff;
    --border: #e4e6ef;
    --border2: #c8cbda;
    --text: #111827;
    --text2: #6b7280;
    --text3: #9ca3af;
    --accent: #2563eb;
    --accent2: #1d4ed8;
    --accent-light: #eff6ff;
    --green: #16a34a;
    --green-bg: #dcfce7;
    --red: #dc2626;
    --red-bg: #fee2e2;
    --amber: #d97706;
    --amber-bg: #fef3c7;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 1px 4px rgba(0, 0, 0, .06), 0 4px 16px rgba(0, 0, 0, .06);
    --shadow-md: 0 4px 24px rgba(0, 0, 0, .10);
    --sidebar-w: 240px;
    --header-h: 60px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'DM Sans', sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.6;
    min-height: 100vh;
}

a {
    color: inherit;
    text-decoration: none;
}

/* ── LAYOUT ── */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* ── SIDEBAR ── */
.sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: var(--white);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 50;
    transition: transform .2s;
}

.sidebar-brand {
    height: var(--header-h);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 20px;
    border-bottom: 1px solid var(--border);
    font-family: 'Instrument Serif', serif;
    font-size: 20px;
    color: var(--text);
    letter-spacing: -.3px;
}

.sidebar-brand .brand-icon {
    width: 32px;
    height: 32px;
    /*background: var(--accent);*/
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 15px;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 10px;
    overflow-y: auto;
}

.nav-section-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--text3);
    padding: 8px 10px 4px;
    margin-top: 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--text2);
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    transition: all .15s;
    margin-bottom: 2px;
}

.nav-item:hover {
    background: var(--bg);
    color: var(--text);
}

.nav-item.active {
    background: var(--accent-light);
    color: var(--accent);
    font-weight: 600;
}

.nav-item .nav-icon {
    font-size: 16px;
    width: 20px;
    text-align: center;
}

.nav-item .nav-badge {
    margin-left: auto;
    background: var(--accent);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 20px;
}

.sidebar-footer {
    padding: 14px 10px;
    border-top: 1px solid var(--border);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background .15s;
}

.sidebar-user:hover {
    background: var(--bg);
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent-light);
    color: var(--accent);
    font-size: 13px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.user-info {
    flex: 1;
    min-width: 0;
}

.user-name {
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    font-size: 11px;
    color: var(--text3);
    text-transform: capitalize;
}

/* ── MAIN CONTENT ── */
.main-content {
    margin-left: var(--sidebar-w);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.top-bar {
    height: var(--header-h);
    background: var(--white);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    position: sticky;
    top: 0;
    z-index: 40;
}

.top-bar-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
}

.top-bar-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.page-body {
    padding: 28px;
    flex: 1;
}

/* ── CARDS ── */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-body {
    padding: 20px;
}

/* ── STAT CARDS ── */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: var(--shadow);
    transition: box-shadow .15s, transform .15s;
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}

.stat-icon.blue {
    background: var(--accent-light);
}

.stat-icon.green {
    background: var(--green-bg);
}

.stat-icon.red {
    background: var(--red-bg);
}

.stat-icon.amber {
    background: var(--amber-bg);
}

.stat-info .stat-value {
    font-size: 28px;
    font-weight: 700;
    line-height: 1.1;
}

.stat-info .stat-label {
    font-size: 12px;
    color: var(--text2);
    margin-top: 2px;
}

/* ── BUTTONS ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all .15s;
    white-space: nowrap;
}

.btn:disabled {
    opacity: .45;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent2);
    border-color: var(--accent2);
}

.btn-outline {
    background: #fff;
    color: var(--text2);
    border-color: var(--border2);
}

.btn-outline:hover:not(:disabled) {
    background: var(--bg);
    color: var(--text);
    border-color: var(--border2);
}

.btn-danger {
    background: var(--red-bg);
    color: var(--red);
    border-color: rgba(220, 38, 38, .2);
}

.btn-danger:hover:not(:disabled) {
    background: #fca5a5;
}

.btn-success {
    background: var(--green-bg);
    color: var(--green);
    border-color: rgba(22, 163, 74, .2);
}

.btn-sm {
    padding: 5px 10px;
    font-size: 12px;
}

.btn-lg {
    padding: 11px 22px;
    font-size: 14px;
}

.btn-block {
    width: 100%;
    justify-content: center;
}

/* ── FORMS ── */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text2);
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.form-control {
    width: 100%;
    padding: 9px 12px;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 13.5px;
    color: var(--text);
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}

.form-control:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

.form-control::placeholder {
    color: var(--text3);
}

select.form-control {
    cursor: pointer;
}

textarea.form-control {
    resize: vertical;
    min-height: 100px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

/* ── BADGES ── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
}

.badge-green {
    background: var(--green-bg);
    color: var(--green);
}

.badge-red {
    background: var(--red-bg);
    color: var(--red);
}

.badge-amber {
    background: var(--amber-bg);
    color: var(--amber);
}

.badge-blue {
    background: var(--accent-light);
    color: var(--accent);
}

.badge-gray {
    background: var(--bg2);
    color: var(--text2);
}

/* ── TABLES ── */
.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

thead th {
    padding: 10px 14px;
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: var(--text2);
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

tbody td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    vertical-align: middle;
}

tbody tr:last-child td {
    border-bottom: none;
}

tbody tr:hover td {
    background: var(--bg);
}

/* ── LOGIN PAGE ── */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #f0f4ff 0%, #fafafa 60%, #f0f9ff 100%);
    padding: 20px;
}

.login-card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow-md);
    width: 100%;
    max-width: 420px;
    padding: 40px;
}

.login-logo {
    text-align: center;
    margin-bottom: 28px;
}

.login-logo .logo-icon {
    width: 52px;
    height: 52px;
    /*background: var(--accent);*/
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: #fff;
    margin-bottom: 12px;
}

.login-logo h1 {
    font-family: 'Instrument Serif', serif;
    font-size: 26px;
    color: var(--text);
    letter-spacing: -.3px;
}

.login-logo p {
    font-size: 13px;
    color: var(--text2);
    margin-top: 4px;
}

.alert {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.alert-danger {
    background: var(--red-bg);
    color: var(--red);
    border: 1px solid rgba(220, 38, 38, .2);
}

.alert-success {
    background: var(--green-bg);
    color: var(--green);
    border: 1px solid rgba(22, 163, 74, .2);
}

.alert-info {
    background: var(--accent-light);
    color: var(--accent);
    border: 1px solid rgba(37, 99, 235, .2);
}

/* ── TAGS INPUT ── */
.tag-input-wrap {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px 8px;
    min-height: 42px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
    background: var(--white);
    cursor: text;
    transition: border-color .15s, box-shadow .15s;
}

.tag-input-wrap:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

.rec-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: var(--accent-light);
    border: 1px solid rgba(37, 99, 235, .2);
    border-radius: 20px;
    font-size: 12px;
    color: var(--accent);
    font-family: 'DM Mono', monospace;
}

.rec-tag .remove-tag {
    cursor: pointer;
    color: var(--text3);
    transition: color .1s;
}

.rec-tag .remove-tag:hover {
    color: var(--red);
}

#tagRealInput {
    border: none;
    outline: none;
    font-size: 13px;
    min-width: 180px;
    padding: 2px 4px;
    flex: 1;
    background: transparent;
    font-family: 'DM Mono', monospace;
    color: var(--text);
}

/* ── EDITOR ── */
.editor-toolbar {
    background: var(--bg);
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    padding: 6px 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    align-items: center;
}

.tb-btn {
    width: 28px;
    height: 26px;
    background: none;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 700;
    color: var(--text2);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .1s;
}

.tb-btn:hover {
    background: var(--border);
    color: var(--text);
}

.tb-sep {
    width: 1px;
    height: 18px;
    background: var(--border);
    margin: 0 3px;
}

.toolbar-select {
    height: 26px;
    font-size: 12px;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0 4px;
    outline: none;
    background: var(--white);
    font-family: inherit;
    cursor: pointer;
}

.toolbar-color {
    width: 28px;
    height: 26px;
    border: none;
    padding: 2px;
    cursor: pointer;
    border-radius: 4px;
    background: none;
}

#emailBody {
    min-height: 300px;
    border: 1px solid var(--border);
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    padding: 16px 18px;
    font-size: 14px;
    line-height: 1.8;
    outline: none;
    color: var(--text);
    background: var(--white);
}

#emailBody:empty:before {
    content: attr(data-placeholder);
    color: var(--text3);
    pointer-events: none;
}

/* ── TEMPLATES ── */
.template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 20px;
}

.template-card {
    border: 2px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: all .18s;
    background: var(--white);
}

.template-card:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.template-card.selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}

.template-preview {
    height: 180px;
    overflow: hidden;
    position: relative;
}

.template-preview iframe {
    width: 100%;
    height: 360px;
    border: none;
    transform: scale(.5);
    transform-origin: top left;
    pointer-events: none;
}

.template-info {
    padding: 12px 14px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.template-name {
    font-size: 13px;
    font-weight: 600;
}

/* ── SENDER PILLS ── */
.sender-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border: 1.5px solid var(--border);
    border-radius: 50px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    color: var(--text2);
    background: var(--bg);
    transition: all .15s;
    margin: 3px 3px 3px 0;
}

.sender-pill.active {
    border-color: var(--accent);
    background: var(--accent-light);
    color: var(--accent);
}

.sender-pill .pill-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
    opacity: .6;
}

/* ── DRAFT LIST ── */
.draft-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background .12s;
}

.draft-item:hover {
    background: var(--bg);
}

.draft-item:last-child {
    border-bottom: none;
}

.draft-subject {
    font-size: 13px;
    font-weight: 600;
    flex: 1;
}

.draft-date {
    font-size: 11px;
    color: var(--text3);
    white-space: nowrap;
}

/* ── ATTACH ── */
.attach-drop {
    border: 2px dashed var(--border2);
    border-radius: var(--radius);
    padding: 18px;
    text-align: center;
    color: var(--text3);
    font-size: 13px;
    cursor: pointer;
    transition: all .15s;
    background: var(--bg);
}

.attach-drop:hover,
.attach-drop.drag-over {
    border-color: var(--accent);
    background: var(--accent-light);
    color: var(--accent);
}

.attach-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-top: 6px;
}

.attach-item .ai-name {
    flex: 1;
    font-size: 12px;
    font-family: 'DM Mono', monospace;
}

.attach-item .ai-size {
    font-size: 11px;
    color: var(--text3);
}

/* ── PROGRESS ── */
.progress {
    height: 5px;
    background: var(--bg2);
    border-radius: 3px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    transition: width .2s;
    width: 0;
}

/* ── MODAL ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .4);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s;
}

.modal-overlay.open {
    opacity: 1;
    pointer-events: all;
}

.modal-box {
    background: var(--white);
    border-radius: 14px;
    box-shadow: var(--shadow-md);
    width: 100%;
    max-width: 680px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    transform: translateY(20px);
    transition: transform .2s;
}

.modal-overlay.open .modal-box {
    transform: translateY(0);
}

.modal-head {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-head h3 {
    font-size: 15px;
    font-weight: 700;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.modal-foot {
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* ── TOAST ── */
.toast-wrap {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--text);
    color: #fff;
    padding: 11px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: var(--shadow-md);
    transform: translateX(120%);
    transition: transform .25s;
    max-width: 320px;
}

.toast.show {
    transform: translateX(0);
}

.toast.success {
    background: var(--green);
}

.toast.error {
    background: var(--red);
}

.toast.info {
    background: var(--accent);
}

/* ── MISC ── */
.divider {
    height: 1px;
    background: var(--border);
    margin: 20px 0;
}

.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text3);
}

.empty-state .empty-icon {
    font-size: 40px;
    margin-bottom: 12px;
}

.empty-state p {
    font-size: 14px;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}

.section-title {
    font-size: 15px;
    font-weight: 700;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 5px;
    height: 5px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border2);
    border-radius: 3px;
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .stat-grid {
        grid-template-columns: 1fr 1fr;
    }
}