/* ==========================================================================
   ABI Law Firm — Case Management
   Design system: clean white, formal typography, blue primary.
   ========================================================================== */

:root {
    /* brand */
    --primary:        #1d4ed8;
    --primary-dark:   #1e40af;
    --primary-darker: #1e3a8a;
    --primary-light:  #dbeafe;
    --primary-soft:   #eff6ff;
    --accent:         #a16207;   /* restrained gold, used sparingly */

    /* semantic */
    --success:        #15803d;
    --success-light:  #dcfce7;
    --warning:        #b45309;
    --warning-light:  #fef3c7;
    --danger:         #b91c1c;
    --danger-light:   #fee2e2;
    --info:           #0e7490;
    --info-light:     #cffafe;
    --purple:         #6d28d9;
    --purple-light:   #ede9fe;

    /* chrome */
    --sidebar-bg:     #101828;
    --sidebar-hover:  #1d2939;
    --sidebar-text:   #cbd5e1;
    --sidebar-muted:  #64748b;
    --sidebar-active: #1d4ed8;

    --bg:             #f8fafc;
    --surface:        #ffffff;
    --surface-alt:    #f8fafc;
    --surface-sunk:   #f1f5f9;

    --text:           #0f172a;
    --text-body:      #334155;
    --text-muted:     #64748b;
    --text-light:     #94a3b8;

    --border:         #e2e8f0;
    --border-strong:  #cbd5e1;

    --radius-sm:      5px;
    --radius:         8px;
    --radius-lg:      12px;

    --shadow-xs:      0 1px 2px rgba(16, 24, 40, .05);
    --shadow-sm:      0 1px 3px rgba(16, 24, 40, .1), 0 1px 2px rgba(16, 24, 40, .06);
    --shadow:         0 4px 12px rgba(16, 24, 40, .08);
    --shadow-lg:      0 12px 32px rgba(16, 24, 40, .16);

    --sidebar-w:      252px;
    --topbar-h:       60px;

    --font:  -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --serif: Georgia, "Times New Roman", "Nimbus Roman", serif;
    --mono:  ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.55;
    color: var(--text-body);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5 { margin: 0; font-weight: 650; line-height: 1.28; color: var(--text); letter-spacing: -.01em; }
h1 { font-size: 21px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p  { margin: 0 0 12px; }

/* Formal serif for case names and record titles — the legal register. */
.serif { font-family: var(--serif); letter-spacing: 0; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 3px; }

.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0;
    margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ==========================================================================
   Auth
   ========================================================================== */

.auth-wrap {
    min-height: 100vh; display: grid; place-items: center; padding: 24px;
    background: linear-gradient(160deg, #101828 0%, #1e3a8a 60%, #1d4ed8 100%);
}

.auth-card {
    width: 100%; max-width: 416px;
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 38px 34px;
}

.auth-brand { text-align: center; margin-bottom: 26px; }

.auth-brand .logo {
    width: 56px; height: 56px; margin: 0 auto 15px;
    border-radius: 12px;
    background: linear-gradient(150deg, var(--primary-darker), var(--primary));
    display: grid; place-items: center;
    color: #fff;
    box-shadow: 0 6px 18px rgba(29, 78, 216, .3);
}
.auth-brand .logo svg { width: 28px; height: 28px; }

.auth-brand h1 { font-family: var(--serif); font-size: 22px; margin-bottom: 4px; }
.auth-brand p  { color: var(--text-muted); font-size: 13px; margin: 0; }

.auth-footer {
    margin-top: 24px; padding-top: 18px;
    border-top: 1px solid var(--border);
    text-align: center; font-size: 12px; color: var(--text-light);
}

/* ==========================================================================
   Shell
   ========================================================================== */

.layout { min-height: 100vh; }

.sidebar {
    position: fixed; inset: 0 auto 0 0;
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    display: flex; flex-direction: column;
    z-index: 60;
    transition: transform .22s ease;
}

.sidebar-head {
    height: var(--topbar-h);
    display: flex; align-items: center; gap: 11px;
    padding: 0 18px;
    border-bottom: 1px solid rgba(148, 163, 184, .14);
    flex-shrink: 0;
}

.sidebar-head .logo {
    width: 34px; height: 34px; border-radius: 8px;
    background: linear-gradient(150deg, var(--primary), var(--primary-darker));
    display: grid; place-items: center; color: #fff; flex-shrink: 0;
}
.sidebar-head .logo svg { width: 18px; height: 18px; }

.sidebar-head .name {
    color: #fff; font-family: var(--serif); font-weight: 600; font-size: 15.5px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.sidebar-nav {
    flex: 1; overflow-y: auto; padding: 14px 10px 24px;
    scrollbar-width: thin; scrollbar-color: #334155 transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 6px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: #334155; border-radius: 3px; }

.nav-group {
    padding: 16px 10px 6px;
    font-size: 10.5px; font-weight: 700; letter-spacing: .1em;
    text-transform: uppercase; color: var(--sidebar-muted);
}

.nav-item {
    display: flex; align-items: center; gap: 11px;
    padding: 9px 11px; margin-bottom: 2px;
    border-radius: 6px;
    color: var(--sidebar-text);
    font-size: 13.5px; font-weight: 500;
    transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }
.nav-item.active { background: var(--sidebar-active); color: #fff; font-weight: 550; }
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }

.nav-item .count {
    margin-left: auto; background: rgba(255, 255, 255, .16);
    padding: 1px 7px; border-radius: 10px; font-size: 11px; font-weight: 600;
}
.nav-item.active .count { background: rgba(255, 255, 255, .26); }

.sidebar-foot { padding: 12px; border-top: 1px solid rgba(148, 163, 184, .14); flex-shrink: 0; }

.sidebar-user { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 7px; color: var(--sidebar-text); }
.sidebar-user:hover { background: var(--sidebar-hover); text-decoration: none; }
.sidebar-user .meta { min-width: 0; }
.sidebar-user .n { color: #fff; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .r { font-size: 11.5px; color: #94a3b8; }

.main { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 14px;
    padding: 0 22px; position: sticky; top: 0; z-index: 40;
}

.topbar .burger {
    display: none; background: none; border: 0; cursor: pointer;
    padding: 7px; border-radius: 6px; color: var(--text-muted);
}
.topbar .burger:hover { background: var(--surface-sunk); }

.page-title { font-size: 16px; font-weight: 650; color: var(--text); }
.topbar-spacer { flex: 1; }

/* search */
.search-box { position: relative; width: 320px; max-width: 34vw; }

.search-box input {
    width: 100%; height: 37px; padding: 0 12px 0 35px;
    border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--surface-sunk); font-size: 13.5px; font-family: inherit; color: var(--text);
}
.search-box input:focus {
    outline: none; border-color: var(--primary); background: #fff;
    box-shadow: 0 0 0 3px var(--primary-soft);
}
.search-box .icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-light); pointer-events: none; }

.search-results {
    position: absolute; top: calc(100% + 6px); left: 0; right: 0;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-lg);
    max-height: 400px; overflow-y: auto; z-index: 70; display: none;
}
.search-results.open { display: block; }
.search-results .row { display: flex; align-items: center; gap: 10px; padding: 10px 13px; border-bottom: 1px solid var(--border); color: var(--text); }
.search-results .row:last-child { border-bottom: 0; }
.search-results .row:hover, .search-results .row:focus { background: var(--primary-soft); text-decoration: none; }
.search-results .row .l { font-weight: 550; font-size: 13.5px; }
.search-results .row .m { font-size: 12px; color: var(--text-muted); }
.search-results .empty { padding: 16px; text-align: center; color: var(--text-muted); font-size: 13px; }

.icon-btn {
    position: relative; width: 37px; height: 37px;
    display: grid; place-items: center;
    border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--surface); color: var(--text-muted); cursor: pointer;
    transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-sunk); color: var(--text); text-decoration: none; }

