:root {
  --bg: #f4f6f2;
  --panel: #ffffff;
  --panel-soft: #f8faf7;
  --text: #151a16;
  --muted: #68736b;
  --line: #dde3dc;
  --green: #1f8f4e;
  --green-dark: #126838;
  --green-soft: #e9f6ee;
  --amber: #a8660a;
  --amber-soft: #fff5df;
  --red: #b93838;
  --red-soft: #fff0f0;
  --blue: #2366a8;
  --blue-soft: #edf5ff;
  --shadow: 0 16px 48px rgba(19, 31, 22, 0.08);
  --radius: 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--bg); color: var(--text); }
body { margin: 0; min-height: 100vh; background: var(--bg); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.brand { font-size: 27px; font-weight: 850; letter-spacing: -1.2px; }
.brand span { color: var(--green); }
.eyebrow { margin: 0 0 8px; color: var(--green-dark); font-size: 12px; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
.muted { color: var(--muted); }
.error { color: var(--red); background: var(--red-soft); border: 1px solid #f3caca; border-radius: 12px; padding: 10px 12px; font-size: 13px; }
.security-note { margin: 20px 0 0; color: var(--muted); font-size: 12px; line-height: 1.55; }

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 28px; background: radial-gradient(circle at 15% 12%, #e3f3e8, transparent 34%), radial-gradient(circle at 90% 86%, #edf2eb, transparent 40%), var(--bg); }
.login-card { width: min(440px, 100%); background: rgba(255,255,255,.94); border: 1px solid var(--line); border-radius: 26px; padding: 34px; box-shadow: var(--shadow); }
.login-card h1 { margin: 22px 0 8px; font-size: 32px; letter-spacing: -.04em; }
.login-card form { display: grid; gap: 14px; margin-top: 26px; }
label { display: grid; gap: 7px; color: #344039; font-size: 13px; font-weight: 700; }
input, select, textarea { width: 100%; border: 1px solid var(--line); background: #fff; color: var(--text); border-radius: 12px; padding: 11px 12px; outline: none; transition: border-color .15s ease, box-shadow .15s ease; }
textarea { min-height: 105px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: #75b992; box-shadow: 0 0 0 3px rgba(31,143,78,.10); }

.primary, .secondary, .ghost, .danger-btn, .link-btn { border-radius: 11px; border: 1px solid transparent; padding: 10px 14px; font-weight: 800; }
.primary { background: var(--green); color: #fff; }
.primary:hover { background: var(--green-dark); }
.secondary { background: #fff; color: var(--text); border-color: var(--line); }
.secondary:hover { background: var(--panel-soft); }
.ghost { background: transparent; color: #d9e5dc; border-color: rgba(255,255,255,.15); }
.ghost:hover { background: rgba(255,255,255,.08); }
.danger-btn { background: var(--red); color: #fff; }
.link-btn { padding: 5px 0; color: var(--green-dark); background: none; }
.small-btn { padding: 7px 10px; border-radius: 9px; font-size: 12px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; background: #142219; color: #fff; padding: 24px 16px 18px; }
.side-top { padding: 2px 8px 22px; border-bottom: 1px solid rgba(255,255,255,.10); }
.side-brand { color: #fff; font-size: 22px; }
.side-top p { margin: 5px 0 0; color: #9ab0a0; font-size: 12px; }
#nav { display: grid; gap: 4px; padding: 20px 0; }
#nav button { display: flex; align-items: center; justify-content: space-between; width: 100%; border: 0; border-radius: 10px; padding: 11px 12px; background: transparent; color: #b9c9bd; text-align: left; font-size: 13px; font-weight: 700; }
#nav button:hover, #nav button.active { background: rgba(255,255,255,.09); color: #fff; }
.nav-badge { min-width: 22px; height: 22px; display: inline-grid; place-items: center; padding: 0 6px; border-radius: 999px; background: #fff; color: #142219; font-size: 11px; }
.side-bottom { margin-top: auto; display: grid; gap: 12px; padding-top: 18px; border-top: 1px solid rgba(255,255,255,.10); }
.identity { color: #dce7df; font-size: 12px; line-height: 1.55; }
.identity strong { display: block; color: #fff; font-size: 13px; }
.identity .role { display: inline-block; margin-top: 5px; color: #9ed7b5; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; font-size: 10px; }

.content { min-width: 0; padding: 28px 34px 60px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 26px; }
.topbar h1 { margin: 0; font-size: 28px; letter-spacing: -.035em; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.status-pill { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 999px; padding: 8px 11px; background: #fff; color: #445047; font-size: 12px; font-weight: 700; }
.dot { width: 8px; height: 8px; background: var(--green); border-radius: 50%; box-shadow: 0 0 0 4px rgba(31,143,78,.12); }

.view { display: grid; gap: 18px; }
.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.metric { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: 0 4px 16px rgba(20,34,25,.03); }
.metric .label { color: var(--muted); font-size: 12px; font-weight: 700; }
.metric .value { margin-top: 8px; font-size: 28px; line-height: 1; font-weight: 850; letter-spacing: -.04em; }
.metric .hint { margin-top: 8px; color: var(--muted); font-size: 11px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: 0 4px 18px rgba(20,34,25,.035); }
.panel-head { min-height: 64px; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 15px 18px; border-bottom: 1px solid var(--line); }
.panel-head h2, .panel-head h3 { margin: 0; font-size: 16px; }
.panel-head p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.panel-body { padding: 18px; }
.panel-grid { display: grid; grid-template-columns: 1.3fr .7fr; gap: 18px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; }
.toolbar input { width: min(300px, 100%); }
.toolbar select { width: auto; min-width: 140px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { padding: 11px 14px; color: var(--muted); background: #fafbf9; font-weight: 800; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--line); }
td { padding: 12px 14px; border-bottom: 1px solid #edf0ec; vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fcfdfb; }
.row-title { font-weight: 800; color: var(--text); }
.row-sub { margin-top: 3px; color: var(--muted); font-size: 11px; }
.empty { padding: 34px 18px; text-align: center; color: var(--muted); }

.badge { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 5px 8px; font-size: 10px; font-weight: 850; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
.badge.green { background: var(--green-soft); color: var(--green-dark); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.blue { background: var(--blue-soft); color: var(--blue); }
.badge.gray { background: #eef1ed; color: #59625c; }
.badge.cs { background: var(--blue-soft); color: var(--blue); }
.badge.manager { background: var(--amber-soft); color: var(--amber); }
.badge.admin { background: var(--red-soft); color: var(--red); }

.cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.case-card { padding: 16px; border: 1px solid var(--line); border-radius: 14px; background: #fff; }
.case-card:hover { border-color: #b8c6bb; }
.case-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.case-number { color: var(--muted); font-size: 10px; font-weight: 850; letter-spacing: .07em; }
.case-card h3 { margin: 7px 0 8px; font-size: 15px; }
.case-card p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.case-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }

.live-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.live-card { border: 1px solid var(--line); background: #fff; border-radius: var(--radius); overflow: hidden; }
.live-card .panel-head { background: #fbfcfa; }
.live-list { display: grid; }
.live-item { display: grid; gap: 5px; padding: 13px 16px; border-bottom: 1px solid #edf0ec; }
.live-item:last-child { border-bottom: 0; }
.live-line { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.live-item small { color: var(--muted); }

.modal { width: min(760px, calc(100vw - 32px)); max-height: min(84vh, 900px); border: 1px solid var(--line); border-radius: 20px; padding: 0; box-shadow: 0 30px 100px rgba(0,0,0,.20); }
.modal::backdrop { background: rgba(11,20,14,.45); backdrop-filter: blur(4px); }
.compact-modal { width: min(520px, calc(100vw - 32px)); }
.dialog-close { position: absolute; top: 12px; right: 14px; width: 34px; height: 34px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 50%; background: #fff; font-size: 21px; }
#caseDialogBody, #actionDialogBody { padding: 26px; }
.modal h2 { margin: 0 46px 4px 0; font-size: 22px; }
.modal h3 { margin: 24px 0 10px; font-size: 14px; }
.modal .meta { color: var(--muted); font-size: 12px; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 18px; }
.form-grid { display: grid; gap: 13px; margin-top: 18px; }
.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.timeline { margin-top: 18px; display: grid; gap: 10px; }
.timeline-item { border-left: 3px solid #d8e5db; padding: 3px 0 3px 12px; }
.timeline-item strong { display: block; font-size: 12px; }
.timeline-item p { margin: 4px 0 0; color: #4f5b52; font-size: 12px; line-height: 1.5; }
.timeline-item small { color: var(--muted); }

.toast { position: fixed; right: 22px; bottom: 22px; max-width: min(420px, calc(100vw - 44px)); padding: 12px 15px; background: #142219; color: #fff; border-radius: 12px; box-shadow: var(--shadow); font-size: 13px; font-weight: 700; z-index: 50; }
.toast.bad { background: #7d2525; }

.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 16px; font-size: 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.codeish { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 11px; }

@media (max-width: 1050px) {
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .panel-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; padding: 16px; }
  #nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .side-bottom { margin-top: 10px; }
  .content { padding: 20px 16px 46px; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .metrics, .cards, .live-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .status-pill { display: none; }
}
