/* =============================================================================
   Kuvaly — Main Stylesheet
   Everything. One system.
   Font: Inter (loaded via <link> in header)

   THEMING
   -------
   All colours are CSS custom properties defined in :root below.
   To create a sector theme (corporate, finance, insurance, etc.) add a
   sector-specific CSS block that overrides the variables you want to change,
   e.g.:

       [data-sector="finance"] {
           --color-primary:  #1D4ED8;
           --pill-active-bg: rgba(29,78,216,.15);
           --pill-active-fg: #93C5FD;
           ...
       }

   The sector attribute is set on <body> by the PHP config system.
   Status pills, buttons, charts and sidebar accent all read from these
   variables — changing them here changes the entire UI.
   ============================================================================= */

@import url('https://fonts.googleapis.com/css2?family=DM+Serif+Display:ital@0;1&family=DM+Sans:wght@300;400;500;600;700&family=DM+Mono:wght@400;500&display=swap');

/* =============================================================================
   1. CSS VARIABLES — Legal Lifecycle Management theme
   ============================================================================= */

:root, [data-theme="light"] {
    /* Brand / primary palette */
    --color-primary:    #2E5FA3;   /* navy-blue */
    --color-secondary:  #1A7A72;   /* teal */
    --color-accent:     #B08D2A;   /* gold */

    /* Semantic colour aliases (Light mode) */
    --navy:       #1B2A4A;
    --navy-deep:  #0F1A33;
    --navy-soft:  #243B6E;
    --blue:       #2E5FA3;
    --blue-hover: #244E89;
    --blue-lt:    #EBF1FB;
    --blue-md:    #C4D8F5;
    --blue-glow:  #6EA8F7;
    --teal:       #1A7A72;
    --teal-lt:    #E0F5F3;
    --gold:       #B08D2A;
    --gold-lt:    #FDF5DC;
    --gold-bright:#D9B254;
    --red:        #C0392B;
    --red-lt:     #FDECEA;
    --red-bright: #E55A48;
    --green:      #1E7D45;
    --green-lt:   #E2F5EA;
    --green-bright:#3FA86A;
    --purple:     #4F46E5;
    --cyan:       #22D3EE;

    /* Pill tokens */
    --pill-active-bg:   #E2F5EA;
    --pill-active-fg:   #1E7D45;
    --pill-hold-bg:     #FDF5DC;
    --pill-hold-fg:     #B08D2A;
    --pill-review-bg:   #EBF1FB;
    --pill-review-fg:   #2E5FA3;
    --pill-draft-bg:    #EEF0F7;
    --pill-draft-fg:    #5A6480;
    --pill-closed-bg:   #EEF0F7;
    --pill-closed-fg:   #9AA3BE;
    --pill-critical-bg: #FDECEA;
    --pill-critical-fg: #C0392B;
    --pill-executed-bg: #1B2A4A;
    --pill-executed-fg: #FFFFFF;

    /* Greys — LIGHT scale (50 = lightest bg, 800 = darkest text) */
    --grey-50:    #F7F8FC;
    --grey-100:   #EEF0F7;
    --grey-150:   #E4E8F2;
    --grey-200:   #DDE1EE;
    --grey-300:   #C1C8DA;
    --grey-400:   #9AA3BE;
    --grey-500:   #6B7592;
    --grey-600:   #5A6480;
    --grey-700:   #3A4262;
    --grey-800:   #1B2A4A;
    --white:      #FFFFFF;

    /* Surfaces */
    --bg-base:    #F7F8FC;
    --bg-elev:    #FFFFFF;
    --bg-soft:    #EEF0F7;
    --border:     #DDE1EE;
    --border-soft:#EEF0F7;

    /* Sidebar */
    --sidebar-bg:     #1B2A4A;
    --sidebar-text:   rgba(255,255,255,0.55);
    --sidebar-active: #7FBAFF;

    /* Layout */
    --sidebar-width:  220px;
    --topbar-height:  58px;
    --radius:         10px;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(27,42,74,0.08), 0 1px 2px rgba(27,42,74,0.04);
    --shadow-md: 0 4px 12px rgba(27,42,74,0.10), 0 2px 4px rgba(27,42,74,0.06);
    --shadow-lg: 0 12px 32px rgba(27,42,74,0.14), 0 4px 8px rgba(27,42,74,0.08);

    /* Typography */
    --font-serif: 'DM Serif Display', Georgia, serif;
    --font-sans:  'DM Sans', system-ui, sans-serif;
    --font-mono:  'DM Mono', 'SF Mono', monospace;
}

