/* Оформление в одной системе с ИИ-агентом и демо-мокапами: тёмная рабочая
   палитра, IBM Plex, высокая плотность. Диспетчерская — экран, за которым
   сидят смену целиком, поэтому контраст по срочности важнее украшений. */

:root {
  --bg: #0A0F14;
  --panel: #121A21;
  --panel-2: #17212A;
  --panel-3: #1D2935;
  --border: #223040;
  --border-soft: #1C2833;
  --text: #E9EEF2;
  --dim: #7F93A1;
  --route: #3AA0FF;
  --urgent: #FF4B5C;
  --urgent-soft: rgba(255, 75, 92, .16);
  --amber: #FFB020;
  --amber-soft: rgba(255, 176, 32, .16);
  --good: #34D399;
  --good-soft: rgba(52, 211, 153, .16);
  --mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --radius: 8px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: 'IBM Plex Sans', system-ui, -apple-system, sans-serif;
  font-size: 13.5px; line-height: 1.45; -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button { font: inherit; }
h2 { font-size: 17px; margin: 0 0 4px; font-weight: 600; }
h3 { font-size: 14px; margin: 0 0 6px; font-weight: 600; }
.dim { color: var(--dim); margin: 0; }
.dim strong { color: var(--text); font-weight: 600; }

/* ------------------------------------------------------------------- вход */
.login { position: fixed; inset: 0; display: grid; place-items: center; background: radial-gradient(1200px 600px at 50% -10%, #1B2430, var(--bg)); z-index: 60; }
.login-card { width: 330px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 26px; display: flex; flex-direction: column; gap: 12px; box-shadow: 0 30px 60px -30px #000; }
.login-mark { font-size: 30px; }
.login-card h1 { font-size: 20px; margin: 0; font-weight: 600; letter-spacing: .01em; }
.login-sub { margin: -6px 0 6px; color: var(--dim); font-size: 12px; }
.login-card label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--dim); }
input, select, textarea {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 8px 10px; font: inherit; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--route); }
.login-card button { background: var(--urgent); color: #fff; border: 0; border-radius: 6px; padding: 10px; font-weight: 600; cursor: pointer; }
.login-error { background: var(--urgent-soft); color: #FFC3C9; border: 1px solid #5B2730; border-radius: 6px; padding: 8px 10px; font-size: 12px; }

/* ----------------------------------------------------------------- каркас */
.app, .crew-app { height: 100%; display: flex; flex-direction: column; }
.topbar { flex: none; height: 46px; display: flex; align-items: center; gap: 16px; padding: 0 14px; background: var(--panel); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.brand-mark { font-size: 16px; }
.stand-badge { font-family: var(--mono); font-size: 10px; text-transform: uppercase; letter-spacing: .04em; padding: 2px 7px; border-radius: 20px; background: var(--amber-soft); color: var(--amber); border: 1px solid #4A3A18; }
.stand-badge[data-prod="1"] { background: var(--urgent-soft); color: #FF98A2; border-color: #5B2730; }
.tabs { display: flex; gap: 2px; }
.tab { background: transparent; border: 0; color: var(--dim); padding: 7px 11px; border-radius: 6px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.tab:hover { background: var(--panel-2); color: var(--text); }
.tab.is-active { background: var(--panel-3); color: var(--text); }
.tab-badge { background: var(--route); color: #04121F; border-radius: 20px; font-size: 10px; font-weight: 700; padding: 1px 6px; font-family: var(--mono); }
.tab-badge--urgent { background: var(--urgent); color: #fff; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.icon-btn { background: transparent; border: 0; color: var(--dim); cursor: pointer; font-size: 14px; padding: 4px; border-radius: 5px; }
.icon-btn:hover { color: var(--text); background: var(--panel-2); }
.icon-btn[data-off="1"] { opacity: .4; }
.chip { display: inline-flex; align-items: center; gap: 5px; font-family: var(--mono); font-size: 10px; padding: 3px 7px; border-radius: 20px; border: 1px solid var(--border); color: var(--dim); white-space: nowrap; }
.chip .dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.clock { font-family: var(--mono); font-size: 11px; color: var(--dim); font-variant-numeric: tabular-nums; }
.conn { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); }
.conn[data-state="open"] { background: var(--good); }
.conn[data-state="closed"] { background: var(--urgent); }
.user-chip { display: flex; align-items: center; gap: 7px; font-size: 12px; padding-left: 10px; border-left: 1px solid var(--border); }
.user-role { font-family: var(--mono); font-size: 10px; color: var(--dim); }

.views { flex: 1; min-height: 0; }
.view { display: none; height: 100%; }
.view.is-active { display: block; }
.page { height: 100%; overflow: auto; padding: 18px 20px 40px; }
.page--cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 14px; align-content: start; }
.page-head { margin-bottom: 14px; max-width: 900px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.formula { font-family: var(--mono); font-size: 11.5px; color: var(--route); background: var(--bg); border: 1px solid var(--border-soft); border-radius: 6px; padding: 10px; overflow-x: auto; }

/* ----------------------------------------------------------------- канбан */
.board-wrap { height: 100%; display: grid; grid-template-columns: minmax(0, 1fr) 250px; }
.board { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; background: var(--border-soft); min-height: 0; }
.col { background: var(--bg); display: flex; flex-direction: column; min-height: 0; }
.col-head { flex: none; height: 40px; display: flex; align-items: center; gap: 8px; padding: 0 12px; border-bottom: 1px solid var(--border); background: var(--panel); }
.col-title { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--dim); font-weight: 600; }
.col-count { font-family: var(--mono); font-size: 11px; color: var(--dim); background: var(--panel-3); border-radius: 20px; padding: 1px 7px; }
.col-head .btn { margin-left: auto; }
.col--attention .col-title { color: var(--urgent); }
.col--progress .col-title { color: var(--route); }
.col--done .col-title { color: var(--good); }
.col-body { flex: 1; overflow: auto; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.col-body:empty::before { content: attr(data-empty); color: #3C4B58; font-size: 12px; text-align: center; padding-top: 24px; }

.card-order {
  background: var(--panel); border: 1px solid var(--border); border-left: 3px solid var(--border);
  border-radius: var(--radius); padding: 10px; cursor: pointer;
}
.card-order:hover { background: var(--panel-2); }
.card-order[data-priority="emergency"] { border-left-color: var(--urgent); }
.card-order[data-priority="urgent"] { border-left-color: var(--amber); }
.card-order[data-status="attention"] { background: linear-gradient(90deg, rgba(255,75,92,.08), var(--panel) 45%); }
.card-top { display: flex; align-items: center; gap: 7px; margin-bottom: 5px; flex-wrap: wrap; }
.order-tag { font-family: var(--mono); font-size: 11px; color: var(--route); font-weight: 600; }
.card-addr { font-size: 13px; font-weight: 600; margin-bottom: 3px; }
.card-reason { font-size: 12px; color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-foot { display: flex; align-items: center; gap: 7px; margin-top: 7px; flex-wrap: wrap; }
.tag { font-size: 10.5px; font-family: var(--mono); padding: 2px 6px; border-radius: 4px; background: var(--panel-3); color: var(--dim); white-space: nowrap; }
.tag--crew { background: rgba(58,160,255,.14); color: var(--route); }
.tag--manual { background: var(--amber-soft); color: var(--amber); }
.tag--urgent { background: var(--urgent-soft); color: #FF98A2; }
.tag--good { background: var(--good-soft); color: var(--good); }
.tag--agent { background: rgba(124,77,255,.16); color: #C0A9FF; }
.pulse { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.crew-rail { background: var(--panel); border-left: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.panel-head { flex: none; height: 40px; display: flex; align-items: center; padding: 0 12px; border-bottom: 1px solid var(--border-soft); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--dim); font-weight: 600; }
.crew-list { flex: 1; overflow: auto; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.crew-item { background: var(--panel-2); border: 1px solid var(--border-soft); border-radius: 6px; padding: 8px 10px; }
.crew-item-top { display: flex; align-items: center; gap: 7px; }
.crew-name { font-family: var(--mono); font-weight: 600; font-size: 12px; }
.crew-dot { width: 7px; height: 7px; border-radius: 50%; margin-left: auto; }
.crew-dot[data-s="free"] { background: var(--good); }
.crew-dot[data-s="busy"] { background: var(--route); }
.crew-dot[data-s="offered"] { background: var(--amber); }
.crew-dot[data-s="offline"] { background: #3C4B58; }
.crew-meta { font-size: 11px; color: var(--dim); margin-top: 3px; }

/* ---------------------------------------------------------------- карточка */
.modal-overlay { position: fixed; inset: 0; background: rgba(4,8,12,.72); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; width: min(680px, 100%); max-height: 88vh; overflow: auto; padding: 18px; position: relative; box-shadow: 0 30px 70px -30px #000; }
.modal--form { display: flex; flex-direction: column; gap: 10px; }
.modal--form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--dim); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.modal-close { position: absolute; top: 12px; right: 12px; background: transparent; border: 0; color: var(--dim); font-size: 15px; cursor: pointer; }
.modal-head { display: flex; align-items: center; gap: 8px; }
.modal-addr { font-size: 17px; font-weight: 600; margin: 6px 0 12px; }
.tabs--modal { border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.tab-panel { display: none; }
.tab-panel.is-active { display: block; }
.modal-grid { display: grid; grid-template-columns: 120px 1fr; gap: 5px 10px; font-size: 12.5px; }
.modal-grid dt { color: var(--dim); }
.modal-grid dd { margin: 0; }
.modal-crew { margin: 12px 0; background: var(--panel-2); border: 1px solid var(--border-soft); border-radius: 6px; padding: 10px; }
.timeline { list-style: none; margin: 12px 0 0; padding: 0; border-left: 1px solid var(--border); }
.timeline li { padding: 4px 0 4px 12px; position: relative; font-size: 12px; color: var(--dim); }
.timeline li::before { content: ''; position: absolute; left: -4px; top: 10px; width: 7px; height: 7px; border-radius: 50%; background: var(--border); }
.timeline li strong { color: var(--text); font-weight: 600; }
.timeline time { font-family: var(--mono); font-size: 10.5px; margin-left: 6px; }
.modal-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

.cand { display: flex; align-items: center; gap: 9px; padding: 9px 10px; background: var(--panel-2); border: 1px solid var(--border-soft); border-radius: 6px; margin-bottom: 7px; flex-wrap: wrap; }
.cand[data-status="accepted"] { border-color: #1E5B45; background: var(--good-soft); }
.cand[data-status="declined"], .cand[data-status="timeout"] { opacity: .6; }
.cand-pos { font-family: var(--mono); color: var(--dim); font-size: 11px; }
.cand-name { font-family: var(--mono); font-weight: 600; }
.cand-detail { font-size: 11px; color: var(--dim); width: 100%; font-family: var(--mono); }
.cand-timer { margin-left: auto; font-family: var(--mono); font-size: 11px; color: var(--amber); }

/* --------------------------------------------------------------------- чат */
.chat-log { max-height: 260px; overflow: auto; display: flex; flex-direction: column; gap: 6px; padding: 8px; background: var(--bg); border: 1px solid var(--border-soft); border-radius: 6px; }
.msg { max-width: 82%; padding: 7px 10px; border-radius: 9px; font-size: 12.5px; white-space: pre-wrap; word-break: break-word; }
.msg--coordinator { align-self: flex-end; background: #2E6FF2; }
.msg--crew { align-self: flex-start; background: var(--panel-2); border: 1px solid var(--border-soft); }
.msg--system { align-self: center; background: var(--panel-3); color: var(--dim); font-size: 11.5px; }
.msg .who { display: block; font-size: 10px; opacity: .8; margin-bottom: 2px; font-weight: 600; }
.msg time { display: block; font-family: var(--mono); font-size: 9.5px; opacity: .7; margin-top: 3px; text-align: right; }
.chat-input { display: flex; gap: 7px; margin-top: 8px; }
.chat-input input { flex: 1; }

.chat-fab { position: fixed; right: 18px; bottom: 18px; width: 46px; height: 46px; border-radius: 50%; background: var(--route); color: #04121F; border: 0; cursor: pointer; display: grid; place-items: center; box-shadow: 0 12px 30px -10px #000; z-index: 40; }
.chat-fab-badge { position: absolute; top: -3px; right: -3px; min-width: 18px; height: 18px; border-radius: 20px; background: var(--urgent); color: #fff; font-size: 10px; font-weight: 700; display: grid; place-items: center; font-family: var(--mono); }
.shift-chat { position: fixed; right: 18px; bottom: 74px; width: 330px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 12px; z-index: 41; box-shadow: 0 24px 50px -24px #000; }
.shift-chat-head { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 8px; }
.shift-chat-title { font-weight: 600; font-size: 13px; }
.shift-chat-sub { font-size: 11px; color: var(--dim); }
.shift-chat-head .icon-btn { margin-left: auto; }

/* ------------------------------------------------------------------ кнопки */
.btn { border: 1px solid var(--border); background: var(--panel-2); color: var(--text); border-radius: 6px; padding: 7px 12px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--panel-3); }
.btn--primary { background: var(--route); color: #04121F; border-color: transparent; font-weight: 600; }
.btn--danger { background: var(--urgent-soft); color: #FF98A2; border-color: #5B2730; }
.btn--warn { background: var(--amber-soft); color: var(--amber); border-color: #4A3A18; }
.btn--sm { padding: 4px 9px; font-size: 11.5px; }
.btn--big { padding: 14px 18px; font-size: 15px; }
.btn:disabled { opacity: .5; cursor: default; }

/* --------------------------------------------------------------- таблицы */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); }
.table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.table th { text-align: left; padding: 8px 10px; background: var(--panel-2); color: var(--dim); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; position: sticky; top: 0; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 7px 10px; border-bottom: 1px solid var(--border-soft); vertical-align: top; }
.table tbody tr:hover { background: var(--panel-2); }
.mono { font-family: var(--mono); font-size: 11px; color: var(--dim); }
.form { display: flex; flex-direction: column; gap: 9px; margin-top: 10px; }
.form--row { flex-direction: row; flex-wrap: wrap; align-items: center; }
.form label { font-size: 12px; color: var(--dim); display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.form label span { flex: 1; }
.form input[type="number"] { width: 92px; }
.form-actions { display: flex; gap: 8px; align-items: center; }
.saved { font-size: 11px; color: var(--good); }

/* ---------------------------------------------------------- экран экипажа */
.crew-app { background: var(--bg); }
.crew-top { flex: none; display: flex; align-items: center; gap: 10px; padding: 12px 14px; background: var(--panel); border-bottom: 1px solid var(--border); }
.crew-callsign { font-family: var(--mono); font-size: 18px; font-weight: 600; }
.crew-sub { font-size: 11.5px; color: var(--dim); }
.crew-top-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.crew-body { flex: 1; overflow: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.crew-offer { background: linear-gradient(180deg, rgba(255,75,92,.14), var(--panel)); border: 1px solid #5B2730; border-radius: 12px; padding: 16px; }
.crew-offer-head { display: flex; align-items: center; gap: 9px; }
.offer-timer { margin-left: auto; font-family: var(--mono); font-size: 20px; font-weight: 600; color: var(--amber); font-variant-numeric: tabular-nums; }
.offer-timer[data-low="1"] { color: var(--urgent); }
.crew-offer-addr { font-size: 19px; font-weight: 600; margin: 10px 0 4px; }
.crew-offer-reason { color: var(--dim); font-size: 13.5px; }
.crew-offer-actions { display: flex; gap: 10px; margin-top: 16px; }
.crew-offer-actions .btn { flex: 1; }
.crew-order { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.crew-status-buttons { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0; }
.crew-chat { max-height: 200px; }
.crew-idle { margin: auto; text-align: center; color: var(--dim); padding: 40px 20px; }

/* ----------------------------------------------------------------- тосты */
.toasts { position: fixed; right: 14px; bottom: 74px; display: flex; flex-direction: column; gap: 7px; z-index: 45; }
.toast { background: var(--panel-3); border: 1px solid var(--border); border-left: 3px solid var(--route); border-radius: 6px; padding: 9px 12px; font-size: 12.5px; max-width: 330px; box-shadow: 0 12px 30px -12px #000; }
.toast[data-tone="urgent"] { border-left-color: var(--urgent); }
.toast[data-tone="warn"] { border-left-color: var(--amber); }
.toast[data-tone="good"] { border-left-color: var(--good); }

@media (max-width: 1100px) {
  .board-wrap { grid-template-columns: 1fr; }
  .crew-rail { display: none; }
  .board { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .board { grid-template-columns: 1fr; }
  .shift-chat { width: calc(100vw - 36px); }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }
