/* ==========================================================================
   AgricSoft Design System
   Poultry Farm Management Platform — Custom UI
   Colors: primary green #04673a, accent gold #E4A11B, danger red #a40621
   ========================================================================== */

/* ---------- 1. Reset & Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
html { font-size: 14px; -webkit-text-size-adjust: 100%; -webkit-font-smoothing: antialiased; }
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-app);
    min-height: 100vh;
    overflow-x: hidden;
}
img, svg, video { max-width: 100%; height: auto; display: block; }
a { color: var(--brand-600); text-decoration: none; transition: color .15s; }
a:hover { color: var(--brand-700); text-decoration: underline; }
button { font: inherit; cursor: pointer; border: none; background: none; }
input, textarea, select { font: inherit; color: inherit; }
table { border-collapse: collapse; width: 100%; }

/* ---------- 2. Theme tokens ---------- */
:root {
    /* Brand colors — sourced from existing app */
    --brand-50:  #e8f3ee;
    --brand-100: #c5e1d2;
    --brand-200: #9bcdb3;
    --brand-300: #6cb88f;
    --brand-400: #3ea372;
    --brand-500: #168656;
    --brand-600: #04673a;     /* Primary brand */
    --brand-700: #035330;
    --brand-800: #023f25;
    --brand-900: #012b19;

    --gold:    #E4A11B;
    --gold-50: #fcf3df;
    --gold-700:#b87f10;

    --danger:    #a40621;
    --danger-50: #fbe6ea;
    --danger-700:#7d041a;

    --info:    #1a73e8;
    --info-50: #e8f0fe;

    --success-50: var(--brand-50);
    --success: var(--brand-600);

    /* Neutrals */
    --gray-25:  #fafbfc;
    --gray-50:  #f6f7f9;
    --gray-100: #ecedf0;
    --gray-200: #dfe1e6;
    --gray-300: #c1c7d0;
    --gray-400: #97a0af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #0f172a;

    /* Light theme assignments */
    --bg-app:        var(--gray-50);
    --bg-surface:    #ffffff;
    --bg-surface-2:  var(--gray-25);
    --bg-elevated:   #ffffff;
    --bg-hover:      var(--gray-100);
    --bg-input:      #ffffff;
    --bg-disabled:   var(--gray-100);

    --text-primary:    var(--gray-900);
    --text-secondary:  var(--gray-600);
    --text-tertiary:   var(--gray-500);
    --text-muted:      var(--gray-400);
    --text-on-brand:   #ffffff;
    --text-link:       var(--brand-600);

    --border:        var(--gray-200);
    --border-strong: var(--gray-300);
    --border-input:  var(--gray-300);
    --border-focus:  var(--brand-500);

    --shadow-xs: 0 1px 2px 0 rgba(15, 23, 42, .04);
    --shadow-sm: 0 1px 3px 0 rgba(15, 23, 42, .06), 0 1px 2px -1px rgba(15, 23, 42, .06);
    --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, .08), 0 2px 4px -2px rgba(15, 23, 42, .06);
    --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, .10), 0 4px 6px -4px rgba(15, 23, 42, .08);
    --shadow-xl: 0 20px 25px -5px rgba(15, 23, 42, .12), 0 8px 10px -6px rgba(15, 23, 42, .08);

    --radius-sm:  4px;
    --radius:     8px;
    --radius-md:  10px;
    --radius-lg:  14px;
    --radius-xl:  20px;
    --radius-full: 999px;

    --space-1: 4px;  --space-2: 8px; --space-3: 12px; --space-4: 16px;
    --space-5: 20px; --space-6: 24px; --space-7: 32px; --space-8: 40px;
    --space-9: 48px; --space-10: 64px;

    --font-xs: .75rem;  /* 10.5 */
    --font-sm: .85rem;  /* 12   */
    --font-base: .95rem;/* 13.3 */
    --font-md: 1rem;
    --font-lg: 1.125rem;
    --font-xl: 1.375rem;
    --font-2xl:1.75rem;
    --font-3xl:2.25rem;

    --sidebar-w: 248px;
    --sidebar-w-collapsed: 72px;
    --topbar-h: 60px;

    --transition-fast: 120ms cubic-bezier(.4,0,.2,1);
    --transition: 180ms cubic-bezier(.4,0,.2,1);
}

/* Dark theme (toggled via [data-theme="dark"] on <html>) */
:root[data-theme="dark"] {
    --bg-app:       #0b1220;
    --bg-surface:   #131a2a;
    --bg-surface-2: #0f1626;
    --bg-elevated:  #1a2238;
    --bg-hover:     #1f2940;
    --bg-input:     #1a2238;
    --bg-disabled:  #1a2238;

    --text-primary:    #e6ebf5;
    --text-secondary:  #aab4c8;
    --text-tertiary:   #8a94a8;
    --text-muted:      #6b7589;
    --text-on-brand:   #ffffff;
    --text-link:       #6cb88f;

    --border:        #1f2940;
    --border-strong: #2b3553;
    --border-input:  #2b3553;
    --border-focus:  var(--brand-400);

    --gray-50:  #0f1626;
    --gray-100: #1a2238;
    --gray-200: #1f2940;
    --gray-300: #2b3553;

    --shadow-sm: 0 1px 3px 0 rgba(0,0,0,.4);
    --shadow-md: 0 4px 8px 0 rgba(0,0,0,.45);
    --shadow-lg: 0 12px 24px 0 rgba(0,0,0,.55);
}

/* ---------- 3. Layout: sidebar + topbar + content ---------- */
.app-shell { display: flex; min-height: 100vh; }
.app-sidebar {
    width: var(--sidebar-w);
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    flex-shrink: 0;
    position: fixed; top: 0; left: 0; bottom: 0;
    display: flex; flex-direction: column;
    z-index: 100;
    transition: transform var(--transition), width var(--transition);
}
.app-sidebar__brand {
    display: flex; align-items: center; gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    height: var(--topbar-h);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.app-sidebar__brand img { height: 32px; width: auto; }
.app-sidebar__brand-text {
    font-weight: 700; font-size: 1.05rem; color: var(--brand-600);
    letter-spacing: -0.02em;
}
:root[data-theme="dark"] .app-sidebar__brand-text { color: var(--brand-300); }

.app-sidebar__nav {
    flex: 1; overflow-y: auto;
    padding: var(--space-3) var(--space-2);
    scrollbar-width: thin;
}
.app-sidebar__nav::-webkit-scrollbar { width: 6px; }
.app-sidebar__nav::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

.nav-section { margin-bottom: var(--space-4); }
.nav-section__title {
    text-transform: uppercase; font-size: .68rem; font-weight: 600;
    color: var(--text-muted); letter-spacing: .08em;
    padding: var(--space-2) var(--space-3); margin-bottom: var(--space-1);
}
.nav-item { list-style: none; }
.nav-link {
    display: flex; align-items: center; gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    color: var(--text-secondary); font-size: var(--font-base); font-weight: 500;
    border-radius: var(--radius);
    transition: background var(--transition-fast), color var(--transition-fast);
    text-decoration: none;
    white-space: nowrap; overflow: hidden;
}
.nav-link:hover { background: var(--bg-hover); color: var(--text-primary); text-decoration: none; }
.nav-link.is-active { background: var(--brand-50); color: var(--brand-700); }
:root[data-theme="dark"] .nav-link.is-active { background: rgba(4, 103, 58, 0.18); color: var(--brand-300); }
.nav-link__icon {
    width: 20px; height: 20px; flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center;
}
.nav-link__icon svg { width: 18px; height: 18px; }
.nav-link__text { flex: 1; }
.nav-link__chevron { transition: transform var(--transition-fast); width: 14px; height: 14px; opacity: .6; }
.nav-item.is-open > .nav-link .nav-link__chevron { transform: rotate(180deg); }
.nav-submenu {
    list-style: none;
    padding-left: var(--space-7);
    max-height: 0; overflow: hidden;
    transition: max-height var(--transition);
}
.nav-item.is-open > .nav-submenu { max-height: 500px; }
.nav-submenu .nav-link { font-size: .85rem; padding: 6px var(--space-3); }

/* App main */
.app-main {
    flex: 1; margin-left: var(--sidebar-w);
    min-width: 0; display: flex; flex-direction: column; min-height: 100vh;
    transition: margin-left var(--transition);
    overflow-x: clip;
}
.app-topbar {
    height: var(--topbar-h);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    padding: 0 var(--space-6);
    display: flex; align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 50;
}
.app-topbar__left { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.app-topbar__title {
    font-size: 1.05rem; font-weight: 600; color: var(--text-primary);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.app-topbar__actions { display: flex; align-items: center; gap: var(--space-2); }

.menu-toggle {
    width: 36px; height: 36px;
    display: none; align-items: center; justify-content: center;
    border-radius: var(--radius); color: var(--text-secondary);
}
.menu-toggle:hover { background: var(--bg-hover); }
.menu-toggle svg { width: 20px; height: 20px; }

.app-content { flex: 1; padding: var(--space-6); }
.app-footer {
    padding: var(--space-4) var(--space-6);
    color: var(--text-tertiary); font-size: var(--font-sm);
    border-top: 1px solid var(--border);
    background: var(--bg-surface);
}

/* Mobile nav */
.app-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,.45);
    z-index: 99; opacity: 0; pointer-events: none;
    transition: opacity var(--transition);
}
.app-overlay.is-active { opacity: 1; pointer-events: auto; }
@media (max-width: 1024px) {
    .app-sidebar { transform: translateX(-100%); }
    .app-sidebar.is-open { transform: translateX(0); box-shadow: var(--shadow-xl); }
    .app-main { margin-left: 0; }
    .menu-toggle { display: inline-flex; }
    .app-content { padding: var(--space-4); }
}

/* ---------- 4. Page header ---------- */
.page-header {
    display: flex; flex-wrap: wrap; gap: var(--space-4);
    justify-content: space-between; align-items: flex-start;
    margin-bottom: var(--space-6);
}
.page-header__title { font-size: var(--font-2xl); font-weight: 700; color: var(--text-primary); margin-bottom: 4px; letter-spacing: -.01em; }
.page-header__subtitle { color: var(--text-secondary); font-size: var(--font-base); }
.page-header__actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }

.breadcrumb { display: flex; gap: var(--space-2); font-size: var(--font-sm); color: var(--text-tertiary); margin-bottom: var(--space-2); flex-wrap: wrap; }
.breadcrumb a { color: var(--text-tertiary); }
.breadcrumb a:hover { color: var(--brand-600); }
.breadcrumb__sep { color: var(--text-muted); }

/* ---------- 5. Cards ---------- */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xs);
    overflow: hidden;
}
.card__header {
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
}
.card__title { font-size: 1rem; font-weight: 600; color: var(--text-primary); }
.card__subtitle { color: var(--text-secondary); font-size: var(--font-sm); margin-top: 2px; }
.card__body { padding: var(--space-5); }
.card__footer {
    padding: var(--space-4) var(--space-5); border-top: 1px solid var(--border);
    background: var(--bg-surface-2);
}

/* Stat cards */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--space-4); }
.stat-card {
    background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-md);
    padding: var(--space-5); transition: transform var(--transition), box-shadow var(--transition);
}
.stat-card:hover { box-shadow: var(--shadow-md); }
.stat-card__label { color: var(--text-secondary); font-size: var(--font-sm); font-weight: 500; margin-bottom: var(--space-2); display: flex; align-items: center; gap: var(--space-2); }
.stat-card__icon {
    width: 36px; height: 36px; border-radius: var(--radius);
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--brand-50); color: var(--brand-600);
}
.stat-card__icon svg { width: 18px; height: 18px; }
.stat-card__icon.is-gold { background: var(--gold-50); color: var(--gold-700); }
.stat-card__icon.is-danger { background: var(--danger-50); color: var(--danger); }
.stat-card__icon.is-info { background: var(--info-50); color: var(--info); }
.stat-card__value { font-size: 1.85rem; font-weight: 700; color: var(--text-primary); letter-spacing: -.02em; line-height: 1.1; }
.stat-card__delta { margin-top: var(--space-2); font-size: var(--font-sm); display: flex; align-items: center; gap: 4px; }
.stat-card__delta.is-up { color: var(--brand-600); }
.stat-card__delta.is-down { color: var(--danger); }

/* ---------- 6. Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
    padding: 9px 16px;
    font-size: var(--font-base); font-weight: 500;
    border-radius: var(--radius);
    border: 1px solid transparent;
    cursor: pointer; transition: background-color var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast), box-shadow var(--transition-fast);
    white-space: nowrap; user-select: none;
    line-height: 1.25;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--brand-500); outline-offset: 2px; }
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.btn-primary { background: var(--brand-600); color: var(--text-on-brand); }
.btn-primary:hover:not(:disabled) { background: var(--brand-700); color: #fff; text-decoration: none; }

.btn-secondary { background: var(--bg-surface); color: var(--text-primary); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--bg-hover); text-decoration: none; }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-700); color: #fff; text-decoration: none; }

.btn-ghost { color: var(--text-secondary); background: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--bg-hover); color: var(--text-primary); text-decoration: none; }

.btn-link { background: transparent; color: var(--brand-600); padding: 4px 8px; }
.btn-link:hover { background: transparent; text-decoration: underline; }

.btn-sm { padding: 6px 12px; font-size: .8rem; }
.btn-lg { padding: 12px 24px; font-size: 1rem; }
.btn-icon { padding: 8px; width: 36px; height: 36px; }
.btn-icon.btn-sm { width: 30px; height: 30px; padding: 6px; }
.btn-block { width: 100%; }

.btn-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn-loading::after {
    content: ''; position: absolute; top: 50%; left: 50%;
    width: 16px; height: 16px; margin: -8px 0 0 -8px;
    border: 2px solid currentColor; border-top-color: transparent;
    border-radius: 50%; animation: spin .6s linear infinite;
    color: var(--text-on-brand);
}
.btn-secondary.btn-loading::after, .btn-ghost.btn-loading::after { color: var(--text-primary); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 7. Forms ---------- */
.form-grid { display: grid; gap: var(--space-4); grid-template-columns: 1fr; }
.form-grid-2 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.form-grid-3 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group--span-2 { grid-column: span 2; }
@media (max-width: 600px) { .form-group--span-2 { grid-column: span 1; } }