.icon-btn .dot {
    position: absolute; top: -5px; right: -5px;
    min-width: 17px; height: 17px; padding: 0 4px;
    background: var(--danger); color: #fff;
    border-radius: 9px; border: 2px solid var(--surface);
    font-size: 10px; font-weight: 700; display: grid; place-items: center;
}

/* dropdown */
.dropdown { position: relative; }
.dropdown-menu {
    position: absolute; right: 0; top: calc(100% + 7px); min-width: 222px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-lg);
    padding: 6px; z-index: 70; display: none;
}
.dropdown-menu.open { display: block; }
.dropdown-menu.wide { min-width: 340px; padding: 0; }

.dropdown-menu a, .dropdown-menu button {
    display: flex; align-items: center; gap: 9px; width: 100%;
    padding: 8px 11px; border: 0; background: none; border-radius: 6px;
    font: inherit; font-size: 13.5px; color: var(--text-body); text-align: left; cursor: pointer;
}
.dropdown-menu a:hover, .dropdown-menu button:hover { background: var(--surface-sunk); text-decoration: none; color: var(--text); }
.dropdown-menu .divider { height: 1px; background: var(--border); margin: 5px 0; }
.dropdown-menu .danger { color: var(--danger); }

.dropdown-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 11px 14px; border-bottom: 1px solid var(--border); font-weight: 650; font-size: 13.5px; color: var(--text);
}

.notif-list { max-height: 360px; overflow-y: auto; }
.notif-item { display: block; padding: 11px 14px; border-bottom: 1px solid var(--border); color: var(--text-body); }
.notif-item:last-child { border-bottom: 0; }
.notif-item:hover { background: var(--surface-sunk); text-decoration: none; }
.notif-item.unread { background: var(--primary-soft); }
.notif-item .t { font-weight: 600; font-size: 13px; margin-bottom: 2px; color: var(--text); }
.notif-item .m { font-size: 12.5px; color: var(--text-muted); }
.notif-item .a { font-size: 11.5px; color: var(--text-light); margin-top: 3px; }

