:root {
  --navy: #0f172a; --navy-2: #1e293b; --navy-3: #334155; --nav-text: #cbd5e1;
  --bg: #f1f5f9; --card: #fff; --line: #e2e8f0; --line-2: #cbd5e1;
  --text: #0f172a; --muted: #64748b; --faint: #94a3b8;
  --red: #dc2626; --red-bg: #fef2f2; --red-line: #fecaca;
  --amber: #d97706; --amber-bg: #fffbeb; --amber-line: #fde68a;
  --green: #16a34a; --green-bg: #f0fdf4; --green-line: #bbf7d0;
  --blue: #2563eb; --blue-bg: #eff6ff; --blue-line: #bfdbfe;
  --purple: #7c3aed; --purple-bg: #f5f3ff;
  --radius: 10px; --shadow: 0 1px 2px rgba(15, 23, 42, .06);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 14px; color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; font-weight: 650; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 650; }
h3 { font-size: 14px; margin: 0 0 8px; font-weight: 650; }
.muted { color: var(--muted); } .faint { color: var(--faint); } .small { font-size: 12px; } .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.nowrap { white-space: nowrap; } .right { text-align: right; } .center { text-align: center; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--navy); color: var(--nav-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 16px; color: #fff; font-weight: 650; font-size: 17px; border-bottom: 1px solid var(--navy-2); }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--red); display: inline-flex; align-items: center; justify-content: center; }
.brand-mark::after { content: ''; width: 12px; height: 12px; border: 2px solid #fff; border-radius: 50%; }
.org-card { margin: 12px; padding: 10px 12px; background: var(--navy-2); border-radius: 8px; display: flex; gap: 10px; align-items: center; }
.org-icon { width: 26px; height: 26px; border-radius: 6px; background: var(--blue); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; flex: none; }
.org-icon.tow { background: var(--red); } .org-icon.admin { background: var(--purple); }
.org-card .n { color: #fff; font-size: 13px; line-height: 1.2; } .org-card .r { font-size: 11.5px; color: var(--faint); }
.nav { padding: 4px 8px; flex: 1; overflow: auto; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: var(--nav-text); font-size: 14px; margin-bottom: 2px; }
.nav a:hover { background: var(--navy-2); text-decoration: none; color: #fff; }
.nav a.active { background: var(--navy-3); color: #fff; }
.nav a.sub { padding-left: 36px; font-size: 13px; }
.nav .sec { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); padding: 14px 12px 6px; }
.nav .count { margin-left: auto; background: var(--red); color: #fff; border-radius: 10px; font-size: 11px; padding: 1px 7px; }
.nav .count.amber { background: #f59e0b; }
.ico { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.me { border-top: 1px solid var(--navy-2); padding: 12px 16px; display: flex; align-items: center; gap: 10px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--navy-3); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 650; flex: none; }
.me .n { color: #fff; font-size: 13px; } .me .r { font-size: 11.5px; color: var(--faint); }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 60px; background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 16px; padding: 0 24px; position: sticky; top: 0; z-index: 20; }
.search { position: relative; flex: 0 1 460px; }
.search input[type=search] { width: 100%; padding: 9px 12px 9px 36px; border: 1px solid var(--line); border-radius: 8px; background: #f8fafc; font: inherit; }
.search .ico { position: absolute; left: 11px; top: 10px; color: var(--faint); }
.search-results { position: absolute; top: 44px; left: 0; right: 0; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(15,23,42,.12); max-height: 420px; overflow: auto; }
.search-results a { display: block; padding: 10px 14px; color: var(--text); border-bottom: 1px solid var(--line); }
.search-results a:hover, .search-results a.sel { background: var(--blue-bg); text-decoration: none; }
.search-results .empty { padding: 14px; color: var(--muted); }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.bell { position: relative; background: none; border: 0; cursor: pointer; color: var(--muted); padding: 6px; }
.bell .dot { position: absolute; top: -2px; right: -4px; background: var(--red); color: #fff; font-size: 10.5px; border-radius: 9px; padding: 1px 5px; min-width: 18px; }
.dropdown { position: absolute; right: 0; top: 46px; width: 380px; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 32px rgba(15,23,42,.16); z-index: 40; }
.dropdown .hd { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); font-weight: 650; }
.dropdown .item { display: block; padding: 10px 14px; border-bottom: 1px solid var(--line); color: var(--text); font-size: 13px; }
.dropdown .item.unread { background: #f8fbff; } .dropdown .item.unread::before { content: '●'; color: var(--blue); margin-right: 6px; font-size: 9px; vertical-align: 2px; }
.dropdown .item:hover { background: var(--bg); text-decoration: none; }
.dropdown .ft { padding: 10px 14px; text-align: center; }
.menu a, .menu button { display: block; width: 100%; text-align: left; padding: 10px 14px; background: none; border: 0; font: inherit; color: var(--text); cursor: pointer; }
.menu a:hover, .menu button:hover { background: var(--bg); text-decoration: none; }
.imp-banner { background: #7c2d12; color: #fff; padding: 8px 24px; display: flex; align-items: center; gap: 12px; font-size: 13px; }
.imp-banner button { margin-left: auto; }
.content { padding: 24px; max-width: 1400px; width: 100%; }
.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.crumbs { font-size: 12px; color: var(--faint); margin-bottom: 6px; }
.crumbs a { color: var(--faint); }

/* ---------- components ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.card-head h2 { margin: 0; } .card-head .actions { margin-left: auto; display: flex; gap: 8px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.stack > * + * { margin-top: 16px; }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line-2); background: #fff; color: var(--text); font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f8fafc; text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; } .btn-primary:hover { background: #1d4ed8; }
.btn-red { background: var(--red); border-color: var(--red); color: #fff; } .btn-red:hover { background: #b91c1c; }
.btn-danger-outline { color: var(--red); border-color: var(--red-line); } .btn-danger-outline:hover { background: var(--red-bg); }
.btn-green { background: var(--green); border-color: var(--green); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; } .btn-link { border: 0; background: none; color: var(--blue); padding: 0; cursor: pointer; font: inherit; }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 550; white-space: nowrap; background: #f1f5f9; color: #475569; }
.pill.red { background: var(--red-bg); color: #b91c1c; } .pill.amber { background: #fef3c7; color: #b45309; } .pill.green { background: #dcfce7; color: #15803d; }
.pill.blue { background: #dbeafe; color: #1d4ed8; } .pill.purple { background: #ede9fe; color: #6d28d9; } .pill.gray { background: #f1f5f9; color: #475569; }
.alert { border-radius: var(--radius); padding: 14px 16px; border: 1px solid; display: flex; gap: 12px; align-items: flex-start; }
.alert.red { background: var(--red-bg); border-color: var(--red-line); color: #991b1b; }
.alert.amber { background: var(--amber-bg); border-color: var(--amber-line); color: #92400e; }
.alert.green { background: var(--green-bg); border-color: var(--green-line); color: #166534; }
.alert.blue { background: var(--blue-bg); border-color: var(--blue-line); color: #1e40af; }
.alert .t { font-weight: 650; margin-bottom: 2px; }
.metrics { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.metric { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; cursor: pointer; border-top: 3px solid var(--line); }
.metric:hover { box-shadow: 0 4px 12px rgba(15,23,42,.08); }
.metric .v { font-size: 28px; font-weight: 700; } .metric .l { color: var(--muted); font-size: 13px; }
.metric.red { border-top-color: var(--red); } .metric.red .v { color: var(--red); }
.metric.amber { border-top-color: #f59e0b; } .metric.amber .v { color: var(--amber); }
.metric.green { border-top-color: var(--green); } .metric.green .v { color: var(--green); }
.metric.blue { border-top-color: var(--blue); } .metric.blue .v { color: var(--blue); }

/* tables */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; }
table.t th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line); background: #f8fafc; white-space: nowrap; user-select: none; }
table.t th.sort { cursor: pointer; } table.t th.sort:hover { color: var(--text); }
table.t td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.t tr.click { cursor: pointer; } table.t tr.click:hover td { background: #f8fafc; }
table.t tr.att-overdue td:first-child { box-shadow: inset 3px 0 0 var(--red); }
table.t tr.att-soon td:first-child { box-shadow: inset 3px 0 0 #f59e0b; }
table.t tr.hold td { background: #fff7f7; }
.veh .n { font-weight: 550; } .veh .s { font-size: 12px; color: var(--muted); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 10px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 550; }
.tabs a.active { color: var(--red); border-bottom-color: var(--red); } .tabs a:hover { text-decoration: none; color: var(--text); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 6px 12px; border-radius: 8px; border: 1px solid transparent; color: var(--muted); cursor: pointer; background: none; font: inherit; }
.chip.active { background: #fff; border-color: var(--line); color: var(--text); box-shadow: var(--shadow); }
.chip .c { margin-left: 4px; font-weight: 650; } .chip .c.red { color: var(--red); } .chip .c.amber { color: var(--amber); } .chip .c.green { color: var(--green); }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.toolbar .grow { flex: 1; }

/* forms */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field label { font-weight: 550; font-size: 13px; }
.field label .req { color: var(--red); }
.field .hint { font-size: 12px; color: var(--muted); }
.field .err { font-size: 12px; color: var(--red); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=time], input[type=search], select, textarea {
  font: inherit; padding: 8px 11px; border: 1px solid var(--line-2); border-radius: 8px; background: #fff; color: var(--text); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--blue); }
.invalid input, .invalid select, .invalid textarea { border-color: var(--red); background: #fffafa; }
textarea { min-height: 80px; resize: vertical; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 16px; height: 16px; }
.form-row { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-row.r3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .form-row.r4 { grid-template-columns: 2fr 1fr .7fr 1fr; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.divider-text { display: flex; align-items: center; gap: 10px; color: var(--faint); font-size: 12px; margin: 14px 0; }
.divider-text::before, .divider-text::after { content: ''; flex: 1; border-top: 1px solid var(--line); }

/* key/value */
dl.kv { display: grid; grid-template-columns: 160px 1fr; gap: 8px 14px; margin: 0; }
dl.kv dt { color: var(--muted); } dl.kv dd { margin: 0; }
.kv-row { display: flex; justify-content: space-between; padding: 6px 0; } .kv-row.total { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 10px; font-weight: 650; }

/* case detail */
.case-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.case-meta { display: flex; gap: 16px; flex-wrap: wrap; color: var(--muted); font-size: 13px; margin-top: 8px; }
.progress { display: flex; align-items: flex-start; margin: 22px 0 6px; overflow-x: auto; }
.progress .st { flex: 1; min-width: 92px; text-align: center; position: relative; font-size: 12.5px; }
.progress .st::before { content: ''; position: absolute; top: 15px; left: calc(-50% + 18px); right: calc(50% + 18px); border-top: 2px solid var(--line); }
.progress .st:first-child::before { display: none; }
.progress .st.done::before, .progress .st.cur::before { border-color: var(--green); }
.progress .dot { width: 32px; height: 32px; border-radius: 50%; margin: 0 auto 6px; display: flex; align-items: center; justify-content: center; background: #e2e8f0; color: var(--muted); font-weight: 650; }
.progress .done .dot { background: var(--green); color: #fff; }
.progress .cur .dot { background: var(--red); color: #fff; box-shadow: 0 0 0 4px #fee2e2; }
.progress .cur.ok .dot { background: var(--blue); box-shadow: 0 0 0 4px #dbeafe; }
.progress .lbl { font-weight: 550; } .progress .who { color: var(--faint); font-size: 11.5px; }
.deadlines { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.dl { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; background: #fff; }
.dl .lb { font-size: 12px; color: var(--muted); } .dl .st { font-weight: 650; margin: 4px 0 2px; font-size: 15px; } .dl .sb { font-size: 12px; color: var(--muted); }
.dl.done .st { color: var(--green); } .dl.overdue { border-color: var(--red-line); background: var(--red-bg); } .dl.overdue .st { color: var(--red); }
.dl.soon, .dl.today { border-color: var(--amber-line); background: var(--amber-bg); } .dl.soon .st, .dl.today .st { color: var(--amber); }
.dl.running .st { color: var(--blue); }
.checklist .ci { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid #f1f5f9; }
.checklist .ci:last-child { border: 0; }
.checklist .ci .tag { margin-left: auto; }
.ck { width: 18px; height: 18px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 11px; flex: none; border: 2px solid var(--line-2); color: transparent; }
.ck.yes { background: var(--green); border-color: var(--green); color: #fff; }
.ck.no { border-color: var(--red); }
.activity .ai { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid #f1f5f9; }
.activity .ai:last-child { border: 0; }
.activity .ai .ic { width: 28px; height: 28px; border-radius: 50%; background: var(--blue-bg); color: var(--blue); display: flex; align-items: center; justify-content: center; flex: none; font-size: 12px; }
.activity .ai .ic.sys { background: #f1f5f9; color: var(--muted); }
.activity .ai .a { font-weight: 550; } .activity .ai .d { font-size: 13px; color: #334155; white-space: pre-wrap; word-break: break-word; } .activity .ai .w { font-size: 12px; color: var(--faint); }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.photo { position: relative; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #f8fafc; }
.photo img, .photo .ph { width: 100%; height: 110px; object-fit: cover; display: block; }
.photo .ph { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 12px; }
.photo .cap { padding: 6px 8px; font-size: 12px; display: flex; justify-content: space-between; }
.photo .x { position: absolute; top: 6px; right: 6px; background: rgba(15,23,42,.7); color: #fff; border: 0; border-radius: 50%; width: 24px; height: 24px; cursor: pointer; }
.doc-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid #f1f5f9; }
.doc-row:last-child { border: 0; }
.progressbar { height: 8px; background: #e2e8f0; border-radius: 6px; overflow: hidden; } .progressbar > div { height: 100%; background: #f59e0b; }

/* letters */
.letter-page { background: #fff; color: #111; font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 1.35; padding: 48px 56px; border: 1px solid var(--line); box-shadow: 0 4px 18px rgba(0,0,0,.08); max-width: 816px; margin: 0 auto; }
.letter-page hr { border: 0; border-top: 1px solid #333; margin: 8px 0 12px; }
.letter-page .row { display: flex; justify-content: space-between; margin: 2px 0; } .letter-page .row.b { font-weight: 700; }
.letter-foot { margin-top: 24px; text-align: center; font-size: 11px; color: #666; }
.letter-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
.letter-scroll { max-height: 70vh; overflow: auto; background: #e2e8f0; padding: 16px; border-radius: 10px; }

/* modal + toast */
.modal-back { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 100; overflow: auto; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 560px; box-shadow: 0 24px 64px rgba(15,23,42,.3); }
.modal.wide { max-width: 1100px; }
.modal .mh { padding: 16px 20px; border-bottom: 1px solid var(--line); font-weight: 650; font-size: 16px; display: flex; align-items: center; }
.modal .mh button { margin-left: auto; background: none; border: 0; font-size: 20px; cursor: pointer; color: var(--muted); }
.modal .mb { padding: 18px 20px; } .modal .mf { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.toasts { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--navy); color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: 420px; }
.toast.err { background: #991b1b; } .toast.ok { background: #166534; }

/* auth */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.auth .side { background: var(--navy); color: #fff; padding: 48px; display: flex; flex-direction: column; justify-content: center; }
.auth .side h1 { font-size: 30px; margin: 22px 0 10px; } .auth .side p { color: var(--nav-text); max-width: 420px; line-height: 1.5; }
.auth .side ul { color: var(--nav-text); line-height: 1.9; padding-left: 18px; }
.auth .form { display: flex; align-items: center; justify-content: center; padding: 32px; }
.auth .box { width: 100%; max-width: 380px; }
.auth .box h2 { font-size: 22px; } .auth .foot { margin-top: 24px; font-size: 12px; color: var(--faint); }
.error-page { max-width: 420px; margin: 15vh auto; text-align: center; font-family: system-ui, sans-serif; }
.error-page h1 { font-size: 56px; margin: 18px 0 4px; } .error-page .brand-mark { margin: 0 auto; }
.empty-state { padding: 36px; text-align: center; color: var(--muted); }
.spinner { padding: 40px; text-align: center; color: var(--muted); }

@media (max-width: 1100px) {
  .split, .letter-layout { grid-template-columns: 1fr; } .metrics { grid-template-columns: repeat(2, 1fr); } .g4, .g3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; } .sidebar { position: fixed; left: -260px; width: 240px; z-index: 60; transition: left .2s; } .sidebar.open { left: 0; }
  .menu-toggle { display: inline-flex !important; } .top-actions .btn-red { display: none; } .topbar { padding: 0 12px; gap: 10px; } .content { padding: 16px; } .g2, .g3, .g4, .form-row, .form-row.r3, .form-row.r4 { grid-template-columns: 1fr; }
  .auth { grid-template-columns: 1fr; } .auth .side { display: none; } dl.kv { grid-template-columns: 1fr; } .metrics { grid-template-columns: 1fr 1fr; }
}
.menu-toggle { display: none; }
@media print {
  .sidebar, .topbar, .imp-banner, .no-print, .tabs, .toasts { display: none !important; }
  .app { display: block; } .content { padding: 0; } .card { box-shadow: none; } body { background: #fff; }
  .letter-page { border: 0; box-shadow: none; padding: 0; }
}
