/* ==========================================================================
   DeepSeek Pulse — PWA stylesheet
   Design system: Dark Mode (OLED) · Variance 4 · Motion 4 · Density 8
   Mobile-first, safe-area aware, safe on iOS Safari.
   ========================================================================== */

:root {
  /* surfaces */
  --bg: #0B0F17;
  --bg-top: #0E131E;
  --card: #141A28;
  --card-2: #1A2233;
  --muted: #1E2739;

  /* lines */
  --line: rgba(148, 163, 184, 0.13);
  --line-strong: rgba(148, 163, 184, 0.26);

  /* text */
  --fg: #F1F5F9;
  --fg-muted: #94A3B8;
  --fg-dim: #64748B;

  /* brand + semantics */
  --brand: #5B7CFA;
  --brand-soft: rgba(91, 124, 250, 0.15);
  --brand-line: rgba(91, 124, 250, 0.42);
  --up: #F87171;
  --up-soft: rgba(248, 113, 113, 0.14);
  --down: #34D399;
  --down-soft: rgba(52, 211, 153, 0.14);
  --peak: #FBBF24;
  --peak-soft: rgba(251, 191, 36, 0.14);
  --ok: #34D399;
  --warn: #FBBF24;
  --danger: #F87171;

  /* geometry */
  --r-lg: 18px;
  --r-md: 14px;
  --r-sm: 10px;
  --r-xs: 8px;
  --pad: 16px;
  --gap: 12px;

  /* type */
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC",
          "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, "JetBrains Mono", Menlo,
          Consolas, "Liberation Mono", monospace;

  /* motion (kept subtle: Variance 4 / Motion 4) */
  --ease: cubic-bezier(0.32, 0.72, 0, 1);
  --t-fast: 140ms;
  --t: 200ms;

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 58px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

body {
  min-height: 100dvh;
  background:
    radial-gradient(120% 60% at 50% -10%, rgba(91, 124, 250, 0.10), transparent 60%),
    var(--bg);
  background-attachment: fixed;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

/* ── layout ─────────────────────────────────────────────────────────── */

.app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  position: relative;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: calc(var(--safe-t) + 10px) var(--pad) 10px;
  background: linear-gradient(to bottom, rgba(11, 15, 23, 0.96) 65%, rgba(11, 15, 23, 0));
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
}

.topbar__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 34px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 16px;
  font-weight: 500;
  letter-spacing: -0.01em;
  margin: 0;
  white-space: nowrap;
}
.brand b { font-weight: 700; }
.brand__mark {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 9px;
  color: #fff;
  background: linear-gradient(145deg, #6D8BFF, #3F5BE0);
  box-shadow: 0 4px 14px rgba(91, 124, 250, 0.34), inset 0 1px 0 rgba(255, 255, 255, 0.22);
}
.brand__mark svg { width: 17px; height: 17px; }

.topbar__actions { display: flex; align-items: center; gap: 8px; }

.iconbtn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.03);
  color: var(--fg-muted);
  cursor: pointer;
  transition: color var(--t-fast) var(--ease), background var(--t-fast) var(--ease),
              border-color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.iconbtn svg { width: 16px; height: 16px; }
.iconbtn:hover { color: var(--fg); background: rgba(255, 255, 255, 0.06); }
.iconbtn:active { transform: scale(0.93); }
.iconbtn.is-spinning svg { animation: spin 700ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.conn {
  margin-top: 8px;
  padding: 7px 11px;
  border-radius: var(--r-sm);
  font-size: 12.5px;
  border: 1px solid;
}
.conn--err { color: #FCA5A5; background: var(--up-soft); border-color: rgba(248, 113, 113, 0.3); }
.conn--warn { color: #FCD34D; background: var(--peak-soft); border-color: rgba(251, 191, 36, 0.3); }

.view {
  flex: 1;
  padding: 6px var(--pad) calc(var(--tabbar-h) + var(--safe-b) + 26px);
}

/* ── tab bar ────────────────────────────────────────────────────────── */

.tabbar {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: 520px;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  padding: 5px 8px calc(var(--safe-b) + 5px);
  background: rgba(15, 20, 31, 0.86);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--line);
}
.tab {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 4px;
  border: 0;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--fg-dim);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: color var(--t) var(--ease), background var(--t) var(--ease);
}
.tab svg { width: 21px; height: 21px; transition: transform var(--t) var(--ease); }
.tab:hover { color: var(--fg-muted); }
.tab:active svg { transform: scale(0.9); }
.tab.is-active { color: var(--brand); background: var(--brand-soft); }
.tab.is-active svg { stroke-width: 2.2; }
.tab__dot {
  position: absolute;
  top: 5px;
  right: calc(50% - 15px);
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 0 2px rgba(15, 20, 31, 0.9);
}

/* ── primitives ─────────────────────────────────────────────────────── */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--pad);
  margin-bottom: var(--gap);
}
.card--flush { padding: 0; overflow: hidden; }

.card__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.card__title {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--fg-dim);
}

