/* ========================================================================
   Haldus — Editorial Confidence
   Fraunces (display) + Manrope (body), warm cream + ink + coral
   ====================================================================== */

:root {
    /* Palette */
    --cream-50: #faf6ee;
    --cream-100: #f4ecdb;
    --cream-200: #ebe1cb;
    --cream-300: #e3d6b8;
    --paper: #ffffff;

    --ink-900: #11142b;
    --ink-800: #1a1f44;
    --ink-700: #232a55;
    --ink-600: #364069;
    --ink-500: #555f86;
    --ink-400: #828aa8;
    --ink-300: #b3b8cc;
    --ink-200: #d4d7e1;
    --ink-100: #e8eaf0;

    --coral: #e35846;
    --coral-soft: #f9d7cf;
    --gold: #d8a23b;
    --gold-soft: #f5e3b6;
    --emerald: #2c7a4e;
    --emerald-soft: #c9e3d2;
    --plum: #5d2f6a;
    --sky: #2660b8;

    /* Semantic */
    --bg: var(--cream-50);
    --surface: var(--paper);
    --text: var(--ink-900);
    --text-muted: var(--ink-500);
    --border: rgba(17, 20, 43, 0.08);
    --border-strong: rgba(17, 20, 43, 0.16);
    --primary: var(--coral);
    --primary-strong: #c0432f;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(17, 20, 43, 0.04), 0 1px 3px rgba(17, 20, 43, 0.05);
    --shadow-md: 0 6px 16px -8px rgba(17, 20, 43, 0.18), 0 2px 4px rgba(17, 20, 43, 0.04);
    --shadow-lg: 0 24px 48px -24px rgba(17, 20, 43, 0.30), 0 6px 12px rgba(17, 20, 43, 0.06);
    --shadow-glow: 0 0 0 4px rgba(227, 88, 70, 0.15);

    /* Type */
    --font-display: 'Fraunces', 'Times New Roman', Georgia, serif;
    --font-body: 'Manrope', -apple-system, BlinkMacSystemFont, sans-serif;

    /* Radii */
    --r-xs: 6px;
    --r-sm: 10px;
    --r-md: 14px;
    --r-lg: 20px;
    --r-xl: 28px;

    --sidebar-w: 256px;
    --topbar-h: 76px;
}

/* ---------- Reset / global ------------------------------------------- */

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    background-image:
        radial-gradient(circle at 0% 0%, rgba(227, 88, 70, 0.05), transparent 40%),
        radial-gradient(circle at 100% 0%, rgba(216, 162, 59, 0.05), transparent 35%);
    background-attachment: fixed;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a { color: var(--ink-700); text-decoration: none; transition: color 0.15s; }
a:hover { color: var(--coral); }

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-display);
    font-weight: 500;
    letter-spacing: -0.02em;
    color: var(--ink-900);
    margin: 0;
}

h1 { font-size: 2.4rem; line-height: 1.1; }
h2 { font-size: 1.7rem; line-height: 1.2; }
h3 { font-size: 1.25rem; line-height: 1.3; font-weight: 600; }

.muted { color: var(--text-muted); }
.muted-eyebrow {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--text-muted);
    font-weight: 600;
    margin: 0;
}
.serif { font-family: var(--font-display); }
.serif-italic { font-family: var(--font-display); font-style: italic; }

/* ---------- App shell ------------------------------------------------ */

.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    min-height: 100vh;
}

.app-main {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.app-content {
    flex: 1;
    padding: 32px clamp(20px, 4vw, 56px) 64px;
    width: 100%;
}

.app-footer {
    padding: 16px 32px 24px;
    color: var(--text-muted);
    font-size: 0.78rem;
    display: flex;
    justify-content: space-between;
    border-top: 1px dashed var(--border);
}

@media (max-width: 991.98px) {
    .app-shell { grid-template-columns: 1fr; }
}

/* ---------- Sidebar -------------------------------------------------- */

.sidebar {
    background: linear-gradient(180deg, var(--ink-900) 0%, var(--ink-800) 100%);
    color: var(--cream-100);
    border-right: 1px solid rgba(255, 255, 255, 0.06);
    overflow: hidden;
}
@media (min-width: 992px) {
    .sidebar {
        position: sticky;
        top: 0;
        height: 100vh;
    }
}
@media (max-width: 991.98px) {
    /* Bootstrap's offcanvas-lg handles position: fixed + slide-in transform.
       Override width so 30% of viewport stays as a backdrop click-target. */
    .sidebar.offcanvas-lg {
        --bs-offcanvas-width: 70vw;
        width: 70vw;
        height: 100vh;
    }
}

.sidebar-inner {
    height: 100%;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    padding: 28px 20px 24px;
    gap: 24px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--cream-50);
    text-decoration: none;
    padding: 4px 8px;
}
.brand:hover { color: var(--cream-50); }

