/* ==========================================================================
   FlowMail AI — Application styles
   --------------------------------------------------------------------------
   This file is the single source of design tokens and shell styles for the
   logged-in application UI. It sits on top of Bootstrap 5.3 (loaded first)
   and overrides Bootstrap's CSS variables where needed.

   Reference aesthetics: Stripe Dashboard, Linear, Vercel.
   Philosophy: near-monochrome palette, one accent, thin borders over
   heavy shadows, generous whitespace, no gradients, no glassmorphism.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Inter variable font
   -------------------------------------------------------------------------- */
@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url('fonts/InterVariable.woff2') format('woff2-variations'),
         url('fonts/InterVariable.woff2') format('woff2');
}

/* --------------------------------------------------------------------------
   2. Design tokens
   -------------------------------------------------------------------------- */
:root {
    /* Brand */
    --accent:         #4f46e5;  /* indigo-600 */
    --accent-hover:   #4338ca;  /* indigo-700 */
    --accent-active:  #3730a3;  /* indigo-800 */
    --accent-light:   #eef2ff;  /* indigo-50  */
    --accent-ring:    rgba(79, 70, 229, 0.15);

    /* Neutrals */
    --bg:             #fafafa;
    --surface:        #ffffff;
    --surface-alt:    #f8fafc;  /* subtle row stripe, hover */
    --border:         #e5e7eb;
    --border-strong:  #d1d5db;
    --text:           #0f172a;
    --text-secondary: #475569;
    --text-muted:     #94a3b8;

    /* Status */
    --success:        #059669;
    --success-light:  #d1fae5;
    --danger:         #dc2626;
    --danger-light:   #fee2e2;
    --warning:        #d97706;
    --warning-light:  #fef3c7;
    --info:           #2563eb;
    --info-light:     #dbeafe;

    /* Geometry */
    --radius-sm:      6px;
    --radius-md:      10px;
    --radius-lg:      14px;
    --shadow-card:    0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-pop:     0 10px 25px rgba(15, 23, 42, 0.08), 0 2px 6px rgba(15, 23, 42, 0.04);

    /* Shell dimensions */
    --sidebar-width:  256px;
    --topbar-height:  56px;
}

/* --------------------------------------------------------------------------
   3. Bootstrap variable overrides
   -------------------------------------------------------------------------- */
:root,
[data-bs-theme="light"] {
    --bs-body-font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --bs-body-font-size: 14px;
    --bs-body-font-weight: 400;
    --bs-body-color: var(--text);
    --bs-body-bg: var(--bg);

    --bs-primary: var(--accent);
    --bs-primary-rgb: 79, 70, 229;

    --bs-border-color: var(--border);
    --bs-border-color-translucent: var(--border);
    --bs-border-radius: var(--radius-sm);
    --bs-border-radius-sm: 4px;
    --bs-border-radius-lg: var(--radius-md);

    --bs-secondary-color: var(--text-secondary);
    --bs-tertiary-color: var(--text-muted);
    --bs-tertiary-bg: var(--surface-alt);

    --bs-link-color: var(--accent);
    --bs-link-hover-color: var(--accent-hover);
    --bs-link-color-rgb: 79, 70, 229;
    --bs-link-hover-color-rgb: 67, 56, 202;
}

/* --------------------------------------------------------------------------
   4. Base elements
   -------------------------------------------------------------------------- */
html, body {
    height: 100%;
}

body {
    font-feature-settings: 'cv11', 'ss01', 'ss03';  /* Inter stylistic sets for nicer 1, g, l */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text);
}

