/* Banner Bot mini app — design tokens + components.
   Base colors come from Telegram theme vars so the app follows the user's
   theme; accents are derived with color-mix (static fallbacks first). */

@font-face {
  font-family: "Vazirmatn";
  src: url("/static/fonts/Vazirmatn-Regular.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Vazirmatn";
  src: url("/static/fonts/Vazirmatn-Medium.woff2") format("woff2");
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: "Vazirmatn";
  src: url("/static/fonts/Vazirmatn-Bold.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

:root {
  --bg: var(--tg-theme-bg-color, #f2f2f7);
  --bg2: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #111114);
  --hint: var(--tg-theme-hint-color, #77767e);
  --link: var(--tg-theme-link-color, #5a54d6);
  --accent: var(--tg-theme-button-color, #5a54d6);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);

  /* derived tints (fallback first, color-mix override below) */
  --accent-soft: rgba(90, 84, 214, .12);
  --accent-strong: #4a44c6;
  --hairline: rgba(120, 120, 128, .18);
  --tile: rgba(120, 120, 128, .08);

  /* status — icon/label always accompanies color */
  --ok: #0a8a0a;
  --ok-soft: rgba(12, 163, 12, .12);
  --warn: #a16207;
  --warn-soft: rgba(250, 178, 25, .16);
  --bad: #c22f2f;
  --bad-soft: rgba(208, 59, 59, .12);

  --r-lg: 20px;
  --r-md: 14px;
  --r-sm: 10px;
  --shadow-card: 0 1px 2px rgba(17, 17, 20, .05), 0 4px 16px rgba(17, 17, 20, .05);
}

@supports (color: color-mix(in srgb, red, blue)) {
  :root {
    --accent-soft: color-mix(in srgb, var(--accent) 13%, transparent);
    --accent-strong: color-mix(in srgb, var(--accent) 82%, #000);
    --hairline: color-mix(in srgb, var(--text) 10%, transparent);
    --tile: color-mix(in srgb, var(--text) 5%, transparent);
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --ok: #35c759;
    --ok-soft: rgba(53, 199, 89, .16);
    --warn: #fab219;
    --warn-soft: rgba(250, 178, 25, .16);
    --bad: #ef5350;
    --bad-soft: rgba(239, 83, 80, .16);
    --shadow-card: none;
  }
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: "Vazirmatn", "Segoe UI", Tahoma, system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

#app { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }

.page {
  flex: 1;
  padding: 16px 16px 104px;
  max-width: 640px;
  margin: 0 auto;
  width: 100%;
  animation: page-in .28s ease both;
}
@keyframes page-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ---------------------------------------------------------- bottom nav */
.tabs {
  position: fixed; bottom: 0; right: 0; left: 0; z-index: 20;
  display: flex; justify-content: space-around; align-items: stretch;
  max-width: 640px; margin: 0 auto;
  padding: 8px 10px calc(10px + env(safe-area-inset-bottom));
  background: var(--bg2);
  border-top: 1px solid var(--hairline);
}
@supports ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
  .tabs {
    background: color-mix(in srgb, var(--bg2) 78%, transparent);
    -webkit-backdrop-filter: saturate(160%) blur(18px);
    backdrop-filter: saturate(160%) blur(18px);
  }
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  background: none; border: none; cursor: pointer;
  color: var(--hint);
  font-family: inherit; font-size: 10.5px; font-weight: 500;
  padding: 5px 0 3px;
  border-radius: var(--r-md);
  transition: color .18s ease;
}
.tab .tab-icon {
  width: 40px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 999px;
  transition: background .18s ease, transform .18s ease;
}
.tab svg { width: 21px; height: 21px; display: block; }
.tab.active { color: var(--accent); font-weight: 700; }
.tab.active .tab-icon { background: var(--accent-soft); transform: translateY(-1px); }
.tab:active .tab-icon { transform: scale(.9); }

/* ---------------------------------------------------------- typography */
.section-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 19px; font-weight: 700;
  margin: 2px 2px 14px;
  letter-spacing: -.2px;
}
.section-title .chip { transform: translateY(1px); }

/* ---------------------------------------------------------- hero card */
.hero {
  position: relative; overflow: hidden;
  border-radius: var(--r-lg);
  padding: 20px 18px 18px;
  margin-bottom: 14px;
  color: #fff;
  background: linear-gradient(140deg, var(--accent) 0%, var(--accent-strong) 100%);
  box-shadow: 0 10px 28px -12px var(--accent);
}
.hero::before, .hero::after {
  content: ""; position: absolute; border-radius: 50%;
  background: rgba(255, 255, 255, .10); pointer-events: none;
}
.hero::before { width: 190px; height: 190px; top: -80px; left: -50px; }
.hero::after { width: 120px; height: 120px; bottom: -60px; right: -30px; background: rgba(255,255,255,.07); }
.hero .greet { font-size: 13px; opacity: .92; margin-bottom: 12px; font-weight: 500; }
.hero .lbl { font-size: 12px; opacity: .82; }
.hero .balance { font-size: 30px; font-weight: 700; line-height: 1.35; letter-spacing: -.4px; }
.hero .balance small { font-size: 14px; font-weight: 500; opacity: .85; margin-right: 4px; }
.hero .hero-foot {
  display: flex; gap: 8px; flex-wrap: wrap;
  margin-top: 14px; position: relative;
}
.hero .hero-pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; font-weight: 500;
  background: rgba(255, 255, 255, .16);
  border-radius: 999px; padding: 5px 11px;
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
}

/* ---------------------------------------------------------- cards */
.card {
  background: var(--bg2);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-card);
}
.card h3 {
  display: flex; align-items: center; gap: 8px;
  font-size: 14.5px; font-weight: 700;
  margin-bottom: 12px;
}
.card h3 .h-ic {
  width: 30px; height: 30px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--r-sm);
  background: var(--accent-soft);
  font-size: 15px;
}

/* ---------------------------------------------------------- stat tiles */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.stat {
  background: var(--bg2);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  padding: 13px 14px;
  box-shadow: var(--shadow-card);
}
.card .stat-grid { margin-bottom: 8px; }
.card .stat { box-shadow: none; background: var(--tile); border-color: transparent; }
.stat .s-ic {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--r-sm);
  font-size: 16px;
  background: var(--accent-soft);
  margin-bottom: 9px;
}
.stat.t-ok .s-ic { background: var(--ok-soft); }
.stat.t-warn .s-ic { background: var(--warn-soft); }
.stat.t-bad .s-ic { background: var(--bad-soft); }
.stat .label { font-size: 11px; color: var(--hint); margin-bottom: 3px; font-weight: 500; }
.stat .value { font-size: 17px; font-weight: 700; letter-spacing: -.2px; }
.stat .value small { font-size: 11px; font-weight: 500; color: var(--hint); }

/* ---------------------------------------------------------- rows/lists */
.row {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--hairline);
}
.row:last-child { border-bottom: none; padding-bottom: 2px; }
.row:first-child { padding-top: 2px; }
.row .sub { font-size: 11.5px; color: var(--hint); margin-top: 2px; }
.row .amount { font-weight: 700; white-space: nowrap; font-size: 14px; }
.row .arrow { color: var(--hint); font-size: 18px; font-weight: 400; }
.row[data-pid], .row[data-excat], .row[data-exdeal] { cursor: pointer; }
.amount.pos { color: var(--ok); }
.amount.neg { color: var(--bad); }

/* ---------------------------------------------------------- chips */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 10.5px; font-weight: 700;
  padding: 2.5px 9px; border-radius: 999px;
  background: var(--tile); color: var(--hint);
  vertical-align: middle;
}
.chip::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; flex: none; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }

