/* dgk — пульт снабжения Brask.
   Склад запчастей: чернильно-синяя печать коробок, этикеточная бумага, сигнальный жёлтый складской бирки.
   Раскладка: слева синяя направляющая с биркой dgk и штрихкодом цели; справа рабочее поле. На телефоне — нижние вкладки. */
:root {
  --paper: #edf0f3;
  --surface: #ffffff;
  --sunken: #e3e8ed;
  --ink: #10233a;
  --muted: #5b6b7d;
  --line: #cfd7e0;
  --rail: #10233a;
  --rail-ink: #dde6f0;
  --rail-muted: #8a9bb0;
  --rail-line: #22384f;
  --signal: #ffc21a;
  --signal-ink: #10233a;
  --signal-soft: #fff1c2;
  --mine: #10233a;
  --mine-ink: #f3f7fb;
  --ok: #1e8a5a;
  --ok-soft: #dcf0e5;
  --bad: #c8372d;
  --bad-soft: #f9dedb;
  --warn: #9a6700;
  --warn-soft: #fbefcf;
  --font-display: "Tektur", "Golos Text", system-ui, sans-serif;
  --font-body: "Golos Text", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --r: 6px;
  --rail-w: 232px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0b1724; --surface: #122235; --sunken: #0e1c2c; --ink: #e4ecf4; --muted: #8c9db1; --line: #22364c;
    --rail: #07111c; --rail-line: #172a3e; --signal-soft: #3a2f0c; --mine: #1f4a78; --mine-ink: #f3f7fb;
    --ok: #4cc38a; --ok-soft: #13301f; --bad: #f06a5f; --bad-soft: #3a1b1a; --warn: #e0b243; --warn-soft: #34290b;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0b1724; --surface: #122235; --sunken: #0e1c2c; --ink: #e4ecf4; --muted: #8c9db1; --line: #22364c;
  --rail: #07111c; --rail-line: #172a3e; --signal-soft: #3a2f0c; --mine: #1f4a78; --mine-ink: #f3f7fb;
  --ok: #4cc38a; --ok-soft: #13301f; --bad: #f06a5f; --bad-soft: #3a1b1a; --warn: #e0b243; --warn-soft: #34290b;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--paper); color: var(--ink); font-family: var(--font-body); font-size: 15px; line-height: 1.45; }
[hidden] { display: none !important; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---------- каркас ---------- */
.shell { display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr); min-height: 100%; }
.rail { background: var(--rail); color: var(--rail-ink); position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 26px; padding: calc(20px + env(safe-area-inset-top, 0px)) 18px 20px max(18px, env(safe-area-inset-left, 0px)); }
.main { min-width: 0; padding: 22px max(28px, env(safe-area-inset-right, 0px)) 48px 28px; display: grid; gap: 22px; align-content: start; }

/* бирка dgk — как на иконке: жёлтая этикетка с пробитым отверстием */
.tag-mark { display: inline-flex; align-items: center; gap: 10px; background: var(--signal); color: var(--signal-ink); border-radius: 5px; padding: 6px 14px 7px 10px; text-decoration: none; align-self: flex-start; }
.tag-mark::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--rail); }
.tag-mark b { font-family: var(--font-display); font-weight: 700; font-size: 1.7rem; line-height: 1; letter-spacing: .02em; }
.rail .owner { font-size: .78rem; color: var(--rail-muted); margin-top: -16px; }

nav.tabs { display: grid; gap: 2px; }
nav.tabs a { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 10px; border-radius: 5px; color: var(--rail-muted); text-decoration: none; font-weight: 500; transition: background .15s, color .15s; }
nav.tabs a:hover { color: var(--rail-ink); background: var(--rail-line); }
nav.tabs a[aria-current="page"] { color: var(--rail-ink); background: var(--rail-line); box-shadow: inset 3px 0 0 var(--signal); }
.count { font-family: var(--font-mono); font-size: .72rem; border-radius: 99px; padding: 1px 7px; background: var(--rail-line); color: var(--rail-muted); }
.count.hot { background: var(--signal); color: var(--signal-ink); font-weight: 600; }
.count:empty { display: none; }

