/* ============================================================================
   Admin Mini App — design system
   Theme-aware (uses Telegram theme vars for bg/text) with a Spotify-green
   accent and a small set of reusable primitives shared by every view:
     .card .list-row .stat-tile .pill .btn .field .seg .chip .skeleton
   Keep view modules to these primitives so the UI stays consistent.
   ========================================================================== */
:root {
  /* Theme surfaces (fall back to a light palette outside Telegram) */
  --bg:        var(--tg-theme-bg-color, #f5f6f8);
  --surface:   var(--tg-theme-secondary-bg-color, #ffffff);
  --text:      var(--tg-theme-text-color, #0e1116);
  --hint:      var(--tg-theme-hint-color, #8a9099);
  --link:      var(--tg-theme-link-color, #1db954);

  /* Brand + semantic colors (fixed, theme-independent) */
  --brand:     #1db954;
  --brand-600: #19a44b;
  --brand-tint:rgba(29, 185, 84, 0.12);
  --ok:        #22c55e;
  --warn:      #f59e0b;
  --danger:    #ef4444;
  --danger-tint: rgba(239, 68, 68, 0.12);
  --warn-tint:   rgba(245, 158, 11, 0.14);
  --ok-tint:     rgba(34, 197, 94, 0.14);

  /* Lines, shadows — neutral rgba so they read on light AND dark themes */
  --line:      rgba(128, 128, 128, 0.18);
  --line-soft: rgba(128, 128, 128, 0.10);
  --shadow:    0 1px 2px rgba(0,0,0,.04), 0 6px 18px rgba(0,0,0,.06);
  --shadow-sm: 0 1px 2px rgba(0,0,0,.05);

  --r-lg: 18px;
  --r-md: 14px;
  --r-sm: 10px;
  --gap: 12px;

  --header-h: 52px;
  --nav-h: 52px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ── App chrome ──────────────────────────────────────────────────────────── */
header {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: calc(var(--safe-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.brand .logo {
  width: 26px; height: 26px; flex: 0 0 auto;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--brand), var(--brand-600));
  display: grid; place-items: center;
  color: #fff; font-size: 15px;
  box-shadow: 0 2px 8px rgba(29,185,84,.4);
}
h1 { font-size: 17px; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
#who {
  flex: 0 0 auto;
  font-size: 12px; font-weight: 600;
  color: var(--hint);
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 5px 10px;
  border-radius: 999px;
  max-width: 42%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ── Nav (segmented, scrollable, sticky under header) ────────────────────── */
#nav {
  position: sticky;
  top: calc(var(--safe-top) + var(--header-h));
  z-index: 19;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--line-soft);
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
#nav::-webkit-scrollbar { display: none; }
.nav-tab {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  transition: transform .12s ease, background .15s ease, color .15s ease;
}
.nav-tab .ico { font-size: 14px; line-height: 1; }
.nav-tab:active { transform: scale(.95); }
.nav-tab.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  box-shadow: 0 3px 10px rgba(29,185,84,.35);
}

main { padding: 14px 16px calc(var(--safe-bottom) + 28px); }
.view { animation: fade .22s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ── Typography helpers ──────────────────────────────────────────────────── */
.muted { color: var(--hint); font-size: 13px; }
.error-text { color: var(--danger); }
.section-title {
  font-size: 12px; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; color: var(--hint);
  margin: 18px 2px 8px;
}
.section-title:first-child { margin-top: 4px; }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
}
.card.pad-lg { padding: 16px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.col { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.title { font-weight: 650; font-size: 15px; letter-spacing: -0.01em; }
.subtle { color: var(--hint); font-size: 12.5px; }
.grow { flex: 1 1 auto; min-width: 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spacer { height: 6px; }

/* Tappable list row with chevron affordance */
.list-row {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  padding: 13px 14px;
  margin-bottom: 9px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 12px;
  transition: transform .12s ease, background .15s ease;
}
.list-row.tappable { cursor: pointer; }
.list-row.tappable:active { transform: scale(.985); background: color-mix(in srgb, var(--surface) 92%, var(--brand)); }
.list-row .chev { color: var(--hint); font-size: 18px; flex: 0 0 auto; opacity: .7; }
.list-row .lead {
  width: 38px; height: 38px; flex: 0 0 auto;
  border-radius: 11px;
  display: grid; place-items: center;
  font-size: 16px; font-weight: 700;
  background: var(--brand-tint); color: var(--brand);
}
.list-row .lead.danger { background: var(--danger-tint); color: var(--danger); }
.list-row .lead.warn   { background: var(--warn-tint); color: var(--warn); }
.list-row .lead.ok     { background: var(--ok-tint); color: var(--ok); }

/* ── Stat tiles (dashboard) ──────────────────────────────────────────────── */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  padding: 14px;
  box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; gap: 2px;
  cursor: pointer;
  transition: transform .12s ease;
}
.tile:active { transform: scale(.97); }
.tile .tile-top { display: flex; align-items: center; justify-content: space-between; }
.tile .tile-ico {
  width: 30px; height: 30px; border-radius: 9px;
  display: grid; place-items: center; font-size: 16px;
  background: var(--brand-tint);
}
.tile .tile-num { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; }
.tile .tile-label { font-size: 12.5px; color: var(--hint); font-weight: 600; }
.tile.alert .tile-ico { background: var(--danger-tint); }
.tile.alert .tile-num { color: var(--danger); }
.tile.warn .tile-ico { background: var(--warn-tint); }

/* ── Pills / badges ──────────────────────────────────────────────────────── */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12.5px; font-weight: 700;
  white-space: nowrap;
  background: var(--brand-tint); color: var(--brand);
}
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.ok     { background: var(--ok-tint);     color: var(--ok); }
.pill.warn   { background: var(--warn-tint);   color: var(--warn); }
.pill.danger { background: var(--danger-tint); color: var(--danger); }
.pill.neutral{ background: var(--line); color: var(--hint); }
.pill.solid  { background: var(--brand); color: #fff; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
button, .btn {
  font: inherit; font-weight: 650;
  border: none;
  border-radius: var(--r-sm);
  padding: 11px 15px;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  transition: transform .1s ease, opacity .15s ease, background .15s ease;
}
button:active, .btn:active { transform: scale(.97); }
button.secondary, .btn.secondary {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line);
}
button.danger, .btn.danger { background: var(--danger); color: #fff; }
button.ghost, .btn.ghost { background: transparent; color: var(--brand); padding: 8px 10px; }
button.block, .btn.block { width: 100%; }
button.sm, .btn.sm { padding: 8px 12px; font-size: 13px; border-radius: 9px; }
button:disabled, .btn:disabled { opacity: .45; pointer-events: none; }

.actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.actions.end { justify-content: flex-end; }

/* ── Forms ───────────────────────────────────────────────────────────────── */
label.field { display: block; margin-bottom: 12px; }
label.field > span.lbl,
label.field { font-size: 12.5px; color: var(--hint); font-weight: 600; }
label.field input, label.field select, label.field textarea, .input {
  display: block; width: 100%; margin-top: 6px;
  padding: 11px 12px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font: inherit; font-weight: 500;
  transition: border-color .15s ease, box-shadow .15s ease;
}
label.field input:focus, label.field select:focus, label.field textarea:focus, .input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-tint);
}
textarea { resize: vertical; min-height: 90px; }

/* Segmented control (tabs inside a view) */
.seg {
  display: flex; gap: 4px;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  padding: 4px;
  margin-bottom: 14px;
}
.seg .seg-item {
  flex: 1 1 0;
  text-align: center;
  padding: 8px 10px;
  border-radius: 999px;
  font-size: 13.5px; font-weight: 650;
  color: var(--hint);
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s ease, color .15s ease;
}
.seg .seg-item.active { background: var(--brand); color: #fff; }

/* Filter chips */
.filters { display: flex; gap: 7px; margin-bottom: 12px; flex-wrap: wrap; }
.chip {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 13px; font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: transform .1s ease;
}
.chip:active { transform: scale(.95); }
.chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }

/* Key/value rows (detail cards) */
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line-soft); }
.kv:last-child { border-bottom: none; }
.kv .k { color: var(--hint); font-size: 13.5px; }
.kv .v { font-weight: 600; text-align: right; }

/* Pager */
.pager { display: flex; justify-content: center; gap: 14px; align-items: center; margin-top: 14px; }
.pager .muted { font-weight: 600; }

/* ── Empty / loading states ──────────────────────────────────────────────── */
.empty {
  text-align: center;
  padding: 36px 20px;
  color: var(--hint);
}
.empty .emoji { font-size: 34px; display: block; margin-bottom: 10px; opacity: .85; }
.empty .empty-title { font-weight: 700; color: var(--text); margin-bottom: 4px; }

.skeleton {
  border-radius: var(--r-md);
  background: linear-gradient(90deg,
    var(--line-soft) 25%, var(--line) 37%, var(--line-soft) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease infinite;
}
.skel-row { height: 64px; margin-bottom: 9px; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

/* Inline helpers */
.clickable { cursor: pointer; }
img.receipt { max-width: 100%; border-radius: var(--r-sm); border: 1px solid var(--line); }
.mono { font-variant-numeric: tabular-nums; }
.flag { font-size: 15px; }
