/* Диспетчерская — тёмная по умолчанию, светлая по системной настройке или кнопке «Тема».
   Янтарный — только то, что ждёт вашего действия. Зелёный — деньги. Красный — сбои. */
:root {
  --bg: #172029; --panel: #1E2833; --raise: #263240; --line: #2D3a48;
  --ink: #E3E8EE; --muted: #8B98A7; --faint: #5F6C7B;
  --amber: #F0A92E; --amber-bg: rgba(240,169,46,.10);
  --green: #4FBF8B; --red: #E2626A; --blue: #7FA8FF;
  --fp: #7FA8FF; --po: #C29BFF; --iz: #45C7BE; --on-amber: #1A1205;
  --r: 6px;
  --font: "Onest", system-ui, -apple-system, "Segoe UI", sans-serif;
}
:root[data-theme="light"] {
  --bg: #EFF2F5; --panel: #FFFFFF; --raise: #F5F7F9; --line: #DAE0E6;
  --ink: #17202A; --muted: #5C6977; --faint: #8C97A3;
  --amber: #A86A00; --amber-bg: rgba(214,140,0,.10);
  --green: #1B8455; --red: #BF3842; --blue: #2E5FD1;
  --fp: #2E5FD1; --po: #7A45D6; --iz: #138A82; --on-amber: #FFFFFF;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #EFF2F5; --panel: #FFFFFF; --raise: #F5F7F9; --line: #DAE0E6;
    --ink: #17202A; --muted: #5C6977; --faint: #8C97A3;
    --amber: #A86A00; --amber-bg: rgba(214,140,0,.10);
    --green: #1B8455; --red: #BF3842; --blue: #2E5FD1;
    --fp: #2E5FD1; --po: #7A45D6; --iz: #138A82; --on-amber: #FFFFFF;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 15px/1.5 var(--font); font-variant-numeric: tabular-nums; -webkit-font-smoothing: antialiased; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; border-radius: 3px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--red); min-height: 1.5em; margin: .5rem 0 0; }
.pos { color: var(--green); } .neg { color: var(--red); }

/* --- каркас --- */
.shell { display: grid; grid-template-columns: 196px minmax(0, 1fr); min-height: 100vh; }
.rail { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 2px;
  padding: 20px 12px; border-right: 1px solid var(--line); background: var(--panel); }
.brand { font-weight: 700; font-size: 16px; letter-spacing: -.01em; padding: 0 10px 18px; }
.rail a { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px;
  border-radius: var(--r); color: var(--muted); font-weight: 500; }
.rail a:hover { background: var(--raise); color: var(--ink); text-decoration: none; }
.rail a[aria-current="page"] { background: var(--raise); color: var(--ink); }
.count { background: var(--amber); color: var(--on-amber); border-radius: 10px; padding: 0 7px; font-size: 12px; font-weight: 700; }
.rail-foot { margin-top: auto; display: flex; flex-wrap: wrap; gap: 6px 12px; padding: 0 10px; }
#sound[aria-pressed="true"] { color: var(--amber); }
main { padding: 28px 36px 64px; max-width: 1240px; width: 100%; min-width: 0; outline: none; }
h1 { font-size: 26px; line-height: 1.2; letter-spacing: -.02em; margin: 0; font-weight: 700; }
h2 { font-size: 17px; margin: 36px 0 12px; font-weight: 600; letter-spacing: -.01em; }
.head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.head .muted { font-size: 13px; }

/* --- кнопки и поля --- */
.btn { text-decoration: none !important; display: inline-block; font: inherit; font-weight: 600; font-size: 14px; border: 1px solid var(--line); background: var(--raise);
  color: var(--ink); padding: 7px 14px; border-radius: var(--r); cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--faint); }
.btn.primary { background: var(--amber); border-color: var(--amber); color: var(--on-amber); }
.btn.quiet { background: transparent; }
.btn.danger { color: var(--red); background: transparent; }
.btn:disabled { opacity: .5; cursor: default; }
.link { background: none; border: 0; padding: 0; color: var(--muted); font: inherit; font-size: 13px; cursor: pointer; }
.link:hover { color: var(--ink); }
input, select, textarea { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line);
  border-radius: var(--r); padding: 7px 10px; }
textarea { resize: vertical; min-height: 38px; width: 100%; font-size: 14px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin: 20px 0 12px; align-items: center; }
.filters input[type=search] { min-width: 240px; flex: 1; max-width: 360px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.seg button { font: inherit; font-size: 13px; background: transparent; color: var(--muted); border: 0;
  padding: 6px 12px; cursor: pointer; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--raise); color: var(--ink); font-weight: 600; }

/* --- очередь действий: главный элемент панели --- */
.queue { margin-top: 20px; display: flex; flex-direction: column; gap: 10px; }
.job { display: grid; grid-template-columns: 1fr auto; gap: 10px 24px; padding: 16px 18px 16px 20px;
  background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--amber);
  border-radius: var(--r); }