.brand-mark {
    width: 38px;
    height: 38px;
    border-radius: var(--r-sm);
    background: linear-gradient(135deg, var(--coral), #f08a4d);
    color: white;
    display: grid;
    place-items: center;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1.4rem;
    line-height: 1;
    box-shadow: 0 6px 14px -6px rgba(227, 88, 70, 0.6);
}

.brand-name {
    display: block;
    font-family: var(--font-display);
    font-weight: 500;
    font-size: 1.2rem;
    letter-spacing: -0.01em;
    line-height: 1;
}
.brand-meta {
    display: block;
    font-size: 0.7rem;
    color: var(--ink-300);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    margin-top: 4px;
}

.side-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}

.side-section {
    margin: 16px 12px 6px;
    font-size: 0.66rem;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: rgba(244, 236, 219, 0.45);
    font-weight: 700;
}
.side-section:first-of-type { margin-top: 0; }

.side-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--r-sm);
    color: rgba(244, 236, 219, 0.78);
    font-weight: 500;
    font-size: 0.94rem;
    transition: all 0.15s;
    position: relative;
}
.side-link:hover {
    color: var(--cream-50);
    background: rgba(255, 255, 255, 0.04);
}
.side-link.active {
    color: var(--ink-900);
    background: var(--cream-50);
    box-shadow: 0 4px 14px -6px rgba(0, 0, 0, 0.3);
}
.side-link.active::before {
    content: "";
    position: absolute;
    left: -20px;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--coral);
    border-radius: 0 3px 3px 0;
}
.side-link i { font-size: 1.05rem; flex-shrink: 0; }
.side-link .side-badge {
    margin-left: auto;
    font-family: var(--font-display);
    font-style: italic;
    color: var(--gold);
    font-size: 0.85rem;
}
.side-link.active .side-badge { color: var(--coral); }
.side-link .side-trail { margin-left: auto; font-size: 0.7rem; opacity: 0.5; }

.side-foot {
    margin-top: auto;
}
.side-foot-card {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: var(--r-md);
    padding: 14px 16px;
}
.side-foot-card .muted-eyebrow {
    color: var(--gold);
    font-size: 0.65rem;
    margin-bottom: 6px;
}
.side-foot-text {
    color: var(--ink-200);
    font-size: 0.78rem;
    line-height: 1.5;
    margin: 0;
}
.side-foot-text em {
    font-family: var(--font-display);
    font-style: italic;
    font-weight: 600;
    color: var(--cream-50);
}

/* ---------- Topbar --------------------------------------------------- */