/* ---------------------------------------------------------- progress */
.progress {
  height: 8px; border-radius: 999px;
  background: var(--tile);
  overflow: hidden; margin-top: 8px;
}
.progress > div {
  height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-strong));
  transition: width .5s cubic-bezier(.22, 1, .36, 1);
}
.progress.p-ok > div { background: linear-gradient(90deg, var(--ok), var(--ok)); }

/* ---------------------------------------------------------- forms */
label.field { display: block; margin-bottom: 13px; }
label.field span.lbl { display: block; font-size: 12px; color: var(--hint); margin-bottom: 6px; font-weight: 500; }
input[type="text"], input[type="number"], select {
  width: 100%; padding: 12px 14px;
  border-radius: var(--r-md);
  border: 1.5px solid var(--hairline);
  background: var(--tile);
  color: var(--text);
  font-family: inherit; font-size: 15px;
  transition: border-color .15s ease, background .15s ease;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg2);
}
input::placeholder { color: var(--hint); opacity: .7; }
.hint-line { font-size: 11.5px; color: var(--hint); margin-top: 6px; line-height: 1.8; }

/* ---------------------------------------------------------- buttons */
.btn {
  display: block; width: 100%;
  padding: 13px 16px;
  border: none; border-radius: var(--r-md);
  background: linear-gradient(140deg, var(--accent), var(--accent-strong));
  color: var(--accent-text);
  font-family: inherit; font-size: 15px; font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 18px -8px var(--accent);
  transition: transform .12s ease, filter .15s ease, opacity .15s ease;
}
.btn:active { transform: scale(.985); filter: brightness(.96); }
.btn:disabled { opacity: .55; box-shadow: none; }
.btn.ghost {
  background: var(--accent-soft);
  color: var(--accent);
  box-shadow: none;
}
.btn.ghost.danger { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.btn.small { width: auto; padding: 9px 18px; font-size: 13px; display: inline-block; }

.seg { display: flex; gap: 8px; margin-bottom: 13px; }
.seg button {
  flex: 1; padding: 10px 6px;
  border-radius: var(--r-md);
  border: 1.5px solid var(--hairline);
  background: transparent; color: var(--hint);
  font-family: inherit; font-size: 13px; font-weight: 500;
  cursor: pointer;
  transition: all .15s ease;
}
.seg button.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
  font-weight: 700;
}

