/* =========================================================================
   Pilot — Design system
   Dark-first, premium workspace UI. Light theme via [data-theme="light"].
   ========================================================================= */

/* ---------- Design tokens : dark theme (default) ---------- */
:root {
    color-scheme: dark;

    /* Surfaces */
    --bg: #0b0d12;
    --bg-elevated: #11141b;
    --surface: #161922;
    --surface-2: #1b1f2a;
    --surface-3: #232836;
    --surface-hover: #20242f;
    --surface-soft: #14171f;
    --overlay: rgba(8, 10, 14, .72);

    /* Borders */
    --border: #262b37;
    --border-strong: #333a4a;
    --border-subtle: #1e222c;

    /* Text */
    --text: #eef1f6;
    --text-soft: #b8bfd0;
    --text-muted: #7c849a;
    --text-faint: #565e72;

    /* Brand / accents */
    --primary: #7c6cf0;
    --primary-hover: #8d80f3;
    --primary-dark: #6856e6;
    --primary-soft: rgba(124, 108, 240, .14);
    --primary-border: rgba(124, 108, 240, .35);
    --primary-glow: rgba(124, 108, 240, .30);

    --green: #3ecf8e;
    --green-soft: rgba(62, 207, 142, .14);
    --blue: #4d8af0;
    --blue-soft: rgba(77, 138, 240, .14);
    --orange: #f2994a;
    --orange-soft: rgba(242, 153, 74, .14);
    --red: #f06a6a;
    --red-soft: rgba(240, 106, 106, .14);
    --purple: #b08cf0;
    --purple-soft: rgba(176, 140, 240, .14);

    /* Radius */
    --radius-xs: 6px;
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-pill: 999px;

    /* Shadows */
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, .24);
    --shadow-sm: 0 2px 6px rgba(0, 0, 0, .26);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, .34);
    --shadow-lg: 0 18px 48px rgba(0, 0, 0, .44);
    --shadow-glow: 0 0 0 4px var(--primary-soft);

    /* Typography */
    --font-sans: "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --font-display: "Manrope", var(--font-sans);
    --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;

    /* Layout */
    --sidebar-w: 260px;
    --topbar-h: 64px;
    --content-max: 1840px;

    /* Motion */
    --ease: cubic-bezier(.4, 0, .2, 1);
    --ease-out: cubic-bezier(.16, 1, .3, 1);
    --t-fast: .12s;
    --t: .18s;
    --t-slow: .28s;
}

/* ---------- Light theme ---------- */
[data-theme="light"] {
    color-scheme: light;

    --bg: #f5f6fa;
    --bg-elevated: #ffffff;
    --surface: #ffffff;
    --surface-2: #f8f9fc;
    --surface-3: #eef0f6;
    --surface-hover: #f3f4f9;
    --surface-soft: #f8f9fc;
    --overlay: rgba(20, 24, 35, .42);

    --border: #e6e8ef;
    --border-strong: #d3d7e2;
    --border-subtle: #eef0f6;

    --text: #141826;
    --text-soft: #444c5e;
    --text-muted: #767f93;
    --text-faint: #9aa2b4;

    --primary: #5b47e0;
    --primary-hover: #4936c7;
    --primary-dark: #3f2db8;
    --primary-soft: rgba(91, 71, 224, .10);
    --primary-border: rgba(91, 71, 224, .30);
    --primary-glow: rgba(91, 71, 224, .16);

    --green: #159467;
    --green-soft: rgba(21, 148, 103, .12);
    --blue: #2878d0;
    --blue-soft: rgba(40, 120, 208, .12);
    --orange: #c77819;
    --orange-soft: rgba(199, 120, 25, .12);
    --red: #d14343;
    --red-soft: rgba(209, 67, 67, .10);
    --purple: #7c4ddb;
    --purple-soft: rgba(124, 77, 219, .12);

    --shadow-xs: 0 1px 2px rgba(16, 24, 40, .05);
    --shadow-sm: 0 1px 3px rgba(16, 24, 40, .06);
    --shadow-md: 0 8px 24px rgba(16, 24, 40, .08);
    --shadow-lg: 0 18px 48px rgba(16, 24, 40, .12);
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
    min-height: 100vh;
    min-height: 100dvh;
    color: var(--text);
    background: var(--bg);
    font-family: var(--font-sans);
    font-feature-settings: "cv02", "cv03", "cv04", "ss01";
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    line-height: 1.5;
    transition: background var(--t) var(--ease), color var(--t) var(--ease);
}
img, svg, video, canvas { display: block; max-width: 100%; }
input, button, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; touch-action: manipulation; }
a { color: inherit; text-decoration: none; touch-action: manipulation; }
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Focus-visible : visibles partout (a11y) */
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-radius: var(--radius-xs);
}
input:focus-visible, textarea:focus-visible, select:focus-visible { outline: none; }

/* Skip link */
.skip-link {
    position: absolute;
    left: 12px;
    top: -60px;
    z-index: 100;
    padding: 10px 16px;
    background: var(--primary);
    color: #fff;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: .85rem;
    transition: top var(--t) var(--ease);
}
.skip-link:focus { top: 12px; }

.sr-only {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* =========================================================================
   App shell
   ========================================================================= */
.app-body {
    background:
        radial-gradient(1200px 600px at 80% -10%, rgba(124, 108, 240, .06), transparent 60%),
        var(--bg);
}
[data-theme="light"] .app-body {
    background:
        radial-gradient(1200px 600px at 80% -10%, rgba(91, 71, 224, .05), transparent 60%),
        var(--bg);
}

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    width: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    background: var(--bg-elevated);
    border-right: 1px solid var(--border);
    transition: transform var(--t-slow) var(--ease);
}
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 18px 24px;
    color: var(--text);
}
.brand-mark {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    color: #fff;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border-radius: 11px;
    box-shadow: 0 8px 20px var(--primary-glow), inset 0 1px 0 rgba(255, 255, 255, .2);
    flex-shrink: 0;
}
.brand-mark svg { width: 22px; stroke-width: 1.6; }
.sidebar-brand strong {
    display: block;
    font: 800 1.12rem var(--font-display);
    letter-spacing: -.03em;
    line-height: 1.1;
}
.sidebar-brand small {
    display: block;
    margin-top: 2px;
    color: var(--text-muted);
    font-size: .72rem;
}

.sidebar-nav {
    flex: 1;
    min-height: 0;
    padding: 0 12px 12px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 6px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 99px; }