.topbar {
    height: var(--topbar-h);
    padding: 0 clamp(20px, 4vw, 40px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(250, 246, 238, 0.85);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 1040;
}

.topbar-left, .topbar-right { display: flex; align-items: center; gap: 12px; }

.btn.topbar-burger {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: var(--r-sm);
    border: 1px solid var(--border);
    background: var(--paper);
    font-size: 1.2rem;
    color: var(--ink-700);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

/* Tenant switcher */
.tenant-switch { position: relative; }
.tenant-trigger {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 14px 8px 8px;
    border-radius: var(--r-md);
    border: 1px solid var(--border);
    background: var(--paper);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: all 0.15s;
}
.tenant-trigger:hover {
    border-color: var(--border-strong);
    box-shadow: var(--shadow-md);
}
.tenant-mark {
    width: 36px; height: 36px;
    border-radius: var(--r-sm);
    background: linear-gradient(135deg, var(--ink-900), var(--ink-700));
    color: var(--cream-50);
    display: grid; place-items: center;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1.05rem;
    line-height: 1;
    flex-shrink: 0;
}
.tenant-words { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.2; }
.tenant-eyebrow {
    font-size: 0.62rem;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--text-muted);
    font-weight: 700;
}
.tenant-name {
    font-family: var(--font-display);
    font-size: 0.98rem;
    font-weight: 600;
    color: var(--ink-900);
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.tenant-chev {
    color: var(--ink-400);
    font-size: 0.85rem;
    transition: transform 0.15s;
}
.tenant-trigger[aria-expanded="true"] .tenant-chev { transform: rotate(180deg); }

.tenant-menu { min-width: 280px; padding: 6px; }
.tenant-menu .dropdown-item {
    display: flex; align-items: center; gap: 10px;
    border-radius: var(--r-sm);
    padding: 8px 10px;
    font-size: 0.93rem;
}
.tenant-menu .dropdown-item.active {
    background: var(--cream-100);
    color: var(--ink-900);
    font-weight: 600;
}
.tenant-menu .dropdown-item.soft { color: var(--text-muted); }
.tenant-dot {
    width: 26px; height: 26px;
    border-radius: var(--r-xs);
    background: var(--ink-100);
    color: var(--ink-700);
    font-family: var(--font-display);
    font-weight: 600;
    display: grid; place-items: center;
    font-size: 0.78rem;
}

.tenant-empty {
    padding: 8px 14px;
    border-radius: var(--r-sm);
    background: var(--gold-soft);
    color: #6b4d10;
    font-size: 0.85rem;
    display: flex; align-items: center; gap: 8px;
}

/* User pill */
.user-pill {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 14px 6px 6px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--paper);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: all 0.15s;
}
.user-pill:hover { box-shadow: var(--shadow-md); border-color: var(--border-strong); }
.user-pill-avatar {
    width: 34px; height: 34px;
    border-radius: 50%;
    color: white;
    display: grid; place-items: center;
    font-weight: 700;
    font-size: 0.78rem;
    letter-spacing: 0.02em;
    box-shadow: 0 0 0 2px rgba(255,255,255,0.7);
}
.user-pill-avatar.lg { width: 44px; height: 44px; font-size: 0.92rem; }
.user-pill-words { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.2; }
.user-pill-name { font-weight: 600; color: var(--ink-900); font-size: 0.92rem; }
.user-pill-meta { font-size: 0.72rem; color: var(--text-muted); }

@media (max-width: 575.98px) {
    .user-pill-words, .tenant-words { display: none; }
    .user-pill { padding: 4px; }
    .tenant-trigger { padding: 6px; }
}

.user-menu-head {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 14px;
}
.user-menu-name { font-weight: 600; margin: 0; line-height: 1.2; }
.user-menu-mail { font-size: 0.78rem; color: var(--text-muted); margin: 0; }

.dropdown-menu {
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-lg);
    padding: 6px;
    background: var(--paper);
}
.dropdown-item {
    border-radius: var(--r-sm);
    padding: 8px 12px;
    font-size: 0.92rem;
    display: flex; align-items: center; gap: 10px;
}
.dropdown-item:hover, .dropdown-item:focus { background: var(--cream-100); color: var(--ink-900); }
.dropdown-item.danger { color: var(--coral); }
.dropdown-item.danger:hover { background: var(--coral-soft); color: var(--primary-strong); }

/* ---------- Page header / cards / panels ----------------------------- */

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 24px;
    flex-wrap: wrap;
    margin-bottom: 28px;
    padding-bottom: 24px;
    border-bottom: 1px dashed var(--border);
}
.page-eyebrow {
    font-size: 0.72rem;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--coral);
    font-weight: 700;
    margin: 0 0 8px;
}
.page-title {
    font-family: var(--font-display);
    font-size: clamp(1.8rem, 3vw, 2.6rem);
    font-weight: 500;
    line-height: 1.05;
    margin: 0;
}
.page-title em {
    font-style: italic;
    font-weight: 400;
    color: var(--coral);
}
.page-lede {
    margin-top: 10px;
    color: var(--text-muted);
    max-width: 60ch;
    font-size: 0.96rem;
}
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* Bootstrap card overrides */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.card.shadow-sm { box-shadow: var(--shadow-sm) !important; }
.card-header, .card-footer { background: transparent; border-color: var(--border); padding: 14px 20px; }
.card-body { padding: 20px; }

.panel-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 16px 22px;
    border-bottom: 1px solid var(--border);
}
.panel-head h3 { font-size: 1rem; font-weight: 600; font-family: var(--font-body); letter-spacing: -0.01em; }

/* Stat cards */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 18px; }
.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 22px 22px 24px;
    position: relative;
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat::after {
    content: "";
    position: absolute;
    top: -40px; right: -40px;
    width: 120px; height: 120px;
    background: radial-gradient(circle, var(--coral-soft) 0%, transparent 65%);
    opacity: 0.7;
    pointer-events: none;
}
.stat--gold::after { background: radial-gradient(circle, var(--gold-soft), transparent 65%); }
.stat--emerald::after { background: radial-gradient(circle, var(--emerald-soft), transparent 65%); }
.stat-eyebrow {
    font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.14em;
    color: var(--text-muted); font-weight: 700; margin: 0;
}
.stat-value {
    font-family: var(--font-display);
    font-weight: 500;
    font-size: 3rem;
    line-height: 1;
    margin: 14px 0 6px;
    letter-spacing: -0.03em;
}
.stat-meta { color: var(--text-muted); font-size: 0.85rem; margin: 0; position: relative; z-index: 2; }
.stat-link {
    margin-top: 14px;
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 0.85rem; color: var(--coral); font-weight: 600;
    position: relative; z-index: 2;
}
.stat-link:hover { color: var(--primary-strong); }

/* ---------- Buttons -------------------------------------------------- */

.btn {
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 0.92rem;
    border-radius: var(--r-sm);
    padding: 0.55rem 1.05rem;
    transition: all 0.15s;
    letter-spacing: -0.005em;
}
.btn-sm { padding: 0.4rem 0.7rem; font-size: 0.82rem; border-radius: var(--r-xs); }
.btn-lg { padding: 0.8rem 1.5rem; font-size: 1rem; border-radius: var(--r-md); }

.btn-primary {
    --bs-btn-bg: var(--coral);
    --bs-btn-border-color: var(--coral);
    --bs-btn-hover-bg: var(--primary-strong);
    --bs-btn-hover-border-color: var(--primary-strong);
    --bs-btn-active-bg: var(--primary-strong);
    --bs-btn-active-border-color: var(--primary-strong);
    box-shadow: 0 6px 14px -6px rgba(227, 88, 70, 0.5);
}
.btn-primary:hover { box-shadow: 0 10px 22px -6px rgba(227, 88, 70, 0.6); transform: translateY(-1px); }

.btn-outline-primary {
    --bs-btn-color: var(--coral);
    --bs-btn-border-color: var(--coral);
    --bs-btn-hover-bg: var(--coral-soft);
    --bs-btn-hover-color: var(--primary-strong);
    --bs-btn-hover-border-color: var(--coral);
}
.btn-outline-secondary {
    --bs-btn-color: var(--ink-700);
    --bs-btn-border-color: var(--border-strong);
    --bs-btn-hover-bg: var(--cream-100);
    --bs-btn-hover-color: var(--ink-900);
    --bs-btn-hover-border-color: var(--ink-300);
    background: var(--paper);
}
.btn-outline-success {
    --bs-btn-color: var(--emerald);
    --bs-btn-border-color: var(--emerald);
    --bs-btn-hover-bg: var(--emerald-soft);
    --bs-btn-hover-color: #1f5638;
    --bs-btn-hover-border-color: var(--emerald);
}
.btn-outline-danger {
    --bs-btn-color: var(--coral);
    --bs-btn-border-color: var(--coral);
    --bs-btn-hover-bg: var(--coral-soft);
    --bs-btn-hover-color: var(--primary-strong);
    --bs-btn-hover-border-color: var(--coral);
}
.btn-link { color: var(--text-muted); text-decoration: none; font-weight: 500; }
.btn-link:hover { color: var(--coral); }

/* ---------- Forms ---------------------------------------------------- */

.form-label {
    font-weight: 600;
    font-size: 0.82rem;
    color: var(--ink-700);
    letter-spacing: 0.01em;
    margin-bottom: 6px;
}

.form-control, .form-select {
    border-radius: var(--r-sm);
    border-color: var(--border-strong);
    background: var(--paper);
    padding: 0.55rem 0.85rem;
    font-size: 0.94rem;
    color: var(--text);
    box-shadow: none;
    transition: all 0.15s;
}
.form-control:focus, .form-select:focus {
    border-color: var(--coral);
    box-shadow: var(--shadow-glow);
    background: var(--paper);
    color: var(--text);
}
.form-control::placeholder { color: var(--ink-300); }

.form-control-color { padding: 0.25rem; height: 42px; }

.form-check-input {
    border-color: var(--border-strong);
    width: 1.05rem; height: 1.05rem;
}
.form-check-input:checked {
    background-color: var(--coral);
    border-color: var(--coral);
}
.form-check-input:focus { box-shadow: var(--shadow-glow); border-color: var(--coral); }

textarea.form-control { font-family: var(--font-body); }

/* ---------- Tables --------------------------------------------------- */