/* ---------------------------------------------------------- quote box */
.quote-box {
  border: 1.5px dashed var(--hairline);
  border-radius: var(--r-md);
  padding: 12px 14px;
  margin: 13px 0;
  background: var(--tile);
}
.quote-box .row { padding: 5px 0; border: none; font-size: 13px; }
.quote-box .total {
  font-size: 15px; font-weight: 700;
  border-top: 1px solid var(--hairline);
  padding-top: 9px; margin-top: 5px;
}
.quote-box .total .amount { color: var(--accent); font-size: 16px; }

/* ---------------------------------------------------------- states */
.empty { text-align: center; color: var(--hint); padding: 34px 12px; font-size: 13.5px; line-height: 2; }
.empty .e-ic { font-size: 34px; display: block; margin-bottom: 8px; }

.back-link {
  display: inline-flex; align-items: center; gap: 4px;
  margin-bottom: 12px;
  color: var(--link); font-size: 13px; font-weight: 500;
  cursor: pointer; background: none; border: none; font-family: inherit;
  padding: 4px 0;
}

/* skeleton loading */
.sk { animation: sk-pulse 1.3s ease-in-out infinite; }
.sk-hero { height: 148px; border-radius: var(--r-lg); background: var(--tile); margin-bottom: 14px; }
.sk-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.sk-tile { height: 96px; border-radius: var(--r-lg); background: var(--tile); }
.sk-card { height: 150px; border-radius: var(--r-lg); background: var(--tile); }
@keyframes sk-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }

/* ---------------------------------------------------------- toast */
.toast {
  position: fixed; bottom: 96px; right: 20px; left: 20px; z-index: 50;
  max-width: 600px; margin: 0 auto;
  background: color-mix(in srgb, var(--text) 88%, var(--bg));
  color: var(--bg2);
  border-radius: var(--r-md);
  padding: 13px 16px;
  font-size: 13.5px; font-weight: 500; text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
  transition: opacity .25s ease, transform .25s ease;
}
.toast.hidden { opacity: 0; transform: translateY(12px); pointer-events: none; }
.toast.ok { background: var(--ok); color: #fff; }
.toast.err { background: var(--bad); color: #fff; }

code { font-size: 12px; direction: ltr; unicode-bidi: embed; word-break: break-all; }
