/* MailCraft Pro - Premium Design System */
/* Colors: Gold #D4AF37, Navy #0a1628, BG #F5F2EC, Surface #FFFFFF */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

*, *::before, *::after { margin:0; padding:0; box-sizing:border-box; }

:root {
    --gold: #D4AF37;
    --gold-hover: #c4a030;
    --gold-light: rgba(212,175,55,0.08);
    --gold-15: rgba(212,175,55,0.15);
    --navy: #0a1628;
    --navy-light: #162240;
    --navy-mid: #1a2a45;
    --navy-text: #2a3a55;
    --bg: #F5F2EC;
    --surface: #FFFFFF;
    --surface-alt: #FAFAF8;
    --input-bg: #F8F7F4;
    --border: #E2DDD5;
    --border-light: #EDEAE4;
    --input-border: #D8D3CB;
    --text: #1A1A1A;
    --text-secondary: #555;
    --text-muted: #8A8A8A;
    --text-light: #8899b4;
    --text-navy-muted: #556b8a;
    --success: #166534;
    --success-bg: #f0fdf4;
    --success-border: #bbf7d0;
    --error: #991b1b;
    --error-bg: #fef2f2;
    --error-border: #fecaca;
    --error-text: #dc2626;
    --radius: 8px;
    --radius-sm: 6px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 9999px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
    --transition: all .15s ease;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* =========================================
   LAYOUT
   ========================================= */
.app-layout { display:flex; height:100vh; overflow:hidden; }

/* --- Sidebar --- */
.sidebar {
    width: 240px;
    background: var(--navy);
    color: #fff;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    border-right: 1px solid rgba(255,255,255,0.05);
}
.sidebar-header {
    padding: 24px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-header h1 {
    font-size: 18px;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.01em;
}
.sidebar-header h1 span { color: var(--gold); }

.sidebar-nav {
    flex: 1;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow-y: auto;
}
.sidebar-footer {
    padding: 16px;
    border-top: 1px solid rgba(255,255,255,0.08);
}

.main-content { flex:1; display:flex; flex-direction:column; overflow:hidden; background: var(--bg); }
.content-area { flex:1; overflow-y:auto; padding:24px; min-height:0; }

/* --- Nav buttons --- */
.nav-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    background: transparent;
    color: rgba(255,255,255,0.55);
    text-decoration: none;
    font-family: inherit;
    text-align: left;
    border-left: 3px solid transparent;
}
.nav-btn:hover {
    background: rgba(255,255,255,0.06);
    color: rgba(255,255,255,0.85);
}
.nav-btn.active {
    background: rgba(212,175,55,0.1);
    color: var(--gold);
    border-left-color: var(--gold);
}
.nav-btn.danger:hover {
    background: rgba(239,68,68,.08);
    color: #f87171;
}
.nav-btn svg { width:18px; height:18px; flex-shrink:0; opacity:0.85; }
.nav-divider { border:none; border-top:1px solid rgba(255,255,255,0.08); margin:8px 0; }

/* =========================================
   CARDS
   ========================================= */
.card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}
.card-body { padding: 24px; }

/* =========================================
   FORMS
   ========================================= */
.form-group { margin-bottom: 16px; }
.form-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 6px;
}
.form-input, .form-select, .form-textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--input-border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    background: var(--input-bg);
    color: var(--text);
    transition: border-color .2s, box-shadow .2s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
    outline: none;
    border-color: var(--gold);
    box-shadow: 0 0 0 3px rgba(212,175,55,0.12);
    background: var(--surface);
}
.form-textarea { resize:vertical; min-height:120px; font-family:'Courier New',monospace; }
.form-input-row { display:flex; align-items:center; gap:8px; }
.form-input-row .form-label { width:60px; margin-bottom:0; flex-shrink:0; }
.form-hint { font-size:12px; color:var(--text-muted); margin-top:4px; }
.form-row { display:grid; grid-template-columns:1fr 1fr; gap:16px; }