/* DARK THEME — same variable names, dark values */
[data-theme="dark"] {
    --navy:       #0B1426;
    --navy-deep:  #050B17;
    --navy-soft:  #1A2848;
    --blue:       #4A82D4;
    --blue-hover: #6098E6;
    --blue-lt:    rgba(110,168,247,0.12);
    --blue-md:    rgba(110,168,247,0.25);
    --blue-glow:  #7FBAFF;
    --teal:       #44B5AB;
    --teal-lt:    rgba(68,181,171,0.12);
    --gold:       #D9B254;
    --gold-lt:    rgba(217,178,84,0.12);
    --gold-bright:#FBBF24;
    --red:        #E55A48;
    --red-lt:     rgba(229,90,72,0.12);
    --red-bright: #FF7560;
    --green:      #3FA86A;
    --green-lt:   rgba(63,168,106,0.12);
    --green-bright:#5BC885;

    --pill-active-bg:   rgba(63,168,106,0.18);
    --pill-active-fg:   #5BC885;
    --pill-hold-bg:     rgba(217,178,84,0.18);
    --pill-hold-fg:     #E5C36D;
    --pill-review-bg:   rgba(110,168,247,0.18);
    --pill-review-fg:   #7FBAFF;
    --pill-draft-bg:    rgba(255,255,255,0.06);
    --pill-draft-fg:    #A8B0C6;
    --pill-closed-bg:   rgba(255,255,255,0.06);
    --pill-closed-fg:   #6B7592;
    --pill-critical-bg: rgba(229,90,72,0.18);
    --pill-critical-fg: #FF7560;
    --pill-executed-bg: #1A2848;
    --pill-executed-fg: #7FBAFF;

    /* DARK scale (50 = darkest bg, 800 = lightest text) */
    --grey-50:    #0B1426;
    --grey-100:   #131F38;
    --grey-150:   #16243F;
    --grey-200:   #1A2848;
    --grey-300:   #243057;
    --grey-400:   #6B7592;
    --grey-500:   #8A93AB;
    --grey-600:   #A8B0C6;
    --grey-700:   #C9D0DD;
    --grey-800:   #F2F4F9;

    --bg-base:    #0B1426;
    --bg-elev:    #131F38;
    --bg-soft:    #1A2848;
    --border:     rgba(255,255,255,0.08);
    --border-soft:rgba(255,255,255,0.04);

    --sidebar-bg:     #050B17;
    --sidebar-text:   rgba(255,255,255,0.5);
    --sidebar-active: #7FBAFF;

    --shadow-sm: 0 1px 3px rgba(0,0,0,0.35), 0 1px 2px rgba(0,0,0,0.25);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4),  0 2px 4px rgba(0,0,0,0.3);
    --shadow-lg: 0 12px 32px rgba(0,0,0,0.45), 0 4px 8px rgba(0,0,0,0.3);
}


/* =============================================================================
   2. RESET & BASE
   ============================================================================= */

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

html { height: 100%; }

body {
    font-family: var(--font-sans);
    font-size: 13px;
    background: var(--bg-base);
    color: var(--grey-800);
    height: 100%;
    -webkit-font-smoothing: antialiased;
    transition: background 0.2s, color 0.2s;
}

/* Serif headings — the legal-product signature */
h1, h2, h3, .card-title, .card-header .card-title,
.page-title, .stat-value, .hero-value {
    font-family: var(--font-serif);
    letter-spacing: 0.005em;
}

/* Monospace for figures, references, hashes */
.text-mono, code, .data-value.mono, .ref, .amount {
    font-family: var(--font-mono);
}

a {
    color: inherit;
    text-decoration: none;
}

ul, ol { list-style: none; }

button, input, select, textarea {
    font-family: inherit;
    font-size: inherit;
}

img { max-width: 100%; display: block; }


/* =============================================================================
   3. PAGE LAYOUT
   ============================================================================= */

.page-wrapper {
    display: flex;
    flex-direction: row;
    height: 100vh;
    overflow: hidden;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--navy);
    flex-shrink: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    transition: width .2s ease;
}