.table {
    --bs-table-bg: transparent;
    color: var(--text);
    margin-bottom: 0;
}
.table > thead > tr > th {
    font-family: var(--font-body);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-muted);
    font-weight: 700;
    border-bottom: 1px solid var(--border);
    padding: 14px 16px;
    background: rgba(244, 236, 219, 0.4);
}
.table-light > thead > tr > th, .table > thead.table-light > tr > th { background: rgba(244, 236, 219, 0.4); }
.table > tbody > tr > td {
    padding: 14px 16px;
    border-color: var(--border);
    vertical-align: middle;
}
.table-hover > tbody > tr:hover > td { background: rgba(244, 236, 219, 0.5); }
.table strong { font-weight: 600; }
.table a { color: var(--ink-900); font-weight: 600; }
.table a:hover { color: var(--coral); }

.table-danger, .table-warning {
    --bs-table-bg: transparent;
}
.table-danger > td, .table > tbody > tr.table-danger > td { background: rgba(227, 88, 70, 0.07); color: var(--ink-800); }
.table-warning > td, .table > tbody > tr.table-warning > td { background: rgba(216, 162, 59, 0.1); color: var(--ink-800); }

/* ---------- Badges --------------------------------------------------- */

.badge {
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 0.7rem;
    letter-spacing: 0.04em;
    padding: 0.35em 0.6em;
    border-radius: 999px;
    text-transform: uppercase;
}
.badge.text-bg-primary { background: var(--ink-800) !important; color: var(--cream-50) !important; }
.badge.text-bg-success { background: var(--emerald-soft) !important; color: #1f5638 !important; }
.badge.text-bg-danger  { background: var(--coral-soft) !important; color: var(--primary-strong) !important; }
.badge.text-bg-warning { background: var(--gold-soft) !important; color: #6b4d10 !important; }
.badge.text-bg-secondary { background: var(--ink-100) !important; color: var(--ink-700) !important; }
.badge.text-bg-light { background: var(--cream-100) !important; color: var(--ink-700) !important; }
.badge.text-bg-info { background: rgba(38, 96, 184, 0.14) !important; color: #1d4382 !important; }

/* ---------- Alerts (in-flow, used inside forms) ---------------------- */

.alert {
    border-radius: var(--r-md);
    border: 1px solid var(--border);
    padding: 14px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: var(--paper);
    box-shadow: var(--shadow-sm);
    font-size: 0.93rem;
}
.alert-success { background: var(--emerald-soft); color: #1f5638; border-color: rgba(44,122,78,0.2); }
.alert-warning { background: var(--gold-soft); color: #6b4d10; border-color: rgba(216,162,59,0.3); }
.alert-error,
.alert-danger { background: var(--coral-soft); color: var(--primary-strong); border-color: rgba(227,88,70,0.25); }
.alert-info { background: rgba(38,96,184,0.08); color: #1d4382; border-color: rgba(38,96,184,0.2); }
.alert .btn-close { padding: 6px; }

/* ---------- Toast popups (Django messages -> top-right toasts) ------ */

.toast-stack {
    position: fixed;
    top: calc(var(--topbar-h) + 16px);
    right: 24px;
    z-index: 1080;
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-width: min(420px, calc(100vw - 48px));
    pointer-events: none;
}
.toast-msg {
    pointer-events: auto;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: start;
    gap: 12px;
    padding: 14px 14px 14px 16px;
    background: var(--paper);
    color: var(--ink-900);
    border: 1px solid var(--border);
    border-left: 4px solid var(--ink-700);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-lg);
    font-size: 0.92rem;
    line-height: 1.45;
    transform: translateX(120%);
    opacity: 0;
    animation: toast-in 0.45s cubic-bezier(0.32, 0.72, 0.4, 1) forwards;
}
.toast-msg.is-leaving {
    animation: toast-out 0.3s cubic-bezier(0.4, 0, 0.7, 0.4) forwards;
}
@keyframes toast-in {
    0%   { transform: translateX(120%); opacity: 0; }
    60%  { transform: translateX(-6px); opacity: 1; }
    100% { transform: translateX(0); opacity: 1; }
}
@keyframes toast-out {
    0%   { transform: translateX(0); opacity: 1; }
    100% { transform: translateX(120%); opacity: 0; }
}
.toast-msg__icon { font-size: 1.2rem; line-height: 1.2; margin-top: 1px; }
.toast-msg__body { color: var(--ink-900); font-weight: 500; }
.toast-msg__close {
    border: 0; background: transparent; color: var(--ink-400);
    cursor: pointer; padding: 2px 6px; line-height: 1;
    border-radius: var(--r-xs);
    font-size: 0.9rem; align-self: flex-start; margin-top: 1px;
    transition: color 0.15s, background 0.15s;
}
.toast-msg__close:hover { color: var(--ink-900); background: var(--cream-100); }
.toast-msg--success { border-left-color: var(--emerald); }
.toast-msg--success .toast-msg__icon { color: var(--emerald); }
.toast-msg--warning { border-left-color: var(--gold); }
.toast-msg--warning .toast-msg__icon { color: var(--gold); }
.toast-msg--error,
.toast-msg--danger { border-left-color: var(--coral); }
.toast-msg--error .toast-msg__icon,
.toast-msg--danger .toast-msg__icon { color: var(--coral); }
.toast-msg--info { border-left-color: var(--sky); }
.toast-msg--info .toast-msg__icon { color: var(--sky); }
@media (max-width: 575.98px) {
    .toast-stack { right: 12px; left: 12px; top: calc(var(--topbar-h) + 12px); max-width: none; }
}

/* ---------- Auth (login) layout -------------------------------------- */

body.auth-page {
    background:
        radial-gradient(circle at 15% 20%, rgba(227, 88, 70, 0.18), transparent 45%),
        radial-gradient(circle at 85% 80%, rgba(216, 162, 59, 0.18), transparent 45%),
        var(--cream-50);
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 32px;
}
.auth-shell {
    width: 100%;
    max-width: 980px;
    background: var(--paper);
    border-radius: var(--r-xl);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    display: grid;
    grid-template-columns: 1.1fr 1fr;
    border: 1px solid var(--border);
}
@media (max-width: 768px) { .auth-shell { grid-template-columns: 1fr; } .auth-aside { display: none; } }
.auth-aside {
    background: linear-gradient(150deg, var(--ink-900) 0%, var(--ink-800) 60%, var(--plum) 110%);
    color: var(--cream-50);
    padding: 48px 44px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    position: relative;
    overflow: hidden;
}
.auth-aside::before {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 80% 0%, rgba(227, 88, 70, 0.4), transparent 60%);
    pointer-events: none;
}
.auth-aside-mark {
    width: 56px; height: 56px;
    border-radius: var(--r-md);
    background: linear-gradient(135deg, var(--coral), #f08a4d);
    display: grid; place-items: center;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1.8rem;
    color: white;
    box-shadow: 0 12px 32px -10px rgba(227,88,70,0.5);
    position: relative;
}
.auth-aside h1 {
    font-family: var(--font-display);
    font-size: 2.6rem;
    color: var(--cream-50);
    line-height: 1.05;
    font-weight: 400;
    margin-top: 32px;
    position: relative;
}
.auth-aside h1 em { color: var(--gold); font-style: italic; font-weight: 400; }
.auth-aside p {
    color: rgba(244, 236, 219, 0.7);
    margin-top: 14px;
    line-height: 1.6;
    max-width: 36ch;
    position: relative;
}
.auth-aside-foot {
    font-size: 0.78rem;
    color: rgba(244, 236, 219, 0.5);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    position: relative;
}

.auth-form-wrap {
    padding: 48px 44px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}
.auth-form-wrap h2 {
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 500;
    margin-bottom: 8px;
}
.auth-form-wrap .lede { color: var(--text-muted); margin-bottom: 32px; }

/* ---------- Calendar overrides (build on the dashboard) -------------- */

#calendar { min-height: 70vh; }
.fc { font-family: var(--font-body); }
.fc .fc-toolbar-title {
    font-family: var(--font-display);
    font-weight: 500;
    font-size: 1.5rem;
    letter-spacing: -0.01em;
}
.fc .fc-button-primary {
    background: var(--paper);
    border-color: var(--border-strong);
    color: var(--ink-700);
    font-weight: 600;
    font-size: 0.85rem;
    padding: 0.4rem 0.8rem;
    border-radius: var(--r-sm);
    text-transform: capitalize;
    box-shadow: var(--shadow-sm);
}
.fc .fc-button-primary:hover {
    background: var(--cream-100);
    color: var(--ink-900);
    border-color: var(--ink-300);
}
.fc .fc-button-primary:not(:disabled).fc-button-active,
.fc .fc-button-primary:not(:disabled):active {
    background: var(--ink-900) !important;
    border-color: var(--ink-900) !important;
    color: var(--cream-50) !important;
}
.fc-theme-standard td, .fc-theme-standard th, .fc-theme-standard .fc-scrollgrid {
    border-color: var(--border);
}

/* Mobile: stack toolbar chunks vertically so prev/next, title, view buttons don't crash into each other */
@media (max-width: 767.98px) {
    .fc .fc-header-toolbar.fc-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    .fc .fc-toolbar-chunk {
        display: flex;
        justify-content: center;
        flex-wrap: wrap;
        gap: 6px;
    }
    .fc .fc-toolbar-title {
        text-align: center;
        font-size: 1.2rem;
        margin: 0;
    }
    .fc .fc-button-primary {
        padding: 0.35rem 0.7rem;
        font-size: 0.8rem;
    }
    .fc .fc-button-group { flex-wrap: wrap; gap: 4px; }
}
.fc .fc-col-header-cell { background: rgba(244, 236, 219, 0.4); }
.fc .fc-col-header-cell-cushion {
    font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.12em;
    color: var(--text-muted); font-weight: 700; padding: 10px 6px;
}
.fc .fc-daygrid-day-number {
    font-family: var(--font-display);
    font-weight: 500;
    color: var(--ink-700);
    padding: 8px;
}
.fc .fc-day-today { background: rgba(227, 88, 70, 0.04) !important; }
.fc .fc-day-today .fc-daygrid-day-number { color: var(--coral); }

/* User filter sidebar */
.user-filter-list .list-group-item { border: none; background: transparent; }
.user-filter-btn {
    border: 0;
    background: transparent;
    padding: 0.45rem 0.6rem;
    border-radius: var(--r-sm);
    transition: background 0.15s, opacity 0.15s;
    width: 100%;
}
.user-filter-btn:hover { background: var(--cream-100); }
.user-filter-btn .user-name {
    font-size: 0.92rem;
    color: var(--ink-900);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
}
.user-filter-btn .user-check { color: var(--emerald); font-size: 1rem; flex-shrink: 0; }
.user-filter-btn.inactive { opacity: 0.4; }
.user-filter-btn.inactive .user-check { visibility: hidden; }
.user-filter-btn.inactive .user-avatar { filter: grayscale(0.7); }

.user-avatar {
    width: 30px; height: 30px;
    border-radius: 50%;
    color: #fff;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 0.74rem; font-weight: 700;
    flex-shrink: 0; letter-spacing: 0.02em;
    box-shadow: 0 0 0 2px rgba(255,255,255,0.7);
}

/* Avatars on calendar events */
.fc-event { overflow: hidden; }
.fc-timegrid-event,
.fc-timegrid-event .fc-event-main { position: relative; }
.event-avatars {
    display: inline-flex;
    gap: 2px;
    margin-right: 4px;
    vertical-align: middle;
}
.event-avatars--corner {
    position: absolute;
    top: 4px; right: 4px;
    margin-right: 0;
    z-index: 2;
}
.event-avatar {
    width: 22px; height: 22px;
    border-radius: 50%;
    color: #fff;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 0.7rem; font-weight: 700; line-height: 1;
    box-shadow: 0 0 0 1.5px rgba(255,255,255,0.7);
}
.fc-list-event .event-avatars { margin-right: 6px; }

/* ---------- Document detail (invoice/quote) -------------------------- */

.doc-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 28px;
    box-shadow: var(--shadow-sm);
}

.doc-meta-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 16px;
    padding: 14px 0;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    margin: 18px 0 22px;
}
.doc-meta-grid dt {
    font-size: 0.7rem; letter-spacing: 0.12em; text-transform: uppercase;
    color: var(--text-muted); font-weight: 700; margin: 0 0 4px;
}
.doc-meta-grid dd {
    font-family: var(--font-display);
    font-weight: 500;
    margin: 0;
    color: var(--ink-900);
    font-size: 1rem;
}

/* ---------- Line-item formset --------------------------------------- */

.line-row input,
.line-row select {
    padding: 0.35rem 0.55rem;
    font-size: 0.88rem;
    border-radius: var(--r-xs);
}

/* ---------- Documents (folders + notes + files) --------------------- */

.docs-breadcrumb {
    margin-top: 10px;
    font-size: 0.85rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
}
.docs-breadcrumb a {
    color: var(--text-muted);
    transition: color 0.15s;
}
.docs-breadcrumb a:hover { color: var(--coral); }
.docs-breadcrumb .sep { font-size: 0.7rem; opacity: 0.5; }
.docs-breadcrumb span { color: var(--ink-900); font-weight: 600; }

.folder-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 14px;
}
.folder-tile {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    text-decoration: none;
    color: inherit;
    transition: all 0.15s;
    box-shadow: var(--shadow-sm);
}
.folder-tile:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--coral);
    color: inherit;
}
.folder-tile__icon {
    color: var(--gold);
    font-size: 1.7rem;
    flex-shrink: 0;
}
.folder-tile__body { flex: 1; min-width: 0; }
.folder-tile__name {
    font-family: var(--font-display);
    font-weight: 500;
    font-size: 1.05rem;
    margin: 0;
    color: var(--ink-900);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.folder-tile__meta {
    margin: 2px 0 0;
    font-size: 0.78rem;
    color: var(--text-muted);
}
.folder-tile__chev { color: var(--ink-300); }

.doc-list {
    list-style: none;
    margin: 0;
    padding: 0;
}
.doc-row {
    display: grid;
    grid-template-columns: 44px 1fr auto;
    align-items: center;
    gap: 14px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}
.doc-row:last-child { border-bottom: 0; }
.doc-row:hover { background: rgba(244, 236, 219, 0.4); }
.doc-row__icon {
    width: 44px; height: 44px;
    border-radius: var(--r-sm);
    background: var(--cream-100);
    color: var(--ink-700);
    display: grid; place-items: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}
.doc-row__icon--note { background: rgba(216,162,59,0.15); color: var(--gold); }
.doc-row__icon--image { background: rgba(44,122,78,0.12); color: var(--emerald); }
.doc-row__icon--video { background: rgba(38,96,184,0.12); color: var(--sky); }
.doc-row__icon--audio { background: rgba(93,47,106,0.12); color: var(--plum); }
.doc-row__icon--pdf { background: var(--coral-soft); color: var(--coral); }
.doc-row__main { min-width: 0; }
.doc-row__title {
    margin: 0;
    font-weight: 600;
    color: var(--ink-900);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.doc-row__meta {
    margin: 2px 0 0;
    font-size: 0.78rem;
    color: var(--text-muted);
}
.doc-row__actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}
.doc-row__actions form { margin: 0; }

.empty-state {
    text-align: center;
    padding: 56px 20px;
    color: var(--text-muted);
}
.empty-state i {
    font-size: 3rem;
    opacity: 0.45;
    color: var(--ink-400);
}
.empty-state p { margin-top: 14px; }

.storage-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 18px 22px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
}
.storage-card__head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 16px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}
.storage-card__stats {
    margin: 6px 0 0;
    font-size: 0.95rem;
    color: var(--ink-700);
    display: flex;
    align-items: baseline;
    gap: 8px;
}
.storage-card__stats strong {
    font-family: var(--font-display);
    font-weight: 500;
    font-size: 1.45rem;
    color: var(--ink-900);
    letter-spacing: -0.01em;
}
.storage-card__percent {
    margin-left: auto;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}
