/* Build Watch — Dark OLED design system
   bg #0F172A · surface #131C31/#1A2540 · primary #3B82F6 · good #34D399 ·
   bad #F87171 · warn #FBBF24 · Fira Sans (UI) + Fira Code (numbers) */

:root {
  --bg: #0F172A;
  --surface: #131C31;
  --surface-2: #1A2540;
  --border: rgba(255, 255, 255, 0.08);
  --fg: #F1F5F9;
  --fg-2: #94A3B8;
  --fg-3: #64748B;
  --primary: #3B82F6;
  --primary-deep: #1E40AF;
  --good: #34D399;
  --bad: #F87171;
  --warn: #FBBF24;
  --font-ui: 'Fira Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-num: 'Fira Code', ui-monospace, 'SF Mono', Menlo, monospace;
  --shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03), 0 8px 24px rgba(2, 6, 23, 0.5);
}

* { box-sizing: border-box; }
html { color-scheme: dark; }
html, body { margin: 0; padding: 0; }
body {
  background:
    radial-gradient(1100px 480px at 50% -12%, rgba(59, 130, 246, 0.13), transparent 60%),
    var(--bg);
  color: var(--fg);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
::selection { background: rgba(59, 130, 246, 0.35); }
a { color: var(--primary); }
.num, .price, .total, .chip, .progCount, .stats b {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
}
.dim { color: var(--fg-2); }
code { font-family: var(--font-num); font-size: 0.92em; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.sep { font-style: normal; color: var(--fg-3); margin: 0 2px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: rgba(15, 23, 42, 0.86);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex; align-items: center; gap: 9px;
  font-weight: 600; font-size: 16.5px; letter-spacing: 0.01em;
  padding-left: 2px;
}
.brand svg { width: 21px; height: 21px; color: var(--primary); flex: none; }
.status {
  margin-left: auto;
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; font-weight: 500; letter-spacing: 0.03em;
  color: var(--fg-2);
  max-width: 46vw;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--fg-3); flex: none; }
.status.fresh .dot { background: var(--good); box-shadow: 0 0 10px rgba(52, 211, 153, 0.8); animation: pulse 2.2s ease-in-out infinite; }
.status.busy  .dot { background: var(--warn); box-shadow: 0 0 10px rgba(251, 191, 36, 0.7); }
.status.bad   .dot { background: var(--bad);  box-shadow: 0 0 10px rgba(248, 113, 113, 0.7); }
#refreshBtn {
  width: 44px; height: 44px; flex: none;
  display: grid; place-items: center;
  background: var(--surface-2); color: var(--fg);
  border: 1px solid var(--border); border-radius: 12px;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.15s, background 0.2s;
  touch-action: manipulation;
}
#refreshBtn:hover { border-color: rgba(59, 130, 246, 0.55); }
#refreshBtn:active { transform: scale(0.94); }
#refreshBtn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
#refreshBtn svg { width: 20px; height: 20px; }
#refreshBtn.busy svg { animation: spin 1s linear infinite; color: var(--primary); }

/* ---------- layout ---------- */
#main {
  max-width: 680px;
  margin: 0 auto;
  padding: 16px 14px calc(28px + env(safe-area-inset-bottom));
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes flashbg { 0% { background: rgba(59, 130, 246, 0.35); } 100% { background: transparent; } }