.nav-label {
    margin: 18px 10px 6px;
    color: var(--text-faint);
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
}
.nav-label:first-child { margin-top: 4px; }
.nav-link {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 11px;
    margin-bottom: 2px;
    border-radius: var(--radius-sm);
    color: var(--text-soft);
    font-size: .88rem;
    font-weight: 500;
    transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.nav-link:hover { color: var(--text); background: var(--surface-hover); }
.nav-link.active {
    color: var(--text);
    background: var(--surface-3);
    font-weight: 600;
    position: relative;
}
.nav-link.active::before {
    content: "";
    position: absolute;
    left: -12px;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 18px;
    background: var(--primary);
    border-radius: 99px;
}
.nav-link svg { width: 18px; height: 18px; flex-shrink: 0; opacity: .85; }
.nav-link.active svg { opacity: 1; color: var(--primary); }

.nav-mailbox {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 11px;
    margin-bottom: 2px;
    border-radius: var(--radius-sm);
    color: var(--text-soft);
    font-size: .86rem;
    transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.nav-mailbox:hover { background: var(--surface-hover); color: var(--text); }
.nav-mailbox.active { background: var(--primary-soft); color: var(--text); }
.mailbox-avatar {
    width: 26px;
    height: 26px;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    color: var(--primary);
    background: var(--primary-soft);
    border: 1px solid var(--primary-border);
    border-radius: var(--radius-sm);
    font-weight: 700;
    font-size: .72rem;
    text-transform: uppercase;
}
.mailbox-label { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.mailbox-label strong {
    font-size: .82rem;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.mailbox-label small {
    color: var(--text-muted);
    font-size: .7rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-footer {
    margin: 12px;
    padding: 12px;
    display: flex;
    align-items: center;
    gap: 11px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}
.sidebar-footer > div { min-width: 0; }
.sidebar-footer strong { display: block; font-size: .78rem; font-weight: 600; }
.sidebar-footer small { display: block; margin-top: 1px; color: var(--text-muted); font-size: .7rem; }
.status-dot {
    width: 8px;
    height: 8px;
    flex: 0 0 auto;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 0 4px var(--green-soft);
    animation: pulse 2.4s var(--ease) infinite;
}
@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 4px var(--green-soft); }
    50% { box-shadow: 0 0 0 6px var(--green-soft); }
}

.app-shell {
    margin-left: var(--sidebar-w);
    min-width: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ---------- Topbar ---------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    height: var(--topbar-h);
    padding: 0 32px;
    display: flex;
    align-items: center;
    gap: 16px;
    background: color-mix(in srgb, var(--bg-elevated) 82%, transparent);
    backdrop-filter: blur(12px) saturate(1.4);
    -webkit-backdrop-filter: blur(12px) saturate(1.4);
    border-bottom: 1px solid var(--border);
}
.mobile-menu {
    display: none;
    width: 38px;
    height: 38px;
    align-items: center;
    justify-content: center;
    color: var(--text-soft);
    border-radius: var(--radius-sm);
}
.mobile-menu:hover { background: var(--surface-hover); color: var(--text); }
.topbar-search {
    position: relative;
    flex: 0 1 360px;
    display: flex;
    align-items: center;
}
.topbar-search svg { position: absolute; left: 12px; width: 16px; height: 16px; color: var(--text-muted); pointer-events: none; }
.topbar-search input {
    width: 100%;
    height: 38px;
    padding: 0 12px 0 36px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: .85rem;
    transition: border var(--t) var(--ease), box-shadow var(--t) var(--ease);
}
.topbar-search input::placeholder { color: var(--text-muted); }
.topbar-search input:focus { border-color: var(--primary-border); box-shadow: 0 0 0 3px var(--primary-soft); }
.topbar-search kbd {
    position: absolute;
    right: 8px;
    padding: 2px 6px;
    color: var(--text-muted);
    background: var(--surface-3);
    border: 1px solid var(--border);
    border-radius: 5px;
    font: 600 .66rem var(--font-mono);
}
.topbar-context {
    color: var(--text-muted);
    font-size: .85rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.topbar-context span { padding: 0 7px; color: var(--text-faint); }
.topbar-context strong { color: var(--text-soft); font-weight: 600; }
.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}
.icon-btn {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    color: var(--text-soft);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: all var(--t-fast) var(--ease);
}
.icon-btn:hover { color: var(--text); background: var(--surface-hover); border-color: var(--border-strong); }
.icon-btn svg { width: 18px; height: 18px; }
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }
[data-theme="light"] .theme-toggle .icon-sun { display: block; }
[data-theme="light"] .theme-toggle .icon-moon { display: none; }

.user-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 38px;
    padding: 0 12px 0 6px;
    color: var(--text-soft);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    font-size: .82rem;
    font-weight: 600;
    transition: all var(--t-fast) var(--ease);
}
.user-chip:hover { background: var(--surface-hover); }
.user-chip .avatar { width: 26px; height: 26px; border-radius: 50%; font-size: .7rem; }

.content {
    flex: 1;
    width: 100%;
    max-width: var(--content-max);
    margin: 0 auto;
    padding: 32px 36px 64px;
    animation: fade-in .4s var(--ease-out);
}
@keyframes fade-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Sidebar backdrop (mobile) */
.sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 35;
    background: var(--overlay);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--t-slow) var(--ease), visibility var(--t-slow);
}
.sidebar-backdrop.show { opacity: 1; visibility: visible; }

/* =========================================================================
   Typography & layout primitives
   ========================================================================= */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 28px;
}
.page-header h1 {
    font: 800 1.85rem/1.15 var(--font-display);
    letter-spacing: -.035em;
}
.eyebrow {
    margin-bottom: 8px;
    color: var(--primary);
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .09em;
    text-transform: uppercase;
}
.subtitle { margin-top: 8px; color: var(--text-muted); font-size: .92rem; line-height: 1.55; max-width: 60ch; }
.subtitle .badge { vertical-align: middle; }
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.header-actions, .card-actions, .inline-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* =========================================================================
   Cards
   ========================================================================= */
.card {
    margin-bottom: 20px;
    padding: 22px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}
.card-header > div > p, .card-header p { margin-top: 3px; }
.card h2, .card h3 {
    font-family: var(--font-display);
    letter-spacing: -.025em;
    line-height: 1.2;
}
.card h2 { font-size: 1rem; font-weight: 700; }
.card h3 { font-size: 1rem; font-weight: 700; }
.card p.text-muted { font-size: .82rem; }

.form-card { width: 100%; }
.form-card.compact { max-width: 720px; }
.form-card.wide { max-width: none; }

.grid-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
}
.list-card {
    position: relative;
    transition: transform var(--t) var(--ease), box-shadow var(--t) var(--ease), border-color var(--t) var(--ease);
}
.list-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
    border-color: var(--border-strong);
}
.list-meta { display: flex; align-items: center; gap: 10px; margin: 18px 0 16px; }

/* =========================================================================
   Stats
   ========================================================================= */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}
.stats-grid.campaign-stats { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.stat-card {
    position: relative;
    min-height: 120px;
    padding: 18px 20px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.stat-card::after {
    content: "";
    position: absolute;
    inset: 0 0 auto auto;
    width: 120px;
    height: 120px;
    background: radial-gradient(circle at top right, var(--primary-soft), transparent 70%);
    opacity: 0;
    transition: opacity var(--t-slow) var(--ease);
    pointer-events: none;
}
.stat-card:hover::after { opacity: .5; }
.stat-head { display: flex; align-items: center; justify-content: space-between; color: var(--text-muted); }
.stat-label { font-size: .78rem; font-weight: 600; }
.stat-icon {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border-radius: var(--radius-sm);
    background: var(--surface-3);
    color: var(--text-muted);
}
.stat-icon svg { width: 17px; }
.stat-value {
    margin-top: 10px;
    font: 800 1.85rem var(--font-display);
    letter-spacing: -.04em;
    line-height: 1;
}
.stat-trend, .stat-foot { font-size: .74rem; color: var(--text-muted); margin-top: 6px; }
.stat-trend { color: var(--green); font-weight: 600; display: inline-flex; align-items: center; gap: 4px; }
.stat-card.accent .stat-icon { color: var(--primary); background: var(--primary-soft); }
.stat-card.green .stat-icon { color: var(--green); background: var(--green-soft); }
.stat-card.blue .stat-icon { color: var(--blue); background: var(--blue-soft); }
.stat-card.orange .stat-icon { color: var(--orange); background: var(--orange-soft); }
.stat-card.purple .stat-value { color: var(--purple); }
.badge-clicked { background: var(--purple-soft); color: var(--purple); }
.stat-card.red .stat-icon { color: var(--red); background: var(--red-soft); }

/* =========================================================================
   Tables
   ========================================================================= */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: .86rem;
}
.table th {
    padding: 11px 14px;
    color: var(--text-muted);
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .05em;
    text-align: left;
    text-transform: uppercase;
    white-space: nowrap;
}
.table th.sortable { cursor: pointer; user-select: none; }
.table th.sortable:hover { color: var(--text-soft); }
.table td {
    padding: 13px 14px;
    border-bottom: 1px solid var(--border-subtle);
    vertical-align: middle;
}
.table tbody tr { transition: background var(--t-fast) var(--ease); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-hover); }
.table-title { font-weight: 600; color: var(--text); }
.table a { color: var(--primary); font-weight: 500; }
.table a:hover { text-decoration: underline; }
.error-cell { max-width: 220px; color: var(--red); font-size: .78rem; }

/* =========================================================================
   Badges
   ========================================================================= */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: var(--radius-pill);
    background: var(--surface-3);
    color: var(--text-soft);
    font-size: .7rem;
    font-weight: 700;
    text-transform: capitalize;
    white-space: nowrap;
    border: 1px solid transparent;
}
.badge::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    opacity: .85;
}
.badge-draft, .badge-pending { background: var(--surface-3); color: var(--text-muted); }
.badge-running, .badge-sent { background: var(--green-soft); color: var(--green); }
.badge-paused { background: var(--orange-soft); color: var(--orange); }
.badge-completed, .badge-opened { background: var(--blue-soft); color: var(--blue); }
.badge-cancelled, .badge-failed { background: var(--red-soft); color: var(--red); }
.badge-replied, .badge-processing, .badge-default { background: var(--primary-soft); color: var(--primary); }
.badge-unsubscribed, .badge-disabled { background: var(--surface-3); color: var(--text-muted); }
.badge-scheduled { background: var(--purple-soft); color: var(--purple); }

/* =========================================================================
   Buttons
   ========================================================================= */
