/* Telegram injects --tg-theme-* variables; the fallbacks cover plain browsers. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f1f3f6);
  --section: var(--tg-theme-section-bg-color, var(--bg));
  --text: var(--tg-theme-text-color, #111418);
  --hint: var(--tg-theme-hint-color, #7d8590);
  --link: var(--tg-theme-link-color, #2481cc);
  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --header: var(--tg-theme-section-header-text-color, var(--hint));
  --danger: var(--tg-theme-destructive-text-color, #e5484d);
  --sep: color-mix(in srgb, var(--hint) 22%, transparent);
  --sea: #1e88e5;
  --port: #2e9d5b;
  --idle: #9aa1a9;
  --dep: #e5484d;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not(.tg) {
    --bg: #17212b; --bg2: #0e1621; --section: #17212b; --text: #f5f5f5;
    --hint: #708499; --link: #6ab3f3; --accent: #5288c1;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg2); color: var(--text); }
body {
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
  overscroll-behavior-y: contain;
}
a { color: var(--link); text-decoration: none; }
button { font: inherit; color: inherit; }

main { max-width: 640px; margin: 0 auto; padding: 12px 12px 8px; }

/* ---------- headings & sections ---------- */
.page-title { font-size: 22px; font-weight: 700; margin: 4px 4px 2px; }
.page-sub { color: var(--hint); margin: 0 4px 14px; font-size: 13px; }
.section-h {
  text-transform: uppercase; font-size: 12.5px; letter-spacing: .04em;
  color: var(--header); margin: 18px 6px 6px; display: flex; justify-content: space-between; align-items: baseline;
}
.section-h small { text-transform: none; letter-spacing: 0; color: var(--hint); }
.card { background: var(--section); border-radius: var(--radius); overflow: hidden; }
.card.pad { padding: 14px; }

