:root {
    --navy: #1a3c5e;
    --navy-dark: #122a42;
    --navy-light: #24507c;
    --gold: #c9a24b;
    --gold-dark: #b08a35;
    --gold-light: #ddbd72;
    --bg: #eef1f5;
    --border: #e2e6ec;
    --text: #1f2733;
    --text-soft: #5b6573;
    --danger: #c0392b;
    --danger-soft: #fdecea;
    --success: #1f8a4c;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 3px rgba(18, 42, 66, .08);
    --shadow-md: 0 4px 16px rgba(18, 42, 66, .10);
    --shadow-lg: 0 12px 36px rgba(18, 42, 66, .18);
    --ring: 0 0 0 3px rgba(201, 162, 75, .30);
    --t: .18s ease;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, Arial, sans-serif;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    line-height: 1.5;
}
h2 { color: var(--navy); letter-spacing: -.01em; }

/* ---------- Top bar ---------- */
.topbar {
    background: linear-gradient(120deg, var(--navy), var(--navy-dark));
    color: #fff;
    box-shadow: var(--shadow-md);
    border-bottom: 3px solid var(--gold);
    position: relative;
    z-index: 20;
}
.topbar-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 14px 24px;
}
.topbar-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: nowrap;
}
.topbar .brand { font-weight: 700; font-size: 19px; white-space: nowrap; letter-spacing: .2px; }
.topbar nav { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 4px; }
.topbar nav a {
    color: #d4deea;
    text-decoration: none;
    padding: 7px 14px;
    border-radius: 999px;
    font-size: 14px;
    font-weight: 500;
    transition: background var(--t), color var(--t);
}
.topbar nav a:hover { color: #fff; background: rgba(255,255,255,.10); }
.topbar nav a.active {
    color: var(--navy-dark);
    background: linear-gradient(120deg, var(--gold-light), var(--gold));
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(201,162,75,.4);
}
.topbar .userbox { font-size: 13px; display: flex; align-items: center; gap: 14px; white-space: nowrap; flex-shrink: 0; }
.topbar .userbox span { color: #cdd8e4; }
.topbar .userbox a { color: var(--gold-light); text-decoration: none; font-weight: 600; transition: color var(--t); }
.topbar .userbox a:hover { color: #fff; }

/* Phone-only bottom tab bar (mirrors .topbar nav); hidden on desktop/tablet. */
.bottom-tabbar { display: none; }

.container { max-width: 1100px; margin: 28px auto; padding: 0 16px; }

/* ---------- Login ---------- */
.login-bg {
    background: linear-gradient(135deg, var(--navy), var(--navy-dark));
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 20px;
}
.login-box {
    background: #fff;
    padding: 44px 40px;
    border-radius: 18px;
    width: 360px;
    max-width: 100%;
    box-shadow: var(--shadow-lg);
    text-align: center;
    border-top: 4px solid var(--gold);
}
.login-box h2 { color: var(--navy); margin-top: 0; margin-bottom: 6px; letter-spacing: .3px; }
.login-box h2 span { color: var(--gold); font-size: 16px; font-weight: 500; }
.login-box label { display: block; text-align: left; font-size: 13px; margin-top: 16px; color: var(--text-soft); font-weight: 500; }
.login-box input {
    width: 100%; padding: 11px 12px; margin-top: 5px; border: 1px solid var(--border);
    border-radius: var(--radius-sm); font-size: 14px; transition: border-color var(--t), box-shadow var(--t);
}
.login-box input:focus { outline: none; border-color: var(--gold); box-shadow: var(--ring); }
.login-box button {
    width: 100%; margin-top: 24px; padding: 12px; background: linear-gradient(120deg, var(--navy-light), var(--navy));
    color: #fff; border: none; border-radius: var(--radius-sm); cursor: pointer; font-size: 15px; font-weight: 600;
    transition: transform var(--t), box-shadow var(--t), background var(--t);
}
.login-box button:hover { background: var(--navy-dark); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.error { color: var(--danger); font-size: 13px; }

/* ---------- Calendar ---------- */
.cal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; flex-wrap: wrap; gap: 10px; }
.cal-header h2 { color: var(--navy); margin: 0; }
.cal-header .nav-btns a {
    display: inline-block; padding: 8px 16px; background: #fff; color: var(--navy);
    text-decoration: none; border-radius: var(--radius-sm); margin-left: 8px; font-size: 14px; font-weight: 600;
    border: 1px solid var(--border); box-shadow: var(--shadow-sm); transition: all var(--t);
}
.cal-header .nav-btns a:hover { background: var(--navy); color: #fff; transform: translateY(-1px); box-shadow: var(--shadow-md); }
.calendar {
    width: 100%; border-collapse: separate; border-spacing: 0; background: #fff;
    box-shadow: var(--shadow-md); border-radius: var(--radius); overflow: hidden;
}
.calendar th { background: linear-gradient(120deg, var(--navy), var(--navy-dark)); color: #fff; padding: 11px 8px; font-size: 13px; font-weight: 600; letter-spacing: .3px; }
.calendar td { border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); height: 92px; width: 14.28%; vertical-align: top; padding: 7px; position: relative; transition: background var(--t); }
.calendar td:hover:not(.empty) { background: #fafbfd; }
.calendar tr td:last-child { border-right: none; }
.calendar td.empty { background: #f7f9fb; }
.calendar .daynum { font-weight: 600; font-size: 13px; color: var(--text-soft); }
.calendar td.today { background: #fffaf0; box-shadow: inset 0 0 0 2px var(--gold); }
.calendar .today .daynum { color: var(--gold-dark); font-weight: 700; }
.calendar .case-count {
    display: inline-block;
    margin-top: 7px;
    background: linear-gradient(120deg, var(--gold-light), var(--gold));
    color: #fff;
    border-radius: 999px;
    padding: 3px 11px;
    font-size: 12px;
    font-weight: 600;
    text-decoration: none;
    box-shadow: 0 2px 6px rgba(201,162,75,.35);
    transition: all var(--t);
}
.calendar .case-count:hover { background: var(--navy); transform: translateY(-1px); box-shadow: var(--shadow-md); }
/* Past hearing dates (already heard) show green instead of gold. */
.calendar .case-count-past {
    background: linear-gradient(120deg, #4caf50, #2e7d32);
    box-shadow: 0 2px 6px rgba(46,125,50,.35);
}
.calendar .case-count-past:hover { background: var(--navy); }

.show-all-bar { text-align: center; margin-top: 26px; }
.btn-show-all {
    display: inline-block;
    padding: 12px 32px;
    background: linear-gradient(120deg, var(--navy-light), var(--navy));
    color: #fff;
    text-decoration: none;
    border-radius: 999px;
    font-size: 14px;
    font-weight: 600;
    box-shadow: var(--shadow-md);
    transition: transform var(--t), box-shadow var(--t), background var(--t);
}
.btn-show-all:hover { background: var(--navy-dark); transform: translateY(-2px); box-shadow: var(--shadow-lg); }

.fab-add {
    position: fixed;
    bottom: 32px;
    right: 32px;
    background: linear-gradient(135deg, var(--gold-light), var(--gold-dark));
    color: #fff;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    text-decoration: none;
    box-shadow: 0 6px 20px rgba(176,138,53,.5);
    transition: transform var(--t), box-shadow var(--t);
    z-index: 40;
}
.fab-add:hover { transform: translateY(-3px) scale(1.05); box-shadow: 0 10px 26px rgba(176,138,53,.6); }

/* ---------- Forms ---------- */
.form-card { background: #fff; padding: 28px; border-radius: var(--radius); box-shadow: var(--shadow-md); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px 22px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid label { display: block; font-size: 13px; color: var(--text-soft); margin-bottom: 5px; font-weight: 500; }
.form-grid input, .form-grid select, .form-grid textarea {
    width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 14px;
    font-family: inherit; transition: border-color var(--t), box-shadow var(--t); background: #fff;
}
.form-grid input:focus, .form-grid select:focus, .form-grid textarea:focus,
.login-box input:focus, .search-bar input:focus {
    outline: none; border-color: var(--gold); box-shadow: var(--ring);
}
.field-with-add { display: flex; gap: 6px; }
.field-with-add select { flex: 1; }
.btn-add-inline {
    background: var(--navy); color: #fff; border: none; border-radius: var(--radius-sm); width: 40px; font-size: 18px; cursor: pointer;
    transition: background var(--t), transform var(--t);
}
.btn-add-inline:hover { background: var(--navy-dark); transform: translateY(-1px); }
.caseno-row { display: flex; gap: 8px; }
.caseno-row input { flex: 2; }
.caseno-row button { flex: 1; background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; font-weight: 600; color: var(--navy); transition: all var(--t); }
.caseno-row button:hover { background: var(--bg); border-color: var(--gold); }
.caseno-row select { padding: 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 14px; }

.form-actions { margin-top: 24px; text-align: right; }
.btn-primary {
    background: linear-gradient(120deg, var(--navy-light), var(--navy)); color: #fff; border: none;
    padding: 11px 24px; border-radius: var(--radius-sm); cursor: pointer; font-size: 14px; font-weight: 600;
    box-shadow: var(--shadow-sm); transition: transform var(--t), box-shadow var(--t), background var(--t);
}
.btn-primary:hover { background: var(--navy-dark); transform: translateY(-1px); box-shadow: var(--shadow-md); }

.autocomplete-box { position: relative; }
.ac-list { position: absolute; top: 100%; left: 0; right: 0; background: #fff; border: 1px solid var(--border); border-radius: 0 0 var(--radius-sm) var(--radius-sm); max-height: 220px; overflow-y: auto; z-index: 50; box-shadow: var(--shadow-md); }
.ac-list div { padding: 9px 12px; cursor: pointer; font-size: 13px; border-bottom: 1px solid #f0f2f5; transition: background var(--t); }
.ac-list div:last-child { border-bottom: none; }
.ac-list div:hover { background: var(--bg); }
.ac-list div.ac-active { background: var(--navy); color: #fff; }

/* ---------- Modal ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(18,42,66,.55); display: none; align-items: center; justify-content: center; z-index: 100; backdrop-filter: blur(2px); }
.modal-overlay.show { display: flex; }
.modal-box { background: #fff; padding: 26px; border-radius: var(--radius); width: 340px; max-width: 90%; box-shadow: var(--shadow-lg); }
.modal-box h3 { margin-top: 0; color: var(--navy); }
.modal-box input, .modal-box select, .modal-box textarea { width: 100%; padding: 10px; margin: 8px 0; border: 1px solid var(--border); border-radius: var(--radius-sm); font-family: inherit; font-size: 14px; transition: border-color var(--t), box-shadow var(--t); }
.modal-box input:focus, .modal-box select:focus, .modal-box textarea:focus { outline: none; border-color: var(--gold); box-shadow: var(--ring); }
.modal-box .modal-actions { text-align: right; margin-top: 14px; }
.modal-box button { padding: 9px 16px; border-radius: var(--radius-sm); border: none; cursor: pointer; margin-left: 8px; font-weight: 600; transition: all var(--t); }
.modal-box .cancel { background: #eceff3; color: var(--text-soft); }
.modal-box .cancel:hover { background: #e0e4ea; }
.modal-box .confirm { background: var(--navy); color: #fff; }
.modal-box .confirm:hover { background: var(--navy-dark); }

/* ---------- Tables ---------- */
table.list {
    width: 100%; border-collapse: separate; border-spacing: 0; background: #fff;
    box-shadow: var(--shadow-md); border-radius: var(--radius); overflow: hidden;
}
table.list th, table.list td { padding: 11px 12px; border-bottom: 1px solid var(--border); font-size: 13px; text-align: left; line-height: 1.4; }
table.list th { background: linear-gradient(120deg, var(--navy), var(--navy-dark)); color: #fff; font-weight: 600; letter-spacing: .2px; white-space: nowrap; }
table.list tr:last-child td { border-bottom: none; }
table.list tbody tr { transition: background var(--t); }
table.list tr:hover { background: #f6f9fc; }
.search-bar { margin-bottom: 18px; }
.search-bar input { width: 100%; max-width: 440px; padding: 11px 14px; border: 1px solid var(--border); border-radius: 999px; font-size: 14px; box-shadow: var(--shadow-sm); transition: border-color var(--t), box-shadow var(--t); }
.pill { padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--bg); border: 1px solid var(--border); display: inline-block; }
.pill-undated { background: var(--danger-soft); border-color: #f3b9b9; color: var(--danger); margin-left: 6px; }
.row-save-cell { display: none; } /* per-card Save on Case Update — mobile-card layout only */

.undated-popup {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    background: var(--danger-soft);
    border: 1px solid #f3b9b9;
    border-radius: var(--radius);
    padding: 12px 40px 12px 18px;
    margin-top: 16px;
    font-size: 14px;
    text-align: center;
    box-shadow: var(--shadow-sm);
}
.undated-popup a { color: var(--danger); font-weight: 600; text-decoration: none; }
.undated-popup a:hover { text-decoration: underline; }
.undated-popup-close {
    position: absolute;
    top: 6px;
    right: 8px;
    background: none;
    border: none;
    color: var(--danger);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    padding: 2px 6px;
}
.case-title-link { color: var(--navy); font-weight: 600; text-decoration: none; transition: color var(--t); }
.case-title-link:hover { text-decoration: underline; color: var(--gold-dark); }
.client-sub { display: block; font-size: 0.8em; font-style: italic; font-weight: normal; color: #555; margin-top: 2px; }
.actions-cell a { margin-right: 10px; font-size: 12px; }
.actions-cell .action-link { display: inline-flex; align-items: center; gap: 4px; color: var(--navy); text-decoration: none; font-weight: 500; transition: color var(--t); }
.actions-cell .action-link:hover { color: var(--gold-dark); }
.actions-cell .action-link i { font-size: 14px; }

.admin-subnav { display: flex; gap: 20px; margin-bottom: 20px; border-bottom: 2px solid var(--border); }
.admin-subnav a { padding: 10px 4px; font-size: 14px; color: var(--text-soft); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -2px; font-weight: 500; transition: color var(--t); }
.admin-subnav a:hover { color: var(--navy); }
.admin-subnav a.active { color: var(--navy); font-weight: 700; border-bottom-color: var(--gold); }

.update-table .next-date-input, .update-table .stage-input, .update-table .remark-input { padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 13px; width: 100%; transition: border-color var(--t), box-shadow var(--t); }
.update-table .next-date-input:focus, .update-table .stage-input:focus, .update-table .remark-input:focus { outline: none; border-color: var(--gold); box-shadow: var(--ring); }
.update-table .stage-input, .update-table .remark-input { min-width: 160px; }

.history-table td, .history-table th { font-size: 13px; }
.fees-summary { display: flex; gap: 24px; background: #fff; padding: 20px 24px; border-radius: var(--radius); box-shadow: var(--shadow-md); margin-bottom: 20px; flex-wrap: wrap; }
.fees-summary .stat { text-align: center; flex: 1; min-width: 120px; }
.fees-summary .stat .label { font-size: 12px; color: var(--text-soft); text-transform: uppercase; letter-spacing: .5px; }
.fees-summary .stat .value { font-size: 22px; font-weight: 700; color: var(--navy); margin-top: 4px; }
.fees-summary .stat .value.due { color: var(--danger); }

.stats-summary { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; background: transparent; padding: 0; margin-bottom: 18px; }
.stats-summary .stat {
    text-align: center; padding: 11px 8px; border: 1px solid var(--border); border-top: 3px solid var(--gold);
    text-decoration: none; display: block; border-radius: var(--radius-sm); background: #fff; box-shadow: var(--shadow-sm);
    transition: transform var(--t), box-shadow var(--t);
}
.stats-summary .stat:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stats-summary .stat .label { font-size: 11px; color: var(--text-soft); margin-bottom: 3px; text-transform: uppercase; letter-spacing: .3px; font-weight: 500; }
.stats-summary .stat .value { font-size: 22px; font-weight: 700; color: var(--navy); line-height: 1.1; }
.stats-summary .stat .value.disposed { color: var(--danger); }
@media (max-width: 900px) {
    .stats-summary { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 700px) {
    .stats-summary { grid-template-columns: repeat(3, 1fr); gap: 8px; }
    .stats-summary .stat { padding: 8px 4px; border-top-width: 2px; }
    .stats-summary .stat .label { font-size: 9px; letter-spacing: .2px; margin-bottom: 2px; }
    .stats-summary .stat .value { font-size: 17px; }
    .topbar-inner { padding: 12px 16px; }
    .form-grid { grid-template-columns: 1fr; }
    .container { margin: 20px auto; }
}

/* ---------- Responsive: tablet ---------- */
@media (max-width: 1024px) {
    .container { padding: 0 14px; }
    .form-grid { gap: 16px 18px; }
}

/* ---------- Responsive: wide data tables scroll instead of overflowing ---------- */
@media (max-width: 820px) {
    table.list:not(.print-table) {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    /* Keep other columns to their content width so the Case Title column can breathe */
    table.list:not(.print-table) th,
    table.list:not(.print-table) td { white-space: nowrap; }
    /* Give the Case Title column real space; let it (and the client line) wrap inside it */
    table.list:not(.print-table) td.col-title { white-space: normal; min-width: 200px; }
    .col-title .case-title-link { white-space: normal; }
    /* Keep the dispose / inline edit forms (rendered inside a full-width td) usable */
    table.list:not(.print-table) td > form { white-space: normal; }
}

/* ---------- Responsive: phone ---------- */
@media (max-width: 600px) {
    h2 { font-size: 20px; }
    .topbar .brand { font-size: 16px; }
    .topbar .userbox { font-size: 12px; gap: 8px; }

    /* Navigation moves to a fixed bottom tab bar (thumb-reachable); the top
       link row is dropped so the page title isn't pushed down by wrapped links. */
    .topbar nav { display: none; }
    .bottom-tabbar {
        display: flex;
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
        background: linear-gradient(120deg, var(--navy), var(--navy-dark));
        border-top: 3px solid var(--gold);
        padding: 6px 2px calc(6px + env(safe-area-inset-bottom));
        box-shadow: 0 -4px 16px rgba(15,33,56,.25);
    }
    .bottom-tabbar a {
        flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
        color: #c9d6e4; text-decoration: none; font-size: 10px; font-weight: 600;
        padding: 4px 2px; border-radius: 10px; transition: color var(--t), background var(--t);
    }
    .bottom-tabbar a i { font-size: 19px; }
    .bottom-tabbar a.active { color: var(--gold-light); background: rgba(255,255,255,.08); }
    body { padding-bottom: 66px; } /* keep content clear of the fixed bar */

    /* Search bar + action buttons stack neatly (overrides inline flex) */
    .search-bar { flex-wrap: wrap !important; }
    .search-bar form { flex: 1 1 100% !important; }
    .search-bar input { max-width: none; }
    .search-bar .btn-primary { flex: 1; }

    /* Compact month calendar */
    .cal-header { flex-direction: column; align-items: flex-start; gap: 8px; }
    .calendar th { padding: 6px 2px; font-size: 11px; }
    .calendar td { height: auto; min-height: 56px; padding: 4px; }
    .calendar .daynum { font-size: 11px; }
    .calendar .case-count { font-size: 10px; padding: 2px 7px; margin-top: 4px; }

    .form-card { padding: 18px; }
    .form-actions { text-align: stretch; }
    .form-actions .btn-primary { width: 100%; }

    .fab-add { bottom: 82px; right: 20px; width: 54px; height: 54px; font-size: 28px; }
}

/* ---------- Responsive: Case Update table becomes stacked cards ----------
   Unlike other tables, the columns hidden by horizontal scroll here are the
   actual data-entry inputs (Next Hearing Date / Stage / Proceeding) — the
   whole point of this page — so a scroll-to-see-them table isn't good enough. */
@media (max-width: 700px) {
    table.update-table { display: block; overflow: visible !important; white-space: normal !important; }
    table.update-table tr:first-child { display: none; } /* desktop header row */
    table.update-table tr {
        display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px;
        border: 1px solid var(--border); border-radius: var(--radius-sm);
        padding: 12px; margin-bottom: 10px; background: #fff; box-shadow: var(--shadow-sm);
    }
    table.update-table td { border: none; padding: 0; white-space: normal !important; }
    table.update-table td:nth-child(1) { font-size: 12px; font-weight: 600; color: var(--navy); }
    table.update-table td:nth-child(2) { font-size: 12px; color: #6b7684; text-align: right; }
    table.update-table td:nth-child(3),
    table.update-table td:nth-child(4),
    table.update-table td:nth-child(5),
    table.update-table td:nth-child(6) { grid-column: 1 / 3; }
    table.update-table td:nth-child(3) { margin-bottom: 4px; }
    table.update-table td:nth-child(4)::before,
    table.update-table td:nth-child(5)::before,
    table.update-table td:nth-child(6)::before {
        content: "Next Hearing Date"; display: block; font-size: 11px; font-weight: 600;
        color: #6b7684; letter-spacing: .2px; margin: 6px 0 3px;
    }
    table.update-table td:nth-child(5)::before { content: "Stage"; }
    table.update-table td:nth-child(6)::before { content: "Proceeding"; }
    table.update-table td:nth-child(4) input,
    table.update-table td:nth-child(5) input,
    table.update-table td:nth-child(6) input { width: 100%; }

    /* Per-card Save — an addition to "Save All Updates" below the table, so a
       single case can be recorded and cleared without waiting to fill the rest. */
    table.update-table td.row-save-cell { display: block; grid-column: 1 / 3; margin-top: 8px; }
    .btn-row-save {
        width: 100%; padding: 9px; border: none; border-radius: var(--radius-sm);
        background: var(--navy); color: #fff; font-weight: 600; font-size: 13px; cursor: pointer;
        transition: background var(--t);
    }
    .btn-row-save:active { background: var(--navy-dark); }
    .btn-row-save:disabled { opacity: .6; }
    .btn-row-save.is-saved { background: var(--success); }
    .row-save-status { display: block; margin-top: 6px; font-size: 12px; text-align: center; color: var(--success); }
    .row-save-status.is-error { color: var(--danger); }
}

/* ---------- Responsive: Pending Cases table becomes stacked cards ----------
   Court, Stage and every action (Share/History/Edit) were off-screen past the
   right edge on a phone; cards put all of it in view without side-scrolling. */
@media (max-width: 700px) {
    table.cases-table { display: block; overflow: visible !important; white-space: normal !important; }
    table.cases-table tr:first-child { display: none; } /* desktop header row */
    table.cases-table tr {
        display: grid; grid-template-columns: 1fr 1fr; gap: 3px 10px;
        border: 1px solid var(--border); border-radius: var(--radius-sm);
        padding: 12px; margin-bottom: 10px; background: #fff; box-shadow: var(--shadow-sm);
    }
    table.cases-table td { border: none; padding: 0; white-space: normal !important; font-size: 12px; color: var(--text-soft); }
    table.cases-table td:nth-child(1) { order: 1; font-weight: 700; color: var(--navy); font-size: 13px; }
    table.cases-table td:nth-child(2) { order: 2; text-align: right; }
    table.cases-table td:nth-child(4) { order: 3; grid-column: 1 / 3; margin: 4px 0 2px; }
    table.cases-table td:nth-child(3) { order: 4; }
    table.cases-table td:nth-child(5) { order: 5; text-align: right; }
    table.cases-table td:nth-child(6) { order: 6; }
    table.cases-table td:nth-child(7) { order: 7; text-align: right; }
    table.cases-table td:nth-child(8) { order: 8; grid-column: 1 / 3; }

    table.cases-table td:nth-child(3)::before { content: "File No. "; font-weight: 600; }
    table.cases-table td:nth-child(5)::before { content: "Court: "; font-weight: 600; }
    table.cases-table td:nth-child(6)::before { content: "Stage: "; font-weight: 600; }
    table.cases-table td:nth-child(7)::before { content: "On behalf: "; font-weight: 600; }

    table.cases-table .actions-cell {
        display: flex; gap: 6px; border-top: 1px solid var(--border); padding-top: 9px; margin-top: 6px;
    }
    table.cases-table .actions-cell .action-link {
        flex: 1; justify-content: center; padding: 7px 4px; border-radius: 8px; background: var(--bg); font-size: 11.5px;
    }
}

/* ---------- Responsive: Case History hearing table becomes a timeline ----------
   Stage, Next Hearing Date and the Edit/admin-Delete actions were off-screen
   past the right edge on a phone; a stacked entry list keeps them in view. */
@media (max-width: 700px) {
    table.hearing-history-table { display: block; overflow: visible !important; white-space: normal !important; }
    /* The browser auto-inserts a <tbody> even though the markup has none; it stays
       display:table-row-group by default, which breaks percentage-width resolution
       and "auto" grid-track sizing for the row cards below unless overridden too. */
    table.hearing-history-table tbody { display: block; width: 100%; }
    table.hearing-history-table tr:first-child { display: none; } /* desktop header row */
    table.hearing-history-table tr {
        display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; align-items: center;
        width: 100%; /* mixing an "auto" track with 1fr otherwise shrinks the row to
                         content width — the browser's auto-inserted <tbody> stays a
                         table-row-group even though the <table> itself is display:block */
        border-left: 3px solid var(--gold); border-top: 1px solid var(--border); border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
        border-radius: var(--radius-sm);
        padding: 12px; margin-bottom: 10px; background: #fff; box-shadow: var(--shadow-sm);
    }
    table.hearing-history-table td { border: none; padding: 0; white-space: normal !important; font-size: 12px; color: var(--text-soft); }
    table.hearing-history-table td:nth-child(1) { order: 1; font-weight: 700; color: var(--navy); font-size: 13px; }
    /* Stage sits as a small badge right next to the date, instead of stretching
       across the row and stranding short values ("—") far off to the right. */
    table.hearing-history-table td:nth-child(2) {
        order: 2; justify-self: start; font-weight: 600; color: var(--navy);
        background: var(--bg); border: 1px solid var(--border); border-radius: 999px; padding: 2px 10px; font-size: 11px;
    }
    table.hearing-history-table td:nth-child(3) { order: 3; grid-column: 1 / 3; color: var(--text, #333); margin: 2px 0; }
    /* Next Hearing / By share a row too — "auto" sizes column 1 to that row's
       own label width, so column 2 starts right after it instead of far right. */
    table.hearing-history-table td:nth-child(4) { order: 4; justify-self: start; }
    table.hearing-history-table td:nth-child(5) { order: 5; justify-self: start; }
    table.hearing-history-table td:nth-child(6) { order: 6; grid-column: 1 / 3; font-size: 11px; }
    table.hearing-history-table td:nth-child(7) { order: 7; grid-column: 1 / 3; }

    table.hearing-history-table td:nth-child(4)::before { content: "Next Hearing: "; font-weight: 600; }
    table.hearing-history-table td:nth-child(5)::before { content: "By: "; font-weight: 600; }
    table.hearing-history-table td:nth-child(6)::before { content: "Recorded: "; font-weight: 600; }

    table.hearing-history-table .actions-cell {
        display: flex; gap: 6px; border-top: 1px solid var(--border); padding-top: 9px; margin-top: 6px;
    }
    table.hearing-history-table .actions-cell a {
        flex: 1; text-align: center; padding: 7px 4px; border-radius: 8px; background: var(--bg); font-size: 11.5px; text-decoration: none; color: var(--navy);
    }
}

.print-table { display: none; }
.print-only-heading { display: none; }
.print-only-subheading { display: none; }
.print-only-subheading-text { display: none; }
@media print {
    @page { size: A4 portrait; margin: 10mm; }
    .topbar, .search-bar, .fab-add, table.list:not(.print-table), .no-print {
        display: none !important;
    }
    .print-only-heading { display: block !important; text-align: center; }
    .print-only-subheading {
        display: block !important;
        border: none;
        border-top: 1px solid #000;
        margin: 0 0 14px;
    }
    .print-only-subheading-text {
        display: block !important;
        text-align: center;
        margin: -8px 0 14px;
        font-size: 13px;
        color: #555;
    }
    .print-table { display: table !important; table-layout: fixed; width: 100%; }
    .print-table th, .print-table td { padding: 4px 5px; font-size: 10px; overflow-wrap: break-word; word-break: break-word; border: none; vertical-align: top; }
    /* Underline the column-header row so it reads clearly (backgrounds don't print by default) */
    .print-table tr > th { border-bottom: 1.2px solid #000; font-weight: 700; }
    body { background: #fff; }
    .container { margin: 0; padding: 0; max-width: 100%; }
    table.list th { background: #eee !important; color: #000 !important; }
    .print-table .print-section-header td {
        font-weight: 600;
        font-size: 12px;
        padding: 8px 4px;
        border-top: 2px solid #000 !important;
        border-bottom: 2px solid #000 !important;
        background: #fff !important;
        color: #000 !important;
    }
    .print-table .print-section-header .psh-row {
        display: grid;
        grid-template-columns: 1fr auto 1fr;
        align-items: center;
        width: 100%;
    }
    .print-table .print-section-header .psh-title { text-align: center; }
    .print-table .print-section-header .psh-total { text-align: right; }
}
