/* Admin panel: plain, dense, table-first */
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 14px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }

.adm { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }

/* Sidebar */
.adm-side {
  position: sticky; top: 0; height: 100vh; box-sizing: border-box;
  display: flex; flex-direction: column; gap: 20px;
  padding: 18px 12px; border-right: 1px solid var(--line); background: var(--soft);
}
.adm-brand { display: flex; align-items: center; gap: 8px; padding: 0 8px; color: var(--ink); text-decoration: none; }
.adm-brand .mark { width: 24px; height: 24px; flex: none; }
.adm-brand .wordmark { font-size: 14px; font-weight: 700; letter-spacing: 0.06em; }
.adm-brand .wordmark span { color: var(--green-dark); }
.adm-tag { margin-left: auto; font-size: 12px; font-weight: 600; color: var(--muted); }
.adm-nav { display: flex; flex-direction: column; gap: 1px; }
.adm-nav a {
  display: flex; align-items: center; gap: 10px; height: 34px; padding: 0 10px; border-radius: 4px;
  color: var(--muted); text-decoration: none; font-weight: 500;
}
.adm-nav a:hover { color: var(--ink); background: color-mix(in srgb, var(--ink) 5%, transparent); }
.adm-nav a[aria-current] { color: var(--ink); background: var(--surface); box-shadow: 0 0 0 1px var(--line); font-weight: 600; }
.adm-nav svg { width: 17px; height: 17px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.adm-nav span { flex: 1; }
.badge { min-width: 18px; height: 18px; padding: 0 5px; box-sizing: border-box; border-radius: 4px; background: var(--ink); color: var(--bg); font-size: 11px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.adm-side-foot { margin-top: auto; display: flex; align-items: center; gap: 14px; padding: 0 4px; }
.adm-side-foot .theme-toggle { margin-right: auto; }
.adm-side .theme-toggle { width: 34px; height: 34px; border-radius: 4px; }
.adm-exit { font-size: 13px; font-weight: 500; color: var(--muted); text-decoration: none; }
.adm-exit:hover { color: var(--ink); }

/* Main */
.adm-main { padding: 24px 32px 64px; box-sizing: border-box; outline: none; min-width: 0; }
.adm-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; min-height: 36px; }
.adm-head h1 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -0.3px; }

.stats {
  display: grid; grid-template-columns: repeat(6, minmax(0, 1fr));
  border: 1px solid var(--line); border-radius: 6px; background: var(--surface); margin-bottom: 28px; overflow: hidden;
}
.stat { display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; color: var(--ink); text-decoration: none; border-left: 1px solid var(--line); }
.stat:first-child { border-left: 0; }
.stat:hover { background: var(--soft); }
.stat span { font-size: 12px; color: var(--muted); }
.stat strong { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }

.sec-head { display: flex; align-items: baseline; justify-content: space-between; margin: 0 0 10px; }
.sec-head h2 { margin: 0; font-size: 15px; font-weight: 700; }
.sec-head a { font-size: 13px; font-weight: 600; color: var(--green-dark); text-decoration: none; }

/* Tables */
.tbl-wrap { border: 1px solid var(--line); border-radius: 6px; background: var(--surface); overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; }
.tbl th {
  padding: 9px 12px; text-align: left; white-space: nowrap;
  font-size: 12px; font-weight: 600; color: var(--muted); background: var(--soft); border-bottom: 1px solid var(--line);
}
.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover td { background: color-mix(in srgb, var(--soft) 55%, transparent); }
.tbl .grow { width: 100%; min-width: 220px; }
.tbl .nowrap { white-space: nowrap; }
.tbl .num { text-align: right; white-space: nowrap; }
.tbl .strong { font-weight: 600; }
.tbl .act { text-align: right; white-space: nowrap; }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }

.subj { display: flex; align-items: center; gap: 10px; min-width: 0; }
.th { width: 32px; height: 32px; border-radius: 4px; object-fit: cover; flex: none; background: var(--soft) center / cover no-repeat; }
.th.av { border-radius: 50%; background-color: var(--green-tint); color: var(--green-dark); display: inline-flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; overflow: hidden; }
.th.av svg { width: 55%; height: 55%; }
.s-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 420px; }
.s-title.wrap { white-space: normal; }
.s-sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 420px; }

.st { display: inline-flex; align-items: center; gap: 6px; }
.st i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.st-ok { color: var(--green-dark); }
.st-off { color: var(--muted); }
.st-bad { color: var(--error); }
.rc { font-weight: 700; color: var(--error); }
.tag-bad { margin-left: 4px; font-size: 11px; font-weight: 600; color: var(--error); }

