:root {
  --green: #009E49; --green-dark: #007a38; --green-soft: #e3f5ea;
  --ink: #1A1A2E; --text: #22223a; --muted: #6b6b80; --line: #e6e6ee; --bg: #f5f6f8; --card: #fff;
  --amber: #b26a00; --amber-soft: #fff3df; --red: #c0392b; --red-soft: #fdecea; --blue: #1f6fb2; --blue-soft: #e6f0fa;
  --radius: 10px;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text); background: var(--bg); font-size: 14px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--red); min-height: 1em; }
h1 { font-size: 20px; margin: 0; font-weight: 600; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 14px; margin: 16px 0 8px; font-weight: 600; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; color: #fff; padding: 20px 18px; }
.brand.big { color: var(--ink); font-size: 22px; padding: 0 0 4px; }
.logo { width: 30px; height: 30px; border-radius: 8px; background: var(--green); color: #fff; display: grid; place-items: center; font-weight: 800; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--card); padding: 28px; border-radius: 14px; width: 100%; max-width: 360px; box-shadow: 0 6px 30px rgba(0,0,0,.06); display: grid; gap: 12px; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
input, select, textarea { font: inherit; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--green-soft); border-color: var(--green); }
textarea { min-height: 80px; resize: vertical; }

.shell { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.sidebar { background: var(--ink); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
nav { display: grid; padding: 4px 10px; gap: 2px; overflow-y: auto; }
nav a { color: #c9c9da; text-decoration: none; padding: 9px 12px; border-radius: 8px; display: flex; justify-content: space-between; align-items: center; }
nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
nav a.active { background: var(--green); color: #fff; }
nav .count { background: rgba(255,255,255,.18); border-radius: 10px; padding: 0 7px; font-size: 12px; }
.me { margin-top: auto; padding: 16px 18px; display: grid; gap: 2px; color: #fff; font-size: 13px; border-top: 1px solid rgba(255,255,255,.08); }
.me .muted { color: #9a9ab0; }
.link { background: none; border: 0; color: #9fd9b8; cursor: pointer; padding: 6px 0 0; text-align: left; font: inherit; }

main { padding: 0 28px 40px; min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 22px 0 18px; flex-wrap: wrap; }

.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.two { grid-template-columns: 1fr 1fr; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; }
.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 4px; }
.kpi .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.kpi.alert .value { color: var(--amber); }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #fafbfc; }
.table-wrap { overflow-x: auto; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; background: #eef0f3; color: #4a4a5e; 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); }

.btn { font: inherit; border: 1px solid var(--line); background: #fff; color: var(--text); padding: 8px 14px; border-radius: 8px; cursor: pointer; font-weight: 600; }
.btn:hover { border-color: #c9c9d6; }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:hover { background: var(--green-dark); }
.btn.danger { color: var(--red); border-color: #f1c6c0; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters button.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.form { display: grid; gap: 10px; }
.form.inline { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); align-items: end; }

#map { height: calc(100vh - 170px); min-height: 420px; border-radius: var(--radius); border: 1px solid var(--line); }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--muted); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }

.drawer { position: fixed; inset: 0; background: rgba(20,20,35,.35); display: flex; justify-content: flex-end; z-index: 2000; }
.drawer-panel { background: #fff; width: min(560px, 100%); height: 100%; overflow-y: auto; padding: 24px; position: relative; }
.drawer-close { position: absolute; top: 12px; right: 14px; border: 0; background: none; font-size: 26px; cursor: pointer; color: var(--muted); }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.timeline { display: grid; gap: 8px; border-left: 2px solid var(--line); padding-left: 14px; }
.msg { padding: 10px 12px; border-radius: 10px; background: #f3f4f6; max-width: 90%; }
.msg.staff { background: var(--green-soft); margin-left: auto; }
.msgs { display: grid; gap: 8px; margin: 12px 0; }
.empty { color: var(--muted); padding: 24px; text-align: center; }
.split { display: flex; height: 26px; border-radius: 6px; overflow: hidden; font-size: 12px; font-weight: 600; color: #fff; }
.split > div { display: grid; place-items: center; white-space: nowrap; overflow: hidden; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 3000; max-width: 90vw; }
.toast.err { background: var(--red); }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.switch:last-child { border-bottom: 0; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  nav { grid-auto-flow: column; overflow-x: auto; padding-bottom: 10px; }
  .me { display: none; }
  main { padding: 0 16px 32px; }
  .two { grid-template-columns: 1fr; }
}
