/* --acc* — акцент темы. Задаётся из JS (app.js::applyTheme) и может быть любого цвета,
   поэтому переменные названы нейтрально: «--red» со значением зелёного — верный способ
   запутать себя же через полгода. Значения ниже — дефолтная чёрно-красная тема. */
:root {
  --bg: #08070a;
  --bg-2: #0e0c10;
  --card: #131016;
  --card-2: #191419;
  --line: #2a1f26;
  --line-2: #3a2830;
  --txt: #ececf0;
  --txt-dim: #9a8f96;
  --txt-mute: #6b6169;
  --acc: #ff2d3f;
  --acc-bright: #ff4d5e;
  --acc-deep: #b3121f;
  --acc-glow: rgba(255, 45, 63, .35);
  --ok: #26d07c;
  --warn: #ffb02e;
  --bad: #ff2d3f;
  --r: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; min-height: 100%;
  background:
    radial-gradient(1100px 600px at 82% -12%, rgba(255, 45, 63, .14), transparent 62%),
    radial-gradient(760px 460px at 8% 108%, rgba(255, 45, 63, .09), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--txt);
  font: 15px/1.5 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg-2); }
::-webkit-scrollbar-thumb { background: linear-gradient(var(--acc-deep), #6d0a13); border-radius: 6px; border: 2px solid var(--bg-2); }
::-webkit-scrollbar-thumb:hover { background: linear-gradient(var(--acc), var(--acc-deep)); }

/* канвас атомов лежит поверх, но клики проходят сквозь (pointer-events в atoms.js) */
#atoms { position: fixed; inset: 0; }

/* ── типовые элементы ───────────────────────────────────── */
button {
  font: inherit; cursor: pointer; border-radius: 9px; border: 1px solid var(--line-2);
  background: var(--card-2); color: var(--txt); padding: 9px 14px;
  transition: .15s border-color, .15s background, .15s transform;
}
button:hover { border-color: var(--acc); background: #221a20; }
button:active { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: not-allowed; }

.btn-red {
  background: linear-gradient(180deg, var(--acc), var(--acc-deep));
  border-color: var(--acc-deep); color: #fff; font-weight: 600;
  box-shadow: 0 4px 18px -6px var(--acc-glow);
}
.btn-red:hover { background: linear-gradient(180deg, var(--acc-bright), var(--acc)); border-color: var(--acc); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.btn-danger { border-color: #5c1420; color: #ff8b96; }
.btn-danger:hover { background: #2a1015; border-color: var(--acc); }

input, textarea, select {
  font: inherit; width: 100%; padding: 10px 12px; border-radius: 9px;
  border: 1px solid var(--line); background: #0c0a0e; color: var(--txt); outline: none;
  transition: .15s border-color, .15s box-shadow;
}
input:focus, textarea:focus, select:focus { border-color: var(--acc); box-shadow: 0 0 0 3px rgba(255, 45, 63, .12); }
input::placeholder, textarea::placeholder { color: var(--txt-mute); }
label { display: block; font-size: 12px; color: var(--txt-dim); margin: 0 0 5px; letter-spacing: .3px; }
.field { margin-bottom: 12px; }
.hint { font-size: 12px; color: var(--txt-mute); margin-top: 5px; }

.card {
  background: linear-gradient(180deg, var(--card), var(--bg-2));
  border: 1px solid var(--line); border-radius: var(--r); padding: 16px;
}

.row { display: flex; gap: 10px; align-items: center; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--txt-dim); }
.mono { font-family: 'Cascadia Code', Consolas, monospace; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ── вход ───────────────────────────────────────────────── */
#login-screen {
  position: relative; z-index: 2;
  min-height: 100vh; display: grid; place-items: center; padding: 20px;
}
.login-box { width: 100%; max-width: 380px; }
.login-logo {
  font-size: 30px; font-weight: 800; letter-spacing: 5px; text-align: center; margin-bottom: 4px;
  background: linear-gradient(180deg, #fff, var(--acc)); -webkit-background-clip: text;
  background-clip: text; color: transparent;
}
.login-sub { text-align: center; color: var(--txt-mute); font-size: 13px; margin-bottom: 22px; }

/* ── каркас приложения ──────────────────────────────────── */
#app { position: relative; z-index: 2; min-height: 100vh; display: flex; flex-direction: column; }

header.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px; padding: 11px 18px;
  background: rgba(10, 8, 11, .85); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; letter-spacing: 3px; color: var(--acc); }
.role-chip {
  font-size: 11px; padding: 3px 9px; border-radius: 999px;
  border: 1px solid var(--line-2); color: var(--txt-dim); text-transform: uppercase; letter-spacing: 1px;
}

.tabs { display: flex; gap: 4px; padding: 0 18px; border-bottom: 1px solid var(--line); background: rgba(10, 8, 11, .6); }
.tab {
  position: relative; padding: 10px 14px; border: 0; background: transparent; color: var(--txt-dim);
  border-radius: 0; border-bottom: 2px solid transparent;
}
.tab:hover { background: transparent; color: var(--txt); border-color: var(--line-2); }
.tab.active { color: var(--acc-bright); border-bottom-color: var(--acc); }
.tab .badge {
  position: absolute; top: 4px; right: 2px; min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 999px; background: var(--acc); color: #fff; font-size: 10px; line-height: 16px; font-weight: 700;
}

main { flex: 1; padding: 18px; max-width: 1200px; width: 100%; margin: 0 auto; }
.pane { display: none; }
.pane.active { display: block; }

/* ── список сделок ──────────────────────────────────────── */
.deal {
  background: linear-gradient(180deg, var(--card), var(--bg-2));
  border: 1px solid var(--line); border-radius: var(--r); padding: 14px; margin-bottom: 10px;
  transition: .15s border-color, .15s transform;
}
.deal:hover { border-color: var(--line-2); }
.deal.hot { border-color: var(--acc); box-shadow: 0 0 0 1px var(--acc-glow), 0 8px 30px -14px var(--acc-glow); }
.deal-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.deal-id { font-size: 12px; color: var(--txt-mute); }
.deal-acc { font-weight: 700; font-size: 16px; }
.deal-price { margin-left: auto; font-size: 18px; font-weight: 800; color: var(--acc-bright); }
.deal-body { margin-top: 10px; display: grid; gap: 8px; }
.deal-actions { margin-top: 12px; display: flex; gap: 8px; flex-wrap: wrap; }

.status {
  font-size: 11px; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--line-2);
  color: var(--txt-dim); letter-spacing: .4px; white-space: nowrap;
}
.status.new    { border-color: var(--acc); color: var(--acc-bright); }
.status.priced { border-color: #8a6a1e; color: var(--warn); }
.status.agreed { border-color: #1e6a4a; color: var(--ok); }
.status.payout { border-color: #6a3a8a; color: #c98bff; }
.status.done   { border-color: var(--line-2); color: var(--txt-mute); }

/* ── шкала стадий ───────────────────────────────────────── */
.steps { display: flex; gap: 6px; margin: 12px 0 2px; }
.step {
  flex: 1; text-align: center; font-size: 10px; color: var(--txt-mute);
  padding-top: 8px; border-top: 3px solid var(--line); letter-spacing: .2px;
}
.step.on { color: var(--acc-bright); border-top-color: var(--acc); }
.step.done { color: var(--txt-dim); border-top-color: var(--acc-deep); }

/* ── калькуляция ────────────────────────────────────────── */
table.calc { width: 100%; border-collapse: collapse; font-size: 13px; }
table.calc th {
  text-align: left; font-size: 11px; color: var(--txt-mute); text-transform: uppercase;
  letter-spacing: .6px; padding: 6px 8px; border-bottom: 1px solid var(--line);
}
table.calc td { padding: 8px; border-bottom: 1px solid var(--line); }
table.calc tr.owner td { color: var(--warn); }
table.calc tr.total td { font-weight: 800; border-top: 2px solid var(--line-2); border-bottom: 0; font-size: 15px; }
table.calc td.amt { text-align: right; font-weight: 700; color: var(--acc-bright); white-space: nowrap; }
table.calc td.pct { text-align: right; color: var(--txt-dim); white-space: nowrap; }
.wallet-row { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; }
.wallet-row input.w { flex: 1; }
.wallet-row input.p { width: 90px; }
.sum-warn { color: var(--warn); font-size: 12px; }
.sum-ok { color: var(--ok); font-size: 12px; }

/* ── чат ────────────────────────────────────────────────── */
.chat-wrap { display: flex; flex-direction: column; height: 460px; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; background: var(--bg-2); }
.chat-head { padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--card); font-size: 13px; }
.chat-log { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 74%; padding: 8px 12px; border-radius: 12px; background: var(--card-2); border: 1px solid var(--line); font-size: 14px; word-break: break-word; }
.msg.me { align-self: flex-end; background: linear-gradient(180deg, #4a0f18, #2e0a10); border-color: var(--acc-deep); }
.msg .who { font-size: 10px; color: var(--txt-mute); margin-bottom: 3px; text-transform: uppercase; letter-spacing: .5px; }
.msg .time { font-size: 10px; color: var(--txt-mute); margin-top: 3px; text-align: right; }
.msg img { max-width: 100%; border-radius: 8px; cursor: zoom-in; display: block; margin-top: 4px; }
.chat-input { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); background: var(--card); }
.chat-input textarea { resize: none; height: 40px; max-height: 120px; }

#lightbox {
  position: fixed; inset: 0; z-index: 9999; background: rgba(0, 0, 0, .92);
  display: none; place-items: center; padding: 30px; cursor: zoom-out;
}
#lightbox.on { display: grid; }
#lightbox img { max-width: 100%; max-height: 100%; border-radius: 10px; }

/* ── тосты ──────────────────────────────────────────────── */
#toasts { position: fixed; top: 14px; right: 14px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; max-width: 340px; }
.toast {
  background: linear-gradient(180deg, var(--card-2), var(--card)); border: 1px solid var(--acc-deep);
  border-left: 3px solid var(--acc); border-radius: 10px; padding: 10px 14px; font-size: 13px;
  box-shadow: 0 10px 34px -12px #000; animation: slide .25s ease-out;
}
@keyframes slide { from { transform: translateX(20px); opacity: 0; } }

/* ── таблица юзеров ─────────────────────────────────────── */
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th { text-align: left; font-size: 11px; color: var(--txt-mute); text-transform: uppercase; letter-spacing: .6px; padding: 8px; border-bottom: 1px solid var(--line-2); }
table.grid td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.grid tr:hover td { background: rgba(255, 45, 63, .04); }

.empty { text-align: center; color: var(--txt-mute); padding: 40px 20px; font-size: 14px; }
.sec-title { font-size: 12px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--txt-mute); margin: 22px 0 10px; }
.sec-title:first-child { margin-top: 0; }

/* ── плитки статистики ──────────────────────────────────── */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.tile { background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 13px; }
.tile-label { font-size: 11px; color: var(--txt-mute); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 6px; }
.tile-value { font-size: 23px; font-weight: 800; line-height: 1.15; }

/* ── шапка заявки на оплату (видно, что делим 90%) ──────── */
.payout-head {
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg-2);
  padding: 12px; font-size: 14px;
}
.ph-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 5px 0; }
.ph-row b { white-space: nowrap; }
.ph-row.cut { color: var(--warn); border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.ph-row.cut i { font-size: 11px; color: var(--txt-mute); font-style: normal; }
.ph-row.base { padding-top: 9px; font-size: 15px; }
.ph-row.base b { font-size: 19px; color: var(--acc-bright); }
.ph-owners { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 11px; color: var(--txt-mute); padding-bottom: 6px; }

/* ── ставки скупщиков ───────────────────────────────────── */
.bid {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  margin-bottom: 8px; background: var(--bg-2);
}
.bid.best { border-color: var(--acc); box-shadow: 0 0 0 1px var(--acc-glow); }
.bid-name { font-weight: 700; }
.bid-price { font-size: 18px; font-weight: 800; color: var(--acc-bright); }
.bid-note { width: 100%; font-size: 12px; color: var(--txt-dim); }

/* ── ветки чата (у продавца свой чат с каждым) ──────────── */
.thread-tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; }
.thread-tab {
  position: relative; white-space: nowrap; font-size: 13px; padding: 7px 12px;
  border: 1px solid var(--line); background: var(--bg-2); color: var(--txt-dim);
}
.thread-tab.on { border-color: var(--acc); color: var(--acc-bright); background: var(--card-2); }
.thread-tab .badge {
  display: inline-block; min-width: 16px; height: 16px; padding: 0 4px; margin-left: 6px;
  border-radius: 999px; background: var(--acc); color: #fff; font-size: 10px; line-height: 16px; font-weight: 700;
}

/* системная строка в чате — не «сообщение», а отметка события */
.msg.sys {
  align-self: center; max-width: 92%; background: transparent; border: 1px dashed var(--line-2);
  color: var(--txt-mute); font-size: 12px; text-align: center; padding: 5px 12px;
}

/* ── прогресс массовой загрузки ─────────────────────────── */
.progress { margin-top: 12px; }
.bar { height: 8px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--acc-deep), var(--acc)); transition: width .2s; }
.bar-text { font-size: 12px; color: var(--txt-dim); margin-top: 5px; text-align: center; }

/* широкие таблицы скроллятся сами, а не растягивают страницу вбок */
.tbl-scroll { overflow-x: auto; }

/* ── модалки (звуки, темы, заставка) ────────────────────── */
.modal {
  position: fixed; inset: 0; z-index: 9998; background: rgba(0, 0, 0, .78);
  display: none; place-items: center; padding: 20px; backdrop-filter: blur(3px);
}
.modal.on { display: grid; }
.modal-box {
  background: linear-gradient(180deg, var(--card), var(--bg-2));
  border: 1px solid var(--line-2); border-radius: 14px; padding: 20px;
  width: 100%; max-width: 560px; max-height: 86vh; overflow-y: auto;
  box-shadow: 0 30px 80px -20px #000;
}
.modal-head { display: flex; align-items: center; margin-bottom: 16px; }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-head button { margin-left: auto; }

/* ── строки звуков ──────────────────────────────────────── */
.snd-row { padding: 12px 0; border-bottom: 1px solid var(--line); }
.snd-row:last-child { border-bottom: 0; }
.snd-name { font-weight: 600; font-size: 14px; margin-bottom: 2px; }
.snd-desc { font-size: 12px; color: var(--txt-mute); margin-bottom: 8px; }
.snd-ctl { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.snd-ctl select { width: auto; flex: 1; min-width: 130px; padding: 6px 10px; }
.snd-vol { display: flex; align-items: center; gap: 6px; min-width: 130px; }
.snd-vol input[type=range] { width: 90px; padding: 0; accent-color: var(--acc); }
.snd-vol span { font-size: 11px; color: var(--txt-mute); width: 30px; }

/* ── темы ───────────────────────────────────────────────── */
.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.theme-card {
  border: 2px solid var(--line); border-radius: 10px; padding: 10px; cursor: pointer;
  background: var(--bg-2); text-align: center; transition: .15s border-color, .15s transform;
}
.theme-card:hover { transform: translateY(-2px); }
.theme-card.on { border-color: var(--acc); }
.theme-dot { width: 100%; height: 26px; border-radius: 6px; margin-bottom: 7px; }
.theme-card span { font-size: 11px; color: var(--txt-dim); }

/* ── хранилище ботов ────────────────────────────────────── */
.bot-row {
  display: flex; gap: 10px; align-items: center; padding: 10px;
  border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; background: var(--bg-2);
  flex-wrap: wrap;
}
.bot-row.bad { border-color: var(--bad); background: rgba(255, 45, 63, .05); }
.bot-row.sent { opacity: .55; }
.bot-login { font-weight: 700; font-family: 'Cascadia Code', Consolas, monospace; }
.chk { font-size: 11px; padding: 3px 8px; border-radius: 999px; white-space: nowrap; }
.chk.ok { border: 1px solid #1e6a4a; color: var(--ok); }
.chk.bad { border: 1px solid var(--bad); color: var(--acc-bright); }
.entries {
  font-family: 'Cascadia Code', Consolas, monospace; font-size: 11px; color: var(--txt-dim);
  background: #0a0810; border: 1px solid var(--line); border-radius: 8px;
  padding: 8px; margin-top: 8px; max-height: 150px; overflow: auto; white-space: pre-wrap; word-break: break-all;
}
.danger-box {
  border: 1px solid var(--bad); background: rgba(255, 45, 63, .08);
  border-radius: 10px; padding: 12px; margin-top: 10px; font-size: 13px;
}
.danger-box b { color: var(--acc-bright); }
.ok-box {
  border: 1px solid #1e6a4a; background: rgba(38, 208, 124, .07);
  border-radius: 10px; padding: 12px; margin-top: 10px; font-size: 13px;
}

/* ── заставка после отправки формы ──────────────────────── */
#submit-modal .modal-box { max-width: 460px; text-align: center; }
#submit-modal img { max-width: 100%; border-radius: 10px; margin-bottom: 14px; }
#submit-modal .big { font-size: 19px; font-weight: 700; margin-bottom: 6px; }

.drop {
  border: 2px dashed var(--line-2); border-radius: 10px; padding: 20px; text-align: center;
  color: var(--txt-mute); font-size: 13px; cursor: pointer; transition: .15s border-color, .15s color;
}
.drop:hover, .drop.over { border-color: var(--acc); color: var(--txt-dim); }

/* ══ телефон ══════════════════════════════════════════════
   Главное правило: страница НИКОГДА не едет вбок. Всё широкое
   (таблицы, ветки чата, вкладки) скроллится внутри себя. */
@media (max-width: 720px) {
  html, body { overflow-x: hidden; }
  main { padding: 10px; }

  header.top { padding: 9px 10px; gap: 7px; }
  .brand { font-size: 14px; letter-spacing: 2px; }
  .role-chip { display: none; }              /* роль и так видна по содержимому */
  #who { display: none; }                    /* имя не влезает — оно есть в «Выйти» рядом */
  header.top button { padding: 7px 9px; }

  .tabs { padding: 0 4px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { padding: 10px 11px; font-size: 13px; white-space: nowrap; }

  .card { padding: 13px; }
  .deal { padding: 12px; }
  .deal-acc { font-size: 15px; }
  .deal-price { margin-left: 0; font-size: 16px; }
  .deal-head { gap: 7px; }

  /* 6 стадий в строку не помещаются — оставляем подписи только у соседних */
  .steps { gap: 3px; }
  .step { font-size: 9px; padding-top: 6px; }

  /* поля ввода: строго 16px, иначе iOS зумит страницу при фокусе.
     Уменьшать шрифт у select тут нельзя — зум вернётся. */
  input, textarea, select { font-size: 16px; padding: 11px; }
  .thread-tab { font-size: 14px; }   /* это кнопка, не поле — зум ей не грозит */

  .wallet-row { flex-wrap: wrap; gap: 6px; }
  .wallet-row input.w { flex: 1 1 100%; }
  .wallet-row input.p { width: 80px; }

  .bid { padding: 10px; }
  .bid-price { font-size: 16px; }
  .bid button { flex: 1; }                   /* кнопки во всю ширину — попасть пальцем */

  .chat-wrap { height: 68vh; }
  .msg { max-width: 90%; }
  .chat-input { padding: 8px; }
  .chat-input textarea { height: 44px; }

  .modal { padding: 10px; }
  .modal-box { padding: 15px; max-height: 92vh; }
  .theme-grid { grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 8px; }

  .bot-row { gap: 7px; padding: 9px; }
  .bot-row button { flex: 1; }

  .tiles { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .tile { padding: 11px; }
  .tile-value { font-size: 19px; }
  .payout-head { font-size: 13px; padding: 11px; }
  .ph-row.base b { font-size: 17px; }

  table.calc { font-size: 12px; }
  table.calc td, table.calc th { padding: 6px 5px; }
  table.grid { font-size: 12px; }
  table.grid td, table.grid th { padding: 6px 5px; }

  #toasts { left: 10px; right: 10px; max-width: none; }
  .drop { padding: 16px 10px; }
}

/* очень узкие экраны */
@media (max-width: 380px) {
  .step { font-size: 8px; }
  .brand { display: none; }
}