/* =========================================
   BUTTONS
   ========================================= */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
    text-decoration: none;
    line-height: 1.4;
}
.btn:disabled { opacity:.5; cursor:not-allowed; }
.btn-navy { background:var(--navy); color:#fff; }
.btn-navy:hover:not(:disabled) { background:var(--navy-light); transform:translateY(-1px); box-shadow:var(--shadow-sm); }
.btn-gold { background:var(--gold); color:var(--navy); }
.btn-gold:hover:not(:disabled) { background:var(--gold-hover); transform:translateY(-1px); box-shadow:var(--shadow-sm); }
.btn-outline { background:transparent; border:1px solid var(--border); color:var(--text); }
.btn-outline:hover:not(:disabled) { background:var(--surface-alt); border-color:var(--input-border); }
.btn-danger { background:transparent; border:1px solid #fecaca; color:var(--error-text); }
.btn-danger:hover:not(:disabled) { background:var(--error-bg); }
.btn-sm { padding:6px 12px; font-size:12px; }
.btn-lg { padding:14px 32px; font-size:16px; }
.btn-block { width:100%; }
.btn-link { background:none; border:none; color:var(--gold); font-size:13px; font-weight:500; cursor:pointer; padding:0; font-family:inherit; }
.btn-link:hover { text-decoration:underline; }

/* =========================================
   TONE PILLS
   ========================================= */
.tone-pills { display:flex; gap:6px; flex-wrap:wrap; }
.tone-pill {
    padding: 6px 14px;
    border-radius: var(--radius-full);
    font-size: 12px;
    font-weight: 500;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: var(--transition);
    background: var(--surface);
    color: var(--text-secondary);
}
.tone-pill.active {
    background: var(--gold);
    color: var(--navy);
    border-color: var(--gold);
}
.tone-pill:hover:not(.active) { background:var(--surface-alt); border-color:var(--input-border); }

/* =========================================
   ALERTS
   ========================================= */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    margin-bottom: 16px;
    border-left: 4px solid transparent;
}
.alert-success {
    background: var(--success-bg);
    border-left-color: #22c55e;
    color: var(--success);
}
.alert-error {
    background: var(--error-bg);
    border-left-color: var(--error-text);
    color: var(--error);
}

/* =========================================
   STATUS BADGES
   ========================================= */
.badge { display:inline-block; padding:3px 10px; border-radius:var(--radius-full); font-size:11px; font-weight:600; letter-spacing:0.02em; }
.badge-sent { background:#ecfdf5; color:#059669; }
.badge-failed { background:#fef2f2; color:#dc2626; }
.badge-draft { background:#f5f5f5; color:#666; }
.badge-queued { background:#fefce8; color:#ca8a04; }
.badge-admin { background:var(--gold-light); color:var(--gold); }
.badge-user { background:var(--surface-alt); color:var(--text-secondary); }
.badge-default { background:var(--gold-light); color:var(--gold); padding:4px 10px; font-size:11px; }

/* =========================================
   TABS
   ========================================= */
.tab-bar { display:flex; gap:4px; margin-bottom:24px; overflow-x:auto; background:var(--surface-alt); padding:4px; border-radius:var(--radius); border:1px solid var(--border); }
.tab-btn {
    padding: 8px 18px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
    font-family: inherit;
}
.tab-btn.active { background:var(--navy); color:#fff; box-shadow:var(--shadow-sm); }
.tab-btn:hover:not(.active) { color:var(--text); background:rgba(0,0,0,0.03); }

/* =========================================
   TABLES
   ========================================= */
.data-table { width:100%; border-collapse:collapse; }
.data-table th { text-align:left; font-size:11px; font-weight:600; color:var(--text-muted); text-transform:uppercase; letter-spacing:.5px; padding:12px 16px; border-bottom:2px solid var(--border); }
.data-table td { padding:12px 16px; font-size:14px; border-bottom:1px solid var(--border-light); }
.data-table tr:hover td { background:var(--surface-alt); }

/* =========================================
   EMAIL LIST - Professional Card Layout
   ========================================= */
.email-list { flex:1; overflow-y:auto; }

.email-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    width: 100%;
    text-align: left;
    padding: 14px 16px;
    border: none;
    border-bottom: 1px solid var(--border-light);
    border-left: 3px solid transparent;
    background: var(--surface);
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}
.email-item:hover { background:var(--surface-alt); }
.email-item.active {
    background: var(--gold-light);
    border-left-color: var(--gold);
}
.email-item.unread {
    border-left-color: var(--gold);
    background: rgba(212,175,55,0.03);
}
.email-item.unread .email-item-sender { font-weight: 700; color: var(--navy); }
.email-item.unread .email-item-subject { font-weight: 600; color: var(--text); }

.email-item-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--navy);
    color: var(--gold);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    flex-shrink: 0;
    margin-top: 2px;
}
.email-item-content { flex:1; min-width:0; }
.email-item-header { display:flex; justify-content:space-between; align-items:center; margin-bottom:3px; }
.email-item-sender {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 200px;
}
.email-item-date { font-size:11px; color:var(--text-muted); white-space:nowrap; margin-left:8px; flex-shrink:0; }
.email-item-subject {
    font-size: 13px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-bottom: 2px;
}
.email-item-snippet {
    font-size: 12px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.email-item:hover .email-delete-btn { opacity:0.7 !important; }
.email-delete-btn:hover { opacity:1 !important; color:var(--danger) !important; }
.email-item-to {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* =========================================
   EMAIL READER
   ========================================= */
.email-reader { display:flex; flex-direction:column; height:100%; }
.email-reader-header { padding:20px 24px; border-bottom:1px solid var(--border); background:var(--surface); }
.email-reader-actions { display:flex; gap:8px; }
.email-reader-subject { font-size:18px; font-weight:600; color:var(--navy); margin:12px 0 8px; line-height:1.4; }
.email-reader-meta { display:flex; justify-content:space-between; align-items:center; font-size:13px; color:var(--text-secondary); }
.email-reader-body { flex:1; overflow-y:auto; padding:24px; background:var(--surface); }
.email-reader-body img { max-width:100%; }

/* =========================================
   PREVIEW PANEL
   ========================================= */
.preview-panel { border-left:1px solid var(--border); background:var(--surface); overflow-y:auto; }
.preview-header {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-alt);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.preview-body { padding:24px; }

/* =========================================
   COMPOSE LAYOUT
   ========================================= */
.compose-wrapper { display:flex; flex-direction:row; height:100%; overflow:hidden; }
.compose-form { flex:1; overflow-y:auto; padding:0; min-height:0; }
.compose-form.half { flex:none; width:45%; }

/* =========================================
   INBOX LAYOUT
   ========================================= */
.inbox-wrapper { display:flex; height:100%; }
.inbox-sidebar {
    width: 380px;
    border-right: 1px solid var(--border);
    background: var(--surface);
    display: flex;
    flex-direction: column;
}
.inbox-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    display: flex;
    gap: 6px;
    align-items: center;
}
.inbox-main { flex:1; background:var(--surface); display:flex; flex-direction:column; }

/* =========================================
   FOLDER TABS
   ========================================= */
.folder-tabs { display:flex; gap:2px; background:var(--surface-alt); padding:2px; border-radius:var(--radius-sm); border:1px solid var(--border-light); }
.folder-tab {
    padding: 5px 12px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: var(--transition);
    background: transparent;
    color: var(--text-muted);
    font-family: inherit;
}
.folder-tab.active { background:var(--navy); color:#fff; box-shadow:var(--shadow-sm); }
.folder-tab:hover:not(.active) { color:var(--text); }

/* =========================================
   AI DRAFT BOX
   ========================================= */
.ai-box { background:var(--surface-alt); border-radius:var(--radius); border:1px solid var(--border); padding:12px; }
.ai-box-label { font-size:12px; font-weight:500; color:var(--text-muted); margin-bottom:8px; }
.ai-box-row { display:flex; gap:8px; }

/* =========================================
   CHART DATA
   ========================================= */
.chart-container { background:var(--surface); border-radius:var(--radius); border:1px solid var(--border); padding:16px; margin-top:12px; }
.chart-title { font-size:14px; font-weight:600; color:var(--navy); margin-bottom:12px; }
.chart-bar-row { display:flex; align-items:center; gap:12px; margin-bottom:8px; }
.chart-bar-label { font-size:12px; color:var(--text-secondary); width:96px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.chart-bar-track { flex:1; height:24px; background:var(--border-light); border-radius:4px; overflow:hidden; }
.chart-bar-fill { height:100%; border-radius:4px; transition:width .5s ease; }
.chart-bar-value { font-size:12px; font-weight:500; color:var(--text); width:64px; text-align:right; }

/* =========================================
   SIGNATURE PREVIEW
   ========================================= */
.sig-preview { border:1px solid var(--border); border-radius:var(--radius-lg); padding:24px; background:var(--surface); }
.sig-preview-hint { font-size:13px; color:var(--text-muted); margin-bottom:16px; }
.sig-layout-classic .sig-line { margin-bottom:2px; }
.sig-layout-modern { display:flex; gap:16px; align-items:flex-start; }
.sig-layout-modern .sig-divider { width:2px; align-self:stretch; }
.sig-layout-minimal .sig-name { font-weight:600; }
.sig-layout-minimal .sig-detail { color:#555; font-size:13px; }

/* =========================================
   TEMPLATE PREVIEW
   ========================================= */
.template-preview-wrap { border:1px solid var(--border); border-radius:var(--radius-lg); overflow:hidden; box-shadow:var(--shadow); background:var(--bg); }

/* =========================================
   TEMPLATE LAYOUT GRID
   ========================================= */
.tpl-layout-grid { display:grid; grid-template-columns:repeat(2, 1fr); gap:20px; }
.tpl-layout-card {
    border: 2px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    cursor: pointer;
    transition: var(--transition);
    background: var(--surface);
    position: relative;
}
.tpl-layout-card:hover { border-color: var(--input-border); box-shadow: var(--shadow); transform: translateY(-2px); }
.tpl-layout-card.selected { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(212,175,55,0.2); }
.tpl-layout-thumb {
    height: 400px;
    overflow: hidden;
    background: #F5F2EC;
    border-bottom: 1px solid var(--border-light);
    position: relative;
}
.tpl-thumb-iframe {
    position: absolute;
    top: 0;
    left: 50%;
    width: 680px;
    height: 900px;
    transform: translateX(-50%) scale(0.5);
    transform-origin: top center;
    border: none;
    pointer-events: none;
}
.tpl-layout-info { padding: 12px 16px; }
.tpl-layout-name { font-size: 14px; font-weight: 600; color: var(--navy); margin-bottom: 2px; }
.tpl-layout-desc { font-size: 12px; color: var(--text-muted); line-height: 1.4; }
.tpl-layout-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    background: var(--gold);
    color: var(--navy);
    font-size: 10px;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

@media (max-width: 768px) {
    .tpl-layout-grid { grid-template-columns: 1fr; }
    .tpl-layout-thumb { height: 350px; }
    .tpl-thumb-iframe { transform: translateX(-50%) scale(0.45); }
}

/* =========================================
   COLOR PICKER
   ========================================= */
.color-row { display:flex; gap:8px; align-items:center; }
.color-swatch { width:48px; height:48px; border-radius:var(--radius); border:1px solid var(--input-border); cursor:pointer; padding:0; -webkit-appearance:none; }
.color-swatch::-webkit-color-swatch-wrapper { padding:0; }
.color-swatch::-webkit-color-swatch { border:none; border-radius:6px; }

/* =========================================
   PHONE ROWS
   ========================================= */
.phone-row { display:flex; gap:8px; align-items:center; margin-bottom:8px; }
.phone-row select { width:100px; }
.phone-row .form-input { flex:1; }
.phone-remove { padding:8px; background:none; border:none; color:#f87171; cursor:pointer; transition:var(--transition); }
.phone-remove:hover { color:#dc2626; }

/* =========================================
   SPINNER
   ========================================= */
.spinner { display:inline-block; width:16px; height:16px; border:2px solid currentColor; border-top-color:transparent; border-radius:50%; animation:spin .6s linear infinite; vertical-align:middle; }
.spinner-lg { width:32px; height:32px; border-width:3px; }
@keyframes spin { to { transform:rotate(360deg); } }

/* =========================================
   LOADING / EMPTY STATES
   ========================================= */
.loading-center { display:flex; align-items:center; justify-content:center; padding:48px; }
.empty-state { text-align:center; padding:48px 24px; }
.empty-state svg { width:64px; height:64px; color:var(--border); margin-bottom:16px; }
.empty-state p { font-size:14px; color:var(--text-muted); }

/* =========================================
   LOGIN PAGE
   ========================================= */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    padding: 20px;
}
.login-card { width:100%; max-width:400px; }
.login-header {
    background: var(--navy);
    padding: 32px;
    text-align: center;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
}
.login-header h1 { font-size:22px; font-weight:700; color:#fff; letter-spacing:-0.01em; }
.login-header h1 span { color:var(--gold); }
.login-header p { color:var(--text-light); font-size:13px; margin-top:8px; }
.login-divider { height:3px; background:linear-gradient(90deg,var(--gold),var(--gold-hover),var(--navy)); }
.login-body {
    background: var(--surface);
    padding: 32px;
    border-radius: 0 0 var(--radius-xl) var(--radius-xl);
    border: 1px solid var(--border);
    border-top: none;
    box-shadow: var(--shadow);
}
.login-toggle { text-align:center; margin-top:20px; font-size:13px; color:var(--text-muted); }
.login-toggle a, .login-toggle button { color:var(--gold); font-weight:500; text-decoration:none; background:none; border:none; cursor:pointer; font-size:13px; font-family:inherit; }
.login-toggle a:hover, .login-toggle button:hover { text-decoration:underline; }

/* =========================================
   MODAL
   ========================================= */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(10,22,40,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(4px);
    animation: fadeIn .15s ease;
}
.modal-card {
    background: var(--surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 480px;
    padding: 32px;
    animation: slideUp .2s ease;
}
.modal-title { font-size:18px; font-weight:600; color:var(--navy); margin-bottom:20px; }

@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
@keyframes slideUp { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:translateY(0); } }

/* =========================================
   MOBILE HEADER
   ========================================= */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--navy);
    padding: 0 16px;
    align-items: center;
    justify-content: space-between;
    z-index: 100;
}
.mobile-header h1 { font-size: 18px; color: #fff; margin: 0; }
.mobile-header h1 span { color: var(--gold); }
.hamburger { background: none; border: none; color: #fff; font-size: 24px; cursor: pointer; padding: 8px; }
.sidebar-close-btn { display: none; position: absolute; top: 16px; right: 16px; background: none; border: none; color: rgba(255,255,255,0.6); font-size: 22px; cursor: pointer; padding: 4px 8px; z-index: 210; }
.sidebar-close-btn:hover { color: #fff; }

/* Mobile back button in inbox reader */
.mobile-back-btn { display: none; }

/* =========================================
   RESPONSIVE
   ========================================= */
@media (max-width: 768px) {
    /* Mobile header visible */
    .mobile-header { display: flex; }

    /* Push main content below fixed header */
    .main-content { padding-top: 56px; }

    /* Sidebar as overlay drawer */
    .sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        bottom: 0;
        width: 270px;
        z-index: 200;
        transition: left 0.3s ease;
        flex-direction: column;
        overflow-y: auto;
    }
    .sidebar-close-btn { display: block; }
    .sidebar-open .sidebar { left: 0; }

    /* Dark overlay behind sidebar */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0; left: 0; right: 0; bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 150;
    }
    .sidebar-open .sidebar-overlay { display: block; }

    /* Sidebar nav stays vertical on mobile */
    .sidebar-nav { flex-direction: column; padding: 12px; gap: 2px; }
    .sidebar-footer { display: block; }
    .nav-btn { white-space: nowrap; border-left: 3px solid transparent; border-bottom: none; }
    .nav-btn.active { border-left-color: var(--gold); border-bottom-color: transparent; }

    /* Inbox split panel: list OR reader, not both */
    .inbox-split { flex-direction: column; }
    .inbox-list-panel { width: 100% !important; min-width: 100% !important; border-right: none; border-bottom: 1px solid var(--border-light); }
    .inbox-reader-panel { display: none; width: 100%; }
    .inbox-split.reading .inbox-list-panel { display: none; }
    .inbox-split.reading .inbox-reader-panel { display: flex; width: 100%; }

    /* Mobile back button */
    .mobile-back-btn { display: inline-flex; }

    /* Compose layout */
    .compose-wrapper { flex-direction: column; }
    .compose-form { max-width: 100% !important; }
    .compose-form.half { width: 100%; }
    .preview-panel { width: 100% !important; border-left: none; border-top: 1px solid var(--border); }

    /* Template grid single column */
    .tpl-layout-grid { grid-template-columns: 1fr !important; }

    /* Tabs scroll horizontally */
    .tab-bar { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
    .tab-btn { white-space: nowrap; flex-shrink: 0; }

    /* Forms stack */
    .form-row { grid-template-columns: 1fr; }

    /* Modals full screen */
    .modal-card { width: 95% !important; max-height: 90vh; overflow-y: auto; }

    /* Reduce padding */
    .content-area { padding: 12px; }
    .card-body { padding: 16px; }

    /* Tone pills wrap */
    .tone-pills { flex-wrap: wrap; }

    /* Email list tweaks */
    .email-item-sender { max-width: 140px; }

    /* Buttons full width in cards */
    .card-body .btn-block-mobile { width: 100%; }

    /* Font size adjustments */
    .email-reader-subject { font-size: 16px; }

    /* Inbox wrapper legacy */
    .inbox-wrapper { flex-direction: column; }
    .inbox-sidebar { width: 100%; max-height: 40vh; }
}

@media (max-width: 480px) {
    .content-area { padding: 8px; }
    .card-body { padding: 12px; }
    .login-header { padding: 24px; }
    .login-body { padding: 24px; }
    .email-reader-header { padding: 12px 16px !important; }
    .email-reader-body { padding: 12px !important; }
    .btn { padding: 8px 16px; font-size: 13px; }
    .btn-sm { padding: 6px 10px; font-size: 11px; }
}

/* =========================================
   SCROLLBAR
   ========================================= */
::-webkit-scrollbar { width:6px; height:6px; }
::-webkit-scrollbar-track { background:transparent; }
::-webkit-scrollbar-thumb { background:var(--border); border-radius:3px; }
::-webkit-scrollbar-thumb:hover { background:var(--text-muted); }

/* =========================================
   SELECTION
   ========================================= */
::selection { background:rgba(212,175,55,0.2); color:var(--navy); }

/* =========================================
   SPLIT INBOX LAYOUT
   ========================================= */
.inbox-split { display: flex; height: 100%; }
.inbox-list-panel { width: 380px; min-width: 380px; border-right: 1px solid var(--border-light); overflow-y: auto; display: flex; flex-direction: column; background: var(--surface); }
.inbox-reader-panel { flex: 1; overflow-y: auto; background: #fff; display: flex; flex-direction: column; }

/* Email list item - active/selected state */
.email-item.active { background: rgba(212,175,55,0.08); border-left-color: var(--gold); }

/* =========================================
   RICH TEXT EDITOR
   ========================================= */
.editor-toolbar { display: flex; gap: 2px; padding: 6px 8px; background: #F8F7F4; border: 1px solid var(--border-light); border-bottom: none; border-radius: 6px 6px 0 0; flex-wrap: wrap; }
.editor-toolbar button { width: 32px; height: 32px; border: none; background: transparent; border-radius: 4px; cursor: pointer; font-size: 14px; color: var(--text-secondary); display: flex; align-items: center; justify-content: center; transition: var(--transition); }
.editor-toolbar button:hover { background: #E8E6E1; }
.editor-toolbar button.active { background: var(--gold); color: white; }
.editor-toolbar .separator { width: 1px; background: var(--border-light); margin: 4px 4px; }
.editor-toolbar button.mic-active { background: #dc2626; color: #fff; animation: micPulse 1.2s ease-in-out infinite; }
@keyframes micPulse { 0%,100% { box-shadow: 0 0 0 0 rgba(220,38,38,0.5); } 50% { box-shadow: 0 0 0 5px rgba(220,38,38,0); } }
.editor-body { min-height: 200px; padding: 16px; border: 1px solid var(--border-light); border-radius: 0 0 6px 6px; outline: none; font-family: Georgia, serif; font-size: 14px; line-height: 1.8; color: var(--text); background: var(--surface); }
.editor-body:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(212,175,55,0.1); }

/* Placeholder text for empty contenteditable */
.editor-body:empty::before { content: attr(data-placeholder); color: #aaa; pointer-events: none; }

/* Reader panel in split view */
.inbox-reader-panel .email-reader { display: flex; flex-direction: column; height: 100%; }
.inbox-reader-panel .email-reader-header { padding: 20px 24px; border-bottom: 1px solid var(--border); background: var(--surface); }
.inbox-reader-panel .email-reader-body { flex: 1; overflow: hidden; background: var(--surface); }

/* inbox-split mobile handled in main responsive block above */

/* Contact autocomplete dropdown */
.ac-item:hover, .ac-item.active { background: var(--surface-hover, #f5f5f5); }
.ac-item + .ac-item { border-top: 1px solid var(--border-light, #eee); }

/* =========================================
   PWA - INSTALL BANNER
   ========================================= */
.pwa-install-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    background: linear-gradient(135deg, var(--navy) 0%, var(--navy-light) 100%);
    color: #fff;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    animation: pwa-slide-down 0.3s ease;
}
.pwa-install-banner-text {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    font-weight: 500;
}
.pwa-install-banner-text svg {
    width: 24px;
    height: 24px;
    color: var(--gold);
    flex-shrink: 0;
}
.pwa-install-banner-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}
.pwa-install-btn {
    padding: 8px 20px;
    background: var(--gold);
    color: var(--navy);
    border: none;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: var(--transition);
}
.pwa-install-btn:active { transform: scale(0.96); }
.pwa-dismiss-btn {
    padding: 8px 12px;
    background: rgba(255,255,255,0.1);
    color: rgba(255,255,255,0.7);
    border: none;
    border-radius: var(--radius);
    font-size: 13px;
    cursor: pointer;
    font-family: inherit;
}
@keyframes pwa-slide-down { from { transform: translateY(-100%); } to { transform: translateY(0); } }

/* =========================================
   PWA - BOTTOM NAVIGATION (Mobile)
   ========================================= */
.pwa-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 56px;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--navy);
    border-top: 1px solid rgba(255,255,255,0.08);
    z-index: 1000;
    box-shadow: 0 -2px 12px rgba(0,0,0,0.2);
}
.pwa-bottom-nav-inner {
    display: flex;
    align-items: stretch;
    height: 56px;
}
.pwa-nav-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: none;
    border: none;
    color: #556b8a;
    font-size: 10px;
    font-family: inherit;
    cursor: pointer;
    padding: 4px 0;
    position: relative;
    transition: color 0.15s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
.pwa-nav-tab svg {
    width: 22px;
    height: 22px;
}
.pwa-nav-tab.active {
    color: var(--gold);
}
.pwa-nav-tab .pwa-badge {
    position: absolute;
    top: 2px;
    right: 50%;
    margin-right: -16px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    background: #ef4444;
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

/* Compose FAB above bottom nav */
.pwa-fab-compose {
    display: none;
    position: fixed;
    bottom: calc(64px + env(safe-area-inset-bottom, 0px));
    right: 16px;
    width: 56px;
    height: 56px;
    background: var(--gold);
    color: var(--navy);
    border: none;
    border-radius: 50%;
    box-shadow: 0 4px 16px rgba(212,175,55,0.4);
    cursor: pointer;
    z-index: 1001;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.pwa-fab-compose:active {
    transform: scale(0.92);
}
.pwa-fab-compose svg {
    width: 24px;
    height: 24px;
}

/* =========================================
   PWA - MOBILE ENHANCEMENTS
   ========================================= */

/* Touch optimized */
@media (pointer: coarse) {
    .nav-btn, .btn, .tab-btn, .folder-tab, a, button {
        min-height: 44px;
        min-width: 44px;
    }
    .form-input, .form-select, textarea {
        min-height: 48px;
        font-size: 16px; /* Prevents iOS zoom */
    }
    /* Use active states instead of hover */
    .btn:hover { background: unset; }
    .btn:active { transform: scale(0.97); opacity: 0.9; }
    .btn-gold:active { background: var(--gold-hover); }
    .nav-btn:hover { background: unset; }
    .nav-btn:active { background: rgba(255,255,255,0.08); }
}

/* Global mobile touch settings */
@media (max-width: 768px) {
    * {
        -webkit-tap-highlight-color: transparent;
    }
    body {
        touch-action: manipulation;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-y: contain;
    }

    /* Show bottom nav */
    .pwa-bottom-nav { display: block; }
    .pwa-fab-compose { display: flex; }

    /* Adjust main content for bottom nav */
    .main-content {
        padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px));
    }

    /* Hide desktop sidebar on mobile when bottom nav is active */
    .pwa-mobile-nav-active .sidebar { display: none !important; }
    .pwa-mobile-nav-active .sidebar-overlay { display: none !important; }
    .pwa-mobile-nav-active .hamburger { display: none; }

    /* Mobile header adjustments for PWA */
    .mobile-header {
        padding-top: env(safe-area-inset-top, 0px);
        height: calc(48px + env(safe-area-inset-top, 0px));
    }
    .pwa-mobile-nav-active .main-content {
        padding-top: calc(48px + env(safe-area-inset-top, 0px));
    }

    /* iOS safe areas */
    .pwa-bottom-nav {
        height: calc(56px + env(safe-area-inset-bottom, 0px));
    }
}

/* =========================================
   PWA - VIEW TRANSITIONS (Mobile)
   ========================================= */
.pwa-view-enter-right {
    animation: pwa-slide-in-right 0.25s ease forwards;
}
.pwa-view-enter-left {
    animation: pwa-slide-in-left 0.25s ease forwards;
}
.pwa-view-exit-right {
    animation: pwa-slide-out-right 0.2s ease forwards;
}
.pwa-view-exit-left {
    animation: pwa-slide-out-left 0.2s ease forwards;
}

@keyframes pwa-slide-in-right {
    from { transform: translateX(30%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
@keyframes pwa-slide-in-left {
    from { transform: translateX(-30%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
@keyframes pwa-slide-out-right {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(30%); opacity: 0; }
}
@keyframes pwa-slide-out-left {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(-30%); opacity: 0; }
}

/* Modal slide up from bottom on mobile */
@media (max-width: 768px) {
    .modal-card {
        animation: pwa-modal-up 0.3s ease;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        max-width: 100%;
        max-height: 90vh;
        overflow-y: auto;
    }
    @keyframes pwa-modal-up {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }
}

/* =========================================
   PWA - COMPOSE ON MOBILE
   ========================================= */
@media (max-width: 768px) {
    /* Full screen compose */
    .compose-wrapper {
        flex-direction: column;
        height: 100%;
    }
    .compose-form {
        display: flex;
        flex-direction: column;
        height: 100%;
    }
    .compose-form .card-body {
        display: flex;
        flex-direction: column;
        flex: 1;
        padding-bottom: 80px; /* Space for FAB send */
    }
    /* To/Subject fields sticky */
    .compose-form .form-group:first-child,
    .compose-form .form-group:nth-child(2) {
        position: sticky;
        top: 0;
        z-index: 10;
        background: var(--surface);
    }
    /* Body takes remaining height */
    .editor-body {
        flex: 1;
        min-height: 200px;
    }
    /* Floating send button */
    .pwa-send-fab {
        position: fixed;
        bottom: calc(72px + env(safe-area-inset-bottom, 0px));
        right: 16px;
        width: 56px;
        height: 56px;
        background: var(--gold);
        color: var(--navy);
        border: none;
        border-radius: 50%;
        box-shadow: 0 4px 16px rgba(212,175,55,0.4);
        cursor: pointer;
        z-index: 1001;
        display: flex;
        align-items: center;
        justify-content: center;
        -webkit-tap-highlight-color: transparent;
    }
    .pwa-send-fab:active { transform: scale(0.92); }
    .pwa-send-fab svg { width: 24px; height: 24px; }
}

/* =========================================
   PWA - INBOX ON MOBILE
   ========================================= */
@media (max-width: 768px) {
    /* Full width email list */
    .inbox-split .inbox-list-panel {
        width: 100%;
        min-width: 100%;
    }
    /* Email items: swipe hints */
    .email-item {
        position: relative;
        overflow: hidden;
        transition: transform 0.2s ease;
    }
    .email-item-swipe-bg {
        position: absolute;
        top: 0;
        bottom: 0;
        width: 80px;
        display: flex;
        align-items: center;
        justify-content: center;
        color: #fff;
        font-size: 12px;
        font-weight: 600;
    }
    .email-item-swipe-bg.reply {
        left: 0;
        background: #3b82f6;
    }
    .email-item-swipe-bg.delete {
        right: 0;
        background: #ef4444;
    }
}

/* =========================================
   PWA - EMAIL READER ON MOBILE
   ========================================= */
@media (max-width: 768px) {
    /* Full screen reader */
    .inbox-reader-panel .email-reader {
        height: 100%;
    }
    .email-reader-body {
        padding: 12px !important;
    }
    .email-reader-body img {
        max-width: 100% !important;
        height: auto !important;
    }
    /* Reader action bar at bottom */
    .pwa-reader-actions {
        position: fixed;
        bottom: calc(56px + env(safe-area-inset-bottom, 0px));
        left: 0;
        right: 0;
        display: flex;
        justify-content: space-around;
        padding: 8px 16px;
        background: var(--surface);
        border-top: 1px solid var(--border);
        box-shadow: 0 -2px 8px rgba(0,0,0,0.06);
        z-index: 999;
    }
    .pwa-reader-actions button {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 2px;
        padding: 8px 16px;
        background: none;
        border: none;
        color: var(--text-secondary);
        font-size: 11px;
        font-family: inherit;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }
    .pwa-reader-actions button svg {
        width: 20px;
        height: 20px;
    }
    .pwa-reader-actions button:active {
        color: var(--gold);
    }
}

/* =========================================
   PWA - PULL TO REFRESH
   ========================================= */
.pwa-pull-indicator {
    position: absolute;
    top: -50px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--surface);
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: top 0.2s ease;
    z-index: 50;
}
.pwa-pull-indicator.visible {
    top: 8px;
}
.pwa-pull-indicator .spinner {
    width: 20px;
    height: 20px;
    color: var(--gold);
}

/* =========================================
   PWA - STANDALONE MODE ADJUSTMENTS
   ========================================= */
@media all and (display-mode: standalone) {
    /* Extra top padding for status bar in standalone */
    .mobile-header {
        padding-top: env(safe-area-inset-top, 20px);
        height: calc(48px + env(safe-area-inset-top, 20px));
    }
    .main-content {
        padding-top: calc(48px + env(safe-area-inset-top, 20px));
    }
    /* Login page: account for safe areas */
    .login-page {
        padding-top: env(safe-area-inset-top, 20px);
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
}

/* =========================================
   PWA - APP-LIKE SMOOTH SCROLL
   ========================================= */
.content-area,
.inbox-list-panel,
.inbox-reader-panel,
.email-reader-body,
.compose-form {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* =========================================
   PWA - SKELETON LOADER FOR NATIVE FEEL
   ========================================= */
.pwa-skeleton {
    background: linear-gradient(90deg, var(--border-light) 25%, var(--surface-alt) 50%, var(--border-light) 75%);
    background-size: 200% 100%;
    animation: pwa-shimmer 1.5s infinite;
    border-radius: var(--radius-sm);
}
@keyframes pwa-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* =========================================
   TENANT BRANDING & ACCOUNT SWITCHER
   (a host tenant such as Secura supplies a logo and colours; the colours are
    applied as CSS variables at runtime by App.applyBranding)
   ========================================= */
.login-header .brand-logo { max-height:46px; width:auto; display:inline-block; }
.login-header .brand-wordmark { font-size:22px; font-weight:700; color:#fff; letter-spacing:0.02em; }
.sidebar-header .brand-logo { max-height:34px; width:auto; display:inline-block; }
.sidebar-header .brand-wordmark { font-size:18px; font-weight:700; color:#fff; letter-spacing:0.02em; }
.mobile-header .brand-logo { max-height:26px; width:auto; display:inline-block; }
.mobile-header .brand-wordmark { font-size:18px; color:#fff; margin:0; letter-spacing:0.02em; }

.acct-switcher { padding:4px 8px 8px; margin:0 8px 8px; border-top:1px solid rgba(255,255,255,0.08); }
.acct-switcher-label { font-size:10px; text-transform:uppercase; letter-spacing:0.08em; color:var(--text-navy-muted); margin:8px 4px 6px; }
.acct-switch-btn { display:flex; align-items:center; gap:8px; width:100%; text-align:left; background:rgba(255,255,255,0.03); border:1px solid rgba(255,255,255,0.08); color:var(--text-light); border-radius:var(--radius-sm); padding:8px 10px; margin-bottom:6px; font-size:12px; font-family:inherit; cursor:pointer; transition:var(--transition); }
.acct-switch-btn:hover:not(:disabled) { background:rgba(255,255,255,0.08); color:#fff; }
.acct-switch-btn.active { border-color:var(--gold); color:#fff; cursor:default; }
.acct-dot { width:8px; height:8px; border-radius:50%; background:var(--gold); flex-shrink:0; }
.acct-name { flex:1; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.acct-current { font-size:9px; text-transform:uppercase; letter-spacing:0.06em; color:var(--gold); }