.section-label {
  margin: 20px 2px 9px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-dim);
}
.section-label:first-child { margin-top: 4px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3.5px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.25;
  white-space: nowrap;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--fg-muted);
}
.chip--peak { color: var(--peak); background: var(--peak-soft); border-color: rgba(251, 191, 36, 0.32); }
.chip--off  { color: var(--down); background: var(--down-soft); border-color: rgba(52, 211, 153, 0.3); }
.chip--up   { color: var(--up); background: var(--up-soft); border-color: rgba(248, 113, 113, 0.3); }
.chip--down { color: var(--down); background: var(--down-soft); border-color: rgba(52, 211, 153, 0.3); }
.chip--flat { color: var(--fg-muted); }
.chip__dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chip--live .chip__dot { animation: pulse 1.9s var(--ease) infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.28; } }

.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.dim { color: var(--fg-muted); }
.faint { color: var(--fg-dim); font-size: 12.5px; }
.row { display: flex; align-items: center; gap: 8px; }
.row--between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.spacer { flex: 1; }

/* ── peak status hero ───────────────────────────────────────────────── */

.status {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 15px var(--pad);
}
.status__ring {
  position: relative;
  display: grid;
  place-items: center;
  flex: none;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 2px solid var(--line-strong);
  color: var(--fg-muted);
  transition: border-color var(--t) var(--ease), color var(--t) var(--ease), box-shadow var(--t) var(--ease);
}
.status__ring--peak {
  border-color: rgba(251, 191, 36, 0.5);
  color: var(--peak);
  box-shadow: 0 0 22px rgba(251, 191, 36, 0.18), inset 0 0 16px rgba(251, 191, 36, 0.1);
}
.status__ring--off {
  border-color: rgba(52, 211, 153, 0.45);
  color: var(--down);
  box-shadow: 0 0 22px rgba(52, 211, 153, 0.14), inset 0 0 16px rgba(52, 211, 153, 0.09);
}
.status__ring svg { width: 24px; height: 24px; position: absolute; }
.status__clock { font-family: var(--mono); font-size: 12.5px; font-weight: 600; letter-spacing: -0.02em; }
.status__ring--peak .status__clock { opacity: 0; }
.status__body { min-width: 0; flex: 1; }
.status__title { font-size: 17px; font-weight: 650; letter-spacing: -0.01em; margin: 0 0 2px; }
.status__sub { font-size: 12.5px; color: var(--fg-muted); margin: 0; }
.status__sub b { color: var(--fg); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ── model card ─────────────────────────────────────────────────────── */

.model__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}
.model__name {
  margin: 0;
  font-size: 15.5px;
  font-weight: 650;
  letter-spacing: -0.01em;
  word-break: break-word;
}
.model__key { font-family: var(--mono); font-size: 11.5px; color: var(--fg-dim); }
.model__meta { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 7px; }

.prices { border-top: 1px solid var(--line); }
.prices__row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 4px 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.prices__row:last-child { border-bottom: 0; padding-bottom: 0; }
.prices__label {
  font-size: 13.5px;
  color: var(--fg);
  min-width: 0;
  overflow-wrap: anywhere;
}
.prices__cell {
  min-width: 78px;
  text-align: right;
  padding: 4px 8px;
  border-radius: var(--r-xs);
  border: 1px solid transparent;
  transition: background var(--t) var(--ease), border-color var(--t) var(--ease);
}
.prices__cell--active {
  background: rgba(255, 255, 255, 0.045);
  border-color: var(--line-strong);
}
.prices__cell--active.prices__cell--peak {
  background: var(--peak-soft);
  border-color: rgba(251, 191, 36, 0.3);
}
.prices__cell--active.prices__cell--off {
  background: var(--down-soft);
  border-color: rgba(52, 211, 153, 0.28);
}
.prices__period {
  display: block;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--fg-dim);
  margin-bottom: 1px;
}
.prices__cell--active.prices__cell--peak .prices__period { color: var(--peak); }
.prices__cell--active.prices__cell--off .prices__period { color: var(--down); }
.prices__value {
  font-family: var(--mono);
  font-size: 14.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  white-space: nowrap;
}
.prices__value .cur { font-size: 11px; color: var(--fg-dim); margin-right: 1px; }
.prices__empty { font-size: 12.5px; color: var(--fg-dim); }

/* ── events ─────────────────────────────────────────────────────────── */

.filters {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 2px 2px 12px;
  margin: 0 calc(var(--pad) * -1);
  padding-left: var(--pad);
  padding-right: var(--pad);
}
.filters::-webkit-scrollbar { display: none; }
.filter {
  flex: none;
  padding: 6px 13px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--fg-muted);
  font-size: 12.5px;
  font-weight: 550;
  cursor: pointer;
  transition: all var(--t-fast) var(--ease);
}
.filter:hover { border-color: var(--line-strong); color: var(--fg); }
.filter.is-active {
  background: var(--brand-soft);
  border-color: var(--brand-line);
  color: #A9BBFF;
}