.main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.topbar {
    height: var(--topbar-height);
    background: var(--navy);
    border-bottom: 1px solid rgba(255,255,255,0.08);
    display: flex;
    flex-direction: row;
    align-items: center;
    padding: 0 20px;
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
    gap: 12px;
}
.topbar .breadcrumb { color: rgba(255,255,255,0.65); }
.topbar .breadcrumb a { color: rgba(255,255,255,0.65); }
.topbar .breadcrumb a:hover { color: #fff; }
.topbar .breadcrumb .current { color: #fff; }
.topbar .breadcrumb i { color: rgba(255,255,255,0.65); }
.topbar .icon-btn { color: rgba(255,255,255,0.75); background: transparent; }
.topbar .icon-btn:hover { color: #fff; background: rgba(255,255,255,0.08); }
.topbar input[type="text"], .topbar input[type="search"] {
    background: rgba(255,255,255,0.10);
    border: 1px solid rgba(255,255,255,0.15);
    color: #fff;
}
.topbar input[type="text"]::placeholder, .topbar input[type="search"]::placeholder {
    color: rgba(255,255,255,0.85);
    opacity: 1;
}
.topbar input[type="text"]:focus, .topbar input[type="search"]:focus {
    background: rgba(255,255,255,0.18);
    border-color: rgba(255,255,255,0.35);
    outline: none;
}
.topbar .btn-ghost {
    background: rgba(255,255,255,0.10);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.18);
}
.topbar .btn-ghost:hover:not(:disabled) {
    background: rgba(255,255,255,0.20);
    color: #fff;
    border-color: rgba(255,255,255,0.30);
}
.topbar .btn-ghost kbd {
    color: rgba(255,255,255,0.75) !important;
    background: rgba(255,255,255,0.12) !important;
}

.content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}


/* =============================================================================
   4. SIDEBAR
   ============================================================================= */

.sidebar-header {
    padding: 16px 16px 14px;
    border-bottom: 1px solid rgba(255,255,255,.07);
    flex-shrink: 0;
}

.firm-name {
    font-family: 'Inter', sans-serif;
    color: var(--white);
    font-size: 13px;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.firm-sub {
    font-size: 10px;
    color: rgba(255,255,255,.35);
    margin-top: 2px;
}

.nav-section {
    padding-top: 10px;
}

.nav-label {
    font-size: 9.5px;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: rgba(255,255,255,.30);
    padding: 10px 16px 4px;
    font-weight: 600;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 7px 16px;
    color: rgba(255,255,255,.55);
    border-left: 2px solid transparent;
    transition: background .15s, color .15s, border-color .15s;
    cursor: pointer;
    font-size: 12.5px;
    white-space: nowrap;
    overflow: hidden;
}

.nav-item svg,
.nav-item .nav-icon {
    flex-shrink: 0;
    opacity: .7;
}

.nav-item:hover {
    background: rgba(255,255,255,.05);
    color: rgba(255,255,255,.85);
}

.nav-item.active {
    background: rgba(14,143,58,.12);
    color: #6EDA8F;
    border-left-color: #0E8F3A;
    font-weight: 500;
}

.nav-item.active svg,
.nav-item.active .nav-icon {
    opacity: 1;
}

.nav-badge {
    margin-left: auto;
    background: var(--red);
    color: var(--white);
    font-size: 9px;
    font-weight: 700;
    border-radius: 10px;
    padding: 1px 5px;
    flex-shrink: 0;
    line-height: 1.4;
}

.nav-badge.amber {
    background: var(--gold);
}

.sidebar-footer {
    margin-top: auto;
    padding: 12px 16px;
    border-top: 1px solid rgba(255,255,255,.07);
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.sidebar-footer .user-info {
    overflow: hidden;
    flex: 1;
}

.sidebar-footer .user-name {
    font-size: 12px;
    color: rgba(255,255,255,.80);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-footer .user-role {
    font-size: 10px;
    color: rgba(255,255,255,.35);
}

.avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--blue), #0a6828);
    color: var(--white);
    font-size: 10px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    text-transform: uppercase;
}


/* =============================================================================
   5. TOPBAR
   ============================================================================= */

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--grey-400);
}

.breadcrumb .sep { opacity: .5; }

.breadcrumb .current {
    color: var(--grey-800);   /* #F5F5F5 in dark theme */
    font-weight: 500;
}

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


/* =============================================================================
   6. BUTTONS
   ============================================================================= */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    border-radius: var(--radius);
    font-family: 'Inter', sans-serif;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
    white-space: nowrap;
    line-height: 1.4;
    text-decoration: none;
}

.btn:disabled {
    opacity: .5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--blue);
    color: var(--white);
    border-color: var(--blue);
}
.btn-primary:hover:not(:disabled) {
    background: #0b7a30;
    border-color: #0b7a30;
}

.btn-secondary {
    background: var(--grey-100);
    color: var(--grey-800);
    border-color: var(--grey-200);
}
.btn-secondary:hover:not(:disabled) {
    background: var(--grey-200);
}

.btn-ghost {
    background: transparent;
    color: var(--grey-600);
    border-color: var(--grey-200);
}
.btn-ghost:hover:not(:disabled) {
    background: var(--grey-100);
    color: var(--grey-800);
}