.abs { display: inline-flex; gap: 4px; }
.ab {
  height: 28px; padding: 0 10px; border-radius: 4px; border: 1px solid var(--border);
  background: var(--surface); color: var(--ink); font: inherit; font-size: 13px; font-weight: 500;
  display: inline-flex; align-items: center; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.ab:hover { background: var(--soft); }
.ab.danger { color: var(--error); }
.ab.danger:hover { border-color: var(--error); background: var(--surface); }

.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters .search, .filters select {
  height: 34px; padding: 0 10px; border-radius: 4px; border: 1px solid var(--border);
  background: var(--surface); color: var(--ink); font: inherit; font-size: 13px;
}
.filters .search { width: 220px; }
.filters .search:focus, .filters select:focus { outline: none; border-color: var(--ink); }

.tabs { display: inline-flex; border: 1px solid var(--border); border-radius: 4px; overflow: hidden; }
.tabs button { height: 32px; padding: 0 14px; border: 0; background: var(--surface); color: var(--muted); font: inherit; font-size: 13px; font-weight: 500; cursor: pointer; }
.tabs button + button { border-left: 1px solid var(--border); }
.tabs button[aria-selected="true"] { background: var(--soft); color: var(--ink); font-weight: 600; }
.tabs span { color: var(--muted); font-weight: 500; }

.adm-toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  display: flex; align-items: center; gap: 16px; padding: 10px 12px 10px 16px; border-radius: 4px;
  background: var(--ink); color: var(--bg); font-size: 13px; font-weight: 500; box-shadow: 0 6px 20px rgba(0, 0, 0, .2);
}
.adm-toast[hidden] { display: none; }
.adm-toast button { border: 0; background: none; color: inherit; font: inherit; font-weight: 700; text-decoration: underline; cursor: pointer; padding: 0; }

@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stat:nth-child(4) { border-left: 0; }
  .stat:nth-child(n+4) { border-top: 1px solid var(--line); }
}