.content { flex: 1; padding: 24px; max-width: 1640px; width: 100%; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head .sub { color: var(--text-muted); font-size: 13.5px; margin-top: 4px; }
.page-actions { display: flex; gap: 9px; flex-wrap: wrap; }

.breadcrumb { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-muted); margin-bottom: 8px; flex-wrap: wrap; }
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--primary); }

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    height: 38px; padding: 0 16px;
    border: 1px solid transparent; border-radius: var(--radius);
    background: var(--surface); font: inherit; font-size: 13.5px; font-weight: 550;
    color: var(--text); cursor: pointer; white-space: nowrap;
    transition: background .15s, border-color .15s, box-shadow .15s, opacity .15s;
}
.btn:hover { text-decoration: none; }
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.btn-primary { background: var(--primary); color: #fff; box-shadow: var(--shadow-xs); }
.btn-primary:hover { background: var(--primary-dark); }

.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text-body); }
.btn-secondary:hover { background: var(--surface-sunk); color: var(--text); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #991b1b; }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #166534; }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-sunk); color: var(--text); }

.btn-sm { height: 32px; padding: 0 11px; font-size: 12.5px; }
.btn-sm svg { width: 14px; height: 14px; }
.btn-icon { width: 32px; padding: 0; }

.btn:disabled, .btn.is-loading { opacity: .6; pointer-events: none; }
.btn.is-loading::after {
    content: ''; width: 13px; height: 13px;
    border: 2px solid currentColor; border-right-color: transparent;
    border-radius: 50%; animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.btn-group { display: inline-flex; gap: 6px; }

/* ==========================================================================
   Cards
   ========================================================================== */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-xs);
    margin-bottom: 20px;
    overflow: hidden;
}

.card-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; flex-wrap: wrap;
    padding: 15px 20px; border-bottom: 1px solid var(--border);
}
.card-head h2, .card-head h3 { font-size: 14.5px; }
.card-head .sub { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }

.card-body { padding: 20px; }
.card-body.tight { padding: 0; }
.card-foot {
    padding: 14px 20px; border-top: 1px solid var(--border);
    background: var(--surface-alt);
    display: flex; gap: 9px; justify-content: flex-end; flex-wrap: wrap;
}

/* ==========================================================================
   Stat tiles
   ========================================================================== */

.stat-grid { display: grid; gap: 14px; margin-bottom: 20px; grid-template-columns: repeat(auto-fit, minmax(196px, 1fr)); }

.stat {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 16px;
    box-shadow: var(--shadow-xs);
    display: flex; align-items: flex-start; gap: 13px;
}
a.stat:hover { border-color: var(--primary); box-shadow: var(--shadow-sm); text-decoration: none; }

.stat .ico { width: 40px; height: 40px; border-radius: 9px; display: grid; place-items: center; flex-shrink: 0; }
.stat .ico svg { width: 20px; height: 20px; }

/* label / value / hint must stack */
.stat > span:last-child { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.stat .lbl {
    display: block; font-size: 11.5px; color: var(--text-muted); font-weight: 600;
    text-transform: uppercase; letter-spacing: .05em; line-height: 1.35;
}
.stat .val { display: block; font-size: 26px; font-weight: 700; line-height: 1.12; margin-top: 4px; color: var(--text); letter-spacing: -.02em; }
.stat .hint { display: block; font-size: 12px; color: var(--text-light); margin-top: 3px; line-height: 1.35; }

.ico-blue   { background: var(--primary-light); color: var(--primary); }
.ico-green  { background: var(--success-light); color: var(--success); }
.ico-amber  { background: var(--warning-light); color: var(--warning); }
.ico-red    { background: var(--danger-light);  color: var(--danger); }
.ico-cyan   { background: var(--info-light);    color: var(--info); }
.ico-purple { background: var(--purple-light);  color: var(--purple); }
.ico-slate  { background: var(--surface-sunk);  color: var(--text-muted); }

/* ==========================================================================
   Tables — spacious, formal
   ========================================================================== */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }

table.data th {
    text-align: left; padding: 12px 16px;
    background: var(--surface-alt);
    border-bottom: 1px solid var(--border);
    font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
    color: var(--text-muted); white-space: nowrap;
}
table.data th a { color: inherit; display: inline-flex; align-items: center; gap: 4px; }
table.data th a:hover { color: var(--primary); text-decoration: none; }
table.data th .arrow { opacity: .4; }
table.data th a.sorted .arrow { opacity: 1; color: var(--primary); }

table.data td { padding: 14px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; color: var(--text-body); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--surface-alt); }

/* Wide listings (the case list carries 12 columns) trade a little breathing
   room so every column — including Status and Action — fits without scrolling. */
