:root {
  --navy: #1f4e78;
  --navy-dark: #163a5a;
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1c2430;
  --muted: #667085;
  --line: #e3e7ee;
  --good: #1a7f4b;
  --good-bg: #e6f4ec;
  --warn: #9a6200;
  --warn-bg: #fdf3dc;
  --bad: #b42318;
  --bad-bg: #fde8e6;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--navy); }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* Layout */
.shell { display: flex; min-height: 100vh; }
.side {
  width: 220px; flex: none; background: var(--navy); color: #fff;
  display: flex; flex-direction: column; padding: 20px 12px;
}
.brand { font-weight: 700; font-size: 17px; padding: 0 10px 18px; letter-spacing: .2px; }
.brand span { display: block; font-weight: 400; font-size: 12px; opacity: .75; }
.nav a {
  display: block; color: #fff; text-decoration: none; padding: 9px 10px;
  border-radius: 8px; margin-bottom: 2px; opacity: .85;
}
.nav a:hover { background: rgba(255,255,255,.08); opacity: 1; }
.nav a.active { background: rgba(255,255,255,.16); opacity: 1; font-weight: 600; }
.side .who { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid rgba(255,255,255,.15); font-size: 13px; }
.side .who button { margin-top: 8px; background: none; border: 1px solid rgba(255,255,255,.4); color: #fff; padding: 5px 10px; border-radius: 6px; cursor: pointer; }
.main { flex: 1; min-width: 0; padding: 24px 28px 40px; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }

/* Cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat .n { font-size: 26px; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 13px; }
.grid2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
#map { height: 420px; border-radius: 8px; border: 1px solid var(--line); }

/* Forms */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; margin-bottom: 14px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; color: var(--muted); }
input, select, textarea {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(31,78,120,.25); border-color: var(--navy); }
.btn {
  border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 8px 14px;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: #c5ccd8; }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy-dark); }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .6; cursor: default; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.err { color: var(--bad); margin-top: 10px; min-height: 1em; }

/* Table */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfc; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: #f7f9fc; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* Badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; margin: 0 4px 2px 0; white-space: nowrap; }
.b-good { background: var(--good-bg); color: var(--good); }
.b-warn { background: var(--warn-bg); color: var(--warn); }
.b-bad { background: var(--bad-bg); color: var(--bad); }
.b-muted { background: #eef1f5; color: var(--muted); }

/* Modal */
.overlay { position: fixed; inset: 0; background: rgba(16,24,40,.45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; z-index: 1000; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 720px; padding: 20px; }
.modal .top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.modal .x { border: 0; background: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); }
.photos { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 12px 0; }
.photo { background: #eef1f5; border-radius: 8px; aspect-ratio: 9 / 16; max-height: 360px; display: flex; align-items: center; justify-content: center; overflow: hidden; color: var(--muted); }
.photo img { width: 100%; height: 100%; object-fit: cover; }
dl.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }

/* Login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login .card { width: 100%; max-width: 360px; padding: 28px; }
.login h1 { color: var(--navy); }
.login .field { margin-top: 14px; }
.login .btn { width: 100%; margin-top: 18px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1c2430; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 2000; }

@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .side { width: auto; flex-direction: row; align-items: center; padding: 10px 12px; gap: 8px; overflow-x: auto; }
  .brand { padding: 0 8px 0 0; font-size: 15px; }
  .brand span { display: none; }
  .nav { display: flex; gap: 2px; }
  .nav a { margin: 0; padding: 7px 10px; white-space: nowrap; }
  .side .who { margin: 0 0 0 auto; border: 0; padding: 0; white-space: nowrap; }
  .side .who .name { display: none; }
  .side .who button { margin: 0; }
  .main { padding: 16px; }
  .grid2, .form-grid, .photos { grid-template-columns: 1fr; }
  dl.kv { grid-template-columns: 110px 1fr; }
}