/* штрихкод цели: 50 позиций, толстый штрих — работает, тонкий — почти, пусто — свободно */
.goal { margin-top: auto; display: grid; gap: 8px; }
.goal .label { font-family: var(--font-mono); font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--rail-muted); }
.barcode { display: flex; align-items: stretch; gap: 1px; height: 46px; padding: 6px 8px; background: #f7f9fb; border-radius: 3px; }
.barcode i { flex: 1 1 0; display: flex; justify-content: center; }
.barcode i::after { content: ""; width: 1px; background: #c3ccd6; }
.barcode i.half::after { width: 1px; background: #10233a; }
.barcode i.on::after { width: 100%; background: #10233a; }
.goal .num { font-family: var(--font-mono); font-size: .82rem; color: var(--rail-ink); display: flex; justify-content: space-between; }
.goal .num b { font-family: var(--font-display); font-size: 1.5rem; font-weight: 700; color: var(--signal); }
.rail-foot { display: flex; justify-content: space-between; gap: 8px; font-size: .78rem; color: var(--rail-muted); }
.rail-foot button { background: none; border: 0; color: var(--rail-muted); padding: 0; font: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.rail-foot button:hover { color: var(--rail-ink); }

/* ---------- шапка рабочего поля ---------- */
.head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 16px; }
.head h1 { font-family: var(--font-display); font-weight: 500; font-size: 1.6rem; margin: 0; letter-spacing: .01em; }
.stamp { font-family: var(--font-mono); font-size: .74rem; color: var(--muted); }
.status { display: flex; gap: 12px; align-items: center; padding: 10px 14px; border-radius: var(--r); border: 1px solid var(--line); background: var(--surface); font-size: .92rem; }
.lamp { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--ok); box-shadow: 0 0 0 4px var(--ok-soft); }
.status.down { background: var(--bad-soft); border-color: transparent; }
.status.down .lamp { background: var(--bad); box-shadow: 0 0 0 4px color-mix(in srgb, var(--bad) 25%, transparent); animation: pulse 1.6s ease-in-out infinite; }
.status.unknown .lamp { background: var(--warn); box-shadow: 0 0 0 4px var(--warn-soft); }
.status.paused { background: var(--warn-soft); border-color: transparent; }
.status .hint { color: var(--muted); }
.status.down .hint { color: var(--ink); opacity: .8; }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .status.down .lamp, .typing i { animation: none !important; } }

section.view { display: grid; gap: 30px; }
h2 { font-family: var(--font-display); font-weight: 500; font-size: 1.08rem; margin: 0 0 12px; display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; text-wrap: balance; }
h2 .note { font-family: var(--font-body); font-size: .84rem; color: var(--muted); font-weight: 400; }
.two { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 28px; align-items: start; }
@media (max-width: 1100px) { .two { grid-template-columns: 1fr; } }

/* ---------- сводка дня ---------- */
.today-strip { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); }
.today-strip a { padding: 14px 16px; text-decoration: none; display: grid; gap: 2px; border-left: 1px solid var(--line); }
.today-strip a:first-child { border-left: 0; }
.today-strip a:hover { background: var(--sunken); }
.today-strip b { font-family: var(--font-display); font-size: 1.7rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.today-strip span { color: var(--muted); font-size: .84rem; }
.today-strip a.hot b { color: var(--warn); }

/* ---------- карточки решений: складская бирка ---------- */
.tickets { display: grid; gap: 14px; }
.ticket { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); min-width: 0; overflow: hidden; }
.ticket .stub { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 14px; background: var(--sunken); font-family: var(--font-mono); font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; }
.ticket .stub .kind { display: inline-flex; align-items: center; gap: 8px; color: var(--ink); font-weight: 600; }
.ticket .stub .kind::before { content: ""; width: 8px; height: 8px; border-radius: 1px; background: var(--signal); }
.ticket.silent .stub .kind::before { background: var(--warn); }
.ticket .body { padding: 12px 14px 6px; }
.ticket .msg { white-space: pre-wrap; overflow-wrap: anywhere; font-size: .92rem; max-height: 15.5em; overflow: hidden; position: relative; }
.ticket .msg.open { max-height: none; }
.ticket .msg:not(.open).long::after { content: ""; position: absolute; inset: auto 0 0; height: 3em; background: linear-gradient(transparent, var(--surface)); }
.ticket .act { padding: 8px 14px 14px; display: grid; gap: 8px; }
.row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.row.spread { justify-content: space-between; }
.countdown { font-family: var(--font-mono); font-size: .76rem; color: var(--warn); }

button { font: inherit; cursor: pointer; border-radius: 4px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 7px 13px; font-size: .88rem; font-weight: 500; transition: background .12s, border-color .12s, transform .06s; }
button:hover { border-color: var(--muted); }
button:active { transform: translateY(1px); }
button.primary { background: var(--signal); border-color: var(--signal); color: var(--signal-ink); font-weight: 600; }
button.primary:hover { filter: brightness(1.05); }
button.danger { color: var(--bad); }
button.danger.armed { background: var(--bad); border-color: var(--bad); color: #fff; }
button.link { border: 0; background: none; color: var(--muted); padding: 0; text-decoration: underline; text-underline-offset: 3px; }
button:disabled { opacity: .5; cursor: default; }
input[type="text"], input[type="search"], input[type="password"], textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 4px; padding: 8px 10px; width: 100%; min-width: 0; }
textarea { resize: vertical; min-height: 70px; }
.inline-form { display: grid; gap: 6px; }

.done-list, .call-list, .mail-list { display: grid; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); }
.done-item { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 2px 12px; padding: 9px 14px; border-bottom: 1px solid var(--line); font-size: .9rem; }
.done-item:last-child { border-bottom: 0; }
.done-item .res { grid-column: 2; color: var(--muted); font-size: .84rem; overflow-wrap: anywhere; }
.pill { font-family: var(--font-mono); font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; padding: 2px 8px; border-radius: 99px; white-space: nowrap; height: fit-content; background: var(--sunken); color: var(--muted); }
.pill.done { background: var(--ok-soft); color: var(--ok); }
.pill.failed { background: var(--bad-soft); color: var(--bad); }
.pill.approved, .pill.running, .pill.changes_requested { background: var(--warn-soft); color: var(--warn); }