.btn-danger {
    background: var(--red-lt);
    color: var(--red);
    border-color: #f5c6c2;
}
.btn-danger:hover:not(:disabled) {
    background: #fad5d2;
}

.btn-success {
    background: var(--green-lt);
    color: var(--green);
    border-color: rgba(14,143,58,.30);
}
.btn-success:hover:not(:disabled) {
    background: rgba(14,143,58,.25);
}

.btn-tertiary {
    background: rgba(79,70,229,.18);
    color: #818CF8;
    border-color: rgba(79,70,229,.35);
}
.btn-tertiary:hover:not(:disabled) {
    background: rgba(79,70,229,.28);
    color: #A5B4FC;
}

.btn-sm {
    padding: 4px 9px;
    font-size: 11px;
}

.btn-lg {
    padding: 9px 18px;
    font-size: 13px;
}

.icon-btn {
    width: 32px;
    height: 32px;
    border-radius: var(--radius);
    border: 1px solid var(--grey-200);
    background: var(--grey-100);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--grey-600);
    transition: background .15s, color .15s;
    flex-shrink: 0;
}
.icon-btn:hover {
    background: var(--grey-100);
    color: var(--grey-800);
}


/* =============================================================================
   7. STATUS PILLS
   ============================================================================= */

.pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
}

.pill-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}

/*
 * Status pills — specificity (0,2,0) beats .data-table td (0,1,1).
 * All colours read from CSS tokens defined in :root so sector themes
 * and accessibility overrides only need to change the variables.
 */

.pill.pill-active   { background: var(--pill-active-bg);   color: var(--pill-active-fg); }
.pill.pill-active   .pill-dot { background: var(--pill-active-fg); }

.pill.pill-hold     { background: var(--pill-hold-bg);     color: var(--pill-hold-fg); }
.pill.pill-hold     .pill-dot { background: var(--pill-hold-fg); }

.pill.pill-review   { background: var(--pill-review-bg);   color: var(--pill-review-fg); }
.pill.pill-review   .pill-dot { background: var(--pill-review-fg); }

.pill.pill-draft    { background: var(--pill-draft-bg);    color: var(--pill-draft-fg); }
.pill.pill-draft    .pill-dot { background: var(--pill-draft-fg); }

.pill.pill-closed   { background: var(--pill-closed-bg);   color: var(--pill-closed-fg); }
.pill.pill-closed   .pill-dot { background: var(--pill-closed-fg); }

.pill.pill-critical { background: var(--pill-critical-bg); color: var(--pill-critical-fg); }
.pill.pill-critical .pill-dot { background: var(--pill-critical-fg); }

.pill.pill-executed { background: var(--pill-executed-bg); color: var(--pill-executed-fg);
                      border: 1px solid var(--grey-200); }
.pill.pill-executed .pill-dot { background: var(--cyan); }


/* =============================================================================
   8. CARDS
   ============================================================================= */

.card {
    background: var(--grey-100);
    border-radius: var(--radius);
    border: 1px solid var(--grey-200);
    box-shadow: var(--shadow-sm);
}

.card-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--grey-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.card-title {
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    color: var(--grey-800);
    line-height: 1.3;
}

.card-body { padding: 14px 16px; }

.card-footer {
    padding: 10px 16px;
    border-top: 1px solid var(--grey-200);
    background: var(--grey-50);
    border-radius: 0 0 var(--radius) var(--radius);
}

.card-action {
    font-size: 11px;
    color: var(--blue);
    cursor: pointer;
    text-decoration: none;
    transition: opacity .15s;
}
.card-action:hover { text-decoration: underline; }


/* =============================================================================
   9. FORM ELEMENTS
   ============================================================================= */

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

.form-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--grey-600);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.form-control {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--grey-200);
    border-radius: var(--radius);
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    background: var(--grey-50);
    color: var(--grey-800);
    transition: border-color .15s, box-shadow .15s;
    appearance: none;
    -webkit-appearance: none;
}

.form-control:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(14,143,58,.12);
}

.form-control::placeholder { color: var(--grey-400); }

/* Tell the browser this is a dark-theme input so native date/time pickers
   render their calendar icon and popup in light colours. */
input[type="date"].form-control,
input[type="time"].form-control,
input[type="datetime-local"].form-control {
    color-scheme: dark;
}

.form-control:disabled {
    background: var(--grey-50);
    color: var(--grey-400);
    cursor: not-allowed;
}

.form-select {
    width: 100%;
    padding: 8px 32px 8px 12px;
    border: 1px solid var(--grey-200);
    border-radius: var(--radius);
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    background: var(--grey-50) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236B7280' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 10px center;
    color: var(--grey-800);
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
    transition: border-color .15s, box-shadow .15s;
}