.btn {
    min-height: 38px;
    padding: 8px 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    color: var(--text-soft);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: .82rem;
    font-weight: 600;
    line-height: 1;
    text-decoration: none;
    white-space: nowrap;
    transition: all var(--t-fast) var(--ease);
}
.btn:hover { color: var(--text); background: var(--surface-hover); border-color: var(--text-faint); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 15px; height: 15px; flex-shrink: 0; }
.btn-text { display: inline; }
.btn-mobile-icon { gap: 8px; }
.btn-primary {
    color: #fff;
    background: linear-gradient(180deg, var(--primary), var(--primary-dark));
    border-color: transparent;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .2), 0 4px 12px var(--primary-glow);
}
.btn-primary:hover {
    color: #fff;
    background: linear-gradient(180deg, var(--primary-hover), var(--primary));
    border-color: transparent;
    box-shadow: 0 2px 4px rgba(0, 0, 0, .24), 0 6px 16px var(--primary-glow);
}
.btn-danger { color: var(--red); border-color: color-mix(in srgb, var(--red) 40%, transparent); background: var(--red-soft); }
.btn-danger:hover { background: color-mix(in srgb, var(--red) 18%, transparent); border-color: var(--red); color: var(--red); }
.btn-warning { color: var(--orange); border-color: color-mix(in srgb, var(--orange) 40%, transparent); background: var(--orange-soft); }
.btn-warning:hover { background: color-mix(in srgb, var(--orange) 18%, transparent); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-hover); }
.btn-sm { min-height: 31px; padding: 6px 11px; font-size: .75rem; }
.btn-compact { min-height: 36px; }
.btn-block { width: 100%; }
.btn:disabled, .btn[disabled] { opacity: .5; cursor: not-allowed; pointer-events: none; }
.inline-form { display: inline-flex; margin: 0; }

/* =========================================================================
   Forms
   ========================================================================= */
.form-section { margin-bottom: 28px; padding-bottom: 28px; border-bottom: 1px solid var(--border); }
.form-section:last-of-type { border-bottom: 0; padding-bottom: 0; }
.form-section-title { display: flex; gap: 12px; margin-bottom: 20px; }
.form-section-title .step {
    width: 30px;
    height: 30px;
    flex-shrink: 0;
    display: grid;
    place-items: center;
    color: var(--primary);
    background: var(--primary-soft);
    border: 1px solid var(--primary-border);
    border-radius: var(--radius-sm);
    font: 700 .78rem var(--font-mono);
}
.form-section-title h2 { margin: 1px 0 3px; }
.form-section-title p { margin: 0; color: var(--text-muted); font-size: .8rem; }

.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    margin-bottom: 7px;
    color: var(--text-soft);
    font-size: .8rem;
    font-weight: 600;
}
.form-group .req { color: var(--red); }
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    outline: none;
    transition: border var(--t) var(--ease), box-shadow var(--t) var(--ease), background var(--t) var(--ease);
}
.form-group input::placeholder, .form-group textarea::placeholder { color: var(--text-faint); }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
    background: var(--surface);
}
.form-group select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%237c849a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 11px center;
    padding-right: 36px;
}
.form-group textarea { line-height: 1.6; resize: vertical; min-height: 80px; font-family: inherit; }
.form-group textarea[name="body_html"], .form-group textarea[name="body_text"] { font-family: var(--font-mono); font-size: .84rem; }

/* Email composer — editor + live HTML preview */
.email-composer-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(280px, 42%);
    gap: 20px;
    align-items: stretch;
    min-height: max(520px, 52vh);
}
.email-composer-editor {
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.email-composer-editor .form-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    margin-bottom: 0;
    min-height: 0;
}
.email-composer-editor .form-group textarea {
    flex: 1;
    min-height: max(520px, 52vh);
    height: 100%;
}
.email-preview-panel {
    position: sticky;
    top: 16px;
    display: flex;
    flex-direction: column;
    min-height: max(520px, 52vh);
    height: 100%;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
}
.email-preview-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 14px;
    font-size: .78rem;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--text-muted);
    background: var(--surface-3);
    border-bottom: 1px solid var(--border);
}
.email-preview-frame {
    flex: 1;
    width: 100%;
    min-height: 0;
    border: 0;
    background: #fff;
}
.email-composer-layout + .form-group textarea[name="body_text"] {
    min-height: 72px;
}
.email-composer-preview-only .email-preview-panel {
    position: static;
    min-height: 480px;
}
.email-composer-preview-only .email-preview-frame { min-height: 440px; }
.template-subject-preview {
    font-size: .84rem;
    margin: 8px 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.plain-text-preview {
    margin: 0;
    padding: 14px;
    font-family: var(--font-mono);
    font-size: .84rem;
    line-height: 1.6;
    white-space: pre-wrap;
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    overflow-x: auto;
}

/* Email thread — sent message + reply on detail pages */
.email-thread { display: flex; flex-direction: column; gap: 24px; }
.email-thread-block { display: flex; flex-direction: column; gap: 12px; }
.email-thread-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
.email-thread-preview {
    position: static;
    min-height: 320px;
}
.email-thread-preview .email-preview-frame { min-height: 280px; }
.reply-block {
    padding-top: 20px;
    border-top: 1px solid var(--border);
}
.detail-list.compact { margin-bottom: 0; }
.detail-list.compact dd { margin-bottom: 8px; }
.event-timeline {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.event-timeline li {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 10px;
    align-items: center;
    padding: 10px 12px;
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    font-size: .88rem;
}
.form-group input[type="file"] {
    padding: 9px 11px;
    cursor: pointer;
}
.form-group input[type="file"]::file-selector-button {
    margin-right: 12px;
    padding: 6px 12px;
    color: var(--text-soft);
    background: var(--surface-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    cursor: pointer;
}
.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-row.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding-top: 4px;
}
.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 9px;
    margin: 0;
    cursor: pointer;
    color: var(--text);
    font-weight: 500;
}
.checkbox-group input, .permission-option input { width: 17px; height: 17px; accent-color: var(--primary); cursor: pointer; }
.help-text { display: block; margin-top: 6px; color: var(--text-muted); font-size: .77rem; line-height: 1.5; }
.help-text a { color: var(--primary); font-weight: 600; }
.help-text a:hover { text-decoration: underline; }

/* =========================================================================
   Misc components
   ========================================================================= */
.progress-bar {
    width: 100%;
    min-width: 100px;
    height: 6px;
    overflow: hidden;
    background: var(--surface-3);
    border-radius: var(--radius-pill);
}
.progress-bar.large { height: 10px; margin: 16px 0 10px; }
.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--purple));
    border-radius: inherit;
    transition: width .6s var(--ease-out);
}

.detail-list { display: grid; grid-template-columns: 140px 1fr; gap: 12px 16px; margin: 0; }
.detail-list dt { color: var(--text-muted); font-size: .8rem; }
.detail-list dd { margin: 0; font-size: .86rem; font-weight: 500; word-break: break-word; }

.two-columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.users-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.45fr) minmax(340px, .55fr);
    align-items: start;
    gap: 20px;
}
.settings-grid {
    display: grid;
    grid-template-columns: minmax(340px, .78fr) minmax(620px, 1.42fr);
    align-items: start;
    gap: 20px;
}
.settings-grid > * { min-width: 0; }
.settings-grid .card { margin-bottom: 0; }
.settings-defaults { margin-top: 20px; }