.job.attention { border-left-color: var(--red); }
.job .what { font-size: 13px; color: var(--amber); font-weight: 600; }
.job.attention .what { color: var(--red); }
.job .name { font-size: 18px; font-weight: 600; letter-spacing: -.01em; margin: 2px 0 4px; }
.job .meta { color: var(--muted); font-size: 13px; display: flex; gap: 14px; flex-wrap: wrap; }
.job .limit { color: var(--ink); font-weight: 600; }
.job .act { display: flex; flex-direction: column; gap: 8px; align-items: stretch; min-width: 260px; }
.job .row { display: flex; gap: 8px; justify-content: flex-end; }
.job .goods { grid-column: 1 / -1; background: var(--bg); border: 1px dashed var(--line); border-radius: var(--r);
  padding: 8px 10px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; }
.empty { padding: 28px 20px; border: 1px dashed var(--line); border-radius: var(--r); color: var(--muted); }
.empty b { color: var(--ink); font-weight: 600; display: block; margin-bottom: 2px; }

/* --- деньги и здоровье --- */
.ledger { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); border-radius: var(--r);
  background: var(--panel); }
.ledger > div { padding: 14px 18px; border-right: 1px solid var(--line); }
.ledger > div:last-child { border-right: 0; }
.ledger .k { color: var(--muted); font-size: 13px; }
.ledger .v { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.ledger .s { color: var(--muted); font-size: 13px; }
.split { display: grid; grid-template-columns: 1.6fr 1fr; gap: 28px; align-items: start; }
.chart { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 14px 6px; }
.chart svg { display: block; width: 100%; height: 140px; }
.chart .bar { fill: var(--green); opacity: .85; }
.chart .bar.zero { fill: var(--line); opacity: 1; }
.chart .bar:hover { opacity: 1; }
.chart .axis { fill: var(--faint); font-size: 10px; font-family: var(--font); }
.chart-cap { color: var(--muted); font-size: 13px; min-height: 1.5em; padding: 4px 2px; }
.checks { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--r);
  background: var(--panel); }
.checks li { display: flex; justify-content: space-between; gap: 12px; padding: 9px 14px; border-bottom: 1px solid var(--line); font-size: 14px; }
.checks li:last-child { border-bottom: 0; }
.checks .ok::before, .checks .warn::before, .checks .bad::before { content: ""; display: inline-block;
  width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; vertical-align: 1px; }
.checks .ok::before { background: var(--green); } .checks .warn::before { background: var(--amber); }
.checks .bad::before { background: var(--red); }

/* --- таблицы --- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: 13px; padding: 9px 12px;
  border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--raise); }
td.num, th.num { text-align: right; }
td.title { max-width: 420px; }
td.title small { display: block; color: var(--muted); }
.mp { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.mp::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: var(--faint); }
.mp.funpay::before { background: var(--fp); } .mp.playerok::before { background: var(--po); }
.mp.izi::before { background: var(--iz); }
.st { white-space: nowrap; font-size: 13px; }
.st.delivered { color: var(--green); } .st.needs_attention, .st.refunded { color: var(--red); }
.st.manual_delivery, .st.awaiting_goods, .st.new, .st.purchasing, .st.goods_ready { color: var(--amber); }
.flag { font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; margin-left: 6px; }
.flag.pin { color: var(--blue); border-color: var(--blue); }
.acts { display: flex; gap: 6px; justify-content: flex-end; }
.price-edit { width: 90px; text-align: right; }
td .link[data-price] { color: var(--ink); font-size: 14px; border-bottom: 1px dotted var(--faint); }

/* --- чаты --- */
.chat-layout { display: grid; grid-template-columns: 300px 1fr; gap: 0; margin-top: 20px; height: calc(100vh - 150px);
  min-height: 420px; border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); overflow: hidden; }
.chat-list { border-right: 1px solid var(--line); overflow-y: auto; }
.chat-list a { display: block; padding: 10px 14px; border-bottom: 1px solid var(--line); color: var(--ink); }
.chat-list a:hover { background: var(--raise); text-decoration: none; }
.chat-list a[aria-current="true"] { background: var(--raise); box-shadow: inset 3px 0 0 var(--blue); }
.chat-list .who { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; font-size: 14px; }
.chat-list .who time { color: var(--muted); font-weight: 400; font-size: 12px; }
.chat-list .last { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-list .unread .last { color: var(--ink); }
.chat-list .dot { display: inline-block; min-width: 18px; text-align: center; background: var(--amber); color: var(--on-amber);
  border-radius: 9px; font-size: 11px; font-weight: 700; padding: 0 5px; margin-left: 6px; }
.thread { display: flex; flex-direction: column; min-width: 0; }
.thread-head { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; gap: 14px; align-items: baseline; flex-wrap: wrap; }
.thread-head b { font-size: 16px; }
.msgs { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 72%; padding: 8px 12px; border-radius: 10px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; }
.msg.buyer { align-self: flex-start; background: var(--raise); border-bottom-left-radius: 3px; }
.msg.me { align-self: flex-end; background: var(--amber-bg); border: 1px solid var(--line); border-bottom-right-radius: 3px; }
.msg.system { align-self: center; color: var(--muted); font-size: 12px; background: none; }
.msg time { display: block; color: var(--faint); font-size: 11px; margin-top: 2px; }
.msg.pending { opacity: .6; } .msg.failed { border-color: var(--red); }
.composer { border-top: 1px solid var(--line); padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font: inherit; font-size: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--muted);
  border-radius: 12px; padding: 2px 10px; cursor: pointer; }