.form-select:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(14,143,58,.12);
}

textarea.form-control {
    min-height: 100px;
    resize: vertical;
    line-height: 1.5;
}

.form-check {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    cursor: pointer;
}

.form-check input[type="checkbox"],
.form-check input[type="radio"] {
    width: 15px;
    height: 15px;
    accent-color: var(--blue);
    cursor: pointer;
    flex-shrink: 0;
}

.form-hint {
    font-size: 11px;
    color: var(--grey-400);
    margin-top: 4px;
}

.form-error {
    font-size: 11px;
    color: var(--red);
    margin-top: 4px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-row-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 16px;
}


/* =============================================================================
   10. DATA DISPLAY ROWS
   ============================================================================= */

.data-row {
    display: flex;
    align-items: baseline;
    padding: 6px 0;
    border-bottom: 1px solid var(--grey-200);
    gap: 12px;
}

.data-row:last-child { border-bottom: none; }

.data-label {
    font-size: 11px;
    color: var(--grey-400);
    width: 110px;
    flex-shrink: 0;
    line-height: 1.5;
}

.data-value {
    font-size: 12.5px;
    color: var(--grey-800);  /* #F5F5F5 in dark theme */
    flex: 1;
    line-height: 1.5;
}

.data-value.mono {
    font-family: 'Courier New', monospace;
    font-size: 11.5px;
}

.data-value.link {
    color: var(--blue);
    cursor: pointer;
}
.data-value.link:hover { text-decoration: underline; }


/* =============================================================================
   11. STAT TILES
   ============================================================================= */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}

.stat-tile {
    background: var(--grey-100);
    border-radius: var(--radius);
    border: 1px solid var(--grey-200);
    padding: 14px 16px;
    box-shadow: var(--shadow-sm);
}

.stat-label {
    font-size: 10.5px;
    color: var(--grey-400);
    text-transform: uppercase;
    letter-spacing: .05em;
    font-weight: 600;
    margin-bottom: 4px;
}

.stat-value {
    font-family: 'Inter', sans-serif;
    font-size: 22px;
    color: var(--grey-800);
    line-height: 1.2;
}

.stat-sub {
    font-size: 10.5px;
    color: var(--grey-400);
    margin-top: 3px;
}

.stat-sub.up    { color: var(--green); }
.stat-sub.down  { color: var(--red); }
.stat-sub.warn  { color: var(--gold); }


/* =============================================================================
   12. TABLES
   ============================================================================= */

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    text-align: left;
    font-size: 10.5px;
    font-weight: 600;
    color: var(--grey-400);
    text-transform: uppercase;
    letter-spacing: .05em;
    padding: 8px 12px;
    border-bottom: 1px solid var(--grey-200);
    background: var(--grey-50);
    white-space: nowrap;
}

.data-table td {
    padding: 9px 12px;
    border-bottom: 1px solid var(--grey-200);
    font-size: 12.5px;
    color: var(--grey-800);
    vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }

.data-table tbody tr:hover td { background: rgba(255,255,255,.03); }

.data-table .amount {
    font-family: 'Courier New', monospace;
    font-size: 12px;
    text-align: right;
    white-space: nowrap;
}

.data-table .ref {
    font-family: 'Courier New', monospace;
    font-size: 11.5px;
    color: var(--grey-600);
}

.table-wrap {
    border-radius: var(--radius);
    border: 1px solid var(--grey-200);
    overflow: hidden;
    background: var(--grey-100);
    box-shadow: var(--shadow-sm);
}


/* =============================================================================
   13. ALERT BARS
   ============================================================================= */

.alert-bar {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 9px 14px;
    border-radius: var(--radius);
    font-size: 12px;
    margin-bottom: 12px;
    border: 1px solid transparent;
    line-height: 1.5;
}

.alert-bar.warning {
    background: var(--gold-lt);
    color: var(--gold);
    border-color: #e8d28a;
}

.alert-bar.danger {
    background: var(--red-lt);
    color: var(--red);
    border-color: #f0b8b3;
}

.alert-bar.info {
    background: var(--blue-lt);
    color: var(--blue);
    border-color: var(--blue-md);
}

.alert-bar.success {
    background: var(--green-lt);
    color: var(--green);
    border-color: #A5D6B5;
}

.alert-bar .alert-icon { flex-shrink: 0; margin-top: 1px; }


/* =============================================================================
   14. TAB NAVIGATION
   ============================================================================= */

.tab-bar {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--grey-200);
    margin-bottom: 20px;
    overflow-x: auto;
    -ms-overflow-style: none;
    scrollbar-width: none;
}
.tab-bar::-webkit-scrollbar { display: none; }