h1 { font-size: 24px; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
h4 { font-size: 14px; }

a { text-decoration: none; }
a:hover { text-decoration: none; }

hr {
    background-color: var(--border);
    opacity: 1;
}

/* Subtle custom scrollbar (WebKit only — fine to let other browsers use default) */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
    border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* --------------------------------------------------------------------------
   5. Button overrides
   -------------------------------------------------------------------------- */
.btn {
    font-weight: 500;
    font-size: 14px;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.btn-lg {
    font-size: 15px;
    padding: 10px 18px;
}

.btn-sm {
    font-size: 13px;
    padding: 6px 10px;
}

.btn-primary {
    background-color: var(--accent);
    border-color: var(--accent);
    color: #fff;
}
.btn-primary:hover,
.btn-primary:focus {
    background-color: var(--accent-hover);
    border-color: var(--accent-hover);
    color: #fff;
}
.btn-primary:active,
.btn-primary.active {
    background-color: var(--accent-active) !important;
    border-color: var(--accent-active) !important;
}
.btn-primary:focus-visible {
    box-shadow: 0 0 0 3px var(--accent-ring);
}

.btn-secondary,
.btn-outline-secondary {
    background-color: var(--surface);
    border-color: var(--border-strong);
    color: var(--text);
}
.btn-secondary:hover,
.btn-outline-secondary:hover {
    background-color: var(--surface-alt);
    border-color: var(--border-strong);
    color: var(--text);
}
.btn-secondary:focus-visible,
.btn-outline-secondary:focus-visible {
    box-shadow: 0 0 0 3px var(--accent-ring);
}

.btn-danger {
    background-color: var(--danger);
    border-color: var(--danger);
}
.btn-danger:hover {
    background-color: #b91c1c;
    border-color: #b91c1c;
}

/* --------------------------------------------------------------------------
   6. Form controls
   -------------------------------------------------------------------------- */
.form-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 6px;
}

.form-text {
    font-size: 12px;
    color: var(--text-muted);
}

.form-control,
.form-select {
    font-size: 14px;
    padding: 9px 12px;
    min-height: 40px;
    background-color: var(--surface);
    border-color: var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-control::placeholder {
    color: var(--text-muted);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-ring);
}

.input-group-text {
    background-color: var(--surface-alt);
    border-color: var(--border-strong);
    color: var(--text-secondary);
    font-size: 13px;
}

/* --------------------------------------------------------------------------
   7. Cards
   -------------------------------------------------------------------------- */
.card {
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-card);
}

.card-header {
    background-color: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 16px 20px;
    font-weight: 600;
}

.card-body { padding: 20px; }
.card-footer {
    background-color: var(--surface);
    border-top: 1px solid var(--border);
    padding: 12px 20px;
}

/* --------------------------------------------------------------------------
   8. Tables
   -------------------------------------------------------------------------- */
.table {
    --bs-table-bg: var(--surface);
    --bs-table-border-color: var(--border);
    --bs-table-striped-bg: var(--surface-alt);
    --bs-table-hover-bg: var(--surface-alt);
    margin-bottom: 0;
}

.table > thead > tr > th {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
    background-color: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
}

.table > tbody > tr > td {
    font-size: 14px;
    padding: 14px 16px;
    vertical-align: middle;
    border-bottom: 1px solid var(--border);
}

.table > tbody > tr:last-child > td {
    border-bottom: 0;
}

/* --------------------------------------------------------------------------
   9. Alerts
   -------------------------------------------------------------------------- */
.alert {
    border-radius: var(--radius-sm);
    border-width: 1px;
    padding: 12px 16px;
    font-size: 14px;
}

.alert-success {
    background-color: var(--success-light);
    border-color: #a7f3d0;
    color: #065f46;
}
.alert-danger {
    background-color: var(--danger-light);
    border-color: #fecaca;
    color: #991b1b;
}
.alert-warning {
    background-color: var(--warning-light);
    border-color: #fde68a;
    color: #92400e;
}
.alert-info {
    background-color: var(--info-light);
    border-color: #bfdbfe;
    color: #1e40af;
}

/* --------------------------------------------------------------------------
   9b. Flash toasts — position-fixed pop-overs in the top-right corner
   -------------------------------------------------------------------------- */
.fm-flash-toast {
    min-width: 280px;
    max-width: 400px;
    border-width: 1px;
    border-style: solid;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-pop);
    font-size: 14px;
    margin-bottom: 10px;
    opacity: 1;
}

.fm-flash-toast .toast-body {
    padding: 12px 8px 12px 16px;
    flex: 1;
    line-height: 1.45;
}

.fm-flash-toast .toast-body i.fa-solid {
    font-size: 14px;
    flex-shrink: 0;
}

.fm-flash-toast.toast-success {
    background-color: var(--success-light);
    border-color: #a7f3d0;
    color: #065f46;
}
.fm-flash-toast.toast-success .toast-body i { color: var(--success); }