.form-label {
    font-size: var(--font-sm); font-weight: 500; color: var(--text-primary);
    display: flex; align-items: center; gap: 4px;
}
.form-label__required { color: var(--danger); }
.form-label__hint { color: var(--text-tertiary); font-weight: 400; margin-left: auto; font-size: var(--font-xs); }

.form-control {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border-input);
    border-radius: var(--radius);
    padding: 10px 12px;
    font-size: var(--font-base);
    color: var(--text-primary);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.form-control::placeholder { color: var(--text-muted); }
.form-control:hover:not(:disabled) { border-color: var(--border-strong); }
.form-control:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(4, 103, 58, .12);
}
.form-control:disabled { background: var(--bg-disabled); color: var(--text-tertiary); cursor: not-allowed; }
.form-control[readonly] { background: var(--bg-surface-2); }
textarea.form-control { min-height: 90px; resize: vertical; line-height: 1.5; }
select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 12px center;
    padding-right: 36px;
}

.form-control.is-invalid { border-color: var(--danger); }
.form-control.is-invalid:focus { box-shadow: 0 0 0 3px rgba(164, 6, 33, .14); }
.form-control.is-valid { border-color: var(--brand-500); }

.form-error { color: var(--danger); font-size: var(--font-xs); display: flex; gap: 4px; align-items: center; }
.form-error svg { width: 12px; height: 12px; flex-shrink: 0; }
.form-help { color: var(--text-tertiary); font-size: var(--font-xs); }

/* Input addon group */
.input-group { display: flex; align-items: stretch; }
.input-group .form-control { border-radius: var(--radius) 0 0 var(--radius); }
.input-group__addon {
    display: inline-flex; align-items: center; padding: 0 12px;
    background: var(--bg-surface-2); border: 1px solid var(--border-input); border-left: 0;
    border-radius: 0 var(--radius) var(--radius) 0;
    color: var(--text-secondary); font-size: var(--font-sm);
}
.input-group__icon-wrap { position: relative; }
.input-group__icon-wrap .form-control { padding-left: 38px; }
.input-group__icon-wrap > svg, .input-group__icon-wrap > .input-icon {
    position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
    width: 16px; height: 16px; color: var(--text-muted); pointer-events: none;
}
.input-group__icon-wrap--right .form-control { padding-right: 38px; padding-left: 12px; }
.input-group__icon-wrap--right > svg, .input-group__icon-wrap--right > .input-icon { left: auto; right: 12px; pointer-events: auto; cursor: pointer; }

/* Checkbox / radio / toggle */
.check-row { display: flex; align-items: flex-start; gap: var(--space-2); cursor: pointer; }
.check-row input[type="checkbox"], .check-row input[type="radio"] {
    width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px;
    accent-color: var(--brand-600); cursor: pointer;
}
.check-row__text { font-size: var(--font-base); color: var(--text-primary); user-select: none; line-height: 1.4; }
.check-row__hint { color: var(--text-tertiary); font-size: var(--font-xs); display: block; margin-top: 2px; }

.toggle { position: relative; display: inline-block; width: 44px; height: 24px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle__slider {
    position: absolute; cursor: pointer; inset: 0;
    background: var(--gray-300); border-radius: 999px;
    transition: background var(--transition-fast);
}
.toggle__slider::before {
    content: ""; position: absolute; height: 18px; width: 18px;
    left: 3px; top: 3px; background: white; border-radius: 50%;
    transition: transform var(--transition-fast);
    box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle input:checked + .toggle__slider { background: var(--brand-600); }
.toggle input:checked + .toggle__slider::before { transform: translateX(20px); }

.toggle-row { display: flex; align-items: center; gap: var(--space-3); }

/* ---------- 8. Tables ---------- */
.table-toolbar {
    display: flex; flex-wrap: wrap; gap: var(--space-3);
    align-items: center; justify-content: space-between;
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border);
}
.table-toolbar__search { flex: 1; max-width: 320px; min-width: 180px; }
.table-toolbar__actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }

.table-wrap { width: 100%; overflow-x: auto; }
.data-table { width: 100%; font-size: var(--font-base); }
.data-table thead th {
    text-align: left; padding: 12px 16px;
    font-weight: 600; color: var(--text-secondary); font-size: var(--font-sm);
    background: var(--bg-surface-2);
    border-bottom: 1px solid var(--border);
    white-space: nowrap; user-select: none;
    text-transform: uppercase; letter-spacing: .04em;
}
.data-table thead th[data-sortable] { cursor: pointer; }
.data-table thead th[data-sortable]:hover { color: var(--text-primary); }
.data-table thead th[data-sortable]::after {
    content: '⇅'; opacity: .35; margin-left: 6px; font-size: .75em;
}
.data-table thead th.is-sorted-asc::after { content: '↑'; opacity: 1; color: var(--brand-600); }
.data-table thead th.is-sorted-desc::after { content: '↓'; opacity: 1; color: var(--brand-600); }

.data-table tbody td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
    vertical-align: middle;
}
.data-table tbody tr { transition: background var(--transition-fast); }
.data-table tbody tr:hover { background: var(--bg-hover); }
.data-table tbody tr:last-child td { border-bottom: 0; }

/* Externally-funded expense rows: subtle left accent + tinted background */
.data-table tbody tr.expense-row--external td:first-child { box-shadow: inset 3px 0 0 var(--info); }
.data-table tbody tr.expense-row--external { background: var(--info-50); }
.data-table tbody tr.expense-row--external:hover { background: var(--info-50); filter: brightness(.98); }
[data-theme="dark"] .data-table tbody tr.expense-row--external { background: rgba(46, 134, 222, .08); }
[data-theme="dark"] .data-table tbody tr.expense-row--external:hover { background: rgba(46, 134, 222, .14); }

.table-actions { display: inline-flex; gap: var(--space-1); }

.table-pagination {
    display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center;
    justify-content: space-between;
    padding: var(--space-3) var(--space-4); border-top: 1px solid var(--border);
    color: var(--text-secondary); font-size: var(--font-sm);
}
.pagination { display: flex; gap: 4px; align-items: center; }
.pagination__item {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 32px; height: 32px; padding: 0 8px;
    border-radius: var(--radius-sm); background: transparent;
    color: var(--text-secondary); font-size: var(--font-sm);
    transition: background var(--transition-fast);
}
.pagination__item:hover:not(:disabled):not(.is-active) { background: var(--bg-hover); }
.pagination__item.is-active { background: var(--brand-600); color: white; cursor: default; }
.pagination__item:disabled { opacity: .35; cursor: not-allowed; }

.empty-state {
    padding: var(--space-9) var(--space-4); text-align: center; color: var(--text-secondary);
}
.empty-state__icon {
    width: 64px; height: 64px; margin: 0 auto var(--space-4);
    background: var(--bg-surface-2); border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center; color: var(--text-muted);
}
.empty-state__icon svg { width: 28px; height: 28px; }
.empty-state__title { font-size: 1.05rem; font-weight: 600; color: var(--text-primary); margin-bottom: 4px; }
.empty-state__desc { color: var(--text-secondary); font-size: var(--font-sm); margin-bottom: var(--space-4); }

/* ---------- 9. Badges, chips ---------- */
.badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 9px; border-radius: var(--radius-full);
    font-size: .72rem; font-weight: 600;
    background: var(--gray-100); color: var(--gray-700);
    text-transform: uppercase; letter-spacing: .04em;
}
.badge-success { background: var(--brand-50); color: var(--brand-700); }
.badge-danger  { background: var(--danger-50); color: var(--danger-700); }
.badge-warning { background: var(--gold-50); color: var(--gold-700); }
.badge-info    { background: var(--info-50); color: var(--info); }
.badge-soft    { background: var(--bg-surface-2); color: var(--text-secondary); }
.badge-dot::before {
    content: ''; width: 6px; height: 6px; border-radius: 50%;
    background: currentColor; display: inline-block;
}

/* ---------- 10. Modal ---------- */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(15, 23, 42, .55);
    display: flex; align-items: center; justify-content: center;
    z-index: 200; padding: var(--space-4);
    opacity: 0; pointer-events: none; transition: opacity var(--transition);
    backdrop-filter: blur(4px);
}
.modal-overlay.is-open { opacity: 1; pointer-events: auto; }
.modal {
    background: var(--bg-elevated);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    width: 100%; max-width: 520px; max-height: calc(100vh - 32px);
    display: flex; flex-direction: column;
    transform: translateY(20px) scale(.97); opacity: 0;
    transition: transform var(--transition), opacity var(--transition);
}
.modal-overlay.is-open .modal { transform: translateY(0) scale(1); opacity: 1; }
.modal-lg { max-width: 720px; }
.modal-xl { max-width: 960px; }
.modal-sm { max-width: 380px; }
.modal__header {
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
    flex-shrink: 0;
}
.modal__title { font-size: 1.05rem; font-weight: 600; color: var(--text-primary); }
.modal__close {
    width: 32px; height: 32px; border-radius: var(--radius);
    color: var(--text-tertiary);
    display: inline-flex; align-items: center; justify-content: center;
}
.modal__close:hover { background: var(--bg-hover); color: var(--text-primary); }
.modal__close svg { width: 18px; height: 18px; }
.modal__body { padding: var(--space-5); overflow-y: auto; flex: 1; }
.modal > form {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
}
.modal__footer {
    padding: var(--space-4) var(--space-5); border-top: 1px solid var(--border);
    display: flex; gap: var(--space-2); justify-content: flex-end; flex-shrink: 0;
    background: var(--bg-surface-2);
}

/* ---------- 11. Tabs ---------- */
.tabs {
    display: flex; gap: var(--space-1);
    border-bottom: 1px solid var(--border);
    margin-bottom: var(--space-5);
    overflow-x: auto;
    scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
    padding: 10px 16px; font-size: var(--font-base); font-weight: 500;
    color: var(--text-secondary); border-bottom: 2px solid transparent;
    cursor: pointer; transition: color var(--transition-fast), border-bottom-color var(--transition-fast);
    background: transparent; white-space: nowrap;
    display: inline-flex; align-items: center; gap: var(--space-2);
}
.tab svg { width: 14px; height: 14px; }
.tab:hover { color: var(--text-primary); }
.tab.is-active { color: var(--brand-600); border-bottom-color: var(--brand-600); }
.tab-panel { display: none; }
.tab-panel.is-active { display: block; }

/* ---------- 12. Toasts ---------- */
.toast-stack {
    position: fixed; top: var(--space-5); right: var(--space-5);
    display: flex; flex-direction: column; gap: var(--space-2); z-index: 300;
    max-width: calc(100vw - 32px); width: 360px;
}
.toast {
    background: var(--bg-elevated); border: 1px solid var(--border);
    border-left: 4px solid var(--brand-600);
    border-radius: var(--radius); padding: var(--space-3) var(--space-4);
    box-shadow: var(--shadow-lg);
    display: flex; align-items: flex-start; gap: var(--space-3);
    transform: translateX(20px); opacity: 0;
    animation: toastIn .25s forwards;
}
.toast.is-leaving { animation: toastOut .25s forwards; }
@keyframes toastIn { to { transform: translateX(0); opacity: 1; } }
@keyframes toastOut { to { transform: translateX(20px); opacity: 0; } }
.toast--success { border-left-color: var(--brand-600); }
.toast--error   { border-left-color: var(--danger); }
.toast--warning { border-left-color: var(--gold); }
.toast--info    { border-left-color: var(--info); }
.toast__icon { flex-shrink: 0; width: 22px; height: 22px; display: inline-flex; }
.toast__icon svg { width: 22px; height: 22px; }
.toast--success .toast__icon { color: var(--brand-600); }
.toast--error .toast__icon { color: var(--danger); }
.toast--warning .toast__icon { color: var(--gold-700); }
.toast--info .toast__icon { color: var(--info); }
.toast__body { flex: 1; min-width: 0; }
.toast__title { font-weight: 600; color: var(--text-primary); font-size: var(--font-base); margin-bottom: 2px; }
.toast__desc  { color: var(--text-secondary); font-size: var(--font-sm); word-wrap: break-word; }
.toast__close {
    color: var(--text-tertiary); width: 24px; height: 24px;
    border-radius: 4px; display: inline-flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.toast__close:hover { background: var(--bg-hover); color: var(--text-primary); }
.toast__close svg { width: 14px; height: 14px; }

/* ---------- 13. Alerts (inline) ---------- */
.alert {
    display: flex; align-items: flex-start; gap: var(--space-3);
    padding: var(--space-3) var(--space-4); border-radius: var(--radius);
    font-size: var(--font-base); margin-bottom: var(--space-4);
    border: 1px solid;
}
.alert svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 2px; }
.alert--success { background: var(--brand-50); color: var(--brand-700); border-color: rgba(4,103,58,.20); }
.alert--error   { background: var(--danger-50); color: var(--danger-700); border-color: rgba(164,6,33,.20); }
.alert--warning { background: var(--gold-50); color: var(--gold-700); border-color: rgba(228,161,27,.30); }
.alert--info    { background: var(--info-50); color: var(--info); border-color: rgba(26,115,232,.20); }
.alert__title { font-weight: 600; margin-bottom: 2px; }
.alert__list { margin-top: 6px; padding-left: 20px; }

/* ---------- 14. Dropdown ---------- */
.dropdown { position: relative; display: inline-block; }
.dropdown__menu {
    position: absolute; top: calc(100% + 6px); right: 0;
    min-width: 200px;
    background: var(--bg-elevated); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-lg);
    padding: var(--space-1); z-index: 60;
    opacity: 0; transform: translateY(-4px); pointer-events: none;
    transition: opacity var(--transition-fast), transform var(--transition-fast);
}
.dropdown.is-open .dropdown__menu { opacity: 1; transform: translateY(0); pointer-events: auto; }
.dropdown__menu--left { right: auto; left: 0; }
.dropdown__item {
    display: flex; align-items: center; gap: var(--space-2);
    padding: 8px 12px; border-radius: var(--radius-sm);
    color: var(--text-primary); font-size: var(--font-base);
    width: 100%; text-align: left;
    transition: background var(--transition-fast);
}
.dropdown__item:hover { background: var(--bg-hover); text-decoration: none; color: var(--text-primary); }
.dropdown__item svg { width: 16px; height: 16px; opacity: .7; }
.dropdown__separator { height: 1px; background: var(--border); margin: 4px 0; }

/* ---------- 15. Avatar ---------- */
.avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--brand-600); color: white;
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: .85rem; flex-shrink: 0;
    text-transform: uppercase; user-select: none;
}
.avatar-sm { width: 28px; height: 28px; font-size: .72rem; }
.avatar-lg { width: 52px; height: 52px; font-size: 1.1rem; }
.avatar-xl { width: 88px; height: 88px; font-size: 1.6rem; }

/* ---------- 16. Auth Layout ---------- */
.auth-shell {
    min-height: 100vh; display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}
.auth-shell__form-side {
    background: var(--bg-surface);
    display: flex; align-items: center; justify-content: center;
    padding: var(--space-6);
    min-height: 100vh;
}
.auth-shell__hero-side {
    background: linear-gradient(135deg, var(--brand-600) 0%, var(--brand-800) 100%);
    color: #fff; display: flex; align-items: center; justify-content: center;
    padding: var(--space-8); position: relative; overflow: hidden;
}
.auth-shell__hero-side::before {
    content: ''; position: absolute; inset: 0;
    background-image:
        radial-gradient(circle at 20% 20%, rgba(228,161,27,.12) 0, transparent 40%),
        radial-gradient(circle at 80% 80%, rgba(255,255,255,.08) 0, transparent 35%);
}
.auth-form { width: 100%; max-width: 400px; }
.auth-form__brand {
    display: flex; align-items: center; gap: var(--space-3);
    margin-bottom: var(--space-7);
}
.auth-form__brand img { height: 40px; }
.auth-form__title { font-size: 1.65rem; font-weight: 700; color: var(--text-primary); margin-bottom: 8px; letter-spacing: -.02em; }
.auth-form__subtitle { color: var(--text-secondary); margin-bottom: var(--space-6); font-size: var(--font-base); }
.auth-form__footer { text-align: center; margin-top: var(--space-5); color: var(--text-secondary); font-size: var(--font-sm); }

.auth-hero { position: relative; max-width: 480px; text-align: center; }
.auth-hero__logo { height: 64px; margin: 0 auto var(--space-6); filter: brightness(0) invert(1); }
.auth-hero__title { font-size: 2rem; font-weight: 700; margin-bottom: var(--space-3); letter-spacing: -.02em; }
.auth-hero__desc { color: rgba(255,255,255,.85); font-size: var(--font-md); line-height: 1.6; }
.auth-hero__features {
    margin-top: var(--space-7); display: grid; gap: var(--space-3); text-align: left;
}
.auth-hero__feature {
    display: flex; align-items: center; gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: rgba(255,255,255,.08);
    border: 1px solid rgba(255,255,255,.12);
    border-radius: var(--radius);
    backdrop-filter: blur(4px);
}
.auth-hero__feature-icon {
    width: 36px; height: 36px; border-radius: var(--radius);
    background: rgba(228,161,27,.18); color: var(--gold);
    display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.auth-hero__feature-icon svg { width: 18px; height: 18px; }
.auth-hero__feature-text { font-size: var(--font-base); }
.auth-hero__feature-text strong { display: block; font-weight: 600; margin-bottom: 1px; }
.auth-hero__feature-text span { color: rgba(255,255,255,.75); font-size: var(--font-sm); }

@media (max-width: 900px) {
    .auth-shell { grid-template-columns: 1fr; }
    .auth-shell__hero-side { display: none; }
}

/* ---------- 17. Tooltip ---------- */
[data-tooltip] { position: relative; }
[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
    background: var(--gray-900); color: #fff; padding: 4px 8px;
    font-size: var(--font-xs); border-radius: var(--radius-sm); white-space: nowrap;
    z-index: 70; pointer-events: none;
}

/* ---------- 18. Detail page layout ---------- */
.detail-grid {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: var(--space-6);
    align-items: flex-start;
}
@media (max-width: 900px) { .detail-grid { grid-template-columns: 1fr; } }

.detail-info { display: grid; gap: var(--space-2); }
.detail-info__row {
    display: grid; grid-template-columns: 140px 1fr; gap: var(--space-3);
    padding: 10px 0; border-bottom: 1px solid var(--border);
}
.detail-info__row:last-child { border-bottom: 0; }
.detail-info__label { color: var(--text-secondary); font-size: var(--font-sm); }
.detail-info__value { color: var(--text-primary); font-size: var(--font-base); font-weight: 500; word-break: break-word; }

.profile-summary { text-align: center; padding: var(--space-5) var(--space-4); }
.profile-summary__avatar { margin: 0 auto var(--space-3); }
.profile-summary__name { font-size: 1.1rem; font-weight: 600; color: var(--text-primary); }
.profile-summary__role { color: var(--text-secondary); font-size: var(--font-sm); margin-top: 2px; }

/* ---------- 19. Charts container ---------- */
.chart-card { background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--space-5); }
.chart-card__header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: var(--space-4); gap: var(--space-3); }
.chart-card__title { font-size: var(--font-base); font-weight: 600; color: var(--text-primary); }
.chart-card__subtitle { color: var(--text-secondary); font-size: var(--font-sm); margin-top: 2px; }
.chart-card__body { position: relative; min-height: 240px; }

/* ---------- 20. Utilities ---------- */
.u-flex { display: flex; }
.u-inline-flex { display: inline-flex; }
.u-grid { display: grid; }
.u-block { display: block; }
.u-hidden { display: none !important; }
.u-items-center { align-items: center; }
.u-items-start { align-items: flex-start; }
.u-justify-between { justify-content: space-between; }
.u-justify-end { justify-content: flex-end; }
.u-justify-center { justify-content: center; }
.u-gap-1 { gap: var(--space-1); } .u-gap-2 { gap: var(--space-2); } .u-gap-3 { gap: var(--space-3); } .u-gap-4 { gap: var(--space-4); } .u-gap-6 { gap: var(--space-6); }
.u-flex-1 { flex: 1; }
.u-flex-wrap { flex-wrap: wrap; }
.u-flex-col { flex-direction: column; }
.u-w-full { width: 100%; }
.u-text-center { text-align: center; }
.u-text-right { text-align: right; }
.u-text-secondary { color: var(--text-secondary); }
.u-text-tertiary { color: var(--text-tertiary); }
.u-text-success { color: var(--brand-600); }
.u-text-danger { color: var(--danger); }
.u-text-warning { color: var(--gold-700); }
.u-text-sm { font-size: var(--font-sm); }
.u-text-xs { font-size: var(--font-xs); }
.u-text-lg { font-size: var(--font-lg); }
.u-font-medium { font-weight: 500; }
.u-font-semibold { font-weight: 600; }
.u-font-bold { font-weight: 700; }
.u-mt-1 { margin-top: var(--space-1); } .u-mt-2 { margin-top: var(--space-2); } .u-mt-3 { margin-top: var(--space-3); } .u-mt-4 { margin-top: var(--space-4); } .u-mt-6 { margin-top: var(--space-6); }
.u-mb-1 { margin-bottom: var(--space-1); } .u-mb-2 { margin-bottom: var(--space-2); } .u-mb-3 { margin-bottom: var(--space-3); } .u-mb-4 { margin-bottom: var(--space-4); } .u-mb-6 { margin-bottom: var(--space-6); }
.u-mr-2 { margin-right: var(--space-2); }
.u-ml-auto { margin-left: auto; }
.u-truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.u-break-word { word-break: break-word; }
.u-no-shrink { flex-shrink: 0; }
.u-cursor-pointer { cursor: pointer; }
@media (max-width: 768px) { .u-hidden-mobile { display: none !important; } }
@media (min-width: 769px) { .u-hidden-desktop { display: none !important; } }

/* Print styles */
@media print {
    .app-sidebar, .app-topbar, .app-footer, .page-header__actions, .table-toolbar, .table-pagination { display: none !important; }
    .app-main { margin-left: 0 !important; }
    .card, body { box-shadow: none !important; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* ==========================================================================
   PHASE 2 RICH UI ADDITIONS — Premium dashboard, KPI sparklines, polished tables
   ========================================================================== */

/* Premium KPI cards with accent strip */
.kpi-card {
    position: relative;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    overflow: hidden;
    transition: transform .18s, box-shadow .18s;
}
.kpi-card:hover { box-shadow: 0 8px 24px rgba(0,0,0,.08); }
.kpi-card::before {
    content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
    background: var(--brand-600);
}
.kpi-card.kpi-card--gold::before    { background: var(--gold); }
.kpi-card.kpi-card--danger::before  { background: var(--danger); }
.kpi-card.kpi-card--info::before    { background: var(--info); }
.kpi-card__header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: var(--space-3); }
.kpi-card__label  { font-size: var(--font-xs); color: var(--text-tertiary); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi-card__icon   {
    width: 36px; height: 36px; border-radius: 10px;
    background: var(--brand-50); color: var(--brand-700);
    display: flex; align-items: center; justify-content: center;
}
.kpi-card.kpi-card--gold   .kpi-card__icon { background: var(--gold-50); color: var(--gold-700); }
.kpi-card.kpi-card--danger .kpi-card__icon { background: var(--danger-50); color: var(--danger-700); }
.kpi-card.kpi-card--info   .kpi-card__icon { background: var(--info-50); color: var(--info); }
.kpi-card__value  { font-size: 1.85rem; font-weight: 700; color: var(--text-primary); line-height: 1.1; }
.kpi-card__suffix { font-size: 1rem; color: var(--text-tertiary); font-weight: 500; }
.kpi-card__sub    { margin-top: var(--space-1); font-size: var(--font-xs); color: var(--text-secondary); display: flex; align-items: center; gap: 4px; }
.kpi-card__delta--up   { color: var(--brand-600); }
.kpi-card__delta--down { color: var(--danger); }

/* Chart wrapper */
.chart-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
}
.chart-card__header { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--space-4); }
.chart-card__title { font-size: var(--font-base); font-weight: 600; color: var(--text-primary); }
.chart-card__subtitle { font-size: var(--font-xs); color: var(--text-tertiary); margin-top: 2px; }
.chart-card__body { position: relative; min-height: 280px; }
.chart-card__legend { display: flex; gap: var(--space-3); flex-wrap: wrap; margin-top: var(--space-3); }
.chart-card__legend-item { display: flex; align-items: center; gap: 6px; font-size: var(--font-xs); color: var(--text-secondary); }
.chart-card__legend-dot { width: 10px; height: 10px; border-radius: 2px; }

/* Mini stat for inside chart cards */
.mini-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(80px, 1fr)); gap: var(--space-2); }
.mini-stat__value { font-weight: 600; color: var(--text-primary); font-size: var(--font-base); }
.mini-stat__label { font-size: var(--font-xs); color: var(--text-tertiary); margin-top: 2px; }

/* Section heading */
.section-head { display: flex; justify-content: space-between; align-items: center; margin: var(--space-5) 0 var(--space-3); }
.section-head__title { font-size: var(--font-base); font-weight: 600; color: var(--text-primary); }
.section-head__sub { font-size: var(--font-xs); color: var(--text-tertiary); }

/* Polished status pills */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.pill::before { content:''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill--success { background: var(--brand-50); color: var(--brand-700); }
.pill--warning { background: var(--gold-50); color: var(--gold-700); }
.pill--danger  { background: var(--danger-50); color: var(--danger-700); }
.pill--info    { background: var(--info-50); color: var(--info); }
.pill--neutral { background: var(--gray-100); color: var(--gray-700); }

/* Soft cards + outlined cards */
.card { border-radius: var(--radius-lg); }
.card__header { padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.card__body { padding: var(--space-5); }
.card__title { font-size: var(--font-base); font-weight: 600; color: var(--text-primary); }
.card__subtitle { font-size: var(--font-xs); color: var(--text-tertiary); margin-top: 2px; }

/* Row card for kanban-style request lists */
.req-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--space-4);
    margin-bottom: var(--space-3);
    transition: transform .14s, box-shadow .14s;
}
.req-card:hover { box-shadow: 0 4px 14px rgba(0,0,0,.06); }
.req-card__header { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--space-2); margin-bottom: var(--space-2); }
.req-card__title { font-size: var(--font-sm); font-weight: 600; color: var(--text-primary); flex: 1; }
.req-card__desc  { font-size: var(--font-xs); color: var(--text-secondary); margin-bottom: var(--space-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.req-card__meta  { display: flex; justify-content: space-between; align-items: center; font-size: 11px; color: var(--text-tertiary); padding-top: var(--space-2); border-top: 1px solid var(--border); }

/* Funnel columns layout */
.funnel-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: var(--space-4); }
.funnel-col { background: var(--bg-surface-2); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.funnel-col__header { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.funnel-col__title { font-weight: 600; font-size: var(--font-sm); color: var(--text-primary); }
.funnel-col__count { font-size: var(--font-xs); padding: 2px 8px; border-radius: 999px; background: var(--bg-surface); color: var(--text-secondary); }
.funnel-col__body { padding: var(--space-3); min-height: 120px; }
.funnel-col__body .req-card:last-child { margin-bottom: 0; }

/* Rich data tables */
.data-table thead th {
    background: var(--bg-surface-2);
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-tertiary);
    font-weight: 600;
    padding: 12px 16px;
}
.data-table tbody td { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.data-table tbody tr:hover { background: var(--bg-surface-2); }
.data-table tbody tr:last-child td { border-bottom: 0; }

/* Table action group */
.table-actions { display: inline-flex; gap: 4px; }
.btn-icon { width: 32px; height: 32px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg-surface-2); color: var(--text-primary); }

/* Detail info grid */
.detail-info { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
@media (max-width: 720px) { .detail-info { grid-template-columns: 1fr; } }
.detail-info--stacked { grid-template-columns: 1fr !important; }
.detail-info__row { display: grid; grid-template-columns: 180px 1fr; gap: var(--space-3); padding: 12px var(--space-4); border-bottom: 1px solid var(--border); }
.detail-info__row:last-child, .detail-info__row:nth-last-child(2):nth-child(odd) { border-bottom: 0; }
.detail-info--stacked .detail-info__row:last-child { border-bottom: 0; }
.detail-info--stacked .detail-info__row:nth-last-child(2):nth-child(odd) { border-bottom: 1px solid var(--border); }
.detail-info__label { color: var(--text-tertiary); font-size: var(--font-xs); font-weight: 500; }
.detail-info__value { color: var(--text-primary); font-size: var(--font-sm); font-weight: 500; word-break: break-word; }

/* Avatar (small circles) */
.avatar { display: inline-flex; align-items: center; justify-content: center; background: var(--brand-100); color: var(--brand-700); font-weight: 600; border-radius: 50%; font-size: 11px; }
.avatar--xs { width: 24px; height: 24px; font-size: 10px; }
.avatar--sm { width: 32px; height: 32px; font-size: 12px; }
.avatar--md { width: 40px; height: 40px; font-size: 14px; }
.avatar--lg { width: 56px; height: 56px; font-size: 18px; }

/* Form grid responsiveness fix */
.form-grid { display: grid; grid-template-columns: 1fr; gap: var(--space-4); }
.form-grid.form-grid-2 { grid-template-columns: repeat(2, 1fr); }
.form-grid.form-grid-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 720px) {
    .form-grid.form-grid-2, .form-grid.form-grid-3 { grid-template-columns: 1fr; }
}
.form-group--span-2 { grid-column: span 2; }
.form-group--span-3 { grid-column: span 3; }

/* Empty state */
.empty-state { text-align: center; padding: var(--space-8) var(--space-4); }
.empty-state__icon { display: inline-flex; align-items: center; justify-content: center; width: 56px; height: 56px; border-radius: 50%; background: var(--bg-surface-2); color: var(--text-tertiary); margin-bottom: var(--space-3); }
.empty-state__title { font-size: var(--font-base); font-weight: 600; color: var(--text-primary); margin-bottom: 4px; }
.empty-state__desc { font-size: var(--font-sm); color: var(--text-tertiary); }

/* Submenu fix — collapse cleanly */
.nav-submenu {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 0;
    overflow: hidden;
    transition: max-height .25s ease;
}
.nav-submenu li { padding: 0; }
.nav-submenu .nav-link {
    padding: 8px 16px 8px 44px;
    font-size: 13px;
    color: var(--text-secondary);
    border-radius: 6px;
    margin: 1px 8px;
}
.nav-submenu .nav-link:hover { background: var(--gray-100); color: var(--text-primary); text-decoration: none; }
.nav-submenu .nav-link.is-active { background: var(--brand-50); color: var(--brand-700); }
.nav-item.has-children > .nav-link { cursor: pointer; }
.nav-item.has-children.is-open > .nav-submenu { max-height: 400px; }
.nav-item.has-children.is-open > .nav-link .nav-link__chevron { transform: rotate(180deg); }
.nav-link__chevron { transition: transform .2s; margin-left: auto; opacity: 0.5; }
[data-theme="dark"] .nav-submenu .nav-link:hover { background: rgba(255,255,255,.05); }

/* Page header tweaks */
.page-header { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: var(--space-3); margin-bottom: var(--space-5); padding-bottom: var(--space-4); border-bottom: 1px solid var(--border); }
.page-header__title { font-size: 1.5rem; font-weight: 700; color: var(--text-primary); margin-bottom: 4px; line-height: 1.2; }
.page-header__subtitle { color: var(--text-secondary); font-size: var(--font-sm); }
.page-header__back { display: inline-flex; align-items: center; gap: 6px; font-size: var(--font-xs); color: var(--text-tertiary); margin-bottom: 8px; }

/* Tab styling polish */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); padding: 0 var(--space-4); flex-wrap: wrap; overflow-x: auto; }
.tabs .tab {
    background: transparent; border: 0; padding: 12px 16px; cursor: pointer;
    font-size: var(--font-sm); font-weight: 500; color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    transition: color .15s, border-color .15s; white-space: nowrap;
    display: inline-flex; align-items: center; gap: 8px;
}
.tabs .tab:hover { color: var(--text-primary); }
.tabs .tab.is-active { color: var(--brand-700); border-bottom-color: var(--brand-600); }
.tab-panel { display: none; }
.tab-panel.is-active { display: block; }
/* Guard against animation/transform restarts on style recalc — keep tab-panel layout stable */
.tab-panel, .tab-panel.is-active { animation: none !important; transform: none !important; }

/* Profile summary card (employee details sidebar) */
.profile-summary {
    text-align: center;
    padding: var(--space-5) var(--space-4);
    border-bottom: 1px solid var(--border);
}
.profile-summary__avatar { margin: 0 auto var(--space-3); width: 72px; height: 72px; }
.profile-summary__name { font-size: 1rem; font-weight: 600; color: var(--text-primary); }
.profile-summary__role { color: var(--text-tertiary); font-size: var(--font-xs); margin-top: 2px; }

/* Table inline status icons */
.icon-up { color: var(--brand-600); }
.icon-down { color: var(--danger); }

/* Full-width textarea */
textarea.form-control { min-height: 100px; resize: vertical; }

/* Print optimization */
@media print {
    .app-sidebar, .app-topbar, .page-header__back, .no-print { display: none !important; }
    .app-main { margin-left: 0 !important; padding: 0 !important; }
}

/* Subtle utility helpers */
.u-mt-0 { margin-top: 0 !important; }
.u-mt-1 { margin-top: var(--space-1); }
.u-mt-2 { margin-top: var(--space-2); }
.u-mt-3 { margin-top: var(--space-3); }
.u-mt-4 { margin-top: var(--space-4); }
.u-mt-5 { margin-top: var(--space-5); }
.u-mt-6 { margin-top: var(--space-6); }
.u-mb-0 { margin-bottom: 0 !important; }
.u-mb-1 { margin-bottom: var(--space-1); }
.u-mb-2 { margin-bottom: var(--space-2); }
.u-mb-3 { margin-bottom: var(--space-3); }
.u-mb-4 { margin-bottom: var(--space-4); }
.u-mb-5 { margin-bottom: var(--space-5); }
.u-mb-6 { margin-bottom: var(--space-6); }
.u-grid { display: grid; }
.u-grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-3); }
.u-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-3); }
.u-grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-3); }
@media (max-width: 900px) {
    .u-grid-3, .u-grid-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
    .u-grid-2, .u-grid-3, .u-grid-4 { grid-template-columns: 1fr; }
}
.u-gap-2 { gap: var(--space-2); }
.u-gap-3 { gap: var(--space-3); }
.u-gap-4 { gap: var(--space-4); }
.u-flex { display: flex; }
.u-items-center { align-items: center; }
.u-items-end { align-items: flex-end; }
.u-justify-between { justify-content: space-between; }
.u-justify-end { justify-content: flex-end; }
.u-text-center { text-align: center; }
.u-text-right { text-align: right; }
.u-text-xs { font-size: var(--font-xs); }
.u-text-sm { font-size: var(--font-sm); }
.u-text-lg { font-size: var(--font-lg); }
.u-text-xl { font-size: var(--font-xl); }
.u-text-2xl { font-size: 1.5rem; }
.u-text-primary { color: var(--brand-700); }
.u-text-secondary { color: var(--text-secondary); }
.u-text-tertiary { color: var(--text-tertiary); }
.u-text-success { color: var(--brand-600); }
.u-text-danger  { color: var(--danger); }
.u-text-warning { color: var(--gold-700); }
.u-font-medium { font-weight: 500; }
.u-font-semibold { font-weight: 600; }
.u-font-bold { font-weight: 700; }
.u-w-full { width: 100%; }
.u-hidden { display: none; }
.u-truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Modal sizes */
.modal { width: 100%; max-width: 500px; }
.modal.modal-lg  { max-width: 720px; }
.modal.modal-xl  { max-width: 1000px; }
.modal.modal-2xl { max-width: 1200px; }

/* Input groups */
.input-group { position: relative; display: flex; align-items: stretch; }
.input-group .form-control { padding-right: 44px; }
.input-group__btn { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); background: transparent; border: 0; padding: 6px; color: var(--text-tertiary); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.input-group__btn:hover { color: var(--text-primary); }
.input-group__icon-wrap { position: relative; }
.input-group__icon-wrap > svg:first-child { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-tertiary); pointer-events: none; }
.input-group__icon-wrap > .form-control { padding-left: 38px; }
.input-group__icon-wrap--right > .form-control { padding-right: 38px; }
.input-group__icon-wrap--right > .input-icon { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); color: var(--text-tertiary); cursor: pointer; }

/* Check-row for inline checkboxes */
/* Check-row for stacked checkboxes (block-level, full width of container) */
.check-row { display: flex; width: 100%; align-items: center; gap: 8px; cursor: pointer; }
.check-row input[type="checkbox"] { width: 16px; height: 16px; flex-shrink: 0; cursor: pointer; }
.check-row__text { font-size: var(--font-sm); line-height: 1.4; min-width: 0; word-break: break-word; }

