:root {
  --navy: #1f3a5f;
  --navy-2: #163052;
  --ink: #1a2332;
  --muted: #5c6b7a;
  --paper: #ffffff;
  --bg: #eef2f6;
  --line: #d5dde5;
  --ok: #0f7b4a;
  --ok-bg: #e5f6ec;
  --warn: #9a5b00;
  --warn-bg: #fff3d6;
  --bad: #b42318;
  --bad-bg: #fde8e8;
  --info: #1f6feb;
  --info-bg: #e8f1fc;
  --btn: #1f3a5f;
  --btn-text: #fff;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.08), 0 8px 24px rgba(16, 24, 40, 0.06);
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); font-size: 18px; line-height: 1.45; }
body { min-height: 100vh; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
img, svg { max-width: 100%; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9em; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }

/* Lock */
#lock-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(180deg, #14253d, #1f3a5f 55%, #2a4d73);
}
#lock-screen[hidden], #app[hidden], [hidden] { display: none !important; }
.lock-card {
  width: 100%;
  max-width: 440px;
  background: var(--paper);
  border-radius: 20px;
  padding: 28px 24px 24px;
  box-shadow: var(--shadow);
}
.lock-card h1 { margin: 0 0 8px; font-size: 1.6rem; color: var(--navy); }
.lock-card .lead { margin: 0 0 16px; color: var(--muted); }
.lock-warn {
  background: var(--warn-bg);
  color: #5c3b00;
  border-radius: 12px;
  padding: 12px 14px;
  margin: 0 0 18px;
  font-size: 0.95rem;
}
.lock-card label { display: block; font-weight: 650; margin: 0 0 6px; }
.lock-card input[type="password"], .lock-card input[type="text"] {
  width: 100%;
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  margin-bottom: 14px;
  letter-spacing: 0.2em;
}
.lock-error { color: var(--bad); min-height: 1.3em; margin: 0 0 10px; font-weight: 600; }
.lock-actions { display: flex; flex-direction: column; gap: 10px; }
.hint { display: block; color: var(--muted); font-weight: 400; font-size: 0.9rem; margin-top: 2px; }

/* Buttons */
.btn, button.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  padding: 10px 16px;
  border: 0;
  border-radius: 12px;
  background: var(--btn);
  color: var(--btn-text);
  font-weight: 700;
  text-align: center;
  text-decoration: none;
  box-shadow: 0 1px 0 rgba(0,0,0,0.08);
}
.btn:hover { background: var(--navy-2); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.secondary { background: #fff; color: var(--navy); border: 1px solid var(--line); }
.btn.secondary:hover { background: #f5f8fb; }
.btn.danger { background: #9b1c1c; color: #fff; }
.btn.danger:hover { background: #7a1515; }
.btn.quiet { background: #e8edf3; color: var(--ink); font-weight: 650; }
.btn.ok { background: var(--ok); }
.btn.warn { background: #b86a00; }
.btn.big { min-height: 56px; font-size: 1.05rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.linkish { background: none; border: 0; color: var(--navy); text-decoration: underline; min-height: auto; padding: 8px 0; font-weight: 650; cursor: pointer; }

/* App chrome */
#app { max-width: 1120px; margin: 0 auto; padding: 16px 16px 80px; }
header.app-head {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 12px;
}
header.app-head h1 { margin: 0; font-size: 1.7rem; color: var(--navy); }
.sub { margin: 4px 0 0; color: var(--muted); max-width: 46rem; }
.actions {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
  margin: 14px 0;
}
.search-wrap { margin: 8px 0 14px; }
.search-wrap input[type="search"] {
  width: 100%;
  min-height: 56px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 16px;
  background: var(--paper);
  box-shadow: var(--shadow);
}
.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin: 8px 0 16px;
  -webkit-overflow-scrolling: touch;
}
.tabs .tab {
  flex: 0 0 auto;
  min-height: 48px;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-weight: 700;
}
.tabs .tab[aria-selected="true"] { background: var(--navy); color: #fff; border-color: var(--navy); }

.panel { background: var(--paper); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; }
.panel h2 { margin: 0 0 10px; font-size: 1.25rem; color: var(--navy); }
.caption { color: var(--muted); margin: 0 0 12px; }

.metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.metric { background: #f5f8fb; border-radius: 12px; padding: 12px; }
.metric .n { font-size: 1.6rem; font-weight: 800; color: var(--navy); line-height: 1.1; }
.metric .l { color: var(--muted); font-size: 0.9rem; font-weight: 650; }
.metric.bad { background: var(--bad-bg); }
.metric.bad .n { color: var(--bad); }
.metric.warn { background: var(--warn-bg); }
.metric.warn .n { color: var(--warn); }
.metric.ok { background: var(--ok-bg); }

.pill { display: inline-block; border-radius: 999px; padding: 2px 10px; font-size: 0.85rem; font-weight: 700; background: #e8edf3; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.info { background: var(--info-bg); color: var(--info); }

.cards { display: grid; gap: 12px; }
.card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  background: #fff;
}
.card.selected { outline: 3px solid var(--navy); }
.card-top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.card-id { font-weight: 800; color: var(--navy); }
.card-cust { font-weight: 650; margin: 4px 0; }
.card-route, .card-ids { color: var(--muted); font-size: 0.95rem; }
.flag { display: inline-block; margin: 6px 6px 0 0; padding: 4px 8px; border-radius: 8px; font-size: 0.85rem; font-weight: 700; }
.flag.bad { background: var(--bad-bg); color: var(--bad); }
.flag.warn { background: var(--warn-bg); color: var(--warn); }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
table.data th, table.data td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data th { background: #f5f8fb; color: var(--navy); font-weight: 700; position: sticky; top: 0; }
table.data tr.active { background: #eef4fb; }

.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; font-weight: 650; }
.field input, .field select, .field textarea {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  font-weight: 400;
  width: 100%;
  background: #fff;
}
.field textarea { min-height: 90px; resize: vertical; }
.field.wide { grid-column: 1 / -1; }

.wx-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.wx-card { background: #f5f8fb; border-radius: 12px; padding: 12px; }
.wx-card h3 { margin: 0 0 6px; font-size: 1.05rem; color: var(--navy); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%) translateY(20px);
  background: var(--navy);
  color: #fff;
  padding: 12px 18px;
  border-radius: 12px;
  max-width: min(92vw, 520px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 80;
  font-weight: 650;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.warn { background: #9a5b00; }
.toast.bad { background: var(--bad); }

dialog {
  border: 0;
  border-radius: 16px;
  padding: 0;
  width: min(96vw, 720px);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(16, 24, 40, 0.45); }
.dlg-body { padding: 20px; }
.dlg-body h2 { margin: 0 0 8px; color: var(--navy); }
.dlg-foot { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; padding: 12px 20px 20px; }
details.more { margin: 12px 0; }
details.more summary { cursor: pointer; font-weight: 700; color: var(--navy); min-height: 44px; display: flex; align-items: center; }

.update-box { white-space: pre-wrap; background: #f5f8fb; border-radius: 12px; padding: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.92rem; }

.chart-wrap { background: #f3f5f7; border-radius: 12px; overflow: hidden; }

@media (max-width: 640px) {
  #app { padding: 12px 12px 88px; }
  .actions { grid-template-columns: 1fr 1fr; }
  header.app-head h1 { font-size: 1.45rem; }
}