.tab-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    font-size: 13px;
    font-weight: 500;
    color: var(--grey-500);
    /* button reset */
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    outline: none;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: color .15s, border-color .15s, background .15s;
    margin-bottom: -1px;
    flex-shrink: 0;
    font-family: inherit;
    line-height: 1.4;
}
.tab-item:hover { color: var(--grey-800); background: rgba(0,0,0,.03); }
.tab-item.active { color: var(--blue); border-bottom-color: var(--blue); }
.tab-item:focus-visible { outline: 2px solid var(--blue); outline-offset: -2px; }

.tab-pane { display: none; }
.tab-pane.active { display: block; }


/* =============================================================================
   15. TIMELINE
   ============================================================================= */

.timeline { padding: 4px 0; }

.timeline-item {
    display: flex;
    gap: 10px;
    padding-bottom: 14px;
}

.timeline-item:last-child { padding-bottom: 0; }

.timeline-line {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex-shrink: 0;
}

.timeline-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--blue-md);
    flex-shrink: 0;
    margin-top: 4px;
}

.timeline-dot.green  { background: var(--green); }
.timeline-dot.red    { background: var(--red); }
.timeline-dot.gold   { background: var(--gold); }
.timeline-dot.navy   { background: var(--navy); }

.timeline-connector {
    width: 1px;
    background: var(--grey-200);
    flex: 1;
    margin-top: 3px;
}

.timeline-body { flex: 1; min-width: 0; }

.timeline-text {
    font-size: 12px;
    color: var(--grey-800);
    line-height: 1.5;
}

.timeline-meta {
    font-size: 10.5px;
    color: var(--grey-400);
    margin-top: 1px;
}


/* =============================================================================
   15. SEARCH BOX
   ============================================================================= */

.search-box {
    display: flex;
    align-items: center;
    gap: 7px;
    background: rgba(255,255,255,0.12);
    border: 1px solid rgba(255,255,255,0.18);
    border-radius: var(--radius);
    padding: 6px 10px;
    font-size: 12px;
    color: #fff;
    cursor: text;
    min-width: 200px;
    transition: border-color .15s, box-shadow .15s, background .15s;
}

.search-box:focus-within {
    border-color: rgba(255,255,255,0.45);
    background: rgba(255,255,255,0.20);
    box-shadow: 0 0 0 3px rgba(255,255,255,0.08);
}

.search-box input {
    border: none;
    background: transparent;
    outline: none;
    flex: 1;
    font-size: 12px;
    color: #fff;
    min-width: 0;
}

.search-box input::placeholder { color: rgba(255,255,255,0.75); opacity: 1; }

.search-icon { color: rgba(255,255,255,0.75); flex-shrink: 0; }


/* =============================================================================
   16. MODALS
   ============================================================================= */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.50);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2100;
    padding: 20px;
}

.modal-overlay.active { display: flex; }

.modal {
    background: var(--grey-100);
    border-radius: var(--radius);
    padding: 24px;
    width: 500px;
    max-width: 90vw;
    box-shadow: var(--shadow-md);
    max-height: 90vh;
    overflow-y: auto;
    animation: modal-in .18s ease;
}

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

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.modal-title {
    font-family: 'Inter', sans-serif;
    font-size: 18px;
    color: var(--grey-800);
}

.modal-close {
    cursor: pointer;
    color: var(--grey-400);
    transition: color .15s;
    line-height: 1;
    font-size: 18px;
    background: none;
    border: none;
    padding: 2px;
}
.modal-close:hover { color: var(--grey-800); }  /* #F5F5F5 */

.modal-footer {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--grey-200);
}

.modal-lg  { width: 700px; }
.modal-sm  { width: 360px; }

/* modal-box: used in views as the inner box of a .modal-overlay */
.modal-box {
    background: var(--grey-100);
    border-radius: var(--radius);
    width: 500px;
    max-width: 90vw;
    box-shadow: var(--shadow-md);
    max-height: 90vh;
    overflow-y: auto;
    animation: modal-in .18s ease;
    border: 1px solid var(--grey-200);
}


/* =============================================================================
   17. LOGIN PAGE
   ============================================================================= */

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--grey-50);
    padding: 20px;
}

.login-card {
    background: var(--grey-100);
    border-radius: var(--radius);
    padding: 40px;
    width: 400px;
    max-width: 100%;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--grey-200);
}

.login-logo {
    font-family: 'Inter', sans-serif;
    font-size: 36px;
    color: var(--color-primary);
    text-align: center;
    margin-bottom: 8px;
    line-height: 1;
}