/* Permission grid — fixed responsive columns with safe shrinking (minmax(0, 1fr) prevents overflow) */
.permission-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-4);
    min-width: 0;
}
@media (min-width: 640px) {
    .permission-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 900px) {
    .permission-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 1200px) {
    .permission-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
.permission-grid > .card { min-width: 0; overflow: hidden; }

/* ==========================================================================
   FILE EXPLORER — Windows-like file/grid view for Document Vault
   ========================================================================== */

.file-view-toggle {
    display: inline-flex;
    background: var(--bg-surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 2px;
    flex-shrink: 0;
}
.file-view-toggle__btn {
    width: 32px; height: 28px;
    display: inline-flex; align-items: center; justify-content: center;
    background: transparent; color: var(--text-tertiary);
    border-radius: 6px; transition: background .15s, color .15s;
}
.file-view-toggle__btn:hover { color: var(--text-primary); }
.file-view-toggle__btn.is-active { background: var(--bg-surface); color: var(--brand-700); box-shadow: 0 1px 2px rgba(0,0,0,.06); }
[data-theme="dark"] .file-view-toggle__btn.is-active { color: var(--brand-300, #6cb88f); }

/* Grid view */
.file-explorer[data-view="grid"] {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: var(--space-3);
}

/* List view */
.file-explorer[data-view="list"] {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* File card — grid mode */
.file-card {
    position: relative;
    background: var(--bg-surface);
    border: 1px solid transparent;
    border-radius: var(--radius);
    padding: var(--space-4) var(--space-3) var(--space-3);
    transition: background .15s, border-color .15s, transform .12s;
    overflow: hidden;
    min-width: 0;
}
.file-card--clickable { cursor: pointer; }
.file-card:hover {
    background: var(--bg-surface-2);
    border-color: var(--border);
}
.file-card__hit {
    position: absolute; inset: 0; z-index: 1;
    text-decoration: none;
}
.file-card__hit:hover { text-decoration: none; }

/* File icon shape */
.file-card__icon {
    position: relative;
    width: 56px; height: 64px;
    margin: 0 auto var(--space-2);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.file-card__icon svg { width: 100%; height: 100%; display: block; }
.file-card__icon .file-icon-body { fill: var(--bg-surface-2); stroke: var(--border-strong); stroke-width: 1; }
.file-card__icon .file-icon-fold { fill: var(--bg-surface); stroke: var(--border-strong); stroke-width: 1; }

/* Extension badge sits on the lower half of the page */
.file-card__ext {
    position: absolute;
    bottom: 10px; left: 50%; transform: translateX(-50%);
    background: #616161; color: #fff;
    font-size: 9.5px; font-weight: 700;
    padding: 2px 6px; border-radius: 3px;
    letter-spacing: .04em; line-height: 1;
    text-transform: uppercase;
    max-width: 80%;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    box-shadow: 0 1px 2px rgba(0,0,0,.12);
}

/* Color variants — both badge background AND a tint of the icon body */
.file-card__icon--red    .file-card__ext { background: #d32f2f; }
.file-card__icon--green  .file-card__ext { background: #2e7d32; }
.file-card__icon--orange .file-card__ext { background: #ed6c02; }
.file-card__icon--purple .file-card__ext { background: #7b1fa2; }
.file-card__icon--indigo .file-card__ext { background: #3949ab; }
.file-card__icon--teal   .file-card__ext { background: #00796b; }
.file-card__icon--amber  .file-card__ext { background: #c97400; }
.file-card__icon--gray   .file-card__ext { background: #616161; }

.file-card__icon--red    .file-icon-body { fill: #fdecea; stroke: #f4c4be; }
.file-card__icon--green  .file-icon-body { fill: #ecf6ee; stroke: #c6e1cd; }
.file-card__icon--orange .file-icon-body { fill: #fff3e0; stroke: #f3d3a3; }
.file-card__icon--purple .file-icon-body { fill: #f3e8f7; stroke: #d6b9e0; }
.file-card__icon--indigo .file-icon-body { fill: #e8eaf6; stroke: #b9bfe1; }
.file-card__icon--teal   .file-icon-body { fill: #e0f2f1; stroke: #a3d5d1; }
.file-card__icon--amber  .file-icon-body { fill: #fff8e1; stroke: #ebd590; }

[data-theme="dark"] .file-card__icon .file-icon-body { fill: rgba(255,255,255,.04); stroke: rgba(255,255,255,.12); }
[data-theme="dark"] .file-card__icon .file-icon-fold { fill: rgba(255,255,255,.08); stroke: rgba(255,255,255,.12); }
[data-theme="dark"] .file-card__icon--red    .file-icon-body { fill: rgba(211,47,47,.18); stroke: rgba(211,47,47,.45); }
[data-theme="dark"] .file-card__icon--green  .file-icon-body { fill: rgba(46,125,50,.18); stroke: rgba(46,125,50,.45); }
[data-theme="dark"] .file-card__icon--orange .file-icon-body { fill: rgba(237,108,2,.18); stroke: rgba(237,108,2,.45); }
[data-theme="dark"] .file-card__icon--purple .file-icon-body { fill: rgba(123,31,162,.20); stroke: rgba(123,31,162,.45); }
[data-theme="dark"] .file-card__icon--indigo .file-icon-body { fill: rgba(57,73,171,.20); stroke: rgba(57,73,171,.45); }
[data-theme="dark"] .file-card__icon--teal   .file-icon-body { fill: rgba(0,121,107,.20); stroke: rgba(0,121,107,.45); }
[data-theme="dark"] .file-card__icon--amber  .file-icon-body { fill: rgba(201,116,0,.18); stroke: rgba(201,116,0,.45); }

/* Filename and meta */
.file-card__body { text-align: center; min-width: 0; }
.file-card__name {
    font-size: var(--font-sm);
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    word-break: break-word;
    line-height: 1.3;
    min-height: calc(1.3em * 2);
}
.file-card__meta {
    font-size: 11px;
    color: var(--text-tertiary);
    margin-top: 4px;
    display: flex; justify-content: center; gap: 4px; align-items: center;
}
.file-card__meta-sep { opacity: 0.5; }
.file-card__desc {
    font-size: 11px;
    color: var(--text-tertiary);
    margin-top: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-style: italic;
}

/* Hover action buttons in top-right corner */
.file-card__actions {
    position: absolute;
    top: 6px; right: 6px;
    display: flex; gap: 4px;
    opacity: 0;
    transition: opacity .15s;
    z-index: 2;
}
.file-card:hover .file-card__actions,
.file-card:focus-within .file-card__actions { opacity: 1; }
.file-card__action {
    width: 28px; height: 28px;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-secondary);
    text-decoration: none;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
    transition: background .12s, color .12s, border-color .12s;
}
.file-card__action:hover {
    background: var(--bg-hover, var(--bg-surface-2));
    color: var(--text-primary);
    text-decoration: none;
}
.file-card__action--danger:hover { color: var(--danger); border-color: var(--danger); }

/* List view: each card becomes a horizontal row */
.file-explorer[data-view="list"] .file-card {
    display: grid;
    grid-template-columns: 36px 1fr auto;
    gap: var(--space-3);
    align-items: center;
    padding: 8px 12px;
    border: 1px solid transparent;
}
.file-explorer[data-view="list"] .file-card:hover {
    background: var(--bg-surface-2);
    border-color: var(--border);
    transform: none;
}
.file-explorer[data-view="list"] .file-card__icon {
    width: 28px; height: 32px;
    margin: 0;
}
.file-explorer[data-view="list"] .file-card__ext {
    font-size: 7px;
    padding: 1px 3px;
    bottom: 4px;
    letter-spacing: 0;
}
.file-explorer[data-view="list"] .file-card__body { text-align: left; min-width: 0; }
.file-explorer[data-view="list"] .file-card__name {
    -webkit-line-clamp: 1;
    min-height: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}
.file-explorer[data-view="list"] .file-card__meta { justify-content: flex-start; margin-top: 2px; }
.file-explorer[data-view="list"] .file-card__desc { display: none; }
.file-explorer[data-view="list"] .file-card__actions {
    position: static;
    opacity: 1;
}

/* Responsive: tighter grid on small screens */
@media (max-width: 640px) {
    .file-explorer[data-view="grid"] {
        grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
        gap: var(--space-2);
    }
    .file-card__icon { width: 44px; height: 50px; }
    .file-card__ext { font-size: 8.5px; bottom: 8px; }
}

/* ==========================================================================
   RICH TEXT EDITOR — lightweight contenteditable with toolbar
   Markup: <div data-richtext><textarea ...></textarea></div>
   ========================================================================== */

.richtext {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-surface);
    overflow: hidden;
    transition: border-color .15s, box-shadow .15s;
}
.richtext:focus-within {
    border-color: var(--brand-600);
    box-shadow: 0 0 0 3px rgba(4, 103, 58, 0.12);
}

.richtext-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px;
    padding: 6px 8px;
    background: var(--bg-surface-2);
    border-bottom: 1px solid var(--border);
}
.richtext-toolbar__btn {
    height: 28px;
    min-width: 28px;
    padding: 0 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 5px;
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    transition: background .12s, color .12s, border-color .12s;
    user-select: none;
}
.richtext-toolbar__btn:hover {
    background: var(--bg-surface);
    color: var(--text-primary);
    border-color: var(--border);
}
.richtext-toolbar__btn:active { background: var(--brand-50); color: var(--brand-700); }
.richtext-toolbar__sep {
    width: 1px;
    height: 18px;
    background: var(--border);
    margin: 0 4px;
    flex-shrink: 0;
}

.richtext-editor {
    min-height: 140px;
    max-height: 360px;
    overflow-y: auto;
    padding: 12px 14px;
    background: var(--bg-surface);
    color: var(--text-primary);
    font-size: var(--font-base);
    line-height: 1.55;
    outline: none;
}
.richtext-editor[data-placeholder]:empty::before {
    content: attr(data-placeholder);
    color: var(--text-tertiary);
    pointer-events: none;
}
.richtext-editor p { margin: 0 0 8px; }
.richtext-editor p:last-child { margin-bottom: 0; }
.richtext-editor h1, .richtext-editor h2, .richtext-editor h3 {
    font-weight: 600;
    color: var(--text-primary);
    margin: 10px 0 6px;
    line-height: 1.3;
}
.richtext-editor h1 { font-size: 1.25rem; }
.richtext-editor h2 { font-size: 1.1rem; }
.richtext-editor h3 { font-size: 1rem; }
.richtext-editor ul, .richtext-editor ol {
    margin: 6px 0 8px;
    padding-left: 24px;
}
.richtext-editor ul li { list-style: disc; }
.richtext-editor ol li { list-style: decimal; }
.richtext-editor a { color: var(--brand-700); text-decoration: underline; }
.richtext-editor blockquote {
    margin: 8px 0;
    padding: 4px 12px;
    border-left: 3px solid var(--brand-600);
    color: var(--text-secondary);
}
.richtext-editor--invalid {
    border-color: var(--danger) !important;
    box-shadow: 0 0 0 3px rgba(164, 6, 33, 0.14);
}

/* Render saved rich-text content (in notes list) — same prose styling */
.richtext-output { line-height: 1.55; }
.richtext-output p { margin: 0 0 8px; }
.richtext-output p:last-child { margin-bottom: 0; }
.richtext-output ul, .richtext-output ol { margin: 6px 0 8px; padding-left: 24px; }
.richtext-output ul li { list-style: disc; }
.richtext-output ol li { list-style: decimal; }
.richtext-output strong { font-weight: 600; }
.richtext-output em { font-style: italic; }
.richtext-output a { color: var(--brand-700); text-decoration: underline; }

.chat-shell {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 0;
    height: calc(100vh - var(--topbar-height, 64px) - var(--space-8, 32px));
    min-height: 520px;
    background: var(--bg-surface, #fff);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: var(--radius-lg, 12px);
    overflow: hidden;
}

[data-theme="dark"] .chat-shell {
    background: var(--bg-surface);
    border-color: var(--border);
}

.chat-sidebar {
    border-right: 1px solid var(--border);
    background: var(--bg-surface-2, #f9fafb);
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.chat-sidebar__head {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-surface);
}

.chat-sidebar__title {
    font-size: 15px;
    font-weight: 600;
    margin: 0 0 8px 0;
    color: var(--text-primary);
}

.chat-sidebar__search {
    position: relative;
}

.chat-sidebar__search input {
    width: 100%;
    padding: 8px 12px 8px 32px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg-surface-2);
    font-size: 13px;
    color: var(--text-primary);
}

.chat-sidebar__search svg {
    position: absolute;
    left: 11px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-tertiary);
    pointer-events: none;
}

.chat-sidebar__tabs {
    display: flex;
    gap: 4px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-surface);
}

.chat-sidebar__tab {
    flex: 1;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    border: 0;
    background: transparent;
    text-align: center;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.chat-sidebar__tab:hover { background: var(--bg-hover); color: var(--text-primary); }
.chat-sidebar__tab.is-active { background: var(--brand-50); color: var(--brand-700); }

.chat-list {
    flex: 1 1 auto;
    overflow-y: auto;
    min-height: 0;
}

.chat-list__item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.chat-list__item:hover { background: var(--bg-hover); }
.chat-list__item.is-active { background: var(--brand-50); }
[data-theme="dark"] .chat-list__item.is-active { background: rgba(4, 103, 58, .18); }

.chat-list__avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--brand-600);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 13px;
    flex-shrink: 0;
}

.chat-list__body {
    flex: 1;
    min-width: 0;
}

.chat-list__name {
    font-size: 13.5px;
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-list__preview {
    font-size: 12px;
    color: var(--text-tertiary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-top: 2px;
}

.chat-list__meta {
    text-align: right;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

.chat-list__time {
    font-size: 10.5px;
    color: var(--text-tertiary);
}

.chat-list__unread {
    min-width: 18px;
    height: 18px;
    border-radius: 999px;
    background: var(--brand-600);
    color: #fff;
    font-size: 10.5px;
    font-weight: 700;
    line-height: 18px;
    padding: 0 6px;
    text-align: center;
}

.chat-empty {
    padding: 24px;
    text-align: center;
    color: var(--text-tertiary);
    font-size: 13px;
}

/* ---------- Conversation pane ---------- */

.chat-pane {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    background: var(--bg-surface);
}

.chat-pane__head {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-pane__head .chat-list__avatar { width: 40px; height: 40px; font-size: 14px; }

.chat-pane__head-body { flex: 1; min-width: 0; }
.chat-pane__head-name { font-size: 15px; font-weight: 600; color: var(--text-primary); }
.chat-pane__head-status { font-size: 11.5px; color: var(--text-tertiary); }

.chat-pane__messages {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 18px 22px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 0;
    background: var(--bg-surface-2);
}

.chat-msg {
    max-width: 70%;
    display: flex;
    flex-direction: column;
    gap: 4px;
    position: relative;
}

.chat-msg__bubble {
    padding: 9px 13px;
    border-radius: 14px;
    font-size: 13.5px;
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-wrap;
    box-shadow: 0 1px 1px rgba(0,0,0,.04);
}

.chat-msg__meta {
    font-size: 10.5px;
    color: var(--text-tertiary);
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Outgoing (mine) */
.chat-msg--mine { align-self: flex-end; align-items: flex-end; }
.chat-msg--mine .chat-msg__bubble {
    background: var(--brand-600);
    color: #fff;
    border-bottom-right-radius: 4px;
}

/* Incoming (theirs) */
.chat-msg--theirs { align-self: flex-start; align-items: flex-start; }
.chat-msg--theirs .chat-msg__bubble {
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.chat-msg__delete {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    color: var(--text-danger, #a40621);
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

.chat-msg--mine:hover .chat-msg__delete { display: inline-flex; }

.chat-day-divider {
    text-align: center;
    margin: 14px 0 4px;
    font-size: 11px;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: .04em;
}

.chat-pane__composer {
    border-top: 1px solid var(--border);
    padding: 12px 16px;
    display: flex;
    gap: 10px;
    align-items: flex-end;
    background: var(--bg-surface);
}

.chat-pane__composer textarea {
    flex: 1;
    min-height: 40px;
    max-height: 140px;
    resize: none;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 13.5px;
    font-family: inherit;
    background: var(--bg-surface);
    color: var(--text-primary);
    line-height: 1.5;
}

.chat-pane__composer textarea:focus {
    outline: none;
    border-color: var(--brand-600);
    box-shadow: 0 0 0 3px rgba(4, 103, 58, .12);
}

.chat-pane__empty {
    display: flex;
    flex: 1;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--text-tertiary);
    padding: 40px 24px;
    gap: 8px;
}

.chat-pane__empty-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--bg-surface-2);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
}

.chat-pane__empty-title { font-size: 15px; font-weight: 600; color: var(--text-primary); }
.chat-pane__empty-desc  { font-size: 13px; }

/* Mobile: stack pane below sidebar; tap a contact to flip to pane */
@media (max-width: 768px) {
    .chat-shell { grid-template-columns: 1fr; }
    .chat-shell[data-view="thread"] .chat-sidebar { display: none; }
    .chat-shell[data-view="list"] .chat-pane { display: none; }
}

/* ============================================================================
   CHAT — Attachments, file picker, topbar notification bell
   (Append below the chat layout rules)
   ============================================================================ */

/* --- Composer: attach button --- */
.chat-attach-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-surface);
    color: var(--text-secondary);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--transition-fast), color var(--transition-fast);
}
.chat-attach-btn:hover { background: var(--bg-hover); color: var(--brand-600); }

.chat-composer__main { flex: 1; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.chat-composer__main textarea { width: 100%; }

/* --- Pending file chip in composer --- */
.chat-file-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 4px 6px 4px 10px;
    background: var(--brand-50);
    border: 1px solid var(--brand-200, rgba(4, 103, 58, .25));
    border-radius: 999px;
    font-size: 12px;
    color: var(--brand-700);
    max-width: 100%;
    align-self: flex-start;
}
.chat-file-chip[hidden] { display: none !important; }
.chat-file-chip__icon { display: inline-flex; align-items: center; }
.chat-file-chip__name { font-weight: 600; max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-file-chip__size { color: var(--text-tertiary); }
.chat-file-chip__remove {
    background: transparent;
    border: 0;
    color: var(--brand-700);
    cursor: pointer;
    padding: 0 6px;
    font-size: 16px;
    line-height: 1;
    border-radius: 999px;
}
.chat-file-chip__remove:hover { background: var(--brand-100, rgba(4, 103, 58, .12)); }
[data-theme="dark"] .chat-file-chip {
    background: rgba(4, 103, 58, .15);
    color: #c4e5d2;
    border-color: rgba(4, 103, 58, .35);
}
[data-theme="dark"] .chat-file-chip__remove { color: #c4e5d2; }

/* --- Message attachment: image preview --- */
.chat-msg__bubble--with-attachment { padding: 4px; overflow: hidden; }
.chat-msg__image-link { display: block; line-height: 0; }
.chat-msg__image {
    display: block;
    max-width: 280px;
    max-height: 240px;
    border-radius: 10px;
    object-fit: cover;
}
.chat-msg__bubble-text {
    margin-top: 6px;
    padding: 4px 9px 6px;
    font-size: 13.5px;
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-wrap;
}

/* --- Message attachment: generic file card --- */
.chat-msg__file {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 13px;
    max-width: 280px;
}
.chat-msg__file:hover { background: var(--bg-hover); }
.chat-msg__file-icon { font-size: 22px; flex-shrink: 0; }
.chat-msg__file-meta { display: flex; flex-direction: column; min-width: 0; }
.chat-msg__file-name {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 220px;
}
.chat-msg__file-size { font-size: 11px; color: var(--text-tertiary); }

/* When a file attachment lives in MY bubble (green), invert colors */
.chat-msg--mine .chat-msg__file {
    background: rgba(255, 255, 255, .14);
    border-color: rgba(255, 255, 255, .25);
    color: #fff;
}
.chat-msg--mine .chat-msg__file:hover { background: rgba(255, 255, 255, .22); }
.chat-msg--mine .chat-msg__file-size { color: rgba(255, 255, 255, .75); }

/* ============================================================================
   TOPBAR NOTIFICATION BELL
   ============================================================================ */

.topbar-bell {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    color: var(--text-secondary);
    background: transparent;
    text-decoration: none;
    transition: background var(--transition-fast), color var(--transition-fast);
}
.topbar-bell:hover { background: var(--bg-hover); color: var(--text-primary); }
.topbar-bell.has-unread { color: var(--brand-600); }
.topbar-bell.has-unread:hover { color: var(--brand-700); }

.topbar-bell__badge {
    position: absolute;
    top: 4px;
    right: 4px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 999px;
    background: var(--brand-danger, #a40621);
    color: #fff;
    font-size: 9.5px;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
    box-shadow: 0 0 0 2px var(--bg-surface, #fff);
}

@keyframes agricsoft-bell-shake {
    0%, 100% { transform: rotate(0); }
    25%      { transform: rotate(-12deg); }
    50%      { transform: rotate(10deg); }
    75%      { transform: rotate(-6deg); }
}
.topbar-bell.has-unread svg { animation: agricsoft-bell-shake .6s ease-in-out 1; transform-origin: 50% 20%; }

/* ============================================================================
   KANBAN BOARD
   Append to public/css/agricsoft.css (or include separately after it).
   ============================================================================ */

.kanban-shell {
    margin-top: var(--space-4, 16px);
}

.kanban-empty {
    background: var(--bg-surface, #fff);
    border: 1px dashed var(--border, #e5e7eb);
    border-radius: var(--radius-lg, 12px);
    padding: 60px 24px;
    text-align: center;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}
.kanban-empty__icon {
    width: 64px; height: 64px;
    border-radius: 50%;
    background: var(--bg-surface-2);
    display: inline-flex; align-items: center; justify-content: center;
    color: var(--text-tertiary);
}
.kanban-empty__title { font-size: 16px; font-weight: 600; color: var(--text-primary); }
.kanban-empty__desc  { font-size: 13.5px; max-width: 360px; }

.kanban-board {
    background: var(--bg-surface, #fff);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg, 12px);
    padding: 16px;
    min-height: 60vh;
    overflow: hidden;
}
.kanban-board__loader {
    padding: 60px;
    text-align: center;
    color: var(--text-tertiary);
    font-size: 13px;
}

.kanban-board__cols {
    display: flex;
    gap: 14px;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 10px;
    min-height: 55vh;
    align-items: flex-start;
}

/* Columns */
.kanban-column {
    flex: 0 0 280px;
    width: 280px;
    background: var(--bg-surface-2, #f9fafb);
    border: 1px solid var(--border);
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    max-height: 100%;
}
.kanban-column__head {
    padding: 10px 12px;
    border-top: 3px solid #94a3b8;
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
}
.kanban-column__head-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.kanban-column__head-right { display: flex; align-items: center; gap: 2px; opacity: 0; transition: opacity .15s; }
.kanban-column:hover .kanban-column__head-right { opacity: 1; }

.kanban-column__dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: #94a3b8;
    flex-shrink: 0;
}
.kanban-column__name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: .04em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.kanban-column__count {
    font-size: 11px;
    color: var(--text-tertiary);
    background: var(--bg-surface-2);
    padding: 1px 7px;
    border-radius: 999px;
}

.kanban-column__body {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 40px;
}

.kanban-column__add {
    border: 0;
    background: transparent;
    color: var(--text-tertiary);
    font-size: 12.5px;
    padding: 10px;
    cursor: pointer;
    text-align: left;
    border-top: 1px solid var(--border);
    border-bottom-left-radius: 10px;
    border-bottom-right-radius: 10px;
    transition: background var(--transition-fast), color var(--transition-fast);
}
.kanban-column__add:hover { background: var(--bg-hover); color: var(--text-primary); }

.kanban-board__add-col {
    flex: 0 0 280px;
    width: 280px;
    border: 1px dashed var(--border);
    background: transparent;
    color: var(--text-tertiary);
    padding: 14px;
    border-radius: 10px;
    cursor: pointer;
    height: 60px;
    font-size: 13px;
    transition: background var(--transition-fast), color var(--transition-fast);
}
.kanban-board__add-col:hover { background: var(--bg-surface-2); color: var(--text-primary); border-color: var(--brand-600); }

/* Cards */
.kanban-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 11px;
    cursor: grab;
    box-shadow: 0 1px 2px rgba(0,0,0,.04);
    transition: box-shadow var(--transition-fast), border-color var(--transition-fast), transform var(--transition-fast);
}
.kanban-card:hover { box-shadow: 0 2px 5px rgba(0,0,0,.08); border-color: var(--brand-200, rgba(4,103,58,.25)); }
.kanban-card:active { cursor: grabbing; }

.kanban-card__title {
    font-size: 13.5px;
    font-weight: 500;
    color: var(--text-primary);
    line-height: 1.4;
    word-wrap: break-word;
}
.kanban-card__desc {
    margin-top: 4px;
    font-size: 11.5px;
    color: var(--text-tertiary);
    line-height: 1.45;
    word-wrap: break-word;
}
.kanban-card__footer {
    margin-top: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

/* Priority */
.kanban-card__priority {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    padding: 2px 7px;
    border-radius: 999px;
    background: var(--bg-surface-2);
    color: var(--text-secondary);
}
.kanban-card__priority--low      { background: rgba(100, 116, 139, .12); color: #475569; }
.kanban-card__priority--medium   { background: rgba(228, 161, 27, .14);  color: #92590f; }
.kanban-card__priority--high     { background: rgba(229, 90, 48, .14);   color: #b34218; }
.kanban-card__priority--urgent   { background: rgba(164, 6, 33, .14);    color: #a40621; }
[data-theme="dark"] .kanban-card__priority--low    { color: #cbd5e1; }
[data-theme="dark"] .kanban-card__priority--medium { color: #fbbf24; }
[data-theme="dark"] .kanban-card__priority--high   { color: #fb923c; }
[data-theme="dark"] .kanban-card__priority--urgent { color: #fca5a5; }

.kanban-card__due {
    font-size: 11px;
    color: var(--text-secondary);
}
.kanban-card__due--overdue {
    color: var(--brand-danger, #a40621);
    font-weight: 600;
}

.kanban-card__assignees {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
}
.kanban-card__avatar {
    width: 22px; height: 22px;
    border-radius: 50%;
    background: var(--brand-600);
    color: #fff;
    font-size: 9.5px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: -6px;
    border: 2px solid var(--bg-surface);
}
.kanban-card__avatar:first-child { margin-left: 0; }
.kanban-card__avatar--more { background: var(--text-secondary); }

/* SortableJS states */
.kanban-card--ghost {
    opacity: .4;
    background: var(--brand-50);
    border-color: var(--brand-600);
    border-style: dashed;
}
.kanban-card--dragging {
    transform: rotate(2deg);
    box-shadow: 0 8px 16px rgba(0,0,0,.18);
}

/* ============================================================================
   NOTIFICATION BELL (separate from chat bell)
   ============================================================================ */

.notification-bell {
    position: relative;
    display: inline-block;
}
.notification-bell__btn {
    width: 38px; height: 38px;
    border-radius: 50%;
    border: 0;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-fast), color var(--transition-fast);
}
.notification-bell__btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.notification-bell.has-unread .notification-bell__btn { color: var(--brand-600); }

.notification-bell__badge {
    position: absolute;
    top: 4px; right: 4px;
    min-width: 16px; height: 16px;
    padding: 0 4px;
    border-radius: 999px;
    background: var(--brand-danger, #a40621);
    color: #fff;
    font-size: 9.5px;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
    box-shadow: 0 0 0 2px var(--bg-surface, #fff);
}

@keyframes agricsoft-notif-shake {
    0%, 100% { transform: rotate(0); }
    25%      { transform: rotate(-12deg); }
    50%      { transform: rotate(10deg); }
    75%      { transform: rotate(-6deg); }
}
.notification-bell.has-unread svg { animation: agricsoft-notif-shake .6s ease-in-out 1; transform-origin: 50% 20%; }

.notification-bell__dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 340px;
    max-width: 380px;
    max-height: 480px;
    overflow: hidden;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg, 12px);
    box-shadow: 0 10px 30px rgba(0,0,0,.16);
    z-index: 1000;
    display: flex;
    flex-direction: column;
}
.notification-bell__dropdown[hidden] { display: none !important; }

.notification-bell__head {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.notification-bell__title { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.notification-bell__mark-all {
    background: transparent;
    border: 0;
    color: var(--brand-600);
    font-size: 11.5px;
    cursor: pointer;
    padding: 2px 4px;
}
.notification-bell__mark-all:hover { text-decoration: underline; }

.notification-bell__list {
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}
.notification-bell__empty {
    padding: 30px 16px;
    text-align: center;
    color: var(--text-tertiary);
    font-size: 12.5px;
}
.notification-bell__item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    text-decoration: none;
    color: var(--text-primary);
    transition: background var(--transition-fast);
}
.notification-bell__item:hover { background: var(--bg-hover); }
.notification-bell__item.is-unread { background: rgba(4, 103, 58, .04); }
.notification-bell__item.is-unread::before {
    content: '';
    position: absolute;
    margin-left: -8px;
    margin-top: 6px;
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--brand-600);
}
.notification-bell__icon {
    font-size: 18px;
    flex-shrink: 0;
    margin-top: 1px;
}
.notification-bell__body { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.notification-bell__item-title { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.notification-bell__item-text  { font-size: 12px; color: var(--text-secondary); line-height: 1.4; }
.notification-bell__item-time  { font-size: 10.5px; color: var(--text-tertiary); margin-top: 2px; }

/* ============================================================================
   KANBAN — CARD MODAL: Comments + Activity timeline
   ============================================================================ */

.kanban-card-collab {
    margin-top: 18px;
    padding-top: 18px;
    border-top: 1px solid var(--border, #e5e7eb);
}

.kanban-card-collab__tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 14px;
}

.kanban-card-collab__tab {
    background: transparent;
    border: 0;
    padding: 8px 14px;
    margin-bottom: -1px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary, #475569);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: color var(--transition-fast), border-color var(--transition-fast);
}
.kanban-card-collab__tab:hover { color: var(--text-primary, #0f172a); }
.kanban-card-collab__tab.is-active {
    color: var(--brand-600, #04673a);
    border-bottom-color: var(--brand-600, #04673a);
}

.kanban-card-collab__count {
    display: inline-block;
    min-width: 18px;
    height: 18px;
    line-height: 18px;
    padding: 0 6px;
    background: var(--bg-surface-2, #f1f5f9);
    border-radius: 999px;
    font-size: 10.5px;
    font-weight: 700;
    color: var(--text-secondary);
    margin-left: 4px;
    text-align: center;
}
.kanban-card-collab__tab.is-active .kanban-card-collab__count {
    background: var(--brand-50, rgba(4,103,58,.1));
    color: var(--brand-700, #035c34);
}

.kanban-card-collab__pane { animation: none !important; }
.kanban-card-collab__pane[hidden] { display: none !important; }

/* ---------- Comments list ---------- */

.kanban-comment-list {
    max-height: 340px;
    overflow-y: auto;
    padding-right: 4px;
    margin-bottom: 14px;
}

.kanban-comment-list__empty {
    color: var(--text-tertiary, #94a3b8);
    font-size: 13px;
    padding: 14px 6px;
    text-align: center;
}

.kanban-comment {
    display: flex;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}
.kanban-comment:last-child { border-bottom: 0; }

.kanban-comment__avatar {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--brand-600, #04673a);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
}

.kanban-comment__main { flex: 1; min-width: 0; }

.kanban-comment__head {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 2px;
    position: relative;
}

.kanban-comment__name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary, #0f172a);
}

.kanban-comment__time {
    font-size: 11.5px;
    color: var(--text-tertiary);
}

.kanban-comment__delete {
    margin-left: auto;
    background: transparent;
    border: 0;
    color: var(--text-tertiary);
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 0 6px;
    border-radius: 4px;
}
.kanban-comment__delete:hover { background: var(--bg-hover); color: var(--brand-danger, #a40621); }

.kanban-comment__body {
    font-size: 13.5px;
    line-height: 1.5;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-wrap: break-word;
}

.kanban-comment__image-link { display: inline-block; line-height: 0; margin-top: 8px; }
.kanban-comment__image {
    display: block;
    max-width: 280px;
    max-height: 220px;
    border-radius: 8px;
    object-fit: cover;
    border: 1px solid var(--border);
}

.kanban-comment__file {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
    padding: 8px 10px;
    background: var(--bg-surface-2, #f1f5f9);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 13px;
    max-width: 320px;
}
.kanban-comment__file:hover { background: var(--bg-hover, #e2e8f0); }
.kanban-comment__file-icon { font-size: 18px; flex-shrink: 0; }
.kanban-comment__file-meta { display: flex; flex-direction: column; min-width: 0; }
.kanban-comment__file-name {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 240px;
}
.kanban-comment__file-size { font-size: 11px; color: var(--text-tertiary); }

/* ---------- Comment composer ---------- */

.kanban-comment-composer {
    border-top: 1px solid var(--border);
    padding-top: 12px;
}

.kanban-comment-composer__row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}
.kanban-comment-composer__row textarea {
    flex: 1;
    min-height: 40px;
    max-height: 120px;
    resize: vertical;
    font-family: inherit;
}

/* ---------- Activity timeline ---------- */

.kanban-activity {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 360px;
    overflow-y: auto;
}

.kanban-activity__empty {
    color: var(--text-tertiary);
    font-size: 13px;
    text-align: center;
    padding: 14px 6px;
}

.kanban-activity__item {
    display: flex;
    gap: 10px;
    padding: 8px 0;
    position: relative;
}

.kanban-activity__dot {
    flex-shrink: 0;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--brand-600, #04673a);
    margin-top: 6px;
    position: relative;
}
.kanban-activity__item:not(:last-child) .kanban-activity__dot::after {
    content: '';
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    width: 1px;
    height: calc(100% + 6px);
    background: var(--border);
}

.kanban-activity__body { flex: 1; min-width: 0; }

.kanban-activity__text {
    font-size: 13px;
    color: var(--text-primary);
    line-height: 1.45;
}

.kanban-activity__time {
    font-size: 11px;
    color: var(--text-tertiary);
    margin-top: 2px;
}

/* ============================================================================
   KANBAN — CARD MODAL: Creator-only lock for posted fields
   ============================================================================ */

/* Banner shown above the form when current user can't edit title/description */
.kanban-card__lock-hint {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    margin: 0 0 14px 0;
    background: var(--bg-surface-2, #f1f5f9);
    border: 1px solid var(--border, #e5e7eb);
    border-left: 3px solid var(--brand-warning, #E4A11B);
    border-radius: 6px;
    font-size: 12.5px;
    color: var(--text-secondary, #475569);
}
.kanban-card__lock-hint svg { flex-shrink: 0; color: var(--brand-warning, #E4A11B); }
.kanban-card__lock-hint strong { color: var(--text-primary, #0f172a); }
.kanban-card__lock-hint[hidden] { display: none !important; }

/* Visual treatment for locked (readonly) title + description inputs */
.form-control.is-locked,
.form-control.is-locked:focus {
    background: var(--bg-surface-2, #f8fafc);
    color: var(--text-secondary, #475569);
    cursor: not-allowed;
    box-shadow: none;
    border-color: var(--border, #e5e7eb);
}
.form-control.is-locked:hover { border-color: var(--border, #e5e7eb); }

.metrics-shell {
    padding: 24px clamp(16px, 3vw, 32px) 80px;
    transition: opacity 0.2s ease;
}
.metrics-shell.is-loading { opacity: 0.65; pointer-events: none; }

/* ---------- Page header ---------- */

.metrics-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;
    flex-wrap: wrap;
    margin-bottom: 28px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border, #e5e7eb);
}

.metrics-header__title h1 {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary, #0f172a);
    letter-spacing: -0.01em;
    margin: 0 0 6px 0;
    line-height: 1.2;
}
.metrics-header__sub {
    color: var(--text-secondary, #475569);
    font-size: 14px;
    margin: 0;
    max-width: 60ch;
}

/* ---------- Date filter ---------- */

.metrics-filter {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 12px;
}

.metrics-filter__presets {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.metrics-chip {
    padding: 6px 14px;
    border-radius: 999px;
    border: 1px solid var(--border, #e5e7eb);
    background: var(--bg-surface, #fff);
    color: var(--text-secondary, #475569);
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.metrics-chip:hover {
    border-color: var(--brand-600, #04673a);
    color: var(--brand-700, #035c34);
}
.metrics-chip.is-active {
    background: var(--brand-600, #04673a);
    color: #fff;
    border-color: var(--brand-600, #04673a);
}

.metrics-filter__range {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}

.metrics-filter__field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.metrics-filter__field span {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-tertiary, #94a3b8);
    font-weight: 600;
}
.metrics-filter__field input[type="date"] {
    padding: 7px 10px;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 6px;
    background: var(--bg-surface, #fff);
    color: var(--text-primary, #0f172a);
    font-size: 13px;
    font-family: inherit;
    min-width: 140px;
}
.metrics-filter__field input[type="date"]:focus {
    outline: none;
    border-color: var(--brand-600, #04673a);
    box-shadow: 0 0 0 3px rgba(4, 103, 58, 0.12);
}

/* ---------- KPI tiles ---------- */

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-bottom: 36px;
}
@media (max-width: 1100px) { .kpi-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 760px)  { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 440px)  { .kpi-grid { grid-template-columns: 1fr; } }

.kpi-tile {
    background: var(--bg-surface, #fff);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 12px;
    padding: 16px 18px;
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.kpi-tile:hover {
    transform: translateY(-2px);
    border-color: var(--brand-600, #04673a);
    box-shadow: 0 12px 24px -12px rgba(4, 103, 58, 0.15);
}
.kpi-tile__label {
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-tertiary, #94a3b8);
    font-weight: 600;
    margin-bottom: 10px;
}
.kpi-tile__value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary, #0f172a);
    letter-spacing: -0.02em;
    line-height: 1.1;
    margin-bottom: 4px;
}
.kpi-tile__delta {
    font-size: 11.5px;
    color: var(--text-tertiary, #94a3b8);
}
.kpi-tile--primary {
    background: var(--brand-600, #04673a);
    border-color: var(--brand-600, #04673a);
    color: #fff;
}
.kpi-tile--primary .kpi-tile__label,
.kpi-tile--primary .kpi-tile__delta { color: rgba(255, 255, 255, 0.75); }
.kpi-tile--primary .kpi-tile__value { color: #fff; }
.kpi-tile--primary:hover { box-shadow: 0 12px 24px -10px rgba(4, 103, 58, 0.4); }

.kpi-tile--accent {
    background: var(--bg-surface-2, #f8fafc);
    border-color: var(--brand-warning, #E4A11B);
    border-left-width: 4px;
}

/* ---------- Section headings ---------- */

.metrics-section {
    font-size: 14px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-secondary, #475569);
    margin: 36px 0 16px 0;
    padding-left: 12px;
    border-left: 3px solid var(--brand-600, #04673a);
}

/* ---------- Chart grid + cards ---------- */

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 12px;
}
@media (max-width: 1100px) { .metrics-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 720px)  { .metrics-grid { grid-template-columns: 1fr; } }

.chart-card {
    background: var(--bg-surface, #fff);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 12px;
    padding: 18px;
    display: flex;
    flex-direction: column;
}
.chart-card--lg { grid-column: span 2; }
@media (max-width: 720px)  { .chart-card--lg { grid-column: span 1; } }

.chart-card__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}
.chart-card__title {
    font-size: 14.5px;
    font-weight: 600;
    color: var(--text-primary, #0f172a);
    margin-bottom: 4px;
}
.chart-card__subtitle {
    font-size: 12px;
    color: var(--text-tertiary, #94a3b8);
}

.chart-card__body {
    position: relative;
    flex: 1;
    min-height: 280px;
    max-height: 320px;
}
.chart-card--lg .chart-card__body { min-height: 320px; max-height: 360px; }
.chart-card__body canvas { max-width: 100%; height: 100% !important; }

/* ---------- Activity snapshot stats ---------- */

.chart-card--activity .chart-card__body {
    min-height: 0;
    max-height: none;
}

.activity-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    padding: 8px 0;
}
@media (max-width: 600px) { .activity-stats { grid-template-columns: repeat(2, 1fr); } }

.activity-stat {
    padding: 16px;
    background: var(--bg-surface-2, #f8fafc);
    border-radius: 10px;
    border-left: 3px solid var(--brand-600, #04673a);
}
.activity-stat:nth-child(2) { border-left-color: var(--brand-warning, #E4A11B); }
.activity-stat:nth-child(3) { border-left-color: #7C3AED; }
.activity-stat:nth-child(4) { border-left-color: #0EA5E9; }

.activity-stat__num {
    font-size: 30px;
    font-weight: 700;
    color: var(--text-primary, #0f172a);
    letter-spacing: -0.02em;
    line-height: 1;
    margin-bottom: 8px;
}
.activity-stat__label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-tertiary, #94a3b8);
    font-weight: 600;
}

/* ---------- Dark theme adjustments ---------- */

[data-theme="dark"] .kpi-tile,
[data-theme="dark"] .chart-card { background: var(--bg-surface, #1e293b); border-color: var(--border, #334155); }
[data-theme="dark"] .kpi-tile--accent { background: var(--bg-surface-2, #0f172a); }
[data-theme="dark"] .activity-stat { background: var(--bg-surface-2, #0f172a); }

/* ---------- Mobile adjustments ---------- */

@media (max-width: 760px) {
    .metrics-header { flex-direction: column; align-items: stretch; }
    .metrics-filter { align-items: stretch; }
    .metrics-filter__range { flex-direction: row; }
    .chart-card__body { min-height: 240px; max-height: 280px; }
}

/* ---------- Auto-refresh toggle ---------- */

.metrics-autorefresh {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 4px;
    padding: 6px 12px;
    background: var(--bg-surface-2, #f8fafc);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 999px;
    font-size: 12px;
}

.metrics-autorefresh__toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    user-select: none;
    color: var(--text-secondary, #475569);
    font-weight: 500;
}
.metrics-autorefresh__toggle input[type="checkbox"] {
    width: 14px;
    height: 14px;
    accent-color: var(--brand-600, #04673a);
    cursor: pointer;
    margin: 0;
}

.metrics-autorefresh__status {
    color: var(--text-tertiary, #94a3b8);
    font-variant-numeric: tabular-nums;
    border-left: 1px solid var(--border, #e5e7eb);
    padding-left: 12px;
}

@media (max-width: 760px) {
    .metrics-autorefresh { align-self: flex-start; }
}

/* ============================================================================
   AgricSoft — Metrics Dashboard
   Self-contained styles that ride on top of the agricsoft.css design tokens.
   ============================================================================ */

.metrics-shell {
    padding: 24px clamp(16px, 3vw, 32px) 80px;
    transition: opacity 0.2s ease;
}
.metrics-shell.is-loading { opacity: 0.65; pointer-events: none; }

/* ---------- Page header ---------- */

.metrics-header {
    margin-bottom: 16px;
}

.metrics-header__title {
    display: flex;
    align-items: center;
    gap: 16px;
}

.metrics-header__brand {
    flex-shrink: 0;
    display: flex;
    align-items: center;
}

.metrics-header__logo {
    height: 38px;
    width: auto;
    display: block;
}

.metrics-header__title h1 {
    font-size: 26px;
    font-weight: 700;
    color: var(--text-primary, #0f172a);
    letter-spacing: -0.01em;
    margin: 0 0 4px 0;
    line-height: 1.15;
}
.metrics-header__sub {
    color: var(--text-secondary, #475569);
    font-size: 13.5px;
    margin: 0;
    max-width: 70ch;
    line-height: 1.5;
}

/* ---------- Toolbar (single horizontal strip with the three groups) ---------- */

.metrics-toolbar {
    display: flex;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 18px 28px;
    padding: 16px 18px;
    margin-bottom: 28px;
    background: var(--bg-surface, #fff);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 12px;
}

.metrics-toolbar__group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
}
.metrics-toolbar__group--auto {
    margin-left: auto;     /* push auto-refresh to the right */
    align-self: center;
}

.metrics-toolbar__label {
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-tertiary, #94a3b8);
    font-weight: 600;
}

/* ---------- Preset chips ---------- */

.metrics-filter__presets {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    background: var(--bg-surface-2, #f8fafc);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 8px;
    padding: 3px;
}

.metrics-chip {
    padding: 6px 12px;
    border-radius: 6px;
    border: 0;
    background: transparent;
    color: var(--text-secondary, #475569);
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s ease, color 0.15s ease;
    line-height: 1;
    min-width: 38px;
    text-align: center;
}
.metrics-chip:hover {
    color: var(--brand-700, #035c34);
    background: rgba(4, 103, 58, 0.06);
}
.metrics-chip.is-active {
    background: var(--brand-600, #04673a);
    color: #fff;
}

/* ---------- Date range row ---------- */

.metrics-filter__range {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.metrics-date-input {
    padding: 7px 10px;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 6px;
    background: var(--bg-surface, #fff);
    color: var(--text-primary, #0f172a);
    font-size: 13px;
    font-family: inherit;
    min-width: 145px;
    height: 34px;
    line-height: 1;
}
.metrics-date-input:focus {
    outline: none;
    border-color: var(--brand-600, #04673a);
    box-shadow: 0 0 0 3px rgba(4, 103, 58, 0.12);
}

.metrics-filter__sep {
    color: var(--text-tertiary, #94a3b8);
    font-weight: 500;
    padding: 0 2px;
    user-select: none;
}

.metrics-toolbar .btn { height: 34px; padding: 0 16px; }
.metrics-toolbar .metrics-icon-btn {
    width: 34px;
    padding: 0;
    font-size: 16px;
    line-height: 1;
}

/* ---------- Auto-refresh indicator ---------- */

.metrics-autorefresh {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    padding: 7px 14px;
    background: var(--bg-surface-2, #f8fafc);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 999px;
    font-size: 12px;
    height: 34px;
}

.metrics-autorefresh__toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    user-select: none;
    color: var(--text-secondary, #475569);
    font-weight: 600;
    line-height: 1;
}
.metrics-autorefresh__toggle input[type="checkbox"] {
    width: 14px;
    height: 14px;
    accent-color: var(--brand-600, #04673a);
    cursor: pointer;
    margin: 0;
}

.metrics-autorefresh__status {
    color: var(--text-tertiary, #94a3b8);
    font-variant-numeric: tabular-nums;
    border-left: 1px solid var(--border, #e5e7eb);
    padding-left: 12px;
    line-height: 1;
    white-space: nowrap;
}

@media (max-width: 900px) {
    .metrics-toolbar__group--auto { margin-left: 0; }
}
@media (max-width: 560px) {
    .metrics-header__title { flex-direction: column; align-items: flex-start; gap: 12px; }
    .metrics-autorefresh { width: 100%; justify-content: space-between; }
}

/* ---------- KPI tiles ---------- */

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-bottom: 36px;
}
@media (max-width: 1100px) { .kpi-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 760px)  { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 440px)  { .kpi-grid { grid-template-columns: 1fr; } }

.kpi-tile {
    background: var(--bg-surface, #fff);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 12px;
    padding: 16px 18px;
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.kpi-tile:hover {
    transform: translateY(-2px);
    border-color: var(--brand-600, #04673a);
    box-shadow: 0 12px 24px -12px rgba(4, 103, 58, 0.15);
}
.kpi-tile__label {
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-tertiary, #94a3b8);
    font-weight: 600;
    margin-bottom: 10px;
}
.kpi-tile__value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary, #0f172a);
    letter-spacing: -0.02em;
    line-height: 1.1;
    margin-bottom: 4px;
}
.kpi-tile__delta {
    font-size: 11.5px;
    color: var(--text-tertiary, #94a3b8);
}
.kpi-tile--primary {
    background: var(--brand-600, #04673a);
    border-color: var(--brand-600, #04673a);
    color: #fff;
}
.kpi-tile--primary .kpi-tile__label,
.kpi-tile--primary .kpi-tile__delta { color: rgba(255, 255, 255, 0.75); }
.kpi-tile--primary .kpi-tile__value { color: #fff; }
.kpi-tile--primary:hover { box-shadow: 0 12px 24px -10px rgba(4, 103, 58, 0.4); }

.kpi-tile--accent {
    background: var(--bg-surface-2, #f8fafc);
    border-color: var(--brand-warning, #E4A11B);
    border-left-width: 4px;
}

/* ---------- Section headings ---------- */

.metrics-section {
    font-size: 14px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-secondary, #475569);
    margin: 36px 0 16px 0;
    padding-left: 12px;
    border-left: 3px solid var(--brand-600, #04673a);
}

/* ---------- Chart grid + cards ---------- */

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 12px;
}
@media (max-width: 1100px) { .metrics-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 720px)  { .metrics-grid { grid-template-columns: 1fr; } }

.chart-card {
    background: var(--bg-surface, #fff);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 12px;
    padding: 18px;
    display: flex;
    flex-direction: column;
}
.chart-card--lg { grid-column: span 2; }
@media (max-width: 720px)  { .chart-card--lg { grid-column: span 1; } }

.chart-card__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}
.chart-card__title {
    font-size: 14.5px;
    font-weight: 600;
    color: var(--text-primary, #0f172a);
    margin-bottom: 4px;
}
.chart-card__subtitle {
    font-size: 12px;
    color: var(--text-tertiary, #94a3b8);
}

.chart-card__body {
    position: relative;
    flex: 1;
    min-height: 280px;
    max-height: 320px;
}
.chart-card--lg .chart-card__body { min-height: 320px; max-height: 360px; }
.chart-card__body canvas { max-width: 100%; height: 100% !important; }

/* ---------- Activity snapshot stats ---------- */

.chart-card--activity .chart-card__body {
    min-height: 0;
    max-height: none;
}

.activity-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    padding: 8px 0;
}
@media (max-width: 600px) { .activity-stats { grid-template-columns: repeat(2, 1fr); } }

.activity-stat {
    padding: 16px;
    background: var(--bg-surface-2, #f8fafc);
    border-radius: 10px;
    border-left: 3px solid var(--brand-600, #04673a);
}
.activity-stat:nth-child(2) { border-left-color: var(--brand-warning, #E4A11B); }
.activity-stat:nth-child(3) { border-left-color: #7C3AED; }
.activity-stat:nth-child(4) { border-left-color: #0EA5E9; }

.activity-stat__num {
    font-size: 30px;
    font-weight: 700;
    color: var(--text-primary, #0f172a);
    letter-spacing: -0.02em;
    line-height: 1;
    margin-bottom: 8px;
}
.activity-stat__label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-tertiary, #94a3b8);
    font-weight: 600;
}

/* ---------- Dark theme adjustments ---------- */

[data-theme="dark"] .kpi-tile,
[data-theme="dark"] .chart-card { background: var(--bg-surface, #1e293b); border-color: var(--border, #334155); }
[data-theme="dark"] .kpi-tile--accent { background: var(--bg-surface-2, #0f172a); }
[data-theme="dark"] .activity-stat { background: var(--bg-surface-2, #0f172a); }

/* ---------- Mobile adjustments ---------- */

@media (max-width: 760px) {
    .metrics-header { flex-direction: column; align-items: stretch; }
    .metrics-filter { align-items: stretch; }
    .metrics-filter__range { flex-direction: row; }
    .chart-card__body { min-height: 240px; max-height: 280px; }
}

/* ---------- Inline error banner ---------- */
.metrics-error-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    margin-bottom: 14px;
    background: #fff3f3;
    border: 1px solid #fecaca;
    border-left: 3px solid var(--brand-danger, #a40621);
    border-radius: 8px;
    color: #7f1d1d;
    font-size: 13px;
}
.metrics-error-banner__icon { font-size: 16px; }
.metrics-error-banner__msg { flex: 1; }
.metrics-error-banner__close {
    background: transparent;
    border: 0;
    color: #7f1d1d;
    font-size: 18px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}
.metrics-error-banner__close:hover { color: var(--brand-danger, #a40621); }

/* ---------- Organization select (super-admin only) ---------- */
/* Mirrors .metrics-date-input exactly, plus the appearance reset + chevron
   needed for native <select> elements.
   Using select.metrics-org-select for higher specificity so this beats any
   inherited form/normalize CSS reliably. */

.metrics-toolbar__group--org { min-width: 220px; }

select.metrics-org-select,
.metrics-org-select {
    /* Force the native chrome off across every browser (the !important is
       defensive — author CSS sometimes loses to UA stylesheets on selects). */
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    appearance: none !important;

    /* identical box model to .metrics-date-input */
    box-sizing: border-box;
    padding: 7px 32px 7px 10px;     /* extra right padding for chevron */
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 6px;
    background-color: var(--bg-surface, #fff);
    color: var(--text-primary, #0f172a);
    font-size: 13px;
    font-family: inherit;
    min-width: 220px;
    height: 34px;
    line-height: 1;
    margin: 0;
    cursor: pointer;

    /* Custom chevron icon (replaces the native arrow we just disabled) */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 12px 12px;

    /* truncation when org name is long */
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
}

select.metrics-org-select:hover { border-color: var(--brand-600, #04673a); }

select.metrics-org-select:focus,
select.metrics-org-select:focus-visible {
    outline: none !important;        /* kill the native blue focus ring */
    border-color: var(--brand-600, #04673a);
    box-shadow: 0 0 0 3px rgba(4, 103, 58, 0.12);
}

/* Browser-quirk cleanup */
.metrics-org-select::-ms-expand { display: none; }
.metrics-org-select:-moz-focusring {
    color: transparent;
    text-shadow: 0 0 0 var(--text-primary, #0f172a);
}

/* ============================================================================
   ENHANCEMENTS: Skeletons + Export buttons + Comparison toggle
   ============================================================================ */

/* ---------- Chart-card head actions (toggle + export button row) ---------- */

.chart-card__head { gap: 12px; }

.chart-card__head-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* Export button — small icon-only ⬇ */
.chart-export-btn {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-tertiary, #94a3b8);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.chart-export-btn:hover {
    background: var(--bg-surface-2, #f8fafc);
    color: var(--brand-600, #04673a);
    border-color: var(--border, #e5e7eb);
}
.chart-export-btn:focus-visible {
    outline: none;
    border-color: var(--brand-600, #04673a);
    box-shadow: 0 0 0 3px rgba(4, 103, 58, 0.12);
}
.chart-export-btn svg { width: 14px; height: 14px; pointer-events: none; }

/* Inline checkbox-toggle for chart options */
.chart-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    user-select: none;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--text-secondary, #475569);
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--bg-surface-2, #f8fafc);
    border: 1px solid var(--border, #e5e7eb);
    transition: background .15s ease, border-color .15s ease;
}
.chart-toggle:hover { border-color: var(--brand-600, #04673a); }
.chart-toggle input {
    width: 13px;
    height: 13px;
    margin: 0;
    accent-color: var(--brand-600, #04673a);
    cursor: pointer;
}

/* ---------- Per-chart skeleton overlay ---------- */

.chart-card__body { position: relative; }   /* host for the overlay */

.chart-skeleton {
    position: absolute;
    inset: 0;
    border-radius: 8px;
    background: var(--bg-surface-2, #f8fafc);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    gap: 6px;
    padding: 16px;
    pointer-events: none;
    z-index: 2;
}

.chart-skeleton::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255, 255, 255, 0.7) 50%,
        transparent 100%
    );
    transform: translateX(-100%);
    animation: chart-shimmer 1.4s ease-in-out infinite;
}
[data-theme="dark"] .chart-skeleton::before {
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255, 255, 255, 0.04) 50%,
        transparent 100%
    );
}

@keyframes chart-shimmer {
    100% { transform: translateX(100%); }
}

/* The skeleton "bars" mimicking a chart while loading */
.chart-skeleton__row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    height: 100%;
    padding-top: 24px;
}
.chart-skeleton__bar {
    flex: 1;
    background: var(--border, #e5e7eb);
    border-radius: 3px 3px 0 0;
    min-height: 8px;
    opacity: 0.75;
}

/* Variant: donut-style skeleton (centered circle) */
.chart-skeleton--donut .chart-skeleton__row { display: none; }
.chart-skeleton--donut::after {
    content: '';
    position: absolute;
    top: 50%; left: 50%;
    width: 60%;
    aspect-ratio: 1;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background: conic-gradient(
        var(--border, #e5e7eb) 0deg, var(--border, #e5e7eb) 360deg
    );
    -webkit-mask: radial-gradient(circle, transparent 38%, #000 39%);
    mask: radial-gradient(circle, transparent 38%, #000 39%);
    opacity: 0.6;
}

/* Hide the skeleton when its host card is loaded */
.chart-card.is-loaded .chart-skeleton { display: none; }
.chart-card.is-loaded canvas { opacity: 1; }
.chart-card canvas { opacity: 0; transition: opacity .25s ease; }

/* Tiny per-chart error placeholder (replaces skeleton on fetch failure) */
.chart-card.is-errored .chart-skeleton {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--brand-danger, #a40621);
    background: #fff3f3;
    font-size: 12px;
    font-weight: 600;
    padding: 16px;
    text-align: center;
}
.chart-card.is-errored .chart-skeleton::before,
.chart-card.is-errored .chart-skeleton::after,
.chart-card.is-errored .chart-skeleton__row { display: none; }
.chart-card.is-errored .chart-skeleton::before { content: 'Failed to load. Click ↻ to retry.'; opacity: 1; position: static; animation: none; transform: none; background: none; display: block; }

@media (max-width: 560px) {
    .chart-card__head { flex-direction: column; align-items: flex-start; gap: 10px; }
    .chart-card__head-actions { width: 100%; justify-content: flex-end; }
}

/* ============================================================================
   SIDEBAR COLLAPSE — icon-rail mode
   ============================================================================ */

.app-sidebar.is-collapsed {
    width: var(--sidebar-w-collapsed);
}

/* Hide text, section titles, chevrons when collapsed */
.app-sidebar.is-collapsed .nav-link__text,
.app-sidebar.is-collapsed .nav-link__chevron,
.app-sidebar.is-collapsed .nav-section__title,
.app-sidebar.is-collapsed .app-sidebar__brand-text {
    opacity: 0;
    width: 0;
    overflow: hidden;
    pointer-events: none;
}

/* Keep icon centered */
.app-sidebar.is-collapsed .nav-link {
    justify-content: center;
    padding: var(--space-2);
    gap: 0;
}

/* Hide submenus when collapsed */
.app-sidebar.is-collapsed .nav-submenu {
    max-height: 0 !important;
}

/* Brand area: center the logo */
.app-sidebar.is-collapsed .app-sidebar__brand {
    justify-content: center;
    padding: var(--space-4) var(--space-2);
}
.app-sidebar.is-collapsed .app-sidebar__brand img {
    height: 28px;
}

/* Shift main content when collapsed */
.app-main.is-collapsed {
    margin-left: var(--sidebar-w-collapsed);
}

/* Collapse toggle button */
.sidebar-collapse-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--border);
    background: transparent;
    color: var(--text-tertiary);
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast);
    gap: var(--space-2);
    font-size: var(--font-sm);
    font-weight: 500;
    flex-shrink: 0;
}
.sidebar-collapse-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}
.sidebar-collapse-btn svg {
    width: 18px;
    height: 18px;
    transition: transform var(--transition);
    flex-shrink: 0;
}
.app-sidebar.is-collapsed .sidebar-collapse-btn {
    justify-content: center;
    padding: var(--space-3) var(--space-2);
}
.app-sidebar.is-collapsed .sidebar-collapse-btn svg {
    transform: rotate(180deg);
}
.app-sidebar.is-collapsed .sidebar-collapse-btn span {
    display: none;
}

/* Tooltip on nav links when collapsed */
.app-sidebar.is-collapsed .nav-link {
    position: relative;
}
.app-sidebar.is-collapsed .nav-link:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%);
    background: var(--gray-900);
    color: #fff;
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    font-size: var(--font-xs);
    white-space: nowrap;
    z-index: 200;
    pointer-events: none;
    box-shadow: var(--shadow-md);
}

/* Don't collapse on mobile — sidebar already uses transform slide */
@media (max-width: 1024px) {
    .app-sidebar.is-collapsed {
        width: var(--sidebar-w);
    }
    .app-main.is-collapsed {
        margin-left: 0;
    }
    .app-sidebar.is-collapsed .nav-link__text,
    .app-sidebar.is-collapsed .nav-link__chevron,
    .app-sidebar.is-collapsed .nav-section__title,
    .app-sidebar.is-collapsed .app-sidebar__brand-text {
        opacity: 1;
        width: auto;
    }
    .app-sidebar.is-collapsed .nav-link {
        justify-content: flex-start;
        padding: var(--space-2) var(--space-3);
        gap: var(--space-3);
    }
}

.impersonate-banner {
    position: sticky;
    top: 0;
    z-index: 500;
    background: linear-gradient(90deg, #7C3AED, #5B21B6);
    color: #fff;
    padding: 10px 24px;
    box-shadow: 0 2px 8px rgba(92, 33, 182, .35);
}

.impersonate-banner__inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    max-width: 1400px;
    margin: 0 auto;
}

.impersonate-banner__left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.impersonate-banner__icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255,255,255,.15);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.impersonate-banner__icon svg {
    width: 16px;
    height: 16px;
    color: #fff;
}

.impersonate-banner__label {
    display: block;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    opacity: .8;
    margin-bottom: 1px;
}

.impersonate-banner__desc {
    font-size: 13.5px;
    line-height: 1.4;
}

.impersonate-banner__form { flex-shrink: 0; }

.impersonate-banner__btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 18px;
    background: #fff;
    color: #5B21B6;
    border: 0;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: background .15s ease, box-shadow .15s ease;
    white-space: nowrap;
}
.impersonate-banner__btn:hover {
    background: #f3f0ff;
    box-shadow: 0 2px 8px rgba(92,33,182,.25);
}

@media (max-width: 600px) {
    .impersonate-banner { padding: 10px 16px; }
    .impersonate-banner__inner { flex-direction: column; align-items: flex-start; }
}
