:root {
  --bg: #0f1216;
  --panel: #171c22;
  --panel2: #1e252d;
  --line: #2a333d;
  --text: #eef2f6;
  --muted: #93a1b0;
  --red: #e5383b;
  --green: #1fa855;
  --green-d: #178a45;
  --amber: #f0a020;
  --blue: #3b82f6;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------ app-layout */
#app { height: 100dvh; display: flex; flex-direction: column; }
.top { display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--line); }
.who { display: flex; align-items: center; gap: 10px; font-size: 1.15rem; min-width: 0; }
.who strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--amber); flex: none; }
.dot.on { background: var(--green); }
.dot.off { background: var(--red); }
.tools { display: flex; gap: 8px; flex: none; }
.tool { min-height: 44px; min-width: 44px; padding: 0 14px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel2); cursor: pointer; font-size: 1rem; display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.tool:active { background: var(--line); }
.tool.muted { opacity: .45; }

.notice { background: #3a2a05; color: #ffd98a; padding: 10px 14px; border-bottom: 1px solid #5a4210; font-size: 1rem; }
.notice button { margin-left: 10px; }

main { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(360px, 40%) 1fr; }
.panel { overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 14px; border-right: 1px solid var(--line); }
.mapwrap { position: relative; background: #0b0e11; }
.mapwrap iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.map-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 1.1rem; pointer-events: none; }

@media (max-width: 899px), (orientation: portrait) {
  main { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) minmax(220px, 38%); }
  .panel { border-right: 0; }
  .mapwrap { order: 2; border-top: 1px solid var(--line); }
}

/* ------------------------------------------------------------ alarm-kort */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.card.fresh { border-color: var(--red); box-shadow: 0 0 0 2px rgba(229, 56, 59, .35); animation: pulse 1.2s ease-in-out 4; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(229, 56, 59, .15); } }
.card.empty { align-items: center; text-align: center; color: var(--muted); padding: 40px 16px; font-size: 1.2rem; }

.card-head { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.badge { display: inline-block; padding: 4px 10px; border-radius: 999px; background: var(--blue); color: #fff; font-weight: 700; font-size: .95rem; }
.badge.new { background: var(--red); }
.badge.warn { background: var(--amber); color: #201400; }
.when { margin-left: auto; color: var(--muted); font-size: .95rem; }
.code { color: var(--muted); font-size: 1.05rem; letter-spacing: .02em; }
.alarm { font-size: 1.7rem; font-weight: 800; line-height: 1.15; margin: 0; }
.object { font-size: 1.25rem; color: #cfd8e1; margin: 0; }
.address { font-size: 2rem; font-weight: 800; line-height: 1.15; margin: 4px 0 0; overflow-wrap: anywhere; }
.address.missing { color: var(--amber); font-size: 1.3rem; }
.addr-row { display: flex; align-items: flex-start; gap: 8px; }
.addr-row .address { flex: 1; }
.meta { color: var(--muted); font-size: .95rem; }

.btn { display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 64px; padding: 0 18px; border-radius: 14px;
  border: 0; cursor: pointer; text-decoration: none; font-size: 1.5rem; font-weight: 800; }
.btn.go { background: var(--green); color: #fff; }
.btn.go:active { background: var(--green-d); }
.btn.disabled { background: var(--line); color: var(--muted); pointer-events: none; }
.btn.primary { background: var(--blue); color: #fff; min-height: 52px; font-size: 1.1rem; }
.btn.small { min-height: 44px; font-size: 1rem; font-weight: 600; background: var(--panel2); border: 1px solid var(--line); padding: 0 14px; }

details.raw { color: var(--muted); }
details.raw summary { cursor: pointer; padding: 6px 0; }
details.raw pre { margin: 6px 0 0; white-space: pre-wrap; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .95rem; color: var(--text); background: var(--panel2); padding: 10px; border-radius: 10px; }

.edit { display: flex; gap: 8px; }
.edit input { flex: 1; min-height: 48px; padding: 0 12px; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; font-size: 1.1rem; }

.hist-title { margin: 6px 0 0; font-size: .95rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.history li { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; cursor: pointer; display: grid; gap: 2px; }
.history li.sel { border-color: var(--blue); background: var(--panel2); }
.history li .l1 { display: flex; gap: 8px; align-items: center; font-weight: 700; }
.history li .l1 .t { margin-left: auto; color: var(--muted); font-weight: 400; font-size: .9rem; }
.history li .l2 { color: var(--muted); font-size: .95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ------------------------------------------------------------ login */
body.center { display: flex; align-items: center; justify-content: center; padding: 16px; }
.login { width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 28px 24px; display: flex; flex-direction: column; gap: 14px; text-align: center; }
.login img { align-self: center; border-radius: 16px; }
.login h1 { margin: 0; font-size: 1.8rem; }
.login .sub { margin: 0 0 6px; color: var(--muted); }
.login label { display: flex; flex-direction: column; gap: 6px; text-align: left; color: var(--muted); font-size: .95rem; }
.login input { min-height: 52px; padding: 0 14px; background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; font-size: 1.15rem; color: var(--text); }
.login input:focus, .edit input:focus { outline: 2px solid var(--blue); border-color: transparent; }
.err { margin: 0; color: #ff8a8c; }

/* ------------------------------------------------------------ admin */
.admin { max-width: 1100px; margin: 0 auto; padding: 18px 14px 60px; }
.admin h1 { margin: 0 0 4px; }
.admin h2 { margin: 28px 0 10px; font-size: 1.15rem; }
.admin .bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.admin section { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px; overflow-x: auto; }
.admin table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.admin th, .admin td { text-align: left; padding: 8px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.admin th { color: var(--muted); font-weight: 600; white-space: nowrap; }
.admin input[type=text], .admin input[type=password], .admin select, .admin textarea {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-height: 40px; }
.admin textarea { width: 100%; min-height: 140px; font-family: ui-monospace, Menlo, Consolas, monospace; }
.admin .row { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; }
.admin .row label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: .85rem; }
.admin button, .admin .btnl { min-height: 40px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; }
.admin button.p { background: var(--blue); border-color: var(--blue); color: #fff; }
.admin button.d { color: #ff8a8c; }
.admin code { background: var(--panel2); padding: 2px 6px; border-radius: 6px; word-break: break-all; }
.admin .hint { color: var(--muted); font-size: .9rem; margin: 6px 0 0; }
.admin .ok { color: #7ee2a0; } .admin .bad { color: #ff8a8c; }
.admin td.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85rem; max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: #000c; padding: 10px 16px; border-radius: 10px; z-index: 9; }
