:root {
  --bg: #f4f6f8; --panel: #ffffff; --text: #1a202c; --muted: #718096; --line: #e2e8f0;
  --accent: #2b6cb0; --accent-soft: #ebf4ff;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--accent); }
.muted { color: var(--muted); font-size: 12px; }
button { font: inherit; padding: 5px 10px; border: 1px solid var(--line); background: #fff; border-radius: 6px; cursor: pointer; }
button:hover { background: var(--accent-soft); }
button.active, button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
input, select { font: inherit; padding: 5px 7px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
label { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; color: var(--muted); }

.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; font-size: 16px; }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; flex: 1; }
.ranges { display: inline-flex; gap: 2px; }
.ranges button { padding: 4px 8px; }
.user { margin-left: auto; font-size: 13px; }

.layout { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(360px, 1fr); height: calc(100vh - 54px); }
.map-wrap { position: relative; min-height: 320px; }
#map { position: absolute; inset: 0; }
.map-legend { position: absolute; left: 10px; bottom: 10px; z-index: 500; background: rgba(255,255,255,.92); padding: 5px 10px; border-radius: 6px; font-size: 12px; display: flex; gap: 12px; align-items: center; box-shadow: 0 1px 4px rgba(0,0,0,.2); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 3px; vertical-align: middle; }
.dot.start { background: #68d391; border: 1.5px solid #2f855a; }
.dot.mid { background: #63b3ed; border: 1.5px solid #2b6cb0; }
.dot.last { background: #fc8181; border: 1.5px solid #c53030; }

.panel { background: var(--panel); border-left: 1px solid var(--line); overflow: auto; padding: 10px 14px 20px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.tabs button { border: none; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 7px 10px; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); background: none; }
.tab { display: none; }
.tab.active { display: block; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 16px 0 6px; }

.cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.card { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.card .t { font-size: 11px; color: var(--muted); text-transform: uppercase; }
.card .v { font-size: 20px; font-weight: 600; margin: 2px 0; }
.card .s { font-size: 12px; color: var(--muted); }

table.kv { width: 100%; border-collapse: collapse; font-size: 13px; }
table.kv th { text-align: left; color: var(--muted); font-weight: 500; width: 38%; padding: 3px 6px 3px 0; vertical-align: top; }
table.kv td { padding: 3px 0; word-break: break-all; }

.tablewrap { max-height: 60vh; overflow: auto; border: 1px solid var(--line); border-radius: 6px; }
table.grid { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
table.grid th, table.grid td { padding: 4px 6px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
table.grid thead th { position: sticky; top: 0; background: #f7fafc; }
table.grid tbody tr { cursor: pointer; }
table.grid tbody tr:hover { background: var(--accent-soft); }
td.payload { max-width: 320px; overflow: hidden; text-overflow: ellipsis; font-family: ui-monospace, Menlo, Consolas, monospace; }

.search { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.search input { flex: 1; min-width: 160px; }
.detail { margin-top: 10px; background: #1a202c; color: #e2e8f0; padding: 10px; border-radius: 6px; font-size: 12px; white-space: pre-wrap; word-break: break-all; max-height: 40vh; overflow: auto; min-height: 40px; }

/* login */
.login-body { display: grid; place-items: center; }
.login-box { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 26px 28px; width: min(92vw, 340px); display: flex; flex-direction: column; gap: 10px; box-shadow: 0 4px 20px rgba(0,0,0,.08); }
.login-box h1 { margin: 0; font-size: 20px; }
.login-box label { flex-direction: column; align-items: stretch; gap: 3px; }
.login-box .error { color: #c53030; font-size: 13px; min-height: 16px; }
.login-box button { background: var(--accent); color: #fff; border-color: var(--accent); padding: 8px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: 45vh auto; height: auto; }
  .panel { border-left: none; border-top: 1px solid var(--line); }
  .user { margin-left: 0; }
}

/* alerts */
.devname { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 10px; font-size: 13px; }
.devname input { flex: 1; min-width: 120px; }
.rule-form { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 8px; }
.rule-form .error { color: #c53030; font-size: 12px; }
table.grid tr.disabled td { color: var(--muted); }
table.grid tr.alarm td { background: #fff5f5; }
table.grid tr.recovery td { background: #f0fff4; }
table.grid td.wrap { white-space: normal; }
b.alarm { color: #c53030; }
b.ok { color: #2f855a; }
#tgCard code { background: #edf2f7; padding: 2px 6px; border-radius: 4px; font-size: 13px; }
