/* Legal Sathi — corporate UI */
:root {
    --brand: #8b1a1a;
    --brand-600: #a52222;
    --brand-50: #fbf1f1;
    --gold: #d9a21b;
    --gold-50: #fdf6e3;
    --ink: #161a23;
    --ink-2: #1f2430;
    --text: #1f2933;
    --muted: #6b7280;
    --line: #e5e7eb;
    --bg: #f4f5f8;
    --card: #ffffff;
    --ok: #15803d; --ok-50: #ecfdf3;
    --warn: #b45309; --warn-50: #fffbeb;
    --bad: #b91c1c; --bad-50: #fef2f2;
    --info: #1d4ed8; --info-50: #eff6ff;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
    --sidebar: 248px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px; line-height: 1.5; color: var(--text); background: var(--bg);
    -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-600); }
h1, h2, h3, h4 { margin: 0; color: var(--ink); font-weight: 650; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.hidden { display: none !important; }

/* ---------- Shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
    width: var(--sidebar); flex-shrink: 0; background: var(--ink); color: #c9ced8;
    position: fixed; inset: 0 auto 0 0; display: flex; flex-direction: column; z-index: 40;
    transition: transform .2s ease;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 16px; border-bottom: 1px solid rgba(255,255,255,.06); }
.brand img { width: 40px; height: 40px; object-fit: contain; background: #fff; border-radius: 8px; padding: 2px; }
.brand b { display: block; color: #fff; font-size: 15px; letter-spacing: .02em; }
.brand span { font-size: 11px; color: var(--gold); text-transform: uppercase; letter-spacing: .12em; }
.nav { padding: 12px 10px; overflow-y: auto; flex: 1; }
.nav-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .12em; color: #6b7385; padding: 14px 10px 6px; }
.nav a {
    display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 8px;
    color: #c9ced8; font-weight: 500; margin-bottom: 2px;
}
.nav a svg { width: 18px; height: 18px; flex-shrink: 0; opacity: .8; }
.nav a:hover { background: rgba(255,255,255,.05); color: #fff; }
.nav a.active { background: var(--brand); color: #fff; box-shadow: inset 3px 0 0 var(--gold); }
.nav a.active svg { opacity: 1; }
.sidebar-foot { padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.06); font-size: 12px; color: #7d8496; }

.main { flex: 1; margin-left: var(--sidebar); min-width: 0; display: flex; flex-direction: column; }
.topbar {
    height: 60px; background: var(--card); border-bottom: 1px solid var(--line);
    display: flex; align-items: center; gap: 14px; padding: 0 24px; position: sticky; top: 0; z-index: 30;
}
.topbar .title { font-weight: 600; color: var(--ink); font-size: 15px; }
.topbar .spacer { flex: 1; }
.menu-btn { display: none; background: none; border: 0; padding: 6px; cursor: pointer; color: var(--ink); }
.user-chip { display: flex; align-items: center; gap: 10px; }
.avatar {
    width: 34px; height: 34px; border-radius: 50%; background: var(--brand); color: #fff;
    display: grid; place-items: center; font-weight: 600; font-size: 13px;
}
.user-chip .who { line-height: 1.2; }
.user-chip .who b { display: block; font-size: 13px; color: var(--ink); }
.user-chip .who span { font-size: 11.5px; color: var(--muted); }
.content { padding: 24px 28px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.crumbs { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.crumbs a { color: var(--muted); }
.backdrop { display: none; }

/* ---------- Cards / grid ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-head h3 { font-size: 15px; }
.card-body { padding: 18px; }
.card + .card { margin-top: 18px; }
.grid { display: grid; gap: 18px; }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.span-2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }

.stat { padding: 16px 18px; display: flex; gap: 14px; align-items: center; }
.stat .ic { width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center; flex-shrink: 0; }
.stat .ic svg { width: 21px; height: 21px; }
.stat .lbl { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.stat .val { font-size: 22px; font-weight: 700; color: var(--ink); letter-spacing: -.02em; }
.ic-brand { background: var(--brand-50); color: var(--brand); }
.ic-gold { background: var(--gold-50); color: #a87a06; }
.ic-ok { background: var(--ok-50); color: var(--ok); }
.ic-bad { background: var(--bad-50); color: var(--bad); }
.ic-info { background: var(--info-50); color: var(--info); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th {
    text-align: left; font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
    color: var(--muted); background: #f9fafb; padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.table td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fafbfc; }
.table .primary { font-weight: 600; color: var(--ink); }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.b-processing, .b-pending { background: var(--warn-50); color: var(--warn); }
.b-completed, .b-paid, .b-received, .b-approved { background: var(--ok-50); color: var(--ok); }
.b-reject, .b-rejected { background: var(--bad-50); color: var(--bad); }
.b-neutral { background: #f3f4f6; color: #4b5563; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 9px 16px;
    border-radius: 8px; border: 1px solid transparent; font: inherit; font-weight: 600; font-size: 13.5px;
    cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s; line-height: 1.2;
}
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-600); color: #fff; }
.btn-gold { background: var(--gold); color: var(--ink); }
.btn-gold:hover { background: #e6b02a; color: var(--ink); }
.btn-light { background: #fff; color: var(--text); border-color: var(--line); }
.btn-light:hover { background: #f9fafb; color: var(--ink); }
.btn-danger { background: #fff; color: var(--bad); border-color: #f3c7c7; }
.btn-danger:hover { background: var(--bad-50); color: var(--bad); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-block { width: 100%; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; color: var(--brand); cursor: pointer; font-weight: 600; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px 18px; }
.form-grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-weight: 600; font-size: 12.5px; color: #374151; }
.field label .req { color: var(--bad); }
.field .hint { font-size: 12px; color: var(--muted); }
.input, select.input, textarea.input {
    width: 100%; padding: 9px 12px; border: 1px solid #d1d5db; border-radius: 8px; background: #fff;
    font: inherit; color: var(--text); transition: border-color .15s, box-shadow .15s;
}
textarea.input { min-height: 84px; resize: vertical; }
.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(139, 26, 26, .12); }
.input[type=file] { padding: 7px 10px; background: #fafafa; }
.is-invalid { border-color: var(--bad) !important; }
.error-text { color: var(--bad); font-size: 12px; }
.form-section { padding: 22px 22px 24px; }
.form-section + .form-section { border-top: 1px solid var(--line); }
.form-section h3 { font-size: 15px; display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.form-section h3 .step {
    width: 26px; height: 26px; border-radius: 50%; background: var(--brand); color: #fff; font-size: 12.5px;
    display: inline-grid; place-items: center;
}
.form-section > p { margin: 0 0 18px; color: var(--muted); font-size: 13px; }
.sub-head { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--brand); font-weight: 700; margin: 6px 0 12px; }
.repeat-item { border: 1px dashed #d1d5db; border-radius: 10px; padding: 16px; margin-bottom: 14px; position: relative; background: #fcfcfd; }
.repeat-item .remove { position: absolute; top: 10px; right: 12px; }
.repeat-item .ri-title { font-weight: 600; margin-bottom: 12px; color: var(--ink); }
.form-actions { padding: 16px 22px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; background: #fafbfc; border-radius: 0 0 var(--radius) var(--radius); }
.check { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.filters .input { width: auto; min-width: 160px; }

/* ---------- Alerts ---------- */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 18px; border: 1px solid; font-weight: 500; display: flex; gap: 10px; align-items: flex-start; }
.alert-success { background: var(--ok-50); border-color: #bbf7d0; color: #166534; }
.alert-error { background: var(--bad-50); border-color: #fecaca; color: #991b1b; }
.alert ul { margin: 4px 0 0; padding-left: 18px; }

/* ---------- Detail lists ---------- */
.dl { display: grid; grid-template-columns: 170px 1fr; gap: 9px 16px; margin: 0; }
.dl dt { color: var(--muted); font-size: 13px; }
.dl dd { margin: 0; color: var(--ink); font-weight: 500; word-break: break-word; }
.docs { display: flex; flex-wrap: wrap; gap: 8px; }
.doc {
    display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border: 1px solid var(--line);
    border-radius: 8px; font-size: 12.5px; font-weight: 500; color: var(--text); background: #fff;
}
.doc svg { width: 15px; height: 15px; color: var(--brand); }
.doc:hover { border-color: var(--brand); color: var(--brand); }
.doc.missing { color: #9ca3af; background: #f9fafb; border-style: dashed; }
.doc.missing svg { color: #c4c8cf; }
.subcard { border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.subcard + .subcard { margin-top: 12px; }
.subcard h4 { font-size: 14px; margin-bottom: 10px; }

/* ---------- Pagination ---------- */
.pager { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-top: 1px solid var(--line); gap: 10px; flex-wrap: wrap; }
.pager .pages { display: flex; gap: 4px; flex-wrap: wrap; }
.pager .pages a, .pager .pages span { min-width: 32px; padding: 5px 9px; text-align: center; border: 1px solid var(--line); border-radius: 6px; color: var(--text); font-size: 13px; }
.pager .pages .cur { background: var(--brand); border-color: var(--brand); color: #fff; }
.pager .pages .dis { color: #c4c8cf; }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; background: #fff; }
.auth-art {
    background: radial-gradient(circle at 20% 20%, rgba(217,162,27,.18), transparent 45%), linear-gradient(150deg, #1b1f29 0%, #2a0d0d 60%, #5c1111 100%);
    color: #e9e3d6; padding: 48px 56px; display: flex; flex-direction: column; justify-content: space-between;
}
.auth-art .lg { display: flex; align-items: center; gap: 12px; }
.auth-art .lg img { width: 54px; height: 54px; background: #fff; border-radius: 12px; padding: 3px; }
.auth-art .lg b { font-size: 20px; color: #fff; display: block; }
.auth-art .lg span { color: var(--gold); font-size: 11.5px; letter-spacing: .14em; text-transform: uppercase; }
.auth-art h2 { color: #fff; font-size: 34px; line-height: 1.2; max-width: 460px; }
.auth-art h2 em { color: var(--gold); font-style: normal; }
.auth-art p { color: #c8c1b3; max-width: 440px; }
.auth-art ul { list-style: none; padding: 0; margin: 22px 0 0; display: grid; gap: 10px; }
.auth-art li { display: flex; gap: 10px; align-items: center; color: #ddd5c5; }
.auth-art li::before { content: ''; width: 8px; height: 8px; background: var(--gold); border-radius: 2px; transform: rotate(45deg); }
.auth-panel { display: grid; place-items: center; padding: 40px 24px; }
.auth-box { width: 100%; max-width: 420px; }
.auth-box h1 { font-size: 24px; }
.auth-box > p { color: var(--muted); margin: 6px 0 24px; }
.tabs { display: flex; gap: 4px; background: #f3f4f6; padding: 4px; border-radius: 10px; margin-bottom: 22px; }
.tabs button { flex: 1; padding: 9px; border: 0; background: none; border-radius: 7px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; }
.tabs button.on { background: #fff; color: var(--ink); box-shadow: var(--shadow); }
.stack { display: grid; gap: 14px; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
    .g-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .g-main { grid-template-columns: 1fr; }
    .form-grid, .form-grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
    .sidebar { transform: translateX(-100%); }
    body.nav-open .sidebar { transform: none; }
    body.nav-open .backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 35; }
    .main { margin-left: 0; }
    .menu-btn { display: inline-flex; }
    .content { padding: 16px; }
    .topbar { padding: 0 16px; }
    .user-chip .who { display: none; }
    .g-2, .g-3 { grid-template-columns: 1fr; }
    .span-2 { grid-column: auto; }
    .auth { grid-template-columns: 1fr; }
    .auth-art { display: none; }
    .dl { grid-template-columns: 1fr; gap: 2px 0; }
    .dl dd { margin-bottom: 8px; }
}
@media (max-width: 560px) {
    .g-4, .form-grid, .form-grid.cols-2, .form-grid.cols-4 { grid-template-columns: 1fr; }
    .page-head h1 { font-size: 19px; }
    .filters .input { min-width: 0; flex: 1 1 140px; }
}
@media print {
    .sidebar, .topbar, .no-print { display: none !important; }
    .main { margin: 0; }
}
.mobile-logo { display: none; }
@media (max-width: 860px) { .mobile-logo { display: block; } }
@media (max-width: 560px) { .hide-sm { display: none; } }
a.card { color: inherit; display: flex; } a.card:hover { border-color: #d6d9de; }

/* ---------- Full-screen desktop ---------- */
@media (min-width: 1600px) {
    .content { padding: 28px 36px; }
    .g-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .form-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .form-grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.main { min-height: 100vh; }
.content { flex: 1; }
.stack .btn-group, .stack > div > .btn { width: auto; }

/* ---------- Mobile ---------- */
@media (max-width: 860px) {
    .topbar { height: 56px; }
    .topbar .title { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
    .page-head { align-items: stretch; }
    .page-head > .btn, .page-head > .btn-group { width: 100%; }
    .page-head > .btn-group > * { flex: 1 1 auto; }
    .page-head > .btn-group form { display: flex; flex: 1 1 100%; }
    .page-head > .btn-group form .input { flex: 1; width: auto !important; }
    .card-head { flex-wrap: wrap; }
    .card-head > form, .filters { width: 100%; }
    .filters > * { flex: 1 1 140px; }
    .form-actions { flex-direction: column-reverse; }
    .form-actions .btn { width: 100%; }
    .form-section { padding: 18px 16px; }
    .dl { grid-template-columns: 1fr; }
    .subcard .btn-group[style*="float"] { float: none !important; margin-bottom: 10px; }
}
@media (max-width: 760px) {
    /* Tables become stacked cards; labels come from data-label set in layout JS */
    .table-wrap { overflow: visible; }
    table.table, .table tbody, .table tr, .table td { display: block; width: 100%; }
    .table thead { display: none; }
    .table tr { border-bottom: 1px solid var(--line); padding: 10px 14px; }
    .table tbody tr:last-child { border-bottom: 0; }
    .table tbody tr:hover { background: transparent; }
    .table td { border: 0; padding: 5px 0; display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; text-align: right; }
    .table td::before { content: attr(data-label); font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); text-align: left; flex-shrink: 0; padding-top: 2px; }
    .table td:not([data-label])::before, .table td[data-label=""]::before { display: none; }
    .table td:not([data-label]), .table td[data-label=""] { justify-content: flex-end; }
    .table td.empty { justify-content: center; text-align: center; }
    .table td > div, .table td > a, .table td > form { min-width: 0; }
    .table td .btn-group { justify-content: flex-end; }
    .table td select.input { max-width: 60vw; }
    .table .right { text-align: right; }
    .pager { justify-content: center; }
}
@media (max-width: 420px) {
    .content { padding: 12px; }
    .stat { padding: 14px; }
    .stat .val { font-size: 19px; }
    .auth-panel { padding: 24px 16px; }
}

/* Search box */
.search-box { position: relative; flex: 1 1 340px; min-width: 220px; }
.search-box svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 17px; height: 17px; color: var(--muted); pointer-events: none; }
.search-box .input { padding-left: 36px; width: 100%; min-width: 0; }

/* ---------- Case form wizard ---------- */
.wz-hidden { display: none !important; }
.wizard-steps { display: flex; gap: 6px; padding: 14px 18px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; background: #fafbfc; border-radius: var(--radius) var(--radius) 0 0; }
.wizard-steps::-webkit-scrollbar { display: none; }
.wz-step { display: flex; align-items: center; gap: 8px; flex: 1 0 auto; padding: 8px 10px; border: 0; background: none; cursor: pointer; font: inherit; color: var(--muted); border-radius: 8px; white-space: nowrap; position: relative; }
.wz-step:hover { background: #f1f2f4; }
.wz-dot { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 12.5px; font-weight: 700; background: #e5e7eb; color: #4b5563; flex-shrink: 0; }
.wz-label { font-weight: 600; font-size: 13px; }
.wz-step.on { color: var(--ink); background: var(--brand-50); }
.wz-step.on .wz-dot { background: var(--brand); color: #fff; box-shadow: 0 0 0 3px rgba(139,26,26,.15); }
.wz-step.done .wz-dot { background: var(--gold); color: var(--ink); }
.wz-step.done { color: var(--text); }
.wizard-actions { align-items: center; }
.wizard-actions .wizard-count { margin-right: auto; order: -1; }
@media (max-width: 860px) {
    .wz-step:not(.on) .wz-label { display: none; }
    .wz-step { flex: 0 0 auto; }
    .wizard-actions { flex-direction: row; flex-wrap: wrap; }
    .wizard-actions .wizard-count { width: 100%; text-align: center; order: -1; margin: 0 0 4px; }
    .wizard-actions .btn { flex: 1 1 0; width: auto; }
}
