/* ============================================================
   P2P OTC — Panel оператора. МОБІЛЬНИЙ ПЕРШИЙ дизайн.
   Тема ЗАВЖДИ темна, незалежно від теми телефону/Telegram —
   свідоме рішення: змінна прив'язка до tg-theme-* раніше
   ламала контраст у світлій темі (текст ставав темним, а фон
   карток лишався темним — "чорне на чорному"). Фіксована
   палітра прибирає цю категорію багів повністю.
   ============================================================ */

:root {
  --bg: #121418;
  --surface: #1f232c;
  --surface-2: #2a2f3a;
  --surface-3: #343a47;
  --border: rgba(255,255,255,0.14);
  --border-soft: rgba(255,255,255,0.08);
  --text: #f3f4f6;
  --text-dim: #a7adb8;
  --text-faint: #767c87;
  --accent: #5b9bf5;
  --accent-soft: rgba(91,155,245,0.16);
  --good: #46c98f;
  --good-soft: rgba(70,201,143,0.16);
  --warn: #eab554;
  --warn-soft: rgba(234,181,84,0.16);
  --bad: #f0685f;
  --bad-soft: rgba(240,104,95,0.16);
  --r-lg: 18px;
  --r-md: 14px;
  --r-sm: 10px;
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 22px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --shadow-card: 0 1px 3px rgba(0,0,0,0.35), 0 0 0 1px var(--border-soft) inset;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  color-scheme: dark; /* каже системним контролам (напр. datepicker) теж бути темними */
}

#app, #clientApp {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: calc(24px + var(--safe-bottom));
}
#app { padding-bottom: calc(64px + var(--safe-bottom)); } /* запас під нижній таб-бар */

.num { font-variant-numeric: tabular-nums; }

/* ---------- Header ---------- */
header {
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(var(--sp-3) + var(--safe-top)) var(--sp-4) var(--sp-2);
}
h1 { font-size: 19px; font-weight: 700; margin: 0; color: var(--text); }
.badge { font-size: 14px; color: var(--text-dim); }

/* ---------- Status bar ---------- */
.status-bar {
  display: flex; gap: var(--sp-2); padding: 0 var(--sp-4) var(--sp-3);
  font-size: 13px; overflow-x: auto; scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.status-bar::-webkit-scrollbar { display: none; }
.status-bar span {
  white-space: nowrap; background: var(--surface); border: 1px solid var(--border);
  padding: 7px 12px; border-radius: 999px; color: var(--text-dim); flex: 0 0 auto;
}

/* ---------- Content area ---------- */
.tab-content { padding: 0 var(--sp-4) var(--sp-4); }

/* ---------- Bottom tab bar ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: center;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: var(--sp-2) var(--sp-2) calc(var(--sp-2) + var(--safe-bottom));
}
.tabs-inner {
  display: flex; gap: 2px; width: 100%; max-width: 560px;
  overflow-x: auto; scrollbar-width: none;
}
.tabs-inner::-webkit-scrollbar { display: none; }
.tab {
  flex: 1 0 auto; min-width: 64px;
  display: none; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; padding: 6px 8px; background: none; border: none;
  color: var(--text-faint); font-size: 11px; font-weight: 500;
  border-radius: var(--r-sm); cursor: pointer; min-height: 48px;
}
.tab:not(.admin-only) { display: flex; }
.tab .tab-icon { font-size: 19px; line-height: 1; }
.tab.active { color: var(--accent); background: var(--accent-soft); }

/* ---------- Lists & cards ---------- */
.list { display: flex; flex-direction: column; gap: var(--sp-3); }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: var(--sp-4);
  box-shadow: var(--shadow-card);
}
.card h3 { margin: 0 0 var(--sp-3); font-size: 13px; font-weight: 700; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.02em; }
.card p { margin: 0 0 var(--sp-2); color: var(--text-dim); font-size: 13.5px; }

.deal-card { display: flex; flex-direction: column; gap: 10px; }
.deal-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 14px; color: var(--text); }
.deal-row > span:last-child { text-align: right; color: var(--text-dim); }
.deal-amount { font-size: 21px; font-weight: 700; color: var(--text); }

/* Легкий рядок для елементів ВСЕРЕДИНІ вже відкритої картки (акордеон) —
   без повторної обводки/тіні, щоб не було картки в картці */
.subitem {
  background: var(--surface-2); border: 1px solid var(--border-soft);
  border-radius: var(--r-sm); padding: 10px 12px;
}
.subitem + .subitem { margin-top: 0; }

.deal-status {
  font-size: 11.5px; font-weight: 700; padding: 4px 10px; border-radius: 999px;
  display: inline-block; background: var(--accent-soft); color: var(--accent);
  white-space: nowrap;
}
.deal-status.urgent { background: var(--bad-soft); color: var(--bad); }

