:root {
  color-scheme: dark;
  --bg: var(--tg-theme-bg-color, #0f1117);
  --panel: var(--tg-theme-secondary-bg-color, #181b24);
  --card: #1d212b;
  --card-2: #242a36;
  --text: var(--tg-theme-text-color, #f4f6fb);
  --muted: var(--tg-theme-hint-color, #8f98aa);
  --accent: var(--tg-theme-button-color, #6c8cff);
  --accent-text: var(--tg-theme-button-text-color, #0b1020);
  --line: rgba(255, 255, 255, 0.08);
  --danger: #ff7a90;
  --success: #6de3a2;
  --radius: 20px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  -webkit-font-smoothing: antialiased;
  background:
    radial-gradient(900px 420px at 50% -180px, rgba(108, 140, 255, 0.14), transparent 70%),
    var(--bg);
  background-attachment: fixed;
}
.hidden { display: none !important; }
body.picker-open { overflow: hidden; }
.muted { color: var(--muted); margin: 4px 0 0; font-size: 13px; }
.center { text-align: center; }
button:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
::selection { background: rgba(108, 140, 255, .35); }

.boot {
  position: fixed; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px;
  background: radial-gradient(circle at 50% 20%, #24346b 0, var(--bg) 52%);
  color: var(--text); font-size: 14px; z-index: 50;
}
.boot-logo {
  width: 64px; height: 64px; border-radius: 22px; display: grid;
  place-items: center; font-size: 32px;
  background: linear-gradient(135deg, #7f9cff, #c58cff);
  color: #0d1220; box-shadow: 0 18px 42px rgba(104, 130, 255, 0.35);
  animation: float 2.4s ease-in-out infinite;
}
@keyframes float { 50% { transform: translateY(-6px) rotate(3deg); } }

.app { max-width: 760px; margin: 0 auto; padding: 0 16px 104px; }
.topbar {
  position: sticky; top: 0; z-index: 15;
  display: flex; flex-direction: column; align-items: stretch;
  margin: 0 -16px; padding: 12px 16px 14px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--bg) 90%, transparent) 0%, color-mix(in srgb, var(--bg) 62%, transparent) 75%, transparent 100%);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}
.topbar-row {
  display: flex; align-items: center; justify-content: space-between;
}
.brand { font-weight: 750; font-size: 21px; letter-spacing: -0.02em; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--success); margin-left: 3px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font-size: 20px; cursor: pointer;
  transition: border-color .18s, transform .15s;
}
.icon-btn:hover { border-color: rgba(108, 140, 255, .4); }
.icon-btn:active { transform: scale(.94); }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.hero { display: flex; align-items: center; gap: 14px; margin: 6px 0 14px; }
.hero h1 { font-size: 26px; line-height: 1.1; margin: 0; letter-spacing: -0.03em; }
.hero-icon {
  width: 48px; height: 48px; border-radius: 17px; display: grid; place-items: center;
  font-size: 23px; color: #0b1020; background: linear-gradient(135deg, #8fa7ff, #d09bff);
  box-shadow: 0 10px 24px rgba(130, 150, 255, .25);
}
.tab-panel { animation: panel-in .34s var(--ease) both; }
@keyframes panel-in {
  from { opacity: 0; transform: translateY(10px); }
}
.card {
  background: linear-gradient(180deg, var(--card-2), var(--card));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin: 14px 0; box-shadow: 0 16px 40px rgba(0, 0, 0, .18);
}
.label { display: block; font-size: 12px; font-weight: 650; letter-spacing: .03em; color: var(--muted); margin: 14px 0 7px; text-transform: uppercase; }
.label:first-child { margin-top: 0; }
.hint { color: var(--muted); font-size: 12px; line-height: 1.45; margin: 8px 0 0; }
.picker-trigger {
  width: 100%; display: flex; align-items: center; gap: 12px; text-align: left;
  border: 1px solid var(--line); border-radius: 16px; background: var(--panel);
  color: var(--text); padding: 13px 14px; cursor: pointer;
  transition: border-color .18s, transform .18s;
}
.picker-trigger:hover { border-color: rgba(108, 140, 255, .35); }
.picker-trigger:active { border-color: var(--accent); transform: scale(.995); }
.picker-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.picker-body strong { font-size: 15px; letter-spacing: -.01em; }
.picker-body small { color: var(--muted); font-size: 11px; line-height: 1.35; }
.picker-badge {
  flex: 0 0 auto; border-radius: 999px; padding: 6px 10px;
  background: rgba(108, 140, 255, .16); border: 1px solid rgba(108, 140, 255, .22);
  color: #c9d4ff; font-size: 11px; font-weight: 700; white-space: nowrap;
}
.picker-chevron { flex: 0 0 auto; color: var(--muted); font-size: 16px; }

.picker-backdrop {
  position: fixed; inset: 0; z-index: 69; background: rgba(5, 7, 14, .58);
  backdrop-filter: blur(3px);
}
.picker-sheet {
  position: fixed; z-index: 70; left: 50%; bottom: 0; transform: translateX(-50%);
  width: min(720px, 100%); max-height: 84vh; display: flex; flex-direction: column;
  background: var(--bg); border: 1px solid var(--line); border-bottom: 0;
  border-radius: 24px 24px 0 0; box-shadow: 0 -22px 60px rgba(0, 0, 0, .48);
  padding-bottom: calc(14px + env(safe-area-inset-bottom));
  animation: sheet-up .2s ease-out;
}
@keyframes sheet-up { from { transform: translate(-50%, 16px); opacity: .4; } }
.picker-sheet-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 14px;
  padding: 18px 18px 10px;
}
.picker-sheet-head h2 { margin: 2px 0 0; font-size: 20px; letter-spacing: -.02em; }
.picker-kicker { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
.picker-search {
  margin: 0 18px 6px; border: 1px solid var(--line); border-radius: 13px;
  background: var(--panel); color: var(--text); padding: 10px 13px;
  font: inherit; font-size: 13px; outline: none;
}
.picker-search:focus { border-color: var(--accent); }
.picker-list { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 0 12px 8px; }
.picker-group { margin-top: 12px; }
.picker-group-title {
  display: flex; align-items: center; gap: 8px; padding: 6px 6px 8px;
  color: var(--muted); font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em;
}
.picker-group-title span { color: var(--muted); font-weight: 500; opacity: .7; }
.picker-item {
  width: 100%; display: flex; align-items: center; gap: 12px; text-align: left;
  border: 1px solid transparent; border-radius: 15px; background: transparent;
  color: var(--text); padding: 11px 12px; cursor: pointer;
}
.picker-item + .picker-item { margin-top: 2px; }
.picker-item:hover { background: rgba(108, 140, 255, .07); }
.picker-item:active { background: var(--panel); }
.picker-item.selected { background: var(--panel); border-color: rgba(108, 140, 255, .35); }
.picker-item-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.picker-item-main strong { font-size: 14px; }
.picker-item-main small { color: var(--muted); font-size: 11px; line-height: 1.35; }
.picker-item-side { flex: 0 0 auto; text-align: right; display: flex; flex-direction: column; gap: 3px; align-items: flex-end; }
.picker-price { color: #c9d4ff; font-size: 12px; font-weight: 700; }
.picker-price-note { color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: .04em; }
.picker-check { width: 18px; flex: 0 0 auto; color: var(--accent); font-size: 14px; font-weight: 800; opacity: 0; }
.picker-item.selected .picker-check { opacity: 1; }
.picker-star {
  flex: 0 0 auto; width: 26px; height: 26px; display: grid; place-items: center;
  color: var(--muted); font-size: 17px; border-radius: 8px; cursor: pointer;
}
.picker-star:active { background: var(--panel); color: #ffd166; }
button { font: inherit; }
button:active { transform: scale(.99); }
button:disabled { opacity: .45; cursor: not-allowed; }
button:disabled:active { transform: none; }

.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 14px; }
.balance-card {
  background: linear-gradient(135deg, #233b76, #3c2b68 65%, #5a2d62);
  border: 1px solid rgba(150, 175, 255, .25);
  border-radius: var(--radius); padding: 18px; margin: 14px 0;
  box-shadow: 0 18px 40px rgba(28, 40, 92, .28);
  position: relative; overflow: hidden;
}
.balance-card::after {
  content: ""; position: absolute; top: -60px; right: -60px; width: 170px; height: 170px;
  border-radius: 50%; background: radial-gradient(circle, rgba(255,255,255,.16), transparent 70%);
  pointer-events: none;
}
.balance-top { display: flex; justify-content: space-between; gap: 12px; color: #b9c7ee; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.balance-top .hint { margin: 0; font-size: 10px; text-transform: none; letter-spacing: 0; }
.balance-main { display: flex; align-items: baseline; gap: 9px; margin: 12px 0 10px; }
.balance-main strong { font-size: 34px; letter-spacing: -.04em; }
.balance-main span { color: #c3cdf0; font-size: 12px; }
.balance-row { display: flex; justify-content: space-between; gap: 10px; color: #b9c7ee; font-size: 12px; }
.balance-row b { color: #fff; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 17px; padding: 14px; display: flex; flex-direction: column; gap: 7px; transition: border-color .18s; }
.stat:hover { border-color: rgba(108, 140, 255, .3); }
.stat span { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.stat strong { font-size: 19px; letter-spacing: -.02em; }

.skill-head { display: flex; justify-content: space-between; gap: 14px; align-items: flex-start; }
.skill-head h2 { font-size: 18px; margin: 0; letter-spacing: -.02em; }

.stats-head { margin: 14px 0 10px; }
.stats-periods {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px;
  padding: 4px; border: 1px solid var(--line); border-radius: 13px; background: var(--panel);
}
.stats-periods button {
  border: 0; border-radius: 10px; padding: 8px 6px; background: transparent; color: var(--muted);
  font: inherit; font-size: 12px; font-weight: 700; cursor: pointer; transition: .18s;
}
.stats-periods button:not(.active):hover { color: var(--text); }
.stats-periods button.active { background: var(--accent); color: var(--accent-text); }
.spark-card { margin-top: 14px; }
.cost-detail-card { padding-bottom: 14px; }
.cost-summary {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  margin-top: 8px; padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.cost-summary-item {
  display: flex; flex-direction: column; gap: 5px;
  padding: 12px 14px; border-radius: 14px;
  background: var(--panel); border: 1px solid var(--line);
}
.cost-summary-item span {
  color: var(--muted); font-size: 10px; font-weight: 650;
  text-transform: uppercase; letter-spacing: .06em;
}
.cost-summary-item strong { font-size: 19px; letter-spacing: -.02em; }
.cost-list-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 14px 2px 8px; color: var(--muted);
  font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .07em;
}
.cost-list-head span:last-child {
  padding: 2px 7px; border-radius: 999px; background: var(--panel);
  border: 1px solid var(--line); letter-spacing: 0;
}
.cost-list { display: flex; flex-direction: column; gap: 6px; }
.cost-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 13px;
  background: var(--panel); border: 1px solid var(--line);
  cursor: default; user-select: none;
  transition: background .16s, border-color .16s, transform .12s;
}
.cost-row:hover { border-color: rgba(108, 140, 255, .3); }
.cost-row:active { background: color-mix(in srgb, var(--panel) 88%, var(--accent)); transform: scale(.995); }
.cost-row:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.cost-row-main { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cost-row-date {
  font-size: 12px; font-weight: 700; color: var(--text);
  font-variant-numeric: tabular-nums; letter-spacing: -.01em;
}
.cost-row-model {
  display: block; max-width: 100%; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
  color: var(--muted); font-size: 11px; line-height: 1.3;
}
.cost-row-meta {
  color: var(--muted); font-size: 10px; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.cost-row-price {
  justify-self: end; min-width: 62px; text-align: right;
  font-size: 14px; font-weight: 750; color: var(--text);
  font-variant-numeric: tabular-nums; letter-spacing: -.02em;
}
@media (max-width: 400px) {
  .cost-row { gap: 8px; padding: 9px 10px; }
  .cost-row-price { min-width: 54px; font-size: 13px; }
}
.spark { margin-top: 10px; }
.spark svg { display: block; width: 100%; height: 64px; }
.spark rect { fill: rgba(108, 140, 255, .25); }
.spark rect.hot { fill: var(--accent); }
.spark-empty {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 26px 16px; text-align: center; color: var(--muted);
  border: 1.5px dashed var(--line); border-radius: 14px;
}
.spark-empty-icon { font-size: 26px; }
.spark-empty p { margin: 0; font-size: 14px; font-weight: 650; color: var(--text); }
.spark-empty small { font-size: 11px; color: var(--muted); }
.empty { color: var(--muted); font-size: 13px; padding: 10px 0; }

.toast {
  position: fixed; left: 50%; bottom: 92px; transform: translate(-50%, 20px);
  max-width: calc(100% - 40px); padding: 11px 16px; border-radius: 13px;
  background: #e9edff; color: #101426; font-size: 13px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: .22s; z-index: 60;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #ffd9df; color: #52121c; }

@media (min-width: 620px) {
  .hero h1 { font-size: 30px; }
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* ===== DSH tasks panel ===== */
.dsh-list { display: flex; flex-direction: column; gap: 8px; }
.dsh-empty { padding: 14px 6px; text-align: center; color: var(--muted, #8a8f9d); font-size: 13px; }
.dsh-row {
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: rgba(255,255,255,.03);
}
.dsh-row-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.dsh-row-title { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.dsh-badge { flex-shrink: 0; font-size: 11px; padding: 2px 8px; border-radius: 999px; background: rgba(255,255,255,.08); }
.dsh-row-sub { font-size: 11px; color: var(--muted, #8a8f9d); }
.dsh-row-out { font-size: 12px; color: var(--muted, #a9aebc); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
.dsh-row-err { font-size: 12px; color: #ff7a7a; }
.dsh-row-art { font-size: 11px; color: var(--muted, #8a8f9d); }
.dsh-cancel {
  align-self: flex-end;
  margin-top: 2px;
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255,122,122,.45);
  background: transparent;
  color: #ff9a9a;
  cursor: pointer;
}
.dsh-cancel:active { transform: scale(.97); }

/* --- Tabs --- */
.tabbar {
  position: fixed;
  left: 50%; bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 30;
  width: min(420px, calc(100% - 28px));
  display: flex;
  gap: 4px;
  padding: 6px;
  border-radius: 999px;
  background: rgba(22, 24, 31, .88);
  border: 1px solid rgba(255,255,255,.07);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: 0 12px 34px -12px rgba(0,0,0,.65);
}
.tabbar button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 0 7px;
  border: none;
  border-radius: 999px;
  background: transparent;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted, #8a8f9d);
  cursor: pointer;
  transition: background .18s var(--ease), color .18s var(--ease);
}
.tabbar button.active {
  color: #fff;
  background: rgba(255,255,255,.13);
}
.tab-icon { font-size: 18px; line-height: 1; }
.tabbar button {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted, #8a8f9d);
  background: transparent;
  border: none;
  border-radius: 11px;
  cursor: pointer;
  transition: background .18s var(--ease), color .18s var(--ease);
}
.tabbar button.active {
  color: #fff;
  background: rgba(255,255,255,.10);
}
.tab-icon { font-size: 14px; }

.tab-panel { display: none; }
.tab-panel.active { display: block; animation: panel-in .34s var(--ease) both; }

.dsh-hint { margin-top: 10px; }