.user-admin-list { display: grid; gap: 12px; }
.user-admin-card { overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.user-admin-card > summary, details.sender-card > summary { list-style: none; cursor: pointer; }
.user-admin-card > summary::-webkit-details-marker, details.sender-card > summary::-webkit-details-marker { display: none; }
.user-admin-card[open] { border-color: var(--border-strong); }
.user-admin-card > summary { padding: 16px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.user-admin-form { padding: 20px; border-top: 1px solid var(--border); background: var(--surface-soft); }
.user-admin-actions { padding: 0 20px 20px; border-top: 1px solid var(--border); background: var(--surface-soft); justify-content: space-between; }

.permission-section { margin: 4px 0 18px; }
.permission-section > label { display: block; margin-bottom: 3px; color: var(--text-soft); font-size: .8rem; font-weight: 600; }
.permission-grid { margin-top: 10px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.permission-option, .sender-access-card {
    min-width: 0;
    padding: 11px;
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    transition: all var(--t-fast) var(--ease);
}
.permission-option { cursor: pointer; }
.permission-option:hover { border-color: var(--border-strong); }
.permission-option:has(input:checked) { border-color: var(--primary-border); background: var(--primary-soft); }
.permission-option > span:not(.avatar) { min-width: 0; flex: 1; overflow: hidden; }
.permission-option strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .82rem; }
.permission-option small { display: block; margin-top: 2px; color: var(--text-muted); font-size: .7rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.users-layout aside .permission-grid { grid-template-columns: 1fr; }
.sender-access-card { justify-content: space-between; }

.avatar {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    color: var(--primary);
    background: var(--primary-soft);
    border: 1px solid var(--primary-border);
    border-radius: var(--radius-sm);
    font-weight: 700;
    text-transform: uppercase;
    font-size: .82rem;
}
.sender-identity { display: flex; align-items: center; gap: 10px; min-width: 0; }
.sender-identity > div { min-width: 0; overflow: hidden; }
.sender-identity strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .86rem; }
.sender-identity small { display: block; margin-top: 2px; color: var(--text-muted); font-size: .72rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.callout {
    padding: 14px 16px;
    color: var(--text-soft);
    background: var(--primary-soft);
    border: 1px solid var(--primary-border);
    border-radius: var(--radius-sm);
    font-size: .84rem;
    line-height: 1.55;
}
.callout a { color: var(--primary); font-weight: 600; }
.callout strong { color: var(--text); }

details.sender-card { padding: 0; overflow: hidden; margin-bottom: 10px; }
details.sender-card[open] { border-color: var(--border-strong); }
details.sender-card > summary { padding: 16px 20px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.sender-edit { padding: 20px; background: var(--surface-soft); border-top: 1px solid var(--border); }

/* Pagination */
.pagination {
    padding-top: 16px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    color: var(--text-muted);
    font-size: .8rem;
}

/* Empty states */
.empty-state {
    padding: 54px 24px;
    text-align: center;
    color: var(--text-muted);
}
.empty-icon {
    width: 52px;
    height: 52px;
    margin: 0 auto 14px;
    display: grid;
    place-items: center;
    color: var(--primary);
    background: var(--primary-soft);
    border: 1px solid var(--primary-border);
    border-radius: var(--radius);
    font-size: 1.4rem;
}
.empty-state svg { width: 24px; height: 24px; }
.empty-state h3 { margin-bottom: 6px; color: var(--text); font-family: var(--font-display); }
.empty-state p { margin: 0 0 18px; max-width: 42ch; margin-left: auto; margin-right: auto; }

/* Toolbar (search/filter) above tables */
.toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}
.toolbar-search {
    position: relative;
    flex: 1;
    min-width: 200px;
    max-width: 360px;
    display: flex;
    align-items: center;
}
.toolbar-search svg { position: absolute; left: 11px; width: 16px; height: 16px; color: var(--text-muted); pointer-events: none; }
.toolbar-search input {
    width: 100%;
    height: 38px;
    padding: 0 12px 0 34px;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: .85rem;
    transition: border var(--t) var(--ease), box-shadow var(--t) var(--ease);
}
.toolbar-search input::placeholder { color: var(--text-muted); }
.toolbar-search input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); background: var(--surface); }
.filter-group {
    display: inline-flex;
    gap: 2px;
    padding: 3px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}
.filter-chip {
    padding: 6px 12px;
    color: var(--text-muted);
    background: transparent;
    border-radius: var(--radius-xs);
    font-size: .78rem;
    font-weight: 600;
    transition: all var(--t-fast) var(--ease);
    border: 0;
    cursor: pointer;
}
.filter-chip:hover { color: var(--text); }
.filter-chip.active { color: var(--text); background: var(--surface-3); box-shadow: var(--shadow-xs); }

.error-page { max-width: 680px; margin: 10vh auto 0; }

/* =========================================================================
   Flash messages
   ========================================================================= */
.flash-messages {
    position: fixed;
    z-index: 60;
    top: 76px;
    right: 24px;
    width: min(390px, calc(100vw - 48px));
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.flash {
    padding: 13px 15px;
    display: flex;
    gap: 11px;
    align-items: flex-start;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    font-size: .84rem;
    line-height: 1.45;
    animation: flash-in .35s var(--ease-out);
}
@keyframes flash-in {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}
.flash.closing { animation: flash-out .3s var(--ease) forwards; }
@keyframes flash-out {
    to { opacity: 0; transform: translateX(20px); }
}
.flash > span.flash-icon {
    width: 22px;
    height: 22px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    border-radius: 50%;
    font-weight: 700;
    font-size: .76rem;
}
.flash > .flash-body { flex: 1; }
.flash > .flash-close {
    width: 20px;
    height: 20px;
    flex: 0 0 auto;
    color: var(--text-muted);
    border-radius: 4px;
    font-size: 1.1rem;
    line-height: 1;
}
.flash-close:hover { color: var(--text); background: var(--surface-hover); }
.flash-success { border-left: 3px solid var(--green); }
.flash-success .flash-icon { color: var(--green); background: var(--green-soft); }
.flash-error { border-left: 3px solid var(--red); }
.flash-error .flash-icon { color: var(--red); background: var(--red-soft); }

/* =========================================================================
   Auth pages
   ========================================================================= */
.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
    background:
        radial-gradient(900px 500px at 20% 0%, var(--primary-soft), transparent 60%),
        radial-gradient(900px 500px at 90% 100%, var(--purple-soft), transparent 55%),
        var(--bg);
}
.auth-shell { width: 100%; max-width: 440px; }
.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 36px;
    box-shadow: var(--shadow-lg);
    animation: fade-in .4s var(--ease-out);
}
.auth-brand { text-align: center; margin-bottom: 24px; }
.auth-brand h1 { font: 800 1.4rem var(--font-display); margin: 0; letter-spacing: -.03em; }
.auth-form { display: flex; flex-direction: column; gap: 4px; }
.auth-form .btn-block { margin-top: 8px; height: 44px; font-size: .9rem; }
.auth-footer { text-align: center; margin-top: 22px; font-size: .88rem; color: var(--text-muted); }
.auth-footer a { color: var(--primary); font-weight: 600; }
.auth-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 22px;
}
.auth-theme-toggle {
    margin-left: auto;
}

/* =========================================================================
   Responsive — mobile-first enhancements for phones & small tablets
   ========================================================================= */