.login-subtitle {
    color: var(--grey-400);
    text-align: center;
    margin-bottom: 32px;
    font-size: 13px;
}

.login-card .btn-primary {
    width: 100%;
    justify-content: center;
    padding: 9px 12px;
    font-size: 13px;
    margin-top: 4px;
}

.login-footer {
    text-align: center;
    margin-top: 16px;
    font-size: 12px;
    color: var(--grey-400);
}

.login-footer a {
    color: var(--blue);
}
.login-footer a:hover { text-decoration: underline; }


/* =============================================================================
   18. FLASH MESSAGES
   ============================================================================= */

.flash {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 13px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    border: 1px solid transparent;
    line-height: 1.5;
    /* Fixed toast — sits inside the nav bar, never overlaps page content */
    position: fixed;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 3000;
    max-width: 480px;
    min-width: 300px;
    box-shadow: 0 4px 20px rgba(0,0,0,.18);
    animation: flashSlideIn .25s ease;
}
@keyframes flashSlideIn {
    from { opacity: 0; transform: translateX(-50%) translateY(-8px); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.flash.success {
    background: var(--green-lt);
    color: var(--green);
    border-color: #A5D6B5;
}

.flash.error {
    background: var(--red-lt);
    color: var(--red);
    border-color: #f0b8b3;
}

.flash.warning {
    background: var(--gold-lt);
    color: var(--gold);
    border-color: #e8d28a;
}

.flash.info {
    background: var(--blue-lt);
    color: var(--blue);
    border-color: var(--blue-md);
}

.flash-icon { flex-shrink: 0; }

.flash-close {
    margin-left: auto;
    cursor: pointer;
    opacity: .6;
    background: none;
    border: none;
    color: inherit;
    font-size: 16px;
    line-height: 1;
    padding: 0;
}
.flash-close:hover { opacity: 1; }


/* =============================================================================
   19. UTILITY CLASSES
   ============================================================================= */

/* Flex */
.flex        { display: flex; }
.flex-1      { flex: 1; }
.flex-col    { flex-direction: column; }
.items-center{ align-items: center; }
.justify-between { justify-content: space-between; }
.gap-4       { gap: 4px; }
.gap-8       { gap: 8px; }
.gap-12      { gap: 12px; }
.gap-16      { gap: 16px; }

/* Grids */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }

/* Spacing */
.mb-4  { margin-bottom: 4px; }
.mb-8  { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.mb-20 { margin-bottom: 20px; }
.mb-24 { margin-bottom: 24px; }
.mt-8  { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }

/* Typography */
.text-xs     { font-size: 10.5px; }
.text-sm     { font-size: 12px; }
.text-muted  { color: var(--grey-400); }
.text-navy   { color: var(--grey-800); }
.text-blue   { color: var(--blue); }
.text-red    { color: var(--red); }
.text-green  { color: var(--green); }
.text-gold   { color: var(--gold); }
.text-bold   { font-weight: 600; }
.text-serif  { font-family: 'Inter', sans-serif; }
.text-mono   { font-family: 'Courier New', monospace; }
.text-center { text-align: center; }
.text-right  { text-align: right; }

/* Sizing */
.w-full { width: 100%; }

/* Visibility */
.hidden  { display: none; }
.visible { display: block; }

/* Section title */
.section-title {
    font-family: 'Inter', sans-serif;
    font-size: 15px;
    color: var(--grey-800);
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    line-height: 1.2;
}

/* Count badge */
.count-badge {
    font-family: 'Inter', sans-serif;
    font-size: 10.5px;
    font-weight: 600;
    background: var(--grey-200);
    color: var(--grey-400);
    padding: 1px 7px;
    border-radius: 10px;
    display: inline-block;
}

/* Divider */
.divider {
    border: none;
    border-top: 1px solid var(--grey-200);
    margin: 16px 0;
}

/* Page header */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    gap: 12px;
}

.page-title {
    font-family: 'Inter', sans-serif;
    font-size: 20px;
    color: var(--grey-800);
    line-height: 1.2;
}


/* =============================================================================
   20. CUSTOM SCROLLBAR
   ============================================================================= */

::-webkit-scrollbar           { width: 5px; height: 5px; }
::-webkit-scrollbar-track     { background: transparent; }
::-webkit-scrollbar-thumb     { background: var(--grey-200); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--grey-400); }

* { scrollbar-width: thin; scrollbar-color: var(--grey-200) transparent; }


/* =============================================================================
   21. RESPONSIVE — Tablet (≤ 768px): sidebar collapses to icon rail
   ============================================================================= */