/* ---------- чат ---------- */
.chat { display: grid; grid-template-rows: minmax(0, 1fr) auto; height: calc(100vh - 150px); min-height: 420px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); }
.chat-log { overflow-y: auto; padding: 18px 18px 8px; display: flex; flex-direction: column; gap: 10px; }
.day-sep { align-self: center; font-family: var(--font-mono); font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; padding: 6px 0; }
.bubble { max-width: min(680px, 86%); padding: 9px 13px 8px; border-radius: 10px 10px 10px 3px; background: var(--sunken); white-space: pre-wrap; overflow-wrap: anywhere; font-size: .93rem; }
.bubble.owner { align-self: flex-end; background: var(--mine); color: var(--mine-ink); border-radius: 10px 10px 3px 10px; }
.bubble .meta { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; font-family: var(--font-mono); font-size: .66rem; opacity: .65; white-space: nowrap; }
.typing { align-self: flex-start; display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .86rem; padding: 4px 2px; }
.typing span { display: inline-flex; gap: 4px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.composer { border-top: 1px solid var(--line); padding: 10px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: end; }
.composer textarea { min-height: 44px; max-height: 180px; resize: none; border-color: transparent; background: var(--sunken); }
.composer .hint { grid-column: 1 / -1; color: var(--muted); font-size: .76rem; }
.chat-empty { margin: auto; text-align: center; color: var(--muted); max-width: 40ch; }

/* ---------- звонки ---------- */
.calls { display: grid; gap: 22px; }
.day h3 { font-family: var(--font-mono); font-size: .76rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; margin: 0 0 8px; }
.day.now h3 { color: var(--bad); }
.call { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 14px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.call:last-child { border-bottom: 0; }
.call .who { font-weight: 600; }
.call .phone { font-family: var(--font-mono); font-size: .86rem; }
.call .why { grid-column: 1 / -1; color: var(--muted); font-size: .88rem; }
.call .tries { font-family: var(--font-mono); font-size: .72rem; color: var(--muted); white-space: nowrap; }
.call .act { grid-column: 1 / -1; display: grid; gap: 6px; margin-top: 4px; }

/* ---------- поставщики ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip { display: inline-flex; gap: 7px; align-items: center; border-radius: 99px; padding: 5px 12px; font-size: .84rem; }
.chip .count { background: var(--sunken); color: var(--muted); }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.chip[aria-pressed="true"] .count { background: color-mix(in srgb, var(--paper) 22%, transparent); color: var(--paper); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; display: inline-block; }
.toolbar { display: flex; gap: 10px; margin-bottom: 12px; }
.toolbar input { max-width: 380px; }
.tablebox { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); }
table { border-collapse: collapse; width: 100%; min-width: 760px; font-size: .9rem; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .07em; padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--sunken); }
td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr { cursor: pointer; }
tbody tr:hover td { background: color-mix(in srgb, var(--signal-soft) 55%, transparent); }
tr:last-child td { border-bottom: 0; }
td.name { font-weight: 600; min-width: 170px; }
td.stage { white-space: nowrap; }
.when { font-family: var(--font-mono); font-size: .72rem; color: var(--muted); display: block; }
.muted { color: var(--muted); }

.drawer-bg { position: fixed; inset: 0; background: color-mix(in srgb, #000 45%, transparent); z-index: 30; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100%); background: var(--surface); z-index: 31; overflow-y: auto; padding: calc(18px + env(safe-area-inset-top, 0px)) max(18px, env(safe-area-inset-right, 0px)) calc(24px + env(safe-area-inset-bottom, 0px)) 20px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; align-content: start; box-shadow: -12px 0 40px color-mix(in srgb, #000 25%, transparent); }
.drawer h2 { margin: 0; font-size: 1.25rem; }
.drawer dl { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 14px; margin: 0; font-size: .9rem; }
.drawer dt { color: var(--muted); }
.drawer dd { margin: 0; overflow-wrap: anywhere; }
.drawer h3 { font-size: .74rem; font-family: var(--font-mono); text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 0 0 6px; }
.journal { display: grid; gap: 6px; font-size: .88rem; }
.journal div { padding-bottom: 6px; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }

.mail { padding: 11px 14px; border-bottom: 1px solid var(--line); display: grid; gap: 3px; }
.mail:last-child { border-bottom: 0; }
.mail .subj { font-weight: 600; overflow-wrap: anywhere; }
.mail .snip { color: var(--muted); font-size: .88rem; overflow-wrap: anywhere; }

.empty { padding: 24px 18px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--r); }
.flash { position: fixed; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 6px; font-size: .9rem; z-index: 40; max-width: calc(100% - 32px); }
.flash.err { background: var(--bad); color: #fff; }

/* ---------- вход ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--rail); }
.login form { width: min(380px, 100%); background: var(--surface); border-radius: var(--r); padding: 24px; display: grid; gap: 12px; }
.login p { margin: 0; color: var(--muted); font-size: .9rem; }
.login .err { color: var(--bad); font-size: .9rem; min-height: 1.3em; }

/* ---------- телефон: направляющая сверху, вкладки снизу ---------- */
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .rail { position: sticky; top: 0; z-index: 10; height: auto; flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; padding: calc(10px + env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) 10px max(16px, env(safe-area-inset-left, 0px)); }
  .tag-mark b { font-size: 1.3rem; }
  .rail .owner, .rail-foot { display: none; }
  .goal { margin: 0; grid-template-columns: 110px auto; align-items: center; gap: 8px; }
  .goal .label { display: none; }
  .barcode { height: 30px; padding: 4px 5px; }
  .goal .num b { font-size: 1.1rem; }
  .goal .num span { display: none; }
  nav.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr); gap: 0; background: var(--rail); padding: 4px max(4px, env(safe-area-inset-right, 0px)) calc(4px + env(safe-area-inset-bottom, 0px)) max(4px, env(safe-area-inset-left, 0px)); border-top: 1px solid var(--rail-line); }
  nav.tabs a { flex-direction: column; justify-content: center; gap: 2px; padding: 6px 2px; font-size: .74rem; text-align: center; }
  nav.tabs a[aria-current="page"] { box-shadow: inset 0 3px 0 var(--signal); }
  .main { padding: 16px max(16px, env(safe-area-inset-right, 0px)) calc(86px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px)); }
  .chat { height: calc(100dvh - 330px); min-height: 360px; }
  .composer .hint { display: none; }
  .today-strip b { font-size: 1.35rem; }
  .today-strip a { padding: 10px 12px; }
}