@media (max-width: 1180px) {
    .stats-grid.campaign-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 1050px) {
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .two-columns { grid-template-columns: 1fr; }
    .settings-grid { grid-template-columns: 1fr; }
    .users-layout { grid-template-columns: 1fr; }
    .topbar-search { display: none; }
}
@media (max-width: 760px) {
    :root {
        --topbar-h: 56px;
        --touch-min: 44px;
    }

    .sidebar {
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
        padding-bottom: env(safe-area-inset-bottom, 0);
    }
    .sidebar.open { transform: translateX(0); }
    .app-shell { margin-left: 0; }
    .app-body { padding-bottom: env(safe-area-inset-bottom, 0); }

    .topbar {
        height: var(--topbar-h);
        padding: 0 max(12px, env(safe-area-inset-left)) 0 max(12px, env(safe-area-inset-right));
        gap: 8px;
    }
    .mobile-menu {
        display: inline-flex;
        width: var(--touch-min);
        height: var(--touch-min);
        flex-shrink: 0;
    }
    .topbar-context {
        display: flex;
        align-items: center;
        min-width: 0;
        flex: 1;
    }
    .topbar-context-prefix { display: none; }
    .topbar-context strong {
        display: block;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        color: var(--text);
        font-size: .9rem;
    }
    .topbar-actions {
        gap: 6px;
        flex-shrink: 0;
    }
    .icon-btn {
        width: var(--touch-min);
        height: var(--touch-min);
        flex-shrink: 0;
    }
    .user-chip {
        height: var(--touch-min);
        padding: 0 6px;
    }
    .user-chip span:not(.avatar) { display: none; }
    .btn-mobile-icon {
        min-width: var(--touch-min);
        width: var(--touch-min);
        height: var(--touch-min);
        padding: 0;
        justify-content: center;
    }
    .btn-mobile-icon .btn-text { display: none; }

    .nav-link,
    .nav-mailbox {
        min-height: var(--touch-min);
        padding-top: 11px;
        padding-bottom: 11px;
    }

    .content {
        padding: 20px max(16px, env(safe-area-inset-left)) calc(40px + env(safe-area-inset-bottom, 0)) max(16px, env(safe-area-inset-right));
    }
    .page-header {
        flex-direction: column;
        align-items: stretch;
        gap: 16px;
        margin-bottom: 22px;
    }
    .page-header .header-actions,
    .page-header > .btn,
    .page-header > a.btn {
        width: 100%;
    }
    .page-header .header-actions .btn,
    .page-header .header-actions form {
        flex: 1 1 calc(50% - 4px);
    }
    .page-header .header-actions form { display: flex; }
    .page-header .header-actions form .btn { width: 100%; }
    .page-header > .btn { justify-content: center; }

    .card { padding: 18px; margin-bottom: 16px; }
    .card-header {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }
    .card-header .btn { width: 100%; justify-content: center; }

    .stats-grid,
    .stats-grid.campaign-stats { grid-template-columns: 1fr 1fr; gap: 12px; }
    .stats-grid .card[style*="grid-column"] { grid-column: 1 / -1 !important; }
    .stat-card { min-height: 104px; padding: 14px 16px; }
    .stat-value { font-size: 1.5rem; }

    .grid-cards { grid-template-columns: 1fr; }
    .email-composer-layout { grid-template-columns: 1fr; min-height: auto; }
    .email-composer-editor .form-group textarea { min-height: max(360px, 42vh); }
    .email-preview-panel { position: static; min-height: max(360px, 42vh); }

    .form-row, .form-row.three { grid-template-columns: 1fr; gap: 0; }
    .form-group input,
    .form-group select,
    .form-group textarea {
        font-size: 16px;
        min-height: var(--touch-min);
    }
    .form-group textarea { min-height: 120px; }
    .form-actions {
        position: sticky;
        bottom: 0;
        z-index: 20;
        flex-direction: column-reverse;
        align-items: stretch;
        gap: 10px;
        margin: 20px -18px -18px;
        padding: 14px 18px calc(14px + env(safe-area-inset-bottom, 0));
        background: color-mix(in srgb, var(--surface) 92%, transparent);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        border-top: 1px solid var(--border);
    }
    .form-actions .btn { width: 100%; min-height: var(--touch-min); justify-content: center; }

    .permission-grid { grid-template-columns: 1fr; }
    .detail-list { grid-template-columns: 1fr; gap: 4px 0; }
    .detail-list dt { margin-top: 10px; }
    .detail-list dt:first-child { margin-top: 0; }

    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    .toolbar-search {
        max-width: none;
        min-width: 0;
        width: 100%;
    }
    .filter-group {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap;
    }
    .filter-chip {
        min-height: 36px;
        padding: 8px 14px;
        flex-shrink: 0;
    }

    .table th:first-child,
    .table td:first-child {
        position: sticky;
        left: 0;
        z-index: 1;
        background: var(--surface);
        box-shadow: 4px 0 8px -4px rgba(0, 0, 0, .18);
    }
    .table th:first-child { background: var(--surface-2); z-index: 2; }
    .table tbody tr:hover td:first-child { background: var(--surface-hover); }
    .table .btn-sm {
        min-height: 36px;
        padding: 8px 12px;
    }

    .pagination {
        flex-wrap: wrap;
        justify-content: center;
    }

    .auth-body { padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
    .auth-card { padding: 26px 22px; }
    .auth-form .form-group input { font-size: 16px; min-height: var(--touch-min); }

    .flash-messages {
        top: calc(var(--topbar-h) + 8px);
        right: max(12px, env(safe-area-inset-right));
        left: max(12px, env(safe-area-inset-left));
        width: auto;
    }

    .spreadsheet-body .content {
        height: calc(100dvh - var(--topbar-h));
    }
    .spreadsheet-toolbar {
        flex-wrap: wrap;
        padding: 8px 12px;
        gap: 8px;
    }
    .spreadsheet-toolbar-left,
    .spreadsheet-toolbar-right {
        width: 100%;
        justify-content: space-between;
    }
    .spreadsheet-title-input {
        max-width: none;
        flex: 1;
        font-size: .9375rem;
    }
    .spreadsheet-owner { display: none; }

    .goals-month-nav {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        padding: 14px 16px;
    }
    .goals-month-nav > .btn { width: 100%; justify-content: center; }
    .goals-month-title { order: -1; }
    .goals-charts-grid { grid-template-columns: 1fr; }
    .goals-chart-header {
        flex-direction: column;
        align-items: flex-start;
    }
    .goals-plan-grid-header,
    .goals-plan-row {
        grid-template-columns: 1fr 72px 72px;
        gap: 8px;
    }
    .goal-card-actions { flex-direction: column; align-items: stretch; }
    .goal-card-actions .btn { width: 100%; justify-content: center; }

    .list-meta { flex-wrap: wrap; }
    .card-actions { flex-direction: column; }
    .card-actions .btn { width: 100%; justify-content: center; }
}
@media (max-width: 460px) {
    .stats-grid,
    .stats-grid.campaign-stats { grid-template-columns: 1fr; }
    .page-header h1 { font-size: 1.5rem; }
    .page-header .header-actions .btn,
    .page-header .header-actions form { flex: 1 1 100%; }
    .topbar-actions .theme-toggle { display: none; }
}

@media (min-width: 1900px) {
    .content { padding-inline: 52px; }
    .card { padding: 26px; }
    .stats-grid { gap: 18px; }
}

/* =========================================================================
   Reduced motion (a11y)
   ========================================================================= */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
        scroll-behavior: auto !important;
    }
    .status-dot { animation: none; }
}

/* Skeleton loader */
.skeleton {
    background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%);
    background-size: 400% 100%;
    animation: shimmer 1.4s ease infinite;
    border-radius: var(--radius-sm);
}
@keyframes shimmer {
    0% { background-position: 100% 0; }
    100% { background-position: -100% 0; }
}

/* Loading bar (top of page) */
.loading-bar {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--primary), var(--purple));
    z-index: 100;
    width: 0;
    transition: width .3s var(--ease), opacity .3s var(--ease);
    opacity: 0;
}
.loading-bar.active { opacity: 1; width: 100%; }

/* =========================================================================
   Spreadsheets
   ========================================================================= */
.spreadsheet-body .content {
    display: flex;
    flex-direction: column;
    padding: 0;
    max-width: none;
    height: calc(100vh - var(--topbar-h));
    overflow: hidden;
}

.spreadsheet-app {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    background: var(--surface);
}

.spreadsheet-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
    flex-shrink: 0;
}

.spreadsheet-toolbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.spreadsheet-toolbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.spreadsheet-title-form {
    min-width: 0;
}

.spreadsheet-title-input {
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 700;
    padding: 4px 8px;
    min-width: 160px;
    max-width: 320px;
    transition: border-color var(--t), background var(--t);
}

.spreadsheet-title-input:hover,
.spreadsheet-title-input:focus {
    background: var(--surface);
    border-color: var(--border);
    outline: none;
}

.spreadsheet-save-status {
    font-size: .8125rem;
    color: var(--text-muted);
}

.spreadsheet-owner {
    font-size: .8125rem;
}

.spreadsheet-save-status[data-state="saving"] { color: var(--orange); }
.spreadsheet-save-status[data-state="dirty"] { color: var(--blue); }
.spreadsheet-save-status[data-state="error"] { color: var(--red); }

.spreadsheet-grid-wrap {
    flex: 1;
    overflow: auto;
    min-height: 0;
}

.spreadsheet-grid {
    border-collapse: collapse;
    table-layout: fixed;
    width: max-content;
    min-width: 100%;
    font-size: .8125rem;
    font-family: var(--font-mono);
}

.spreadsheet-grid th,
.spreadsheet-grid td {
    border: 1px solid var(--border-subtle);
    padding: 0;
    height: 28px;
    min-width: 100px;
    max-width: 100px;
    vertical-align: middle;
}

.spreadsheet-corner {
    position: sticky;
    top: 0;
    left: 0;
    z-index: 3;
    width: 48px;
    min-width: 48px;
    max-width: 48px;
    background: var(--surface-2);
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

.spreadsheet-col-header {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--surface-2);
    color: var(--text-muted);
    font-weight: 600;
    text-align: center;
    border-bottom: 1px solid var(--border);
    user-select: none;
}

.spreadsheet-row-header {
    position: sticky;
    left: 0;
    z-index: 1;
    width: 48px;
    min-width: 48px;
    max-width: 48px;
    background: var(--surface-2);
    color: var(--text-muted);
    font-weight: 600;
    text-align: center;
    border-right: 1px solid var(--border);
    user-select: none;
}

.spreadsheet-cell {
    background: var(--surface);
    color: var(--text);
    padding: 4px 8px;
    outline: none;
    white-space: nowrap;
    overflow: hidden;
    cursor: cell;
}

.spreadsheet-cell:focus {
    outline: 2px solid var(--primary);
    outline-offset: -2px;
    z-index: 1;
    position: relative;
    background: var(--bg-elevated);
}

.spreadsheet-cell.selected {
    background: var(--primary-soft);
}

.spreadsheet-cell.selected:focus {
    background: var(--bg-elevated);
}

.spreadsheet-tabs {
    display: flex;
    align-items: stretch;
    gap: 0;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
    flex-shrink: 0;
    overflow-x: auto;
}

.spreadsheet-tabs-list {
    display: flex;
    align-items: stretch;
    min-width: 0;
}

.spreadsheet-tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0 14px;
    height: 36px;
    border: none;
    border-right: 1px solid var(--border-subtle);
    background: var(--surface-3);
    color: var(--text-soft);
    font-family: var(--font-sans);
    font-size: .8125rem;
    cursor: pointer;
    white-space: nowrap;
    transition: background var(--t), color var(--t);
}