.fm-flash-toast.toast-danger {
    background-color: var(--danger-light);
    border-color: #fecaca;
    color: #991b1b;
}
.fm-flash-toast.toast-danger .toast-body i { color: var(--danger); }

.fm-flash-toast.toast-warning {
    background-color: var(--warning-light);
    border-color: #fde68a;
    color: #92400e;
}
.fm-flash-toast.toast-warning .toast-body i { color: var(--warning); }

.fm-flash-toast.toast-info {
    background-color: var(--info-light);
    border-color: #bfdbfe;
    color: #1e40af;
}
.fm-flash-toast.toast-info .toast-body i { color: var(--info); }

/* --------------------------------------------------------------------------
   10. Dropdowns
   -------------------------------------------------------------------------- */
.dropdown-menu {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-pop);
    padding: 6px;
    font-size: 14px;
}

.dropdown-item {
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    color: var(--text);
}

.dropdown-item:hover,
.dropdown-item:focus {
    background-color: var(--surface-alt);
    color: var(--text);
}

.dropdown-divider {
    border-top-color: var(--border);
    margin: 6px 0;
}

/* --------------------------------------------------------------------------
   11. Badges
   -------------------------------------------------------------------------- */
.badge {
    font-weight: 500;
    font-size: 11px;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    letter-spacing: 0.02em;
}

.badge.bg-success { background-color: var(--success-light) !important; color: #065f46; }
.badge.bg-danger  { background-color: var(--danger-light)  !important; color: #991b1b; }
.badge.bg-warning { background-color: var(--warning-light) !important; color: #92400e; }
.badge.bg-info    { background-color: var(--info-light)    !important; color: #1e40af; }
.badge.bg-primary { background-color: var(--accent-light)  !important; color: var(--accent-active); }


/* ==========================================================================
   APPLICATION SHELL — sidebar + topbar + main layout
   ========================================================================== */

.app-shell {
    display: flex;
    min-height: 100vh;
    background-color: var(--bg);
}

/* --------------------------------------------------------------------------
   Sidebar
   -------------------------------------------------------------------------- */
.app-sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background-color: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-brand {
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    padding: 0 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.sidebar-brand img {
    max-height: 28px;
    width: auto;
}

.sidebar-brand .wordmark {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text);
}

.sidebar-brand .wordmark-ai {
    color: var(--accent);
    font-weight: 700;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    overflow-y: auto;
}

.nav-section {
    margin-bottom: 20px;
}

.nav-section:last-child {
    margin-bottom: 0;
}

.nav-section-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 0 12px;
    margin-bottom: 6px;
}

.nav-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.nav-list-item {
    margin: 0;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    margin-bottom: 2px;
    transition: background-color 0.12s ease, color 0.12s ease;
}

.nav-link:hover {
    background-color: var(--surface-alt);
    color: var(--text);
}

.nav-link.active {
    background-color: var(--accent-light);
    color: var(--accent-active);
}

.nav-link.active i {
    color: var(--accent);
}

.nav-link i {
    width: 16px;
    text-align: center;
    font-size: 14px;
    color: var(--text-muted);
}

.nav-link:hover i {
    color: var(--text-secondary);
}

.nav-link.gated {
    color: var(--text-muted);
}

.nav-link.gated:hover {
    background-color: var(--surface-alt);
    color: var(--text-secondary);
}

.nav-lock {
    font-size: 11px;
    margin-left: auto;
    color: var(--text-muted);
}

/* --------------------------------------------------------------------------
   Main content area
   -------------------------------------------------------------------------- */
.app-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

/* --------------------------------------------------------------------------
   Topbar
   -------------------------------------------------------------------------- */
.app-topbar {
    height: var(--topbar-height);
    background-color: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 1020;
}

.topbar-toggle {
    background: transparent;
    border: 0;
    padding: 6px 10px;
    font-size: 16px;
    color: var(--text);
    border-radius: var(--radius-sm);
}

.topbar-toggle:hover {
    background-color: var(--surface-alt);
}

.topbar-title {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
    color: var(--text);
}

.topbar-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 14px;
}

.credits-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background-color: var(--accent-light);
    color: var(--accent-active);
    font-size: 13px;
    font-weight: 600;
    border-radius: 999px;
}

.credits-chip i {
    font-size: 11px;
    color: var(--accent);
}

.user-menu-btn {
    background: transparent;
    border: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px 4px 4px;
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
}

.user-menu-btn:hover {
    background-color: var(--surface-alt);
}

.user-menu-btn::after { display: none !important; }  /* kill Bootstrap caret, we use FA */

.avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background-color: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
}