.storage-card__hint { max-width: 62ch; }
.storage-bar {
    height: 8px;
    background: var(--cream-100);
    border-radius: 999px;
    overflow: hidden;
}
.storage-bar__fill {
    height: 100%;
    background: linear-gradient(90deg, var(--emerald), #3a9971);
    border-radius: 999px;
    transition: width 0.4s ease;
}
.storage-card--warn .storage-bar__fill { background: linear-gradient(90deg, var(--gold), #b8861f); }
.storage-card--high .storage-bar__fill { background: linear-gradient(90deg, var(--coral), var(--primary-strong)); }
.storage-card--high .storage-card__percent { color: var(--coral); }

.note-view {
    font-family: var(--font-body);
    font-size: 1rem;
    line-height: 1.65;
    color: var(--ink-800);
    background: var(--cream-50);
    padding: 22px 26px;
    border-radius: var(--r-md);
    border-left: 3px solid var(--coral);
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* ---------- Misc ----------------------------------------------------- */

.divider {
    border: 0;
    height: 1px;
    background: var(--border);
    margin: 24px 0;
}
.list-group-item { border-color: var(--border); }
.list-group-flush > .list-group-item:first-child { border-top: 0; }
.list-group-flush > .list-group-item:last-child { border-bottom: 0; }

.shadow-sm { box-shadow: var(--shadow-sm) !important; }

/* Modal polish */
.modal-content {
    border-radius: var(--r-lg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
}
.modal-header { border-color: var(--border); padding: 18px 22px; }
.modal-title { font-family: var(--font-display); font-weight: 500; font-size: 1.4rem; }
.modal-body { padding: 22px; }
.modal-footer { border-color: var(--border); padding: 16px 22px; gap: 8px; }

/* Selection / focus */
::selection { background: var(--coral-soft); color: var(--ink-900); }

/* Print clean-up */
@media print {
    .sidebar, .topbar, .app-footer { display: none !important; }
    .app-shell { display: block; }
    .app-content { padding: 0; }
}