.spreadsheet-tab:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.spreadsheet-tab.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: inset 0 2px 0 var(--primary);
}

.spreadsheet-tab-label {
    pointer-events: none;
}

.spreadsheet-tab-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: var(--radius-xs);
    font-size: 1rem;
    line-height: 1;
    color: var(--text-muted);
    opacity: 0;
    transition: opacity var(--t), background var(--t), color var(--t);
}

.spreadsheet-tab:hover .spreadsheet-tab-close,
.spreadsheet-tab.active .spreadsheet-tab-close {
    opacity: 1;
}

.spreadsheet-tab-close:hover {
    background: var(--red-soft);
    color: var(--red);
}

.spreadsheet-tab-add {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    border-right: 1px solid var(--border-subtle);
    background: transparent;
    color: var(--text-muted);
    font-size: 1.25rem;
    cursor: pointer;
    flex-shrink: 0;
    transition: background var(--t), color var(--t);
}

.spreadsheet-tab-add:hover {
    background: var(--primary-soft);
    color: var(--primary);
}

/* =========================================================================
   Monthly goals
   ========================================================================= */
.goals-month-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 20px;
    margin-bottom: 20px;
}

.goals-month-nav h2 {
    margin: 0;
    font-family: var(--font-display);
    font-size: 1.25rem;
}

.goals-month-title {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.goals-month-notice {
    margin-bottom: 20px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    background: var(--blue-soft);
    color: var(--text-soft);
    font-size: .875rem;
}

.goals-month-notice a {
    color: var(--blue);
    font-weight: 600;
}

.goals-stats {
    margin-bottom: 20px;
}

.goals-section-title {
    margin: 0 0 16px;
    font-family: var(--font-display);
    font-size: 1.125rem;
}

.goals-charts-section {
    margin-bottom: 24px;
}

.goals-charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 16px;
}

.goals-chart-card {
    padding: 16px 18px;
}

.goals-chart-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}

.goals-chart-header h4 {
    margin: 0;
    font-size: 1rem;
}

.goals-chart-legend {
    display: flex;
    gap: 12px;
    font-size: .75rem;
    color: var(--text-muted);
}

.legend-item i {
    display: inline-block;
    width: 16px;
    height: 3px;
    vertical-align: middle;
    margin-right: 4px;
    border-radius: 2px;
}

.legend-target i { background: var(--primary); opacity: .85; }
.legend-actual i { background: var(--green); }

.goals-chart-canvas {
    width: 100%;
    display: block;
}

.goals-layout-wide {
    grid-template-columns: 360px 1fr;
}

.goals-sidebar {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.goals-plan-card h3,
.goals-add-card h3 {
    margin: 0 0 8px;
}

.goals-plan-help {
    margin: 0 0 16px;
    font-size: .8125rem;
}

.goals-plan-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.goals-plan-grid-header {
    display: grid;
    grid-template-columns: 1fr 80px 80px;
    gap: 10px;
    font-size: .75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    margin-bottom: 4px;
}

.goals-plan-row {
    display: grid;
    grid-template-columns: 1fr 80px 80px;
    align-items: center;
    gap: 10px;
    font-size: .875rem;
}

.goals-plan-row input {
    width: 100%;
}

.goals-numeric-row {
    display: grid;
    grid-template-columns: 1fr 80px 80px;
    gap: 10px;
}

.goal-progress-badge {
    display: flex;
    align-items: baseline;
    gap: 4px;
    font-size: .875rem;
}

.goal-progress-bar-wrap {
    margin-bottom: 12px;
}

.goal-progress-bar {
    height: 6px;
    background: var(--surface-3);
    border-radius: var(--radius-pill);
    overflow: hidden;
}

.goal-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--green));
    border-radius: var(--radius-pill);
    transition: width var(--t);
}

.goals-timeline-card h3 {
    margin: 0 0 4px;
}

.goals-timeline-help {
    margin: 0 0 16px;
    font-size: .875rem;
}

.goals-timeline {
    position: relative;
    padding: 8px 0 48px;
    overflow-x: auto;
}

.goals-timeline-track {
    display: flex;
    gap: 0;
    min-width: 100%;
    border-bottom: 2px solid var(--border);
    padding-bottom: 8px;
}

.goals-timeline-day {
    flex: 1;
    min-width: 28px;
    text-align: center;
    font-size: .6875rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.goals-timeline-day.today {
    color: var(--primary);
    font-weight: 700;
}

.goals-timeline-markers {
    position: relative;
    height: 40px;
    margin-top: 12px;
    min-width: 100%;
}

.goals-timeline-marker {
    position: absolute;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    max-width: 120px;
}

.marker-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-muted);
    border: 2px solid var(--surface);
    box-shadow: var(--shadow-xs);
}

.goals-timeline-marker.status-pending .marker-dot { background: var(--text-muted); }
.goals-timeline-marker.status-in_progress .marker-dot { background: var(--orange); }
.goals-timeline-marker.status-done .marker-dot { background: var(--green); }

.marker-label {
    margin-top: 4px;
    font-size: .6875rem;
    color: var(--text-soft);
    text-align: center;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.goals-timeline-marker:hover .marker-label {
    color: var(--text);
}

.goals-layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 20px;
    align-items: start;
}

.goals-add-card h3,
.goals-list h3 {
    margin: 0 0 16px;
}

.goals-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.goal-card {
    position: relative;
    border-left: 4px solid var(--border-strong);
}

.goal-card.status-border-pending { border-left-color: var(--text-muted); }
.goal-card.status-border-in_progress { border-left-color: var(--orange); }
.goal-card.status-border-done { border-left-color: var(--green); }

.goal-card-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.goal-status-select {
    appearance: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px 28px 6px 10px;
    font-family: var(--font-sans);
    font-size: .8125rem;
    font-weight: 600;
    background: var(--surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237c849a' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 8px center;
    cursor: pointer;
}

.goal-status-select.status-pending { color: var(--text-muted); }
.goal-status-select.status-in_progress { color: var(--orange); background-color: var(--orange-soft); }
.goal-status-select.status-done { color: var(--green); background-color: var(--green-soft); }

.goal-title-input {
    font-family: var(--font-display);
    font-size: 1.0625rem;
    font-weight: 700;
    border: 1px solid transparent;
    background: transparent;
    width: 100%;
    padding: 4px 0;
    color: var(--text);
}

.goal-title-input:focus {
    outline: none;
    border-bottom-color: var(--primary);
}

.goal-card-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.goal-meta {
    font-size: .8125rem;
}

.goal-delete-form {
    position: absolute;
    top: 16px;
    right: 16px;
}

@media (max-width: 960px) {
    .goals-layout,
    .goals-layout-wide {
        grid-template-columns: 1fr;
    }
    .goals-numeric-row {
        grid-template-columns: 1fr;
    }
    .goal-delete-form {
        position: static;
        margin-top: 12px;
    }
}

/* =========================================================================
   Shared calendar
   ========================================================================= */
.calendar-legend {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 20px;
    padding: 12px 16px;
    margin-bottom: 20px;
}

.calendar-legend-label {
    font-size: .75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
}

.calendar-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: .8125rem;
    color: var(--text-soft);
}

.calendar-legend-item i {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.calendar-layout {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 20px;
    align-items: start;
}

.calendar-layout-full {
    grid-template-columns: 1fr;
}

.calendar-grid-wrap {
    padding: 0;
    overflow: hidden;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
}

.calendar-weekday {
    padding: 10px 8px;
    text-align: center;
    font-size: .75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
}

.calendar-day {
    min-height: 100px;
    padding: 6px;
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 4px;
    cursor: pointer;
}

.calendar-day:nth-child(7n) {
    border-right: none;
}

.calendar-day-outside {
    background: var(--surface-2);
    opacity: .5;
}

.calendar-day-today {
    background: var(--blue-soft);
}

.calendar-day-selected {
    outline: 2px solid var(--primary);
    outline-offset: -2px;
    z-index: 1;
}

.calendar-day-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    font-size: .8125rem;
    font-weight: 500;
    color: var(--text-soft);
    text-decoration: none;
    border-radius: 50%;
    flex-shrink: 0;
    border: none;
    background: transparent;
    padding: 0;
    cursor: pointer;
    font-family: inherit;
}

.calendar-day-number.today {
    background: var(--primary);
    color: #fff;
    font-weight: 700;
}

.calendar-day-number:hover {
    background: var(--surface-3);
    color: var(--text);
}

.calendar-day-number.today:hover {
    background: var(--primary);
    color: #fff;
    opacity: .9;
}

.calendar-day-events {
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow: hidden;
    flex: 1;
}

