:root {
  --bg: #0b0f17; --panel: #131a26; --panel2: #1a2333; --line: #243049; --text: #e6ebf5; --muted: #8a97b1;
  --accent: #14b8a6; --accent2: #0f766e; --green: #22c55e; --red: #ef4444; --orange: #f59e0b; --blue: #60a5fa;
  --radius: 14px; --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
body { min-height: 100vh; min-height: 100dvh; overscroll-behavior-y: none; }
.hidden { display: none !important; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 10px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
p { margin: 6px 0; }
.muted { color: var(--muted); }
.up, .pos { color: var(--green); } .down, .neg { color: var(--red); } .warn { color: var(--orange); }
.mono { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

/* ---------- вхід */
.login { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 20px;
  padding: 26px 22px; display: grid; gap: 14px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.brand.big { font-size: 26px; justify-content: center; margin-bottom: 6px; }
.logo { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 10px;
  background: linear-gradient(135deg, #14b8a6, #0ea5e9); color: #04121a; font-weight: 800; }
.err { color: var(--red); min-height: 1.3em; margin: 0; font-size: 14px; }

/* ---------- каркас */
.app { display: grid; grid-template-columns: 210px 1fr; grid-template-rows: auto 1fr; min-height: 100vh; min-height: 100dvh; }
.top { grid-column: 1 / 3; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: calc(10px + var(--safe-t)) 18px 10px;
  background: rgba(11,15,23,.92); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.top-info { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.chip { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: var(--panel2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.chip:empty { display: none; }
.chip.ok, .status.ok { color: var(--green); border-color: rgba(34,197,94,.4); background: rgba(34,197,94,.1); }
.chip.warn, .status.warn { color: var(--orange); border-color: rgba(245,158,11,.4); background: rgba(245,158,11,.1); }
.chip.err, .status.err { color: var(--red); border-color: rgba(239,68,68,.4); background: rgba(239,68,68,.1); }
.tabs { display: flex; flex-direction: column; gap: 4px; padding: 14px 10px; border-right: 1px solid var(--line); position: sticky; top: 56px; align-self: start; }
.tabs button { display: flex; align-items: center; gap: 10px; border: 0; background: transparent; color: var(--muted); padding: 11px 12px;
  border-radius: 10px; font: inherit; cursor: pointer; text-align: left; }
.tabs button i { font-style: normal; width: 20px; text-align: center; font-size: 17px; }
.tabs button:hover { background: var(--panel); color: var(--text); }
.tabs button.active { background: var(--panel2); color: var(--text); box-shadow: inset 3px 0 0 var(--accent); }
main { padding: 18px; min-width: 0; max-width: 1180px; width: 100%; }
.tab { display: none; } .tab.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- елементи */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.grid { display: grid; gap: 14px; } .g2 { grid-template-columns: 1fr 1fr; } .g3 { grid-template-columns: repeat(3, 1fr); }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 14px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; min-width: 0; }
.kpi .l { color: var(--muted); font-size: 12px; } .kpi .v { font-size: 20px; font-weight: 650; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; }
.kpi .s { color: var(--muted); font-size: 12px; margin-top: 2px; }
.kpi.big .v { font-size: 26px; }
.btn { border: 1px solid var(--line); background: var(--panel2); color: var(--text); padding: 11px 16px; border-radius: 11px; font: inherit; font-weight: 600; cursor: pointer; min-height: 44px; }
.btn:hover { border-color: #38507d; } .btn:active { transform: scale(.98); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #031a17; }
.btn.danger { background: rgba(239,68,68,.14); border-color: rgba(239,68,68,.5); color: #ff9a9a; }
.btn.small { padding: 6px 10px; min-height: 34px; font-size: 13px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.controls { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
label { display: grid; gap: 5px; font-size: 13px; color: var(--muted); }
input, select { width: 100%; background: #0e1522; border: 1px solid var(--line); color: var(--text); border-radius: 10px; padding: 10px 12px; font: inherit; font-size: 16px; min-height: 44px; }
input:focus, select:focus { outline: 2px solid rgba(20,184,166,.5); border-color: var(--accent); }
input[type=checkbox] { width: 22px; height: 22px; min-height: 0; accent-color: var(--accent); }
.check { display: flex; align-items: center; gap: 10px; color: var(--text); font-size: 14px; }
.seg { display: inline-flex; background: #0e1522; border: 1px solid var(--line); border-radius: 11px; padding: 3px; gap: 3px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; color: var(--muted); padding: 8px 12px; border-radius: 8px; font: inherit; cursor: pointer; min-height: 38px; }
.seg button.on { background: var(--accent); color: #031a17; font-weight: 650; }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; align-items: end; }
.fields .wide { grid-column: 1 / -1; }
.hint { font-size: 12px; color: var(--muted); margin-top: 3px; }
.note { padding: 10px 12px; border-radius: 10px; font-size: 13px; background: rgba(96,165,250,.1); border: 1px solid rgba(96,165,250,.3); color: #bcd7ff; margin: 8px 0; }
.note.warn { background: rgba(245,158,11,.1); border-color: rgba(245,158,11,.4); color: #ffd58a; }
.note.err { background: rgba(239,68,68,.1); border-color: rgba(239,68,68,.4); color: #ffb0b0; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: right; color: var(--muted); font-weight: 600; font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--line); }
td { text-align: right; padding: 8px; border-bottom: 1px solid rgba(36,48,73,.6); }
th:first-child, td:first-child { text-align: left; }
tr.filled td { color: var(--green); } tr.placed td { color: var(--orange); } tr.liq td { color: var(--red); }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.badge.filled { color: var(--green); border-color: rgba(34,197,94,.5); } .badge.placed { color: var(--orange); border-color: rgba(245,158,11,.5); }
.scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
canvas.chart { width: 100%; height: 300px; display: block; border-radius: 10px; background: #0e1522; }
.steps { display: grid; gap: 8px; }
.step { display: grid; grid-template-columns: 22px 1fr auto; gap: 10px; align-items: center; font-size: 14px; }
.step .dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line); }
.step.done .dot { background: var(--green); border-color: var(--green); } .step.active .dot { border-color: var(--orange); background: rgba(245,158,11,.3); animation: pulse 1s infinite; }
.step.skip .dot { background: var(--muted); border-color: var(--muted); opacity: .5; }
.step .bar { grid-column: 2 / 4; height: 3px; background: var(--line); border-radius: 3px; overflow: hidden; }
.step .bar b { display: block; height: 100%; background: var(--orange); width: 0; transition: width .4s linear; }
@keyframes pulse { 50% { opacity: .4; } }
.events { max-height: 340px; overflow: auto; font-size: 13px; display: grid; gap: 5px; }
.ev { display: grid; grid-template-columns: 62px 1fr; gap: 8px; } .ev .t { color: var(--muted); } .ev.ok .x { color: var(--green); } .ev.warn .x { color: var(--orange); } .ev.err .x { color: var(--red); }
.order-list { display: grid; gap: 6px; }
.order-item { display: grid; grid-template-columns: 1fr 90px auto; gap: 8px; align-items: center; background: #0e1522; border: 1px solid var(--line); border-radius: 10px; padding: 6px 8px 6px 12px; }
.order-item input { min-height: 36px; padding: 6px 8px; font-size: 15px; }
.toast { position: fixed; left: 50%; bottom: calc(80px + var(--safe-b)); transform: translateX(-50%) translateY(20px); background: #1f2a40; border: 1px solid var(--line);
  padding: 11px 16px; border-radius: 12px; opacity: 0; pointer-events: none; transition: .2s; z-index: 50; max-width: min(92vw, 520px); font-size: 14px; }
.toast.show { opacity: 1; transform: translateX(-50%); } .toast.err { border-color: var(--red); color: #ffb0b0; }
.cards-m { display: none; }

/* ---------- телефон (iPhone 14 Pro Max = 430 px) */
@media (max-width: 760px) {
  .app { display: block; padding-bottom: calc(66px + var(--safe-b)); }
  .top { padding: calc(8px + var(--safe-t)) 14px 8px; }
  .brand-name { display: none; }
  .tabs { position: fixed; bottom: 0; left: 0; right: 0; top: auto; z-index: 30; flex-direction: row; justify-content: space-around; gap: 0;
    padding: 6px 6px calc(6px + var(--safe-b)); background: rgba(14,21,34,.96); backdrop-filter: blur(12px); border-top: 1px solid var(--line); border-right: 0; }
  .tabs button { flex-direction: column; gap: 1px; padding: 6px 4px; flex: 1; align-items: center; font-size: 11px; text-align: center; }
  .tabs button.active { box-shadow: none; color: var(--accent); background: transparent; }
  main { padding: 12px; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi .v { font-size: 18px; } .kpi.big .v { font-size: 24px; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .fields { grid-template-columns: 1fr 1fr; }
  canvas.chart { height: 250px; }
  .controls .btn { flex: 1 1 45%; }
  .table-d { display: none; } .cards-m { display: grid; gap: 8px; }
  .mrow { background: #0e1522; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: grid; grid-template-columns: 1fr 1fr; gap: 3px 10px; font-size: 14px; }
  .mrow .h { grid-column: 1 / -1; display: flex; justify-content: space-between; font-weight: 650; }
  .mrow span.k { color: var(--muted); font-size: 12px; display: block; }
  .toast { bottom: calc(86px + var(--safe-b)); }
}
@media (max-width: 760px) { .order-item { grid-template-columns: 1fr auto; } .order-item span:first-child { grid-column: 1 / -1; } }
@media (max-width: 380px) { .fields { grid-template-columns: 1fr; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* режими, ключі, модальне вікно */
.hidden { display: none !important; }
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.65); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 20px; max-width: 440px; width: 100%; max-height: 90vh; overflow: auto; }
.modal h3 { margin: 0 0 10px; }
.modal p { color: var(--muted); font-size: 14px; line-height: 1.45; margin: 8px 0; }
.modal label { display: block; margin: 12px 0; font-size: 13px; color: var(--muted); }
.modal input { width: 100%; margin-top: 6px; }
.modal input.bad { border-color: var(--red); }
.keylist { display: grid; gap: 6px; margin: 12px 0; }
.keyrow { display: flex; justify-content: space-between; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; font-size: 14px; }
.keyrow.sel { border-color: var(--accent); background: rgba(45,212,191,.08); }
.recovery .row { flex-wrap: wrap; }
.btn.small { padding: 6px 12px; min-height: 34px; font-size: 13px; }