/* Phone: top bar + stacked rows */
@media (max-width: 860px) {
  .adm { grid-template-columns: minmax(0, 1fr); }
  .adm-side { position: sticky; z-index: 10; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 14px 0; border-right: 0; border-bottom: 1px solid var(--line); }
  .adm-brand { padding: 0; }
  .adm-tag { margin-left: 4px; }
  .adm-side-foot { margin: 0 0 0 auto; }
  .adm-exit { display: none; }
  .adm-nav { order: 3; width: 100%; flex-direction: row; overflow-x: auto; gap: 2px; padding-bottom: 8px; scrollbar-width: none; }
  .adm-nav a { flex: none; }
  .adm-nav span { flex: none; }
  .adm-main { padding: 16px 14px 64px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat, .stat:nth-child(4) { border-left: 0; border-top: 1px solid var(--line); }
  .stat:nth-child(even) { border-left: 1px solid var(--line); }
  .stat:nth-child(-n+2) { border-top: 0; }
  .filters { width: 100%; }
  .filters .search { flex: 1; width: auto; min-width: 0; }

  .tbl thead { display: none; }
  .tbl, .tbl tbody, .tbl tr, .tbl td { display: block; width: auto; }
  .tbl tr { padding: 10px 12px; border-bottom: 1px solid var(--line); }
  .tbl tbody tr:last-child { border-bottom: 0; }
  .tbl td { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; border: 0; text-align: right; }
  .tbl td::before { content: attr(data-l); color: var(--muted); font-size: 12px; text-align: left; flex: none; }
  .tbl td.grow { display: block; text-align: left; padding-bottom: 6px; min-width: 0; }
  .tbl td.grow::before, .tbl td.act::before { content: none; }
  .tbl td.act { justify-content: flex-start; padding-top: 8px; }
  .s-title, .s-sub { max-width: none; }
}

/* Report cases */
.ref { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; letter-spacing: .2px; }
.st-warn { color: #B26B00; }
[data-theme="dark"] .st-warn { color: #F5B544; }
.tbl tr.clickable { cursor: pointer; }

.cd-scrim { position: fixed; inset: 0; z-index: 40; background: rgba(15, 17, 20, .35); }
.cd {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 41; width: min(480px, 100vw);
  display: flex; flex-direction: column; background: var(--surface); border-left: 1px solid var(--line);
  box-shadow: -12px 0 32px rgba(0, 0, 0, .12); animation: cdIn .18s ease-out;
}
@keyframes cdIn { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.cd-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.cd-head h2 { margin: 2px 0 0; font-size: 18px; }
.cd-x { width: 32px; height: 32px; border: 1px solid var(--border); border-radius: 4px; background: var(--surface); color: var(--ink); display: flex; align-items: center; justify-content: center; cursor: pointer; flex: none; }
.cd-x svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2.2; }
.cd-body { flex: 1; overflow-y: auto; padding: 4px 20px 20px; }
.cd-meta { margin: 12px 0 0; border: 1px solid var(--line); border-radius: 6px; }
.cd-meta div { display: flex; justify-content: space-between; gap: 12px; padding: 8px 12px; border-top: 1px solid var(--line); }
.cd-meta div:first-child { border-top: 0; }
.cd-meta dt { color: var(--muted); }
.cd-meta dd { margin: 0; font-weight: 500; }
.cd-sec { margin-top: 18px; }
.cd-sec p { margin: 0; line-height: 1.55; white-space: pre-wrap; }
.cd-label { display: block; margin-bottom: 6px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.cd-link { display: inline-block; margin-top: 8px; font-size: 13px; font-weight: 600; color: var(--green-dark); text-decoration: none; }
.cd-ev { display: flex; gap: 8px; flex-wrap: wrap; }
.cd-ev img { width: 96px; height: 96px; border-radius: 4px; object-fit: cover; border: 1px solid var(--line); display: block; }
.cd-hist { margin: 0; padding: 0; list-style: none; border-left: 2px solid var(--line); }
.cd-hist li { position: relative; display: flex; justify-content: space-between; gap: 12px; padding: 4px 0 10px 14px; }
.cd-hist li::before { content: ""; position: absolute; left: -5px; top: 9px; width: 8px; height: 8px; border-radius: 50%; background: var(--border); }
.cd-hist li:last-child::before { background: var(--ink); }
.cd-hist time { color: var(--muted); font-size: 12px; white-space: nowrap; }
.cd-foot { padding: 14px 20px 18px; border-top: 1px solid var(--line); background: var(--soft); }
.cd-note { width: 100%; box-sizing: border-box; padding: 8px 10px; border: 1px solid var(--border); border-radius: 4px; background: var(--surface); color: var(--ink); font: inherit; font-size: 13px; resize: vertical; }
.cd-note:focus { outline: none; border-color: var(--ink); }
.cd-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.cd-actions .abs { display: contents; }
.cd .subj .s-title, .cd .subj .s-sub { max-width: 340px; }
body.has-case { overflow: hidden; }

.cd-msgs { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; }
.cd-msgs li { padding: 10px 12px; border-radius: 6px; background: var(--soft); }
.cd-msgs p { margin: 0 0 4px; }
.cd-msgs time { font-size: 12px; color: var(--muted); }
.cd-sep { flex: 1; }
.cd-hint { margin: 8px 0 0; font-size: 12px; color: var(--muted); }

/* Locations */
.loc-add { display: flex; gap: 8px; margin: 0 0 12px; max-width: 520px; }
.loc-add input {
  flex: 1; min-width: 0; height: 38px; padding: 0 12px; border-radius: 6px;
  border: 1.5px solid var(--border-soft); background: var(--surface); color: var(--ink); font: inherit; font-size: 14px;
}
.loc-add input:focus { outline: none; border-color: var(--green-dark); }
.loc-add .ab { height: 38px; padding: 0 16px; }
.loc-err { margin: -4px 0 12px; font-size: 13px; color: var(--error); }
.loc-add input + input { flex: .8; }
.pin-edit { display: flex; gap: 6px; align-items: center; }
.pin-edit input {
  width: 210px; height: 32px; padding: 0 10px; border-radius: 6px;
  border: 1.5px solid var(--border-soft); background: var(--surface); color: var(--ink); font: inherit; font-size: 13px;
}
.pin-edit input:focus { outline: none; border-color: var(--green-dark); }

/* User details drawer */
.u-form { display: flex; flex-direction: column; }
.u-form .cd-label { margin-top: 12px; }
.u-in {
  width: 100%; box-sizing: border-box; min-height: 36px; padding: 7px 10px; margin-top: 4px; border-radius: 6px;
  border: 1.5px solid var(--border-soft); background: var(--surface); color: var(--ink); font: inherit; font-size: 14px;
}
textarea.u-in { resize: vertical; }
.u-in:focus { outline: none; border-color: var(--green-dark); }
.u-check { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 14px; }
.u-photo { display: flex; align-items: center; gap: 14px; margin-top: 8px; }
.u-photo img { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; }
.u-photo .u-check { margin: 0; }
.u-nophoto { font-size: 13px; color: var(--muted); }
#u-err { margin: 12px 0 0; }