.calendar-event-pill {
    display: block;
    width: 100%;
    padding: 2px 6px;
    border-radius: var(--radius-xs);
    background: color-mix(in srgb, var(--event-color) 18%, transparent);
    border: none;
    border-left: 3px solid var(--event-color);
    font-size: .6875rem;
    line-height: 1.3;
    color: var(--text);
    text-decoration: none;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    text-align: left;
    cursor: pointer;
    font-family: inherit;
}

.calendar-event-pill:hover {
    background: color-mix(in srgb, var(--event-color) 28%, transparent);
}

.calendar-event-time {
    font-family: var(--font-mono);
    font-size: .625rem;
    color: var(--text-muted);
    margin-right: 4px;
}

.calendar-event-title {
    font-weight: 500;
}

.calendar-sidebar {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.calendar-add-card h3 {
    margin: 0 0 16px;
}

.calendar-time-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.calendar-events-list-title {
    margin: 0 0 12px;
    font-family: var(--font-display);
    font-size: 1rem;
}

.calendar-events-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.calendar-event-card {
    padding: 14px 16px;
    border-left: 3px solid var(--event-color);
}

.calendar-event-card-header {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 8px;
}

.calendar-event-card-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--event-color);
    flex-shrink: 0;
    margin-top: 4px;
}

.calendar-event-card-meta {
    font-size: .8125rem;
    margin-top: 2px;
}

.calendar-event-card-desc {
    margin: 0 0 12px;
    font-size: .875rem;
    color: var(--text-soft);
}

.calendar-event-edit {
    margin-bottom: 8px;
}

.calendar-event-edit summary {
    cursor: pointer;
    list-style: none;
    display: inline-block;
    margin-bottom: 12px;
}

.calendar-event-edit summary::-webkit-details-marker {
    display: none;
}

.calendar-edit-form {
    padding-top: 8px;
    border-top: 1px solid var(--border);
    margin-bottom: 8px;
}

.calendar-empty-day {
    padding: 24px 16px;
    text-align: center;
}

.calendar-empty-day-inline {
    padding: 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: .875rem;
}

.calendar-empty-day-inline p {
    margin: 0;
}

.calendar-event-card.is-highlighted {
    box-shadow: 0 0 0 2px var(--primary);
}

.calendar-modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
    background: var(--overlay);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--t-slow) var(--ease), visibility var(--t-slow);
}

.calendar-modal-backdrop.is-open {
    opacity: 1;
    visibility: visible;
}

.calendar-modal {
    width: 100%;
    max-width: 480px;
    max-height: min(90vh, 720px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: calendar-modal-in var(--t-slow) var(--ease);
}

@keyframes calendar-modal-in {
    from {
        opacity: 0;
        transform: translateY(12px) scale(.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.calendar-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.calendar-modal-header h2 {
    margin: 0;
    font-family: var(--font-display);
    font-size: 1.125rem;
    font-weight: 700;
}

.calendar-modal-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: var(--radius);
    background: transparent;
    color: var(--text-muted);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    transition: background var(--t-fast), color var(--t-fast);
}

.calendar-modal-close:hover {
    background: var(--surface-3);
    color: var(--text);
}

.calendar-modal-body {
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.calendar-modal .calendar-add-card h3 {
    margin: 0 0 16px;
    font-family: var(--font-display);
    font-size: 1rem;
}

.calendar-modal .calendar-events-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: .875rem;
    cursor: pointer;
}

@media (max-width: 960px) {
    .calendar-layout {
        grid-template-columns: 1fr;
    }
    .calendar-day {
        min-height: 72px;
        cursor: pointer;
    }
    .calendar-event-pill .calendar-event-time {
        display: none;
    }
    .calendar-modal-backdrop {
        padding: 0;
        align-items: flex-end;
    }
    .calendar-modal {
        max-width: none;
        max-height: 92vh;
        border-bottom-left-radius: 0;
        border-bottom-right-radius: 0;
    }
}

/* =========================================================================
   File manager — desktop-style (Nautilus / Finder inspired)
   ========================================================================= */

.files-page .content {
    max-width: none;
    padding-bottom: 16px;
}

.file-manager {
    --fm-sidebar-w: 210px;
    --fm-inspector-w: min(420px, 34vw);
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--topbar-h) - 40px);
    min-height: 520px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

/* Header & path bar */
.fm-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}

.fm-header-nav,
.fm-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.fm-pathbar {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    padding: 7px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: .8125rem;
    color: var(--text-soft);
}

.fm-path-segment {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
}

.fm-path-segment svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
}

.fm-path-sep { color: var(--text-faint); }
.fm-path-current { color: var(--text); font-weight: 600; }

.fm-subheader {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    flex-wrap: wrap;
}

.fm-search {
    position: relative;
    flex: 1;
    min-width: 180px;
    max-width: 360px;
}

.fm-search svg {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 15px;
    height: 15px;
    stroke: var(--text-muted);
    fill: none;
    stroke-width: 2;
    pointer-events: none;
}

.fm-search input {
    width: 100%;
    padding: 8px 12px 8px 34px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    color: var(--text);
    font: inherit;
    font-size: .8125rem;
}

.fm-search input:focus {
    outline: none;
    border-color: var(--primary-border);
    box-shadow: var(--shadow-glow);
}

.fm-subheader-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.fm-select {
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    color: var(--text-soft);
    font: inherit;
    font-size: .8125rem;
    cursor: pointer;
}

.fm-view-toggle {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.fm-icon-btn {
    display: inline-grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border: 0;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: background var(--t-fast), color var(--t-fast);
}

.fm-icon-btn:disabled {
    opacity: .35;
    cursor: default;
}

.fm-icon-btn:not(:disabled):hover,
.fm-icon-btn.is-active {
    background: var(--surface-hover);
    color: var(--text);
}

.fm-view-toggle .fm-icon-btn.is-active {
    background: var(--primary-soft);
    color: var(--primary);
}

.fm-icon-btn svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.fm-upload-btn,
.fm-upload-trigger {
    cursor: pointer;
}

.fm-upload-btn svg {
    width: 15px;
    height: 15px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
}

/* Workspace layout */
.fm-workspace {
    display: grid;
    grid-template-columns: var(--fm-sidebar-w) 1fr var(--fm-inspector-w);
    flex: 1;
    min-height: 0;
}

.file-manager:not(.has-selection) .fm-inspector {
    opacity: .92;
}

/* Sidebar */
.fm-sidebar {
    display: flex;
    flex-direction: column;
    min-height: 0;
    border-right: 1px solid var(--border);
    background: var(--surface-soft);
    padding: 12px 8px;
}

.fm-sidebar-label {
    margin: 0 8px 8px;
    font-size: .6875rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--text-faint);
}

.fm-sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-height: 0;
    overflow: auto;
}

.fm-sidebar-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 10px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-soft);
    font: inherit;
    font-size: .8125rem;
    text-align: left;
    cursor: pointer;
    transition: background var(--t-fast), color var(--t-fast);
}

.fm-sidebar-item svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.75;
    flex-shrink: 0;
}

.fm-sidebar-item:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.fm-sidebar-item.is-active {
    background: var(--primary-soft);
    color: var(--primary);
    font-weight: 600;
}

.fm-sidebar-count {
    margin-left: auto;
    font-size: .75rem;
    color: var(--text-faint);
    font-variant-numeric: tabular-nums;
}

.fm-sidebar-item.is-active .fm-sidebar-count {
    color: var(--primary);
}

.fm-sidebar-foot {
    margin-top: auto;
    padding: 10px 10px 4px;
    font-size: .75rem;
    color: var(--text-faint);
    border-top: 1px solid var(--border-subtle);
}

/* Files pane */
.fm-files-pane {
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    background: var(--bg-elevated);
}

.fm-list-head {
    display: grid;
    grid-template-columns: 36px 1fr 88px 110px;
    gap: 12px;
    padding: 8px 16px;
    font-size: .6875rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--text-faint);
    border-bottom: 1px solid var(--border-subtle);
    background: var(--surface);
}

.fm-viewport {
    flex: 1;
    overflow: auto;
    min-height: 0;
}

.fm-file-list {
    padding: 12px;
}

.fm-file[hidden] {
    display: none !important;
}

/* Grid view */
.fm-viewport[data-view="grid"] .fm-file-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(124px, 1fr));
    gap: 8px;
}

.fm-viewport[data-view="grid"] .fm-file {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 10px 8px 12px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: transparent;
    color: var(--text);
    cursor: pointer;
    text-align: center;
    transition: background var(--t-fast), border-color var(--t-fast), box-shadow var(--t-fast);
}

.fm-viewport[data-view="grid"] .fm-file:hover {
    background: var(--surface);
    border-color: var(--border-subtle);
}