.chip:hover { color: var(--ink); border-color: var(--faint); }
.composer .row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { flex: 1; }
.thread-empty { margin: auto; color: var(--muted); text-align: center; padding: 20px; }

/* --- ответы --- */
.edit-list { display: flex; flex-direction: column; gap: 10px; }
.edit-row { display: grid; grid-template-columns: 200px 1fr auto; gap: 10px; align-items: start; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--r); padding: 12px; }
.edit-row.off { opacity: .55; }
.edit-row input, .edit-row select, .edit-row textarea { width: 100%; }
.edit-row .side { display: flex; flex-direction: column; gap: 6px; }
.edit-row .acts { flex-direction: column; align-items: stretch; }
.hint { color: var(--muted); font-size: 13px; margin: -4px 0 12px; max-width: 72ch; }

/* --- склад --- */
.new-item { display: grid; grid-template-columns: minmax(0,2fr) repeat(3, minmax(0,1fr)) 110px 70px auto; gap: 8px; align-items: end;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; }
.new-item label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.qty0 { color: var(--amber); font-weight: 600; }
.keys-box { background: var(--bg); }
.keys-box td { padding: 12px; }
.keys-box textarea { min-height: 90px; }
.keys-box .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; flex-wrap: wrap; }
.peek { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.peek span { border: 1px solid var(--line); border-radius: 4px; padding: 1px 6px; font-size: 13px; color: var(--muted); }
.head .tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* --- настройки --- */
.conn { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; }
.conn + .conn { margin-top: 10px; }
.conn-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.conn-head b { font-size: 16px; }
.state { font-size: 13px; }
.state.ok { color: var(--green); } .state.warn { color: var(--amber); } .state.off { color: var(--muted); }
.switch { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); margin-left: auto; cursor: pointer; }
.secret { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; margin-top: 10px; }
.secret label { grid-column: 1 / -1; font-size: 13px; color: var(--muted); }
.opts { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.opt { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px;
  display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.opt small { color: var(--muted); }
.opt .row { display: flex; gap: 8px; } .opt .row input { flex: 1; min-width: 0; }
.apply { position: sticky; bottom: 0; margin-top: 24px; padding: 12px 16px; background: var(--panel);
  border: 1px solid var(--amber); border-radius: var(--r); display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.apply p { margin: 0; flex: 1; min-width: 220px; font-size: 14px; }

/* --- лента --- */
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: grid; grid-template-columns: 64px 120px 1fr; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.feed time { color: var(--muted); }
.feed .kind { color: var(--muted); }
.feed .kind.error, .feed .kind.alert { color: var(--red); }
.feed .kind.delivered, .feed .kind.create { color: var(--green); }
.feed .kind.attention { color: var(--amber); }
.feed li.fresh { animation: fresh 1.6s ease-out; }
@keyframes fresh { from { background: var(--amber-bg); } to { background: transparent; } }

.hours { display: grid; grid-template-columns: repeat(24, 1fr); gap: 3px; align-items: end; height: 90px; }
.hours div { background: var(--green); opacity: .8; border-radius: 2px 2px 0 0; min-height: 2px; }
.hours-axis { display: grid; grid-template-columns: repeat(24, 1fr); color: var(--faint); font-size: 10px; text-align: center; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: var(--r); font-size: 14px;
  transition: opacity .2s, transform .2s; pointer-events: none; max-width: min(560px, 90vw); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.bad { background: var(--red); color: #fff; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-box { width: min(360px, 100%); display: flex; flex-direction: column; gap: 8px; }
.login-box h1 { margin-bottom: 0; }
.login-box p { margin: 0 0 18px; }
.login-box label { font-size: 13px; color: var(--muted); }
.login-box .btn { margin-top: 8px; padding: 10px; }

@media (max-width: 900px) {
  .chat-layout { grid-template-columns: 1fr; height: auto; }
  .chat-list { max-height: 260px; border-right: 0; border-bottom: 1px solid var(--line); }
  .msgs { max-height: 55vh; }
  .edit-row { grid-template-columns: 1fr; }
  .new-item { grid-template-columns: 1fr 1fr; }
  .split { grid-template-columns: 1fr; }
  .job { grid-template-columns: 1fr; }
  .job .act { min-width: 0; }
  .job .row { justify-content: flex-start; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; align-content: start; }
  .filters input[type=search], .head .tools input[type=search] { min-width: 0; max-width: none; width: 100%; flex: 1 1 100%; }
  .table-wrap { -webkit-overflow-scrolling: touch; }
  .ap-form { grid-template-columns: 1fr; }
  .btn, .seg button, .rail a { min-height: 40px; }
  .rail { position: sticky; height: auto; flex-direction: row; overflow-x: auto; padding: 8px; z-index: 5;
    border-right: 0; border-bottom: 1px solid var(--line); }
  .brand, .rail-foot { display: none; }
  .rail a { flex: none; gap: 6px; }
  main { padding: 18px 16px 48px; }
  .ledger { grid-template-columns: 1fr; }
  .ledger > div { border-right: 0; border-bottom: 1px solid var(--line); }
  .ledger > div:last-child { border-bottom: 0; }
  .feed li { grid-template-columns: 52px 1fr; }
  .feed .kind { grid-column: 2; }
  .feed .msg { grid-column: 1 / -1; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

.offline { position: fixed; top: 0; left: 0; right: 0; z-index: 50; padding: 10px 16px; text-align: center;
  background: var(--red); color: #fff; font-weight: 600; }
.offline[hidden] { display: none; }
.msg-acts { display: flex; gap: 12px; margin-top: 4px; font-size: 12px; }
.rail .tier { margin-left: auto; font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 0 6px; }
.locked { margin-top: 16px; padding: 20px; border: 1px dashed var(--line); border-radius: 12px; max-width: 560px; }
.locked p { color: var(--muted); margin: 8px 0; } .locked ul { margin: 0; padding-left: 18px; }
.plan { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 24px; }
.plan section { border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.plan section.cur { border-color: var(--amber, var(--blue)); }
.plan ul { margin: 8px 0 0; padding-left: 18px; font-size: 13px; } .plan li.off { color: var(--muted); }
.ap-note { display: block; color: var(--muted); font-size: 11px; margin-top: 4px; max-width: 220px; }
.ap-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px 16px; align-items: end; }
.ap-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.ap-form label small { color: var(--muted); font-size: 11px; } .ap-form .wide { grid-column: 1 / -1; }
.ap-form .switch { flex-direction: row; align-items: center; gap: 8px; }
table:has(td.ap) td.title { min-width: 200px; }
.switch.ss { display: flex; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); margin-top: 6px; }
.checks .sub { font-size: 12px; padding-left: 8px; color: var(--muted); }
.licbar { padding: 8px 16px; background: var(--amber-bg); border-bottom: 1px solid var(--amber); text-align: center; font-size: 14px; }
.licbar[hidden] { display: none; } .licbar a { color: inherit; font-weight: 600; }
.onboard { border: 1px solid var(--amber); background: var(--amber-bg); border-radius: 12px; padding: 12px 16px; margin: 12px 0 20px; }
.onboard h2 { margin: 0; } .onboard ol { margin: 8px 0 0; padding-left: 22px; line-height: 1.9; }
.onboard li.done a { color: var(--muted); text-decoration: line-through; } .onboard li.done::marker { content: "✓  "; color: var(--green); }
@media (max-width: 760px) { td.title { min-width: 180px; } }
.mp-inline { display: none; }
@media (max-width: 760px) {
  table:has(td.ap) th:first-child, table:has(td.ap) td:first-child { display: none; }
  .mp-inline { display: inline; }
}
.prov { display: block; margin-top: 6px; color: var(--muted); font-size: 12px; }
.prov-results { display: flex; flex-wrap: wrap; gap: 6px; max-height: 220px; overflow: auto; font-size: 12px; }
.prov-results .chip { text-align: left; }
.st-needs_password { color: var(--amber); font-weight: 600; } .st-rented { color: var(--blue); } .st-free { color: var(--green); }

/* лоты пачкой */
details.bulk { margin: 12px 0; border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; background: var(--panel); }
details.bulk summary { cursor: pointer; font-weight: 600; }
details.bulk form { margin-top: 12px; }

/* месяц: ключевые цифры */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 8px 0 12px; }
.kpis > div { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.kpis small { display: block; opacity: .7; font-size: 12px; }
.kpis b { font-size: 18px; }

/* Telegram Mini App: цвета приходят из Telegram (app.js → tgTheme), место под вырезы экрана */
.tg body { overscroll-behavior: none; }
.tg main { padding-bottom: calc(48px + env(safe-area-inset-bottom)); }
.tg #theme { display: none; }