table.data.compact th { padding: 10px 8px; font-size: 10.5px; }
table.data.compact td { padding: 11px 8px; font-size: 12.5px; }
table.data.compact .col-name  { max-width: 205px; }
table.data.compact .col-tight { max-width: 96px; }
table.data.compact .cell-sub  { font-size: 11px; }
table.data.compact .badge     { padding: 2px 7px; font-size: 11px; }

table.data .num { text-align: right; font-variant-numeric: tabular-nums; }
table.data .actions { text-align: right; white-space: nowrap; }
table.data .w-1 { width: 1%; white-space: nowrap; }
table.data .rownum { color: var(--text-light); font-variant-numeric: tabular-nums; font-size: 12.5px; }

.cell-primary { font-weight: 600; color: var(--text); }
.cell-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.cell-uid { font-family: var(--mono); font-size: 12px; color: var(--primary); font-weight: 600; }

.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0; color: #fff; font-size: 12px; font-weight: 650; }
.avatar.sm { width: 26px; height: 26px; font-size: 10px; }
.avatar.lg { width: 52px; height: 52px; font-size: 18px; }

.user-cell { display: flex; align-items: center; gap: 10px; }

/* ==========================================================================
   Badges
   ========================================================================== */

.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 10px; border-radius: 4px;
    font-size: 11.5px; font-weight: 600; white-space: nowrap;
    border: 1px solid transparent;
}

.badge-success { background: var(--success-light); color: #14532d; border-color: #bbf7d0; }
.badge-warning { background: var(--warning-light); color: #78350f; border-color: #fde68a; }
.badge-danger  { background: var(--danger-light);  color: #7f1d1d; border-color: #fecaca; }
.badge-info    { background: var(--info-light);    color: #155e75; border-color: #a5f3fc; }
.badge-primary { background: var(--primary-light); color: var(--primary-darker); border-color: #bfdbfe; }
.badge-muted   { background: var(--surface-sunk);  color: var(--text-muted); border-color: var(--border); }

.badge .swatch { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex-shrink: 0; }

/* Status pill driven by an inline colour from the database. */
.status-pill {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 11px; border-radius: 4px;
    font-size: 11.5px; font-weight: 650; white-space: nowrap;
    border: 1px solid currentColor;
}
.status-pill .swatch { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 10px; background: var(--surface-sunk);
    border: 1px solid var(--border); border-radius: 20px;
    font-size: 12.5px; color: var(--text-body);
}

/* ==========================================================================
   Forms
   ========================================================================== */

.form-grid { display: grid; gap: 18px; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-full { grid-column: 1 / -1; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }

.field label { font-size: 12.5px; font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 4px; }
.field label .req { color: var(--danger); }
.field .help { font-size: 12px; color: var(--text-muted); }

.field input[type=text], .field input[type=email], .field input[type=password],
.field input[type=number], .field input[type=date], .field input[type=time], .field input[type=tel],
.field input[type=url], .field input[type=search], .field input[type=datetime-local],
.field select, .field textarea {
    width: 100%; min-height: 38px; padding: 9px 12px;
    border: 1px solid var(--border-strong); border-radius: var(--radius);
    background: var(--surface); font: inherit; font-size: 13.5px; color: var(--text);
    transition: border-color .15s, box-shadow .15s;
}

.field textarea { min-height: 96px; resize: vertical; line-height: 1.6; }

.field select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' 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 11px center; padding-right: 34px;
}

.field input:focus, .field select:focus, .field textarea:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft);
}
.field input::placeholder, .field textarea::placeholder { color: var(--text-light); }

.field input[aria-invalid=true], .field select[aria-invalid=true], .field textarea[aria-invalid=true] { border-color: var(--danger); }
.field input[aria-invalid=true]:focus { box-shadow: 0 0 0 3px var(--danger-light); }
.field .err { font-size: 12px; color: var(--danger); font-weight: 500; }

.field input:disabled, .field select:disabled, .field textarea:disabled { background: var(--surface-sunk); color: var(--text-muted); cursor: not-allowed; }

.check { display: flex; align-items: flex-start; gap: 9px; font-size: 13.5px; cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; margin: 2px 0 0; accent-color: var(--primary); cursor: pointer; flex-shrink: 0; }
.check .t { font-weight: 550; color: var(--text); }
.check .d { font-size: 12px; color: var(--text-muted); display: block; }

.input-group { display: flex; }
.input-group .prefix {
    display: grid; place-items: center; padding: 0 12px;
    border: 1px solid var(--border-strong); border-right: 0;
    border-radius: var(--radius) 0 0 var(--radius);
    background: var(--surface-sunk); font-size: 13px; color: var(--text-muted);
}
.input-group input { border-radius: 0 var(--radius) var(--radius) 0 !important; }

/* Section heading inside a long form */
.form-section-title {
    font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em;
    color: var(--primary); padding-bottom: 8px; margin-bottom: 4px;
    border-bottom: 2px solid var(--primary-light);
}

/* radio segmented control (existing vs new client) */
.segmented { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
    display: block; padding: 8px 16px; font-size: 13px; font-weight: 550;
    color: var(--text-muted); cursor: pointer; background: var(--surface);
    border-right: 1px solid var(--border);
}
.segmented label:last-child span { border-right: 0; }
.segmented input:checked + span { background: var(--primary); color: #fff; }

/* ==========================================================================
   Filters
   ========================================================================== */

.filters { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)); align-items: end; }
.filters .field label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 700; }
.filters .acts { display: flex; gap: 8px; }

.filter-toggles { display: flex; gap: 18px; flex-wrap: wrap; align-items: center; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }

/* ==========================================================================
   Pagination
   ========================================================================== */

.pagination {
    display: flex; align-items: center; justify-content: space-between;
    gap: 14px; flex-wrap: wrap; padding: 14px 20px;
    border-top: 1px solid var(--border); background: var(--surface-alt);
}
.pagination .info { font-size: 13px; color: var(--text-muted); }
.pagination .pages { display: flex; gap: 4px; flex-wrap: wrap; }

.pagination .pages a, .pagination .pages span {
    min-width: 34px; height: 34px; display: grid; place-items: center; padding: 0 10px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface); font-size: 13px; color: var(--text-body);
}
.pagination .pages a:hover { background: var(--primary-soft); border-color: var(--primary); text-decoration: none; }
.pagination .pages .current { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 650; }
.pagination .pages .gap { border: 0; background: none; color: var(--text-light); }
.pagination .pages .disabled { opacity: .45; pointer-events: none; }