.fm-viewport[data-view="grid"] .fm-file.is-selected {
    background: var(--primary-soft);
    border-color: var(--primary-border);
    box-shadow: inset 0 0 0 1px rgba(124, 108, 240, .15);
}

.fm-viewport[data-view="grid"] .fm-file-icon {
    width: 88px;
    height: 88px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
    background: var(--surface);
    overflow: hidden;
    display: grid;
    place-items: center;
    position: relative;
}

.fm-viewport[data-view="grid"] .fm-file-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.fm-viewport[data-view="grid"] .fm-file-icon svg {
    width: 44px;
    height: 44px;
}

.fm-viewport[data-view="grid"] .fm-file-size,
.fm-viewport[data-view="grid"] .fm-file-date {
    display: none;
}

.fm-viewport[data-view="grid"] .fm-file-name {
    width: 100%;
    font-size: .75rem;
    line-height: 1.35;
    color: var(--text-soft);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-word;
}

.fm-viewport[data-view="grid"] .fm-file.is-selected .fm-file-name {
    color: var(--text);
    font-weight: 500;
}

/* List view */
.fm-viewport[data-view="list"] .fm-file-list {
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding: 0;
}

.fm-viewport[data-view="list"] .fm-file {
    display: grid;
    grid-template-columns: 36px 1fr 88px 110px;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 7px 16px;
    border: 0;
    border-bottom: 1px solid var(--border-subtle);
    background: transparent;
    color: var(--text);
    text-align: left;
    cursor: pointer;
    font-size: .8125rem;
    transition: background var(--t-fast);
}

.fm-viewport[data-view="list"] .fm-file:hover {
    background: var(--surface);
}

.fm-viewport[data-view="list"] .fm-file.is-selected {
    background: var(--primary-soft);
}

.fm-viewport[data-view="list"] .fm-file-icon {
    width: 32px;
    height: 32px;
    display: grid;
    place-items: center;
    position: relative;
}

.fm-viewport[data-view="list"] .fm-file-icon img {
    width: 32px;
    height: 32px;
    object-fit: cover;
    border-radius: 4px;
}

.fm-viewport[data-view="list"] .fm-file-icon svg {
    width: 28px;
    height: 28px;
}

.fm-viewport[data-view="list"] .fm-file-name {
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text);
}

.fm-viewport[data-view="list"] .fm-file-size,
.fm-viewport[data-view="list"] .fm-file-date {
    color: var(--text-muted);
    font-size: .8125rem;
    font-variant-numeric: tabular-nums;
}

.fm-file-icon-pdf { color: #e85d5d; }
.fm-file-icon-document { color: #4d8af0; }
.fm-file-icon-spreadsheet { color: #3ecf8e; }
.fm-file-icon-presentation { color: #f2994a; }
.fm-file-icon-archive { color: #b08cf0; }
.fm-file-icon-text { color: var(--text-soft); }
.fm-file-icon-file { color: var(--text-muted); }

.fm-file-ext {
    position: absolute;
    right: 3px;
    bottom: 3px;
    padding: 1px 4px;
    border-radius: 3px;
    background: rgba(0, 0, 0, .6);
    color: #fff;
    font-size: .5625rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    line-height: 1.2;
}

.fm-viewport[data-view="list"] .fm-file-ext {
    display: none;
}

/* Empty & no results */
.fm-empty,
.fm-no-results {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 280px;
    padding: 40px 24px;
    text-align: center;
}

.fm-empty-visual {
    width: 64px;
    height: 64px;
    display: grid;
    place-items: center;
    margin-bottom: 16px;
    border-radius: var(--radius-lg);
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-muted);
}

.fm-empty-visual svg {
    width: 28px;
    height: 28px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.5;
}

.fm-empty h3,
.fm-no-results p {
    margin: 0 0 8px;
    font-family: var(--font-display);
}

.fm-empty p {
    margin: 0 0 18px;
    color: var(--text-muted);
    max-width: 38ch;
}

/* Drag overlay — only during active drag */
.fm-drag-overlay {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 20;
    align-items: center;
    justify-content: center;
    background: rgba(124, 108, 240, .08);
    backdrop-filter: blur(3px);
    pointer-events: none;
}

.file-manager.is-dragover .fm-drag-overlay {
    display: flex;
}

.fm-drag-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 28px 36px;
    border-radius: var(--radius-lg);
    border: 2px dashed var(--primary-border);
    background: var(--surface);
    box-shadow: var(--shadow-md);
    color: var(--primary);
    text-align: center;
}

.fm-drag-card svg {
    width: 36px;
    height: 36px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
}

.fm-drag-card span {
    font-size: .8125rem;
    color: var(--text-muted);
}

.file-manager.is-uploading::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 30;
    background: var(--overlay);
}

/* Inspector panel */
.fm-inspector {
    display: flex;
    flex-direction: column;
    min-height: 0;
    border-left: 1px solid var(--border);
    background: var(--surface);
}

.fm-inspector-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    flex: 1;
    padding: 32px 24px;
    text-align: center;
    color: var(--text-muted);
    font-size: .8125rem;
}

.fm-inspector-empty svg {
    width: 48px;
    height: 48px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.25;
    opacity: .45;
}

.fm-inspector-content {
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1;
}

.fm-inspector-preview {
    position: relative;
    flex: 1;
    min-height: 180px;
    max-height: 55%;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        linear-gradient(45deg, var(--border-subtle) 25%, transparent 25%),
        linear-gradient(-45deg, var(--border-subtle) 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, var(--border-subtle) 75%),
        linear-gradient(-45deg, transparent 75%, var(--border-subtle) 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
    background-color: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
}

.fm-inspector-preview--pdf,
.fm-inspector-preview--text,
.fm-inspector-preview--spreadsheet {
    background: var(--bg-elevated);
    align-items: stretch;
}

.fm-inspector-preview img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    display: block;
    margin: auto;
    padding: 12px;
}

.fm-inspector-preview iframe {
    width: 100%;
    height: 100%;
    min-height: 280px;
    border: 0;
    background: #fff;
}

.fm-inspector-preview pre {
    width: 100%;
    margin: 0;
    padding: 14px;
    font-family: var(--font-mono);
    font-size: .75rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--text-soft);
    align-self: flex-start;
}

.fm-inspector-preview.is-loading::after {
    content: "Loading…";
    position: absolute;
    color: var(--text-muted);
    font-size: .8125rem;
}

.fm-inspector-fallback {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 24px;
    text-align: center;
    color: var(--text-muted);
    font-size: .8125rem;
}

.fm-inspector-fallback .fm-file-icon svg {
    width: 56px;
    height: 56px;
}

.fm-inspector-info {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    overflow: auto;
}

.fm-inspector-name {
    margin: 0 0 12px;
    font-size: .875rem;
    line-height: 1.4;
    word-break: break-word;
}

.fm-props {
    margin: 0;
    display: grid;
    gap: 8px;
}

.fm-props > div {
    display: grid;
    grid-template-columns: 72px 1fr;
    gap: 8px;
    font-size: .8125rem;
}

.fm-props dt {
    margin: 0;
    color: var(--text-faint);
    font-weight: 500;
}

.fm-props dd {
    margin: 0;
    color: var(--text-soft);
    word-break: break-word;
}

.fm-inspector-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 16px;
    margin-top: auto;
}

.fm-inspector-actions .btn svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
}

.fm-delete-form {
    display: inline;
}

/* Status bar */
.fm-statusbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    font-size: .75rem;
    color: var(--text-muted);
    background: var(--surface-2);
    border-top: 1px solid var(--border);
    font-variant-numeric: tabular-nums;
}

.fm-status-dot {
    opacity: .45;
}

@media (max-width: 1100px) {
    .fm-workspace {
        grid-template-columns: 180px 1fr;
    }

    .fm-inspector {
        position: fixed;
        right: 0;
        bottom: 0;
        left: 0;
        top: auto;
        max-height: 70vh;
        z-index: 50;
        border-left: 0;
        border-top: 1px solid var(--border);
        box-shadow: var(--shadow-lg);
        transform: translateY(100%);
        transition: transform var(--t);
    }

    .file-manager.has-selection .fm-inspector {
        transform: translateY(0);
    }

    .file-manager:not(.has-selection) .fm-inspector {
        display: none;
    }
}

@media (max-width: 768px) {
    .file-manager {
        height: auto;
        min-height: calc(100vh - var(--topbar-h) - 32px);
    }

    .fm-workspace {
        grid-template-columns: 1fr;
    }

    .fm-sidebar {
        display: none;
    }

    .fm-subheader {
        flex-direction: column;
        align-items: stretch;
    }

    .fm-search {
        max-width: none;
    }

    .fm-viewport[data-view="grid"] .fm-file-list {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    }
}