/* ---------- list rows ---------- */
.row {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px; min-height: 52px;
  color: var(--text); position: relative; width: 100%; background: none; border: 0; text-align: left;
}
.row + .row::before {
  content: ""; position: absolute; top: 0; left: 56px; right: 0; border-top: 1px solid var(--sep);
}
.row.plain + .row.plain::before { left: 14px; }
.row .ic {
  width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center;
  flex: none; font-size: 17px; background: var(--bg2);
}
.row .main { flex: 1; min-width: 0; }
.row .t { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .s { color: var(--hint); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .end { color: var(--hint); font-size: 13px; text-align: right; flex: none; }
.row .chev::after { content: "›"; font-size: 20px; color: var(--hint); margin-left: 4px; }
a.row:active, button.row:active { background: var(--bg2); }

/* ---------- stat tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.tile { background: var(--section); border-radius: var(--radius); padding: 12px 14px; }
.tile .v { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.15; }
.tile .l { color: var(--hint); font-size: 12.5px; display: flex; align-items: center; gap: 6px; }
.tile .v small { font-size: 14px; font-weight: 500; color: var(--hint); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.dot.sea { background: var(--sea); } .dot.dep { background: var(--dep); } .dot.port { background: var(--port); } .dot.idle { background: var(--idle); }

/* ---------- chips & buttons ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600;
  padding: 2px 8px; border-radius: 99px; white-space: nowrap;
}
.chip.sea { color: var(--sea); background: color-mix(in srgb, var(--sea) 14%, transparent); }
.chip.port { color: var(--port); background: color-mix(in srgb, var(--port) 14%, transparent); }
.chip.idle { color: var(--idle); background: color-mix(in srgb, var(--idle) 16%, transparent); }
.chip.arr { color: var(--port); } .chip.dep { color: var(--dep); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 10px; padding: 10px 14px; font-weight: 600; cursor: pointer;
  background: var(--accent); color: var(--accent-text); min-height: 42px; white-space: nowrap;
}
.btn.ghost { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); }
.btn.danger { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.btn:disabled { opacity: .55; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.btn-row .btn { flex: 1 1 0; }
.icon-btn {
  border: 0; background: none; color: var(--danger); font-size: 13px; font-weight: 600;
  padding: 8px 4px 8px 10px; cursor: pointer; flex: none;
}

.seg { display: flex; background: var(--bg2); border-radius: 9px; padding: 2px; gap: 2px; }
.seg button {
  flex: 1; border: 0; background: none; padding: 6px 10px; border-radius: 7px; font-size: 13px;
  font-weight: 600; color: var(--hint); cursor: pointer;
}
.seg button.on { background: var(--section); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* ---------- hero (detail pages) ---------- */
.hero { padding: 16px; }
.hero .name { font-size: 21px; font-weight: 700; line-height: 1.2; }
.hero .meta { color: var(--hint); font-size: 13.5px; margin-top: 2px; }
.status-line { margin-top: 12px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.status-line .big { font-size: 15px; }

/* ---------- charts ---------- */
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--hint); font-size: 10px; }
.chart .bar { fill: var(--accent); }
.chart .bar.dim { fill: color-mix(in srgb, var(--accent) 35%, transparent); }
.chart .bar.peak { fill: var(--accent); }
.chart .grid { stroke: var(--sep); }
.chart .val { fill: var(--text); font-size: 10px; font-weight: 600; }

.hbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 3px 10px; padding: 12px 14px; }
.hbar .lbl { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar .num { font-size: 13px; color: var(--hint); font-variant-numeric: tabular-nums; text-align: right; }
.hbar .track { grid-column: 1 / -1; height: 6px; border-radius: 3px; background: var(--bg2); margin-bottom: 8px; overflow: hidden; }
.hbar .fill { height: 100%; border-radius: 3px; background: var(--accent); }
.hbar a.lbl { color: var(--text); }

.tile .delta { font-size: 11.5px; font-weight: 600; color: var(--hint); margin-top: 2px; }
.tile .delta.up { color: var(--port); }
.tile .delta.down { color: var(--dep); }

.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.kv .tile .v { font-size: 20px; }

/* ---------- search ---------- */
.search {
  position: sticky; top: 0; z-index: 5; background: var(--bg2); padding: 4px 0 8px;
}
.search input {
  width: 100%; border: 0; border-radius: 11px; padding: 11px 14px 11px 38px; font: inherit;
  background: var(--section) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%238a939c' stroke-width='2'%3E%3Ccircle cx='7' cy='7' r='5.5'/%3E%3Cpath d='M11 11l4 4'/%3E%3C/svg%3E") no-repeat 13px center;
  color: var(--text); outline: none;
}

/* ---------- toggle ---------- */
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span {
  position: absolute; inset: 0; background: var(--idle); border-radius: 99px; transition: .2s; cursor: pointer;
}
.switch span::before {
  content: ""; position: absolute; width: 26px; height: 26px; left: 2px; top: 2px;
  background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.switch input:checked + span { background: var(--port); }
.switch input:checked + span::before { transform: translateX(20px); }

/* ---------- misc ---------- */
.empty { text-align: center; color: var(--hint); padding: 26px 18px; font-size: 14px; }
.empty .e { font-size: 34px; margin-bottom: 6px; }
.note { color: var(--hint); font-size: 12.5px; margin: 6px 8px 0; }
.muted { color: var(--hint); }
.skel { background: linear-gradient(90deg, var(--section) 0%, var(--bg2) 50%, var(--section) 100%); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: var(--radius); }
@keyframes sk { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.err { color: var(--danger); text-align: center; padding: 30px 16px; }
.time { font-variant-numeric: tabular-nums; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex;
  background: var(--section); border-top: 1px solid var(--sep);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 7px 0 6px; font-size: 11px; color: var(--hint); font-weight: 500;
}
.tabbar .ti { font-size: 20px; filter: grayscale(1); opacity: .7; }
.tabbar a.on { color: var(--accent); }
.tabbar a.on .ti { filter: none; opacity: 1; }
body.detail .tabbar { display: none; }
body.detail { padding-bottom: env(safe-area-inset-bottom); }

.toast {
  position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: rgba(30, 33, 38, .92); color: #fff; padding: 9px 16px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .2s; max-width: 90vw; text-align: center; z-index: 20;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