/* ==========================================================================
   Empty & loading
   ========================================================================== */

.empty-state { padding: 52px 24px; text-align: center; }
.empty-state .ico { width: 60px; height: 60px; margin: 0 auto 16px; border-radius: 14px; background: var(--surface-sunk); display: grid; place-items: center; color: var(--text-light); }
.empty-state .ico svg { width: 28px; height: 28px; }
.empty-state h3 { font-size: 15.5px; margin-bottom: 6px; }
.empty-state p { color: var(--text-muted); font-size: 13.5px; max-width: 430px; margin: 0 auto 18px; }

.skeleton { background: linear-gradient(90deg, #eef2f7 25%, #e2e8f0 37%, #eef2f7 63%); background-size: 400% 100%; animation: shimmer 1.3s ease infinite; border-radius: 5px; }
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

.spinner { width: 17px; height: 17px; border: 2px solid var(--border-strong); border-top-color: var(--primary); border-radius: 50%; animation: spin .65s linear infinite; display: inline-block; }

/* ==========================================================================
   Alerts & toasts
   ========================================================================== */

.alert { display: flex; align-items: flex-start; gap: 11px; padding: 13px 16px; border-radius: var(--radius); border: 1px solid transparent; margin-bottom: 16px; font-size: 13.5px; }
.alert svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }
.alert-success { background: var(--success-light); border-color: #86efac; color: #14532d; }
.alert-error, .alert-danger { background: var(--danger-light); border-color: #fca5a5; color: #7f1d1d; }
.alert-warning { background: var(--warning-light); border-color: #fcd34d; color: #78350f; }
.alert-info { background: var(--info-light); border-color: #67e8f9; color: #155e75; }

.toast-stack { position: fixed; top: 16px; right: 16px; display: flex; flex-direction: column; gap: 9px; z-index: 300; max-width: min(390px, calc(100vw - 32px)); }

.toast {
    display: flex; align-items: flex-start; gap: 11px; padding: 13px 15px;
    background: var(--surface); border: 1px solid var(--border);
    border-left: 3px solid var(--primary); border-radius: var(--radius);
    box-shadow: var(--shadow-lg); animation: toastIn .25s cubic-bezier(.2, .9, .3, 1);
}
.toast.out { animation: toastOut .2s ease forwards; }
.toast .msg { flex: 1; font-size: 13.5px; color: var(--text-body); }
.toast .x { background: none; border: 0; cursor: pointer; color: var(--text-light); padding: 0; line-height: 1; font-size: 18px; }
.toast .x:hover { color: var(--text); }
.toast svg { width: 18px; height: 18px; flex-shrink: 0; }

.toast-success { border-left-color: var(--success); }
.toast-success > svg { color: var(--success); }
.toast-error { border-left-color: var(--danger); }
.toast-error > svg { color: var(--danger); }
.toast-warning { border-left-color: var(--warning); }
.toast-warning > svg { color: var(--warning); }
.toast-info > svg { color: var(--primary); }

@keyframes toastIn  { from { opacity: 0; transform: translateX(20px); } }
@keyframes toastOut { to   { opacity: 0; transform: translateX(20px); } }

/* ==========================================================================
   Modals
   ========================================================================== */

.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .55); backdrop-filter: blur(2px); display: none; place-items: center; padding: 20px; z-index: 250; }
.modal-backdrop.open { display: grid; }

.modal {
    width: 100%; max-width: 480px; background: var(--surface);
    border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
    max-height: calc(100vh - 40px); display: flex; flex-direction: column;
    animation: modalIn .2s cubic-bezier(.2, .9, .3, 1);
}
.modal.lg { max-width: 720px; }
@keyframes modalIn { from { opacity: 0; transform: translateY(-12px) scale(.98); } }

.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 15.5px; }
.modal-head .x { background: none; border: 0; cursor: pointer; color: var(--text-light); padding: 2px; font-size: 20px; line-height: 1; }
.modal-head .x:hover { color: var(--text); }

.modal-body { padding: 22px; overflow-y: auto; }
.modal-foot { padding: 15px 22px; border-top: 1px solid var(--border); display: flex; gap: 9px; justify-content: flex-end; flex-wrap: wrap; }

.modal-icon { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; margin-bottom: 13px; }
.modal-icon svg { width: 23px; height: 23px; }

/* ==========================================================================
   Case detail
   ========================================================================== */

.detail-grid { display: grid; gap: 20px; grid-template-columns: minmax(0, 2.2fr) minmax(0, 1fr); align-items: start; }

/* Grid and flex children default to min-width:auto, which lets wide content
   (the status stepper, tab strips, data tables) push the page wider than the
   viewport instead of scrolling inside their own container. */
.detail-grid > *, .chart-grid > * { min-width: 0; }
.main { min-width: 0; }

/* Case header banner */
.case-header {
    background: var(--surface); border: 1px solid var(--border);
    border-top: 3px solid var(--primary);
    border-radius: var(--radius); padding: 22px; margin-bottom: 20px;
    box-shadow: var(--shadow-xs);
}
.case-header .uid { font-family: var(--mono); font-size: 12.5px; color: var(--primary); font-weight: 650; letter-spacing: .03em; }
.case-header h1 { font-family: var(--serif); font-size: 24px; margin: 6px 0 10px; line-height: 1.25; }
.case-header .tags { display: flex; gap: 8px; flex-wrap: wrap; }
.case-header .meta-row { display: flex; gap: 26px; flex-wrap: wrap; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }
.case-header .meta-row .item .k { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); font-weight: 700; }
.case-header .meta-row .item .v { font-size: 13.5px; color: var(--text); font-weight: 550; margin-top: 3px; }

/* Next hearing highlight */
.next-hearing {
    display: flex; align-items: center; gap: 16px;
    padding: 16px 18px; border-radius: var(--radius);
    background: var(--primary-soft); border: 1px solid #bfdbfe; margin-bottom: 20px;
}
.next-hearing.is-today { background: var(--warning-light); border-color: #fde68a; }
.next-hearing.is-past  { background: var(--danger-light);  border-color: #fecaca; }
.next-hearing .date-block {
    text-align: center; background: var(--surface); border-radius: var(--radius);
    padding: 9px 14px; min-width: 74px; border: 1px solid var(--border);
}
.next-hearing .date-block .d { font-size: 22px; font-weight: 700; line-height: 1; color: var(--text); }
.next-hearing .date-block .m { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--text-muted); font-weight: 700; margin-top: 3px; }
.next-hearing .info { flex: 1; min-width: 0; }
.next-hearing .info .t { font-weight: 650; font-size: 14px; color: var(--text); }
.next-hearing .info .s { font-size: 12.5px; color: var(--text-muted); margin-top: 3px; }

.def-list { display: grid; gap: 0; }
.def-list .row { display: grid; grid-template-columns: 172px 1fr; gap: 16px; padding: 11px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.def-list .row:last-child { border-bottom: 0; }
.def-list dt { color: var(--text-muted); font-size: 12.5px; font-weight: 550; }
.def-list dd { margin: 0; word-break: break-word; color: var(--text); }

/* tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); overflow-x: auto; background: var(--surface-alt); }
.tab {
    padding: 12px 17px; border: 0; border-bottom: 2px solid transparent; background: none; cursor: pointer;
    font: inherit; font-size: 13.5px; font-weight: 600; color: var(--text-muted); white-space: nowrap;
}
.tab:hover { color: var(--text); background: rgba(255,255,255,.6); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); background: var(--surface); }
.tab .n { margin-left: 6px; padding: 1px 6px; background: var(--surface-sunk); border-radius: 9px; font-size: 11px; color: var(--text-muted); }
.tab.active .n { background: var(--primary-light); color: var(--primary-dark); }
.tab-panel { display: none; padding: 20px; }
.tab-panel.active { display: block; }

/* Status workflow stepper — scrolls inside its card rather than widening it */
.workflow { display: flex; gap: 4px; overflow-x: auto; padding: 4px 0 10px; max-width: 100%; }
.workflow .step {
    flex: 1 0 auto; min-width: 96px; text-align: center; padding: 9px 8px;
    background: var(--surface-sunk); border-radius: var(--radius-sm);
    font-size: 11.5px; font-weight: 600; color: var(--text-muted);
    border-top: 3px solid var(--border); position: relative;
}
.workflow .step.done { background: var(--primary-soft); color: var(--primary-dark); border-top-color: var(--primary); }
.workflow .step.current { background: var(--primary); color: #fff; border-top-color: var(--primary-darker); }
.workflow .step .n { display: block; font-size: 10px; opacity: .75; margin-bottom: 2px; }

/* timeline */
.timeline { position: relative; padding-left: 28px; }
.timeline::before { content: ''; position: absolute; left: 10px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.timeline-item { position: relative; padding-bottom: 20px; }
.timeline-item:last-child { padding-bottom: 0; }
.timeline-item .dot {
    position: absolute; left: -28px; top: 0;
    width: 22px; height: 22px; border-radius: 50%;
    background: var(--surface); border: 2px solid var(--border);
    display: grid; place-items: center; color: var(--text-muted);
}
.timeline-item .dot svg { width: 11px; height: 11px; }
.timeline-item .t { font-size: 13.5px; font-weight: 650; color: var(--text); }
.timeline-item .d { font-size: 13px; color: var(--text-muted); margin-top: 2px; white-space: pre-wrap; }
.timeline-item .w { font-size: 11.5px; color: var(--text-light); margin-top: 4px; }

/* Timeline grouped by date */
.timeline-date { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); margin: 18px 0 10px -28px; padding-left: 28px; }
.timeline-date:first-child { margin-top: 0; }

/* notes */
.note { padding: 14px; border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 12px; background: var(--surface); }
.note.pinned { border-color: #fcd34d; background: #fffbeb; }
.note-head { display: flex; align-items: center; gap: 9px; margin-bottom: 8px; }
.note-head .who { font-size: 13px; font-weight: 650; color: var(--text); }
.note-head .when { font-size: 11.5px; color: var(--text-light); }
.note-head .acts { margin-left: auto; display: flex; gap: 3px; }
.note-body { font-size: 13.5px; white-space: pre-wrap; word-break: break-word; color: var(--text-body); }

/* documents */
.doc-item { display: flex; align-items: center; gap: 13px; padding: 13px 14px; border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 9px; background: var(--surface); }
.doc-item .ic { width: 38px; height: 38px; border-radius: var(--radius-sm); background: var(--primary-soft); display: grid; place-items: center; color: var(--primary); flex-shrink: 0; }
.doc-item .n { font-size: 13.5px; font-weight: 600; word-break: break-word; color: var(--text); }
.doc-item .s { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }
.doc-item .a { margin-left: auto; display: flex; gap: 4px; flex-shrink: 0; }

/* hearing card */
.hearing-item { display: flex; gap: 14px; padding: 15px; border: 1px solid var(--border); border-left: 3px solid var(--border-strong); border-radius: var(--radius); margin-bottom: 11px; background: var(--surface); }
.hearing-item.is-scheduled { border-left-color: var(--primary); }
.hearing-item.is-completed { border-left-color: var(--success); }
.hearing-item.is-adjourned { border-left-color: var(--warning); }
.hearing-item.is-cancelled { border-left-color: var(--text-light); opacity: .75; }
.hearing-item .date-block { text-align: center; min-width: 62px; flex-shrink: 0; }
.hearing-item .date-block .d { font-size: 19px; font-weight: 700; line-height: 1; color: var(--text); }
.hearing-item .date-block .m { font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); font-weight: 700; margin-top: 3px; }
.hearing-item .date-block .y { font-size: 10.5px; color: var(--text-light); margin-top: 1px; }
.hearing-item .body { flex: 1; min-width: 0; }
.hearing-item .body .t { font-weight: 650; font-size: 13.5px; color: var(--text); }
.hearing-item .body .s { font-size: 12.5px; color: var(--text-muted); margin-top: 3px; }
.hearing-item .body .outcome { margin-top: 9px; padding: 9px 11px; background: var(--surface-sunk); border-radius: var(--radius-sm); font-size: 12.5px; white-space: pre-wrap; }
.hearing-item .body .outcome b { color: var(--text); }
.hearing-item .acts { display: flex; gap: 4px; align-items: flex-start; flex-shrink: 0; }

/* ==========================================================================
   Charts & progress
   ========================================================================== */

.chart-grid { display: grid; gap: 20px; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.chart-box { width: 100%; overflow: hidden; }
.chart-box svg { display: block; width: 100%; height: auto; }

.chart-legend { display: flex; flex-wrap: wrap; gap: 10px 18px; margin-top: 14px; }
.chart-legend .li { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-muted); }
.chart-legend .sw { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }
.chart-legend .vl { color: var(--text); font-weight: 650; }

.progress { height: 7px; background: var(--surface-sunk); border-radius: 4px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--primary); border-radius: 4px; transition: width .3s; }

.pipeline { display: grid; gap: 11px; }
.pipeline-row { display: grid; grid-template-columns: 158px 1fr 62px; gap: 14px; align-items: center; font-size: 13px; }
.pipeline-row .nm { font-weight: 550; display: flex; align-items: center; gap: 7px; color: var(--text-body); }
.pipeline-row .sw { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.pipeline-row .vl { text-align: right; font-variant-numeric: tabular-nums; font-weight: 650; color: var(--text); }

.funnel { display: grid; gap: 7px; }
.funnel-row { display: grid; grid-template-columns: 168px 1fr 76px; gap: 12px; align-items: center; font-size: 13px; }
.funnel-bar { height: 28px; border-radius: var(--radius-sm); display: flex; align-items: center; padding: 0 10px; color: #fff; font-size: 12px; font-weight: 650; min-width: 3px; }

/* ==========================================================================
   Misc
   ========================================================================== */

.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--text-muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; } .mb-3 { margin-bottom: 24px; }
.flex { display: flex; } .items-center { align-items: center; } .gap-1 { gap: 8px; } .gap-2 { gap: 16px; }
.wrap { flex-wrap: wrap; } .grow { flex: 1; } .col { flex-direction: column; }
.hidden { display: none !important; }

.code-block { font-family: var(--mono); font-size: 12px; background: #101828; color: #e2e8f0; padding: 14px; border-radius: var(--radius); overflow-x: auto; white-space: pre-wrap; word-break: break-all; }

.kv-diff { display: grid; gap: 7px; }
.kv-diff .r { display: grid; grid-template-columns: 148px 1fr 1fr; gap: 10px; font-size: 12.5px; align-items: baseline; }
.kv-diff .k { color: var(--text-muted); font-weight: 650; }
.kv-diff .o { color: var(--danger); text-decoration: line-through; opacity: .8; word-break: break-word; }
.kv-diff .n { color: var(--success); font-weight: 550; word-break: break-word; }

.copy-field { display: flex; align-items: center; gap: 9px; padding: 11px 14px; background: #101828; color: #e2e8f0; border-radius: var(--radius); font-family: var(--mono); font-size: 13px; word-break: break-all; }
.copy-field button { margin-left: auto; flex-shrink: 0; background: rgba(255, 255, 255, .12); border: 0; color: #fff; padding: 5px 11px; border-radius: var(--radius-sm); font: inherit; font-size: 12px; cursor: pointer; }
.copy-field button:hover { background: rgba(255, 255, 255, .22); }

.sidebar-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .5); z-index: 50; display: none; }
.sidebar-backdrop.open { display: block; }

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 1200px) {
    .detail-grid { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
    .sidebar.open { transform: translateX(0); }
    .main { margin-left: 0; }
    .topbar .burger { display: grid; }
    .search-box { width: 100%; max-width: none; }
    .content { padding: 16px; }
    .page-head { flex-direction: column; align-items: stretch; }
    .page-actions .btn { flex: 1; }
    .def-list .row { grid-template-columns: 1fr; gap: 2px; }
    .pipeline-row { grid-template-columns: 112px 1fr 54px; }
    .funnel-row { grid-template-columns: 116px 1fr 56px; }
    .kv-diff .r { grid-template-columns: 1fr; }
    .case-header .meta-row { gap: 16px; }
}

@media (max-width: 640px) {
    :root { --topbar-h: 56px; }
    h1 { font-size: 19px; }
    .content { padding: 13px; }
    .stat-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .stat { padding: 13px; flex-direction: column; gap: 9px; }
    .stat .val { font-size: 21px; }
    .stat .ico { width: 34px; height: 34px; }
    .form-grid { grid-template-columns: 1fr; }
    .form-grid .span-2 { grid-column: span 1; }
    .filters { grid-template-columns: 1fr 1fr; }
    .filters .acts { grid-column: 1 / -1; }
    .card-body { padding: 15px; }
    .card-head { padding: 13px 15px; }
    table.data { font-size: 12.5px; }
    table.data th, table.data td { padding: 10px 11px; }
    .pagination { flex-direction: column; align-items: stretch; gap: 10px; }
    .pagination .pages { justify-content: center; }
    .page-actions { width: 100%; }
    .modal { max-width: none; }
    .search-box { display: none; }
    .toast-stack { left: 12px; right: 12px; max-width: none; }
    .case-header { padding: 16px; }
    .case-header h1 { font-size: 20px; }
    .next-hearing { flex-direction: column; align-items: flex-start; gap: 12px; }
    .hearing-item { flex-direction: column; gap: 10px; }
    .hearing-item .acts { width: 100%; }
    .tab-panel { padding: 15px; }
}

@media (max-width: 420px) {
    .stat-grid { grid-template-columns: 1fr; }
    .filters { grid-template-columns: 1fr; }
}

@media print {
    .sidebar, .topbar, .page-actions, .filters, .pagination, .toast-stack, .tabs { display: none !important; }
    .main { margin-left: 0; }
    .card, .case-header { border: 1px solid #ccc; box-shadow: none; break-inside: avoid; }
    .tab-panel { display: block !important; }
    body { background: #fff; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