.event {
  display: flex;
  gap: 11px;
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  animation: event-in 320ms var(--ease) both;
}
.event:last-child { border-bottom: 0; }
@keyframes event-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
.event__icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 30px;
  height: 30px;
  margin-top: 1px;
  border-radius: 9px;
  border: 1px solid;
}
.event__icon svg { width: 15px; height: 15px; }
.event__icon--down { color: var(--down); background: var(--down-soft); border-color: rgba(52, 211, 153, 0.28); }
.event__icon--up { color: var(--up); background: var(--up-soft); border-color: rgba(248, 113, 113, 0.28); }
.event__icon--flat { color: var(--fg-muted); background: rgba(255, 255, 255, 0.05); border-color: var(--line); }
.event__main { min-width: 0; flex: 1; }
.event__top { display: flex; align-items: baseline; gap: 7px; flex-wrap: wrap; }
.event__model {
  font-size: 13.5px;
  font-weight: 620;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}
.event__tag {
  font-size: 11px;
  color: var(--fg-dim);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 6px;
  white-space: nowrap;
}
.event__delta {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 6px;
  font-family: var(--mono);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  flex-wrap: wrap;
}
.event__from { color: var(--fg-dim); text-decoration: line-through; }
.event__arrow { color: var(--fg-dim); }
.event__to { font-weight: 650; }
.event__to--down { color: var(--down); }
.event__to--up { color: var(--up); }
.event__pct { font-size: 11.5px; font-weight: 600; padding: 1px 6px; border-radius: 6px; }
.event__pct--down { color: var(--down); background: var(--down-soft); }
.event__pct--up { color: var(--up); background: var(--up-soft); }
.event__meta { margin-top: 5px; font-size: 11.5px; color: var(--fg-dim); }

/* ── settings ───────────────────────────────────────────────────────── */

.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field__label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--fg-muted);
  margin-bottom: 6px;
}
.field__hint { font-size: 11.5px; color: var(--fg-dim); margin-top: 6px; line-height: 1.5; }
.input {
  width: 100%;
  padding: 11px 12px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--fg);
  font-size: 16px; /* prevents iOS zoom-on-focus */
  font-family: var(--mono);
  transition: border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.input::placeholder { color: var(--fg-dim); }
.input:focus { outline: none; border-color: var(--brand-line); background: rgba(91, 124, 250, 0.06); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 15px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--fg);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--t-fast) var(--ease);
}
.btn svg { width: 15px; height: 15px; }
.btn:hover { background: rgba(255, 255, 255, 0.09); border-color: var(--line-strong); }
.btn:active { transform: scale(0.975); }
.btn--primary {
  background: linear-gradient(160deg, #6D8BFF, #4460E4);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 5px 18px rgba(91, 124, 250, 0.28);
}
.btn--primary:hover { background: linear-gradient(160deg, #7B96FF, #4B67EA); }
.btn--block { width: 100%; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

.list { display: flex; flex-direction: column; }
.list__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.list__row:first-child { padding-top: 0; }
.list__row:last-child { border-bottom: 0; padding-bottom: 0; }
.list__k { font-size: 13.5px; }
.list__v { font-size: 12.5px; color: var(--fg-muted); font-family: var(--mono); text-align: right; overflow-wrap: anywhere; }

.switch {
  position: relative;
  flex: none;
  width: 46px;
  height: 27px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.06);
  cursor: pointer;
  transition: background var(--t) var(--ease), border-color var(--t) var(--ease);
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 21px;
  height: 21px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  transition: transform var(--t) var(--ease);
}
.switch[aria-checked="true"] { background: var(--brand); border-color: transparent; }
.switch[aria-checked="true"]::after { transform: translateX(19px); }

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 52px 24px;
  text-align: center;
  color: var(--fg-dim);
}
.empty svg { width: 34px; height: 34px; opacity: 0.55; }
.empty p { margin: 0; font-size: 13.5px; line-height: 1.6; }
.empty b { color: var(--fg-muted); font-weight: 600; }

/* skeleton */
.sk { border-radius: var(--r-xs); background: linear-gradient(90deg, rgba(255,255,255,0.045) 25%, rgba(255,255,255,0.09) 37%, rgba(255,255,255,0.045) 63%); background-size: 400% 100%; animation: sk 1.3s ease-in-out infinite; }
@keyframes sk { from { background-position: 100% 0; } to { background-position: 0 0; } }
.sk--line { height: 12px; margin-bottom: 8px; }
.sk--card { height: 176px; border-radius: var(--r-lg); margin-bottom: var(--gap); }

/* toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 18px);
  transform: translate(-50%, 12px);
  z-index: 60;
  max-width: min(420px, calc(100vw - 32px));
  padding: 11px 15px;
  border-radius: var(--r-md);
  background: rgba(26, 34, 51, 0.97);
  border: 1px solid var(--line-strong);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(14px);
  font-size: 13px;
  opacity: 0;
  transition: opacity var(--t) var(--ease), transform var(--t) var(--ease);
  pointer-events: none;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }
.toast--err { border-color: rgba(248, 113, 113, 0.45); color: #FCA5A5; }
.toast--ok { border-color: rgba(52, 211, 153, 0.45); color: #6EE7B7; }

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

@media (min-width: 560px) {
  :root { --pad: 18px; }
  .app { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}