/* ---------- Price cards: чітке кольорове маркування BUY / SELL ---------- */
.price-card { border-left: 3px solid var(--accent); padding-left: calc(var(--sp-4) - 3px); }
.price-card.side-sell { border-left-color: var(--warn); }
.price-side-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--accent);
}
.price-card.side-sell .price-side-label { color: var(--warn); }
.price-big { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; color: var(--text); }
.price-tier-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 9px 0; border-bottom: 1px solid var(--border-soft); font-size: 14px;
}
.price-tier-row:last-child { border-bottom: none; }
.price-tier-row .tier-label { color: var(--text-dim); }
.price-tier-row .tier-value { font-weight: 700; font-size: 16px; }
.competitor-row {
  display: flex; justify-content: space-between; font-size: 12.5px;
  padding: 5px 0; color: var(--text-dim);
}
.competitor-row b { color: var(--text); }

.deal-actions { display: flex; gap: var(--sp-2); margin-top: var(--sp-1); flex-wrap: wrap; }
.deal-actions > * { flex: 1 1 130px; }

/* ---------- Buttons ---------- */
button {
  background: var(--accent); color: #0d1520; border: none; border-radius: var(--r-md);
  padding: 13px 18px; font-size: 15px; font-weight: 700; cursor: pointer;
  min-height: 48px; flex: 1;
  transition: transform 0.1s ease, opacity 0.15s ease;
}
button:active { transform: scale(0.97); opacity: 0.88; }
button:disabled { opacity: 0.35; }
button.secondary { background: var(--surface-3); color: var(--text); border: 1px solid var(--border); }
button.danger { background: var(--bad-soft); color: var(--bad); }

/* ---------- Inputs: помітно світліші за картку, щоб не зливались ---------- */
input, select, textarea {
  width: 100%; padding: 13px 14px; margin-bottom: var(--sp-2);
  border-radius: var(--r-md); border: 1.5px solid var(--border);
  background: var(--surface-2); color: var(--text);
  font-size: 16px; min-height: 48px; font-family: inherit;
}
textarea { min-height: 76px; resize: vertical; }
input::placeholder { color: var(--text-faint); }
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: none; border-color: var(--accent); background: var(--surface-3);
}

/* ---------- Collapsible admin groups ---------- */
details.card { padding: 0; overflow: hidden; }
details.card > summary {
  list-style: none; cursor: pointer; padding: var(--sp-4);
  display: flex; justify-content: space-between; align-items: center;
  font-size: 15px; font-weight: 600; color: var(--text); min-height: 52px;
}
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::after {
  content: "›"; color: var(--accent); font-size: 22px; font-weight: 700;
  transform: rotate(90deg); transition: transform 0.15s ease;
}
details.card[open] > summary {
  border-bottom: 1px solid var(--border-soft);
}
details.card[open] > summary::after { transform: rotate(-90deg); }

/* Явна обгортка для вмісту акордеону — НЕ покладаємось на сусідні
   селектори (~ *), вони раніше плуталися і давали непередбачувані
   відступи. Просто клас з фіксованим padding з усіх боків. */
.details-body { padding: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-3); }
.details-body > *:first-child { margin-top: 0; }

/* ---------- Filters ---------- */
.filters-bar { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin-bottom: var(--sp-4); padding-bottom: 2px; }
.filters-bar::-webkit-scrollbar { display: none; }
.filters-bar select { flex: 0 0 auto; width: auto; min-width: 108px; margin-bottom: 0; padding: 9px 10px; font-size: 13px; min-height: 40px; }

.metric-row { display: flex; justify-content: space-between; font-size: 14px; padding: 8px 0; border-bottom: 1px solid var(--border-soft); color: var(--text); }
.metric-row:last-child { border-bottom: none; }
.metric-row b { font-size: 16px; }

.timeline-item { font-size: 11.5px; color: var(--text-dim); padding: 3px 0 3px 8px; border-left: 2px solid var(--accent); margin-bottom: 3px; }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: flex-end; justify-content: center; z-index: 100;
}
.modal.hidden { display: none; }
.modal-content {
  background: var(--surface); width: 100%; max-width: 560px;
  padding: var(--sp-5) var(--sp-4) calc(var(--sp-4) + var(--safe-bottom));
  border-radius: 22px 22px 0 0;
  border: 1px solid var(--border); border-bottom: none;
}
.modal-content h3 { margin: 0 0 var(--sp-4); font-size: 16px; font-weight: 700; color: var(--text); }
.modal-actions { display: flex; gap: var(--sp-2); margin-top: var(--sp-3); }

.empty-state { text-align: center; color: var(--text-faint); padding: 40px 0; font-size: 14px; }