@media (max-width: 768px) {

    .sidebar {
        width: 48px;
    }

    .sidebar-header {
        padding: 12px 10px;
    }

    .firm-name,
    .firm-sub,
    .nav-label,
    .nav-badge,
    .sidebar-footer .user-info {
        display: none;
    }

    .nav-item {
        padding: 10px 0;
        justify-content: center;
        gap: 0;
    }

    .nav-item svg,
    .nav-item .nav-icon {
        opacity: .7;
    }

    .nav-item.active svg,
    .nav-item.active .nav-icon {
        opacity: 1;
    }

    .sidebar-footer {
        justify-content: center;
        padding: 12px 0;
    }

    .stat-grid  { grid-template-columns: repeat(2, 1fr); }
    .grid-4     { grid-template-columns: repeat(2, 1fr); }
    .grid-3     { grid-template-columns: repeat(2, 1fr); }
    .form-row   { grid-template-columns: 1fr; }
    .form-row-3 { grid-template-columns: 1fr; }

    .content { padding: 12px; }

    .login-card { padding: 28px 20px; }
}

@media (max-width: 480px) {
    .stat-grid { grid-template-columns: 1fr 1fr; }
    .grid-2    { grid-template-columns: 1fr; }
    .modal     { padding: 16px; }
}

/* ── Clause / Template rich text content ────────────────────────────────── */
.clause-content {
    font-size: 13px;
    line-height: 1.7;
    color: var(--grey-800);
}
.clause-content * { color: var(--grey-800) !important; }
.clause-content p { margin-bottom: 0.6em; }
.clause-content ul, .clause-content ol { padding-left: 1.4em; margin-bottom: 0.6em; }

/* ── Quill editor integration ─────────────────────────────────────────────*/
.quill-wrap { border: 1px solid var(--grey-200); border-radius: var(--radius); overflow: hidden; }
.quill-wrap .ql-toolbar { border: none; border-bottom: 1px solid var(--grey-200); background: var(--grey-50); }
.quill-wrap .ql-container { border: none; font-size: 13px; font-family: inherit; }
.quill-wrap .ql-editor { min-height: 200px; max-height: 500px; overflow-y: auto; color: #111827 !important; background: #fff !important; }
.quill-wrap .ql-editor.ql-blank::before { color: #9CA3AF !important; font-style: italic; }
.quill-wrap .ql-editor p, .quill-wrap .ql-editor li { color: #111827 !important; }
.quill-wrap .ql-toolbar .ql-stroke { stroke: #6B7280; }
.quill-wrap .ql-toolbar .ql-fill  { fill:   #6B7280; }
.quill-wrap .ql-toolbar button:hover .ql-stroke { stroke: #111827; }
.quill-wrap .ql-toolbar button:hover .ql-fill   { fill:   #111827; }

/* ── Tooltip system (data-tooltip attribute) ──────────────────────────────── */
[data-tooltip] {
    position: relative;
    cursor: help;
}
[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: #1F2937;
    color: #F9FAFB;
    font-size: 11.5px;
    font-weight: 400;
    line-height: 1.4;
    padding: 5px 10px;
    border-radius: 5px;
    white-space: pre-wrap;
    max-width: 240px;
    text-align: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity .15s;
    z-index: 9000;
    box-shadow: 0 2px 8px rgba(0,0,0,.3);
}
[data-tooltip]:hover::after {
    opacity: 1;
}
/* Tooltip arrow */
[data-tooltip]::before {
    content: '';
    position: absolute;
    bottom: calc(100% + 1px);
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: #1F2937;
    opacity: 0;
    transition: opacity .15s;
    z-index: 9000;
    pointer-events: none;
}
[data-tooltip]:hover::before {
    opacity: 1;
}
/* Tooltip positioned below */
[data-tooltip-pos="below"]::after {
    bottom: auto;
    top: calc(100% + 6px);
}
[data-tooltip-pos="below"]::before {
    bottom: auto;
    top: calc(100% + 1px);
    border-top-color: transparent;
    border-bottom-color: #1F2937;
}

/* ── Form hint text ───────────────────────────────────────────────────────── */
.form-hint {
    font-size: 11.5px;
    color: var(--grey-400);
    margin-top: 3px;
    line-height: 1.4;
}

/* ── Help icon inline button ─────────────────────────────────────────────── */
.help-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--grey-200);
    color: var(--grey-600);
    font-size: 10px;
    cursor: help;
    margin-left: 4px;
    vertical-align: middle;
    flex-shrink: 0;
    transition: background .12s;
}
.help-icon:hover {
    background: var(--blue);
    color: #fff;
}

/* ── Stats grid (reports tile layout) ────────────────────────────────────── */
.stats-grid {
    display: grid;
    gap: 12px;
}