/* ---------- hero ---------- */
.hero {
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 18px 18px 16px;
  box-shadow: var(--shadow);
  animation: rise 0.3s ease-out backwards;
}
.hero .label {
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--fg-2);
}
.hero .total {
  margin-top: 4px;
  font-size: clamp(34px, 9.5vw, 44px);
  font-weight: 600; line-height: 1.12;
  text-shadow: 0 0 26px rgba(59, 130, 246, 0.28);
}
.hero .total .cur { font-size: 0.42em; font-weight: 500; color: var(--fg-2); margin-left: 7px; }
#heroTotal { display: inline-block; border-radius: 6px; }
#heroTotal.flash { animation: flashbg 1.2s ease-out; }
.hero .row2 { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.hero .updated {
  display: flex; align-items: center; gap: 7px;
  margin-top: 12px; font-size: 12.5px; color: var(--fg-2);
}
.hero .updated svg { width: 14px; height: 14px; flex: none; }
.spark { margin-top: 14px; }
.spark svg { width: 100%; height: auto; display: block; }
.spark-t { font-family: var(--font-num); font-size: 10.5px; fill: var(--fg-3); }
.spark-x { fill: #475569; }

/* ---------- chips ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 999px;
  font-size: 12.5px; font-weight: 600; line-height: 1.4;
  border: 1px solid transparent; white-space: nowrap;
}
.chip svg { width: 13px; height: 13px; flex: none; }
.chip.up   { color: var(--bad);  background: rgba(248, 113, 113, 0.10); border-color: rgba(248, 113, 113, 0.28); }
.chip.down { color: var(--good); background: rgba(52, 211, 153, 0.10); border-color: rgba(52, 211, 153, 0.28); }
.chip.flat { color: var(--fg-2); background: rgba(148, 163, 184, 0.08); border-color: rgba(148, 163, 184, 0.22); }
.chip.warnc { color: var(--warn); background: rgba(251, 191, 36, 0.10); border-color: rgba(251, 191, 36, 0.28); }

/* ---------- alerts ---------- */
.alert {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: 14px;
  margin-bottom: 14px;
  font-size: 13.5px; line-height: 1.5;
  border: 1px solid;
  animation: rise 0.25s ease-out backwards;
}
.alert svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.alert.warn { background: rgba(251, 191, 36, 0.08); border-color: rgba(251, 191, 36, 0.32); color: #FDE68A; }
.alert.err  { background: rgba(248, 113, 113, 0.08); border-color: rgba(248, 113, 113, 0.32); color: #FECACA; }
.alert .al-hint { display: block; margin-top: 6px; font-size: 12.5px; opacity: 0.85; }

/* ---------- progress ---------- */
.progress { margin-bottom: 14px; animation: rise 0.25s ease-out backwards; }
.progress .lbl {
  display: flex; justify-content: space-between; gap: 10px;
  font-size: 12.5px; color: var(--fg-2); margin-bottom: 7px;
}
.progress .lbl #progLabel { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress .bar { height: 4px; border-radius: 2px; background: var(--surface-2); overflow: hidden; }
.progress .fill {
  height: 100%; width: 100%;
  background: linear-gradient(90deg, var(--primary-deep), var(--primary));
  transform-origin: left; transform: scaleX(0);
  transition: transform 0.35s ease-out;
}

/* ---------- section titles ---------- */
.sec-title {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  margin: 22px 4px 10px;
  font-size: 11.5px; font-weight: 600;
  letter-spacing: 0.13em; text-transform: uppercase;
  color: var(--fg-2);
}
.sec-title .cnt { font-family: var(--font-num); font-size: 11.5px; letter-spacing: 0; }

/* ---------- part cards ---------- */
.card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 13px 15px;
  margin-bottom: 10px;
  text-decoration: none; color: inherit;
  transition: border-color 0.2s, transform 0.15s;
  animation: rise 0.3s ease-out backwards;
  animation-delay: calc(var(--i, 0) * 30ms);
}
a.card:hover { border-color: rgba(59, 130, 246, 0.5); transform: translateY(-1px); }
a.card:active { transform: scale(0.995); }
a.card:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.card .top { display: flex; align-items: baseline; gap: 8px; }
.card .name { flex: 1; margin: 0; font-size: 14.5px; font-weight: 600; line-height: 1.35; }
.card .ext { width: 13px; height: 13px; flex: none; color: var(--fg-3); align-self: center; }
.card .price {
  font-size: 19px; font-weight: 600; white-space: nowrap;
  display: inline-block; border-radius: 5px;
}
.card .price.flash { animation: flashbg 1.2s ease-out; }
.card .price small { font-size: 11px; color: var(--fg-2); font-weight: 500; margin-left: 3px; font-family: var(--font-ui); }
.card .mid { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 9px; }
.card .stats {
  display: flex; flex-wrap: wrap; gap: 4px 14px;
  margin-top: 9px; font-size: 12.5px; color: var(--fg-2);
}
.card .stats b { color: var(--fg); font-weight: 600; }
.card .shop {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px;
  margin-top: 10px; padding-top: 10px;
  border-top: 1px dashed var(--border);
  font-size: 13px; color: var(--fg-2);
}
.card .shop .shopname { color: var(--fg); font-weight: 500; }
.card .shop .warr { display: inline-flex; align-items: center; gap: 4px; }
.card .shop .warr svg { width: 13px; height: 13px; }
.card .shop .warr.on { color: var(--good); }
.card .shop .warr.off { color: var(--fg-3); }
.card .errtext { font-size: 12.5px; color: var(--fg-2); overflow: hidden; text-overflow: ellipsis; }
.badge {
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.08em;
  padding: 3px 8px; border-radius: 6px;
  color: var(--bad); background: rgba(248, 113, 113, 0.12);
}
.card.oos { border-color: rgba(248, 113, 113, 0.35); }
.card.err { border-color: rgba(248, 113, 113, 0.28); background: rgba(248, 113, 113, 0.04); }
/* explicit "open on Torob" affordance on a failed card (the whole card is the
   link — this row just makes the tap target obvious) */
.card .openrow {
  display: flex; align-items: center; gap: 8px;
  margin-top: 10px; padding: 10px 12px;
  border: 1px solid rgba(59, 130, 246, 0.4); border-radius: 12px;
  background: rgba(59, 130, 246, 0.1);
  font-size: 13px; font-weight: 600; color: var(--primary);
}
.card .openrow .ext { width: 15px; height: 15px; flex: none; }

/* ---------- alternatives (details) ---------- */
.alts { margin-top: 6px; }
.alts summary {
  list-style: none;
  display: flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border); border-radius: 14px;
  font-size: 13px; font-weight: 600; color: var(--fg-2);
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
  touch-action: manipulation;
}
.alts summary::-webkit-details-marker { display: none; }
.alts summary:hover { border-color: rgba(59, 130, 246, 0.4); color: var(--fg); }
.alts summary:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.alts summary svg { width: 14px; height: 14px; transition: transform 0.2s ease-out; flex: none; }
.alts[open] summary svg { transform: rotate(90deg); }
.alts .inner { padding: 10px 4px 4px; }
.alts .card { opacity: 0.92; }

/* ---------- skeletons ---------- */
.skel {
  height: 92px; border-radius: 16px; margin-bottom: 10px;
  background: linear-gradient(100deg, var(--surface) 40%, var(--surface-2) 50%, var(--surface) 60%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- empty state ---------- */
.empty { text-align: center; padding: 60px 20px; color: var(--fg-2); }
.empty svg { width: 42px; height: 42px; color: var(--fg-3); margin-bottom: 14px; }
.empty h2 { font-size: 18px; color: var(--fg); margin: 0 0 6px; }
.empty p { font-size: 13.5px; margin: 0 0 18px; line-height: 1.5; }
.btn {
  min-height: 44px; padding: 10px 22px;
  border-radius: 12px; border: 1px solid rgba(59, 130, 246, 0.4);
  background: var(--primary-deep); color: #fff;
  font-family: var(--font-ui); font-size: 14px; font-weight: 600;
  cursor: pointer;
  transition: filter 0.2s, transform 0.15s;
  touch-action: manipulation;
}
.btn:hover { filter: brightness(1.2); }
.btn:active { transform: scale(0.97); }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.mini { min-height: 36px; padding: 6px 14px; font-size: 13px; display: inline-block; margin-top: 8px; }

/* ---------- footer ---------- */
.foot {
  max-width: 680px; margin: 0 auto;
  padding: 8px 14px calc(24px + env(safe-area-inset-bottom));
  font-size: 12.5px; color: var(--fg-3); line-height: 1.6;
  border-top: 1px solid var(--border);
}
.foot details { padding: 6px 0 2px; }
.foot summary {
  min-height: 44px; display: flex; align-items: center;
  color: var(--fg-2); font-weight: 600; font-size: 13px;
  cursor: pointer; list-style: none;
  touch-action: manipulation;
}
.foot summary::-webkit-details-marker { display: none; }
.foot summary::before { content: '›'; margin-right: 8px; transition: transform 0.2s; display: inline-block; }
.foot details[open] summary::before { transform: rotate(90deg); }
.foot summary:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.foot p { margin: 10px 0; }
.foot code { font-family: var(--font-num); font-size: 11.5px; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.foot .dim { margin-top: 14px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(16px);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 10px 16px; border-radius: 12px;
  font-size: 13.5px; line-height: 1.4;
  max-width: calc(100vw - 40px); text-align: center;
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s ease-out, transform 0.25s ease-out;
  z-index: 100; box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- pull-to-refresh ---------- */
.ptp {
  position: fixed; top: calc(64px + env(safe-area-inset-top)); left: 50%;
  width: 38px; height: 38px;
  display: grid; place-items: center;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 50%; color: var(--primary);
  transform: translateX(-50%) scale(0);
  transition: transform 0.18s ease-out;
  pointer-events: none; z-index: 50; opacity: 0;
}
.ptp.show { opacity: 1; }
.ptp svg { width: 18px; height: 18px; animation: spin 1s linear infinite; }

/* ---------- wide screens ---------- */
@media (min-width: 820px) {
  #main { max-width: 760px; }
  .foot { max-width: 760px; }
  #lists { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  #lists .card { margin-bottom: 0; }
  .sec-title, .alts { grid-column: 1 / -1; }
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