.user-menu-btn .fa-chevron-down {
    font-size: 10px;
    color: var(--text-muted);
}

/* --------------------------------------------------------------------------
   Content area
   -------------------------------------------------------------------------- */
.app-content {
    flex: 1;
    padding: 28px 32px;
    max-width: 1280px;
    width: 100%;
}

.page-header {
    margin-bottom: 24px;
}

.page-header h1 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 4px;
}

.page-header p {
    color: var(--text-secondary);
    margin: 0;
    font-size: 14px;
}

/* --------------------------------------------------------------------------
   Stat cards — small "label / big value" cards used on the dashboard
   -------------------------------------------------------------------------- */
.stat-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 10px;
}

.stat-value {
    font-size: 28px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.1;
    letter-spacing: -0.01em;
}

.stat-sub {
    margin-top: 8px;
    font-size: 12px;
    color: var(--text-muted);
}

.stat-link {
    display: inline-block;
    margin-top: 10px;
    font-size: 13px;
    font-weight: 500;
    color: var(--accent);
}

.stat-link:hover {
    color: var(--accent-hover);
}

/* --------------------------------------------------------------------------
   Empty states — used inside cards/tables when there's nothing to show
   -------------------------------------------------------------------------- */
.empty-state {
    text-align: center;
    padding: 56px 20px;
}

.empty-state-icon {
    font-size: 32px;
    color: var(--text-muted);
    margin-bottom: 14px;
}

.empty-state-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 6px;
}

.empty-state-text {
    color: var(--text-secondary);
    margin-bottom: 18px;
    font-size: 14px;
    max-width: 360px;
    margin-left: auto;
    margin-right: auto;
}

/* --------------------------------------------------------------------------
   CTA card — wide horizontal card with text on left, button on right
   -------------------------------------------------------------------------- */
.cta-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 24px;
}

.cta-card .cta-text h2 {
    font-size: 17px;
    font-weight: 600;
    margin-bottom: 4px;
}

.cta-card .cta-text p {
    color: var(--text-secondary);
    font-size: 14px;
    margin: 0;
}

@media (max-width: 575.98px) {
    .cta-card {
        flex-direction: column;
        align-items: flex-start;
    }
    .cta-card .btn {
        width: 100%;
    }
}

/* --------------------------------------------------------------------------
   Responsive — sidebar becomes Bootstrap offcanvas below md
   -------------------------------------------------------------------------- */
@media (max-width: 767.98px) {
    .app-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        z-index: 1045;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        box-shadow: var(--shadow-pop);
    }
    .app-sidebar.show {
        transform: translateX(0);
    }
    .sidebar-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.5);
        z-index: 1040;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s ease;
    }
    .sidebar-backdrop.show {
        opacity: 1;
        pointer-events: auto;
    }
    .app-content {
        padding: 20px;
    }
}

@media (min-width: 768px) {
    .topbar-toggle { display: none; }
}


/* ==========================================================================
   AUTH LAYOUT — centered card on --bg background, no sidebar
   ========================================================================== */

.auth-shell {
    min-height: 100vh;
    background-color: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-card);
    padding: 36px 32px 28px;
}

.auth-card .wordmark {
    display: block;
    text-align: center;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text);
    margin-bottom: 4px;
}

.auth-card .wordmark-ai {
    color: var(--accent);
}

.auth-card h1 {
    font-size: 22px;
    font-weight: 600;
    text-align: center;
    margin: 20px 0 4px;
}

.auth-card .auth-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 24px;
}

.auth-card .form-group {
    margin-bottom: 16px;
}

.auth-card .btn {
    width: 100%;
}

.auth-footer {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
    text-align: center;
    font-size: 13px;
    color: var(--text-secondary);
}

.auth-footer a {
    color: var(--accent);
    font-weight: 500;
}

.auth-footer a:hover {
    color: var(--accent-hover);
}
