/* The Panel. Colours come from Telegram (it sets --tg-theme-* on the page),
   so light and dark follow the app; the fallbacks are for a plain browser. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #15171a);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --link: var(--tg-theme-link-color, #2a7ae2);
  --button: var(--tg-theme-button-color, #2a7ae2);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --card: var(--tg-theme-secondary-bg-color, #f2f3f5);
  --section: var(--tg-theme-section-bg-color, #ffffff);
  --sep: var(--tg-theme-section-separator-color, rgba(127, 127, 127, 0.18));
  --danger: var(--tg-theme-destructive-text-color, #e5484d);
  --ok: #2f9e44;
  --warn: #e8890c;
  --info: #2a7ae2;
  --muted: #8a8f98;
  --radius: 14px;
  --gap: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not(.tg) {
    --bg: #17191c; --text: #eceef1; --hint: #8d939c; --card: #202328;
    --section: #1c1f23; --sep: rgba(255, 255, 255, 0.08);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--card); color: var(--text); }
body {
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }
a { color: var(--link); text-decoration: none; }

.app { max-width: 760px; margin: 0 auto; padding: 0 0 calc(76px + env(safe-area-inset-bottom)); }
.top { padding: 14px 16px 6px; display: flex; align-items: center; gap: 10px; }
.top h1 { font-size: 22px; font-weight: 700; margin: 0; flex: 1; min-width: 0; }
.top .who { color: var(--hint); font-size: 13px; text-align: right; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px;
  font-weight: 600; background: var(--section); color: var(--hint); }

.content { padding: 4px 12px 12px; display: flex; flex-direction: column; gap: var(--gap); }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--hint); margin: 8px 6px 0; font-weight: 600; }
.card { background: var(--section); border-radius: var(--radius); overflow: hidden; }
.pad { padding: 14px 16px; }
.empty { color: var(--hint); text-align: center; padding: 28px 16px; }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 560px) { .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.kpi { background: var(--section); border-radius: var(--radius); padding: 14px; min-width: 0;
  border: 0; text-align: left; cursor: pointer; }
.kpi .n { font-size: 26px; font-weight: 700; line-height: 1.1; }
.kpi .l { color: var(--hint); font-size: 13px; margin-top: 4px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
.kpi.alert .n { color: var(--warn); }
.kpi.good .n { color: var(--ok); }

/* rows */
.row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; min-width: 0;
  border-top: 1px solid var(--sep); background: none; border-left: 0; border-right: 0;
  border-bottom: 0; width: 100%; text-align: left; cursor: pointer; }
.card > .row:first-child { border-top: 0; }
.row .main { flex: 1; min-width: 0; }
.row .t { font-weight: 600; 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 .side { text-align: right; flex: none; font-size: 13px; color: var(--hint); }
.row.static { cursor: default; }

/* state chips */
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--card); color: var(--text); }
.st-shipped, .st-printing { background: rgba(47, 158, 68, 0.14); color: var(--ok); }
.st-in_review, .st-awaiting_date { background: rgba(232, 137, 12, 0.14); color: var(--warn); }
.st-appointment { background: rgba(42, 122, 226, 0.14); color: var(--info); }
.st-rejected, .st-not_found { background: rgba(229, 72, 77, 0.14); color: var(--danger); }
.st-new, .st-no_appointment, .st-unknown { background: var(--card); color: var(--hint); }

/* filters */
.search { width: 100%; border: 0; border-radius: 12px; padding: 11px 14px; font: inherit;
  background: var(--section); color: var(--text); outline: none; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.fchip { flex: none; border: 0; border-radius: 999px; padding: 7px 12px; font-size: 13px;
  font-weight: 600; background: var(--section); color: var(--text); cursor: pointer; }
.fchip.on { background: var(--button); color: var(--button-text); }

/* bottom tabs */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center;
  background: var(--section); border-top: 1px solid var(--sep);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); z-index: 5; }
.tabs .inner { display: flex; width: 100%; max-width: 760px; }
.tab { flex: 1; min-width: 0; border: 0; background: none; padding: 4px 2px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--hint); }
.tab .i { font-size: 20px; line-height: 1; position: relative; }
.tab .l { font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.tab.on { color: var(--button); }
.badge { position: absolute; top: -4px; right: -10px; min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 999px; background: var(--danger); color: #fff; font-size: 10px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; }

/* detail sheet */
.sheet { position: fixed; inset: 0; background: var(--card); z-index: 10; overflow-y: auto;
  -webkit-overflow-scrolling: touch; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
.sheet .head { padding: 16px 16px 6px; position: relative; }
.sheet .close { position: absolute; top: 12px; right: 12px; width: 34px; height: 34px;
  border-radius: 999px; border: 0; background: var(--section); color: var(--hint);
  font-size: 16px; cursor: pointer; }
.sheet .head h2 { padding-right: 44px; }
.row .s.wrap { white-space: normal; }
.sheet .head h2 { margin: 0 0 6px; font-size: 20px; }
.kv { display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.4fr); gap: 0;
  padding: 0 16px; }
.kv .k, .kv .v { padding: 10px 0; border-top: 1px solid var(--sep); min-width: 0; }
.kv .k { color: var(--hint); font-size: 14px; }
.kv .v { font-size: 14px; overflow-wrap: anywhere; }
.kv .k:first-child, .kv .k:first-child + .v { border-top: 0; }
.actions { display: flex; gap: 10px; padding: 12px; flex-wrap: wrap; }
.btn { flex: 1; min-width: 140px; border: 0; border-radius: 12px; padding: 12px 14px;
  font-weight: 600; background: var(--button); color: var(--button-text); cursor: pointer; }
.btn.secondary { background: var(--section); color: var(--link); }
.btn.small { flex: none; min-width: 0; padding: 7px 12px; font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.timeline { padding: 4px 16px 12px; }
.timeline div { padding: 6px 0; color: var(--hint); font-size: 13px; border-top: 1px solid var(--sep); }
.timeline div:first-child { border-top: 0; }
.toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom));
  transform: translateX(-50%); background: rgba(20, 20, 20, 0.88); color: #fff; padding: 9px 16px;
  border-radius: 999px; font-size: 14px; z-index: 20; }
.bar { height: 8px; border-radius: 999px; background: var(--card); overflow: hidden; margin-top: 8px; }
.bar > div { height: 100%; background: var(--button); }
.center { display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 70vh; text-align: center; padding: 24px; gap: 10px; color: var(--hint); }
.center .big { font-size: 44px; }
