/* АСРП — стиль классического десктопного приложения */
:root {
  --bg: #f0f0f0;
  --panel: #f0f0f0;
  --white: #ffffff;
  --line: #a0a0a0;
  --line-dark: #6b6b6b;
  --btn: #e1e1e1;
  --btn-border: #adadad;
  --btn-hover: #e5f1fb;
  --btn-hover-border: #0078d7;
  --text: #000;
  --muted: #6d6d6d;
  --disabled: #9a9a9a;
  --yellow: #ffe600;
  --blue-item: #00a8f3;
  --red: #ff0000;
  --green: #138a00;
  --green-text: #0f7a00;
  --blue-text: #1a1aff;
  --link: #0033cc;
  font-size: 13px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: Tahoma, "Segoe UI", Arial, sans-serif; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.muted { color: var(--muted); }
.blue { color: #0000ff; }
.green { color: var(--green-text); }
.b { font-weight: bold; }

/* ---------- кнопки ---------- */
.btn {
  background: var(--btn); border: 1px solid var(--btn-border); padding: 6px 12px; cursor: pointer;
  min-height: 30px; text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
}
.btn:hover:not(:disabled) { background: var(--btn-hover); border-color: var(--btn-hover-border); }
.btn:active:not(:disabled) { background: #cce4f7; }
.btn:disabled { color: var(--disabled); cursor: default; }
.btn-red { color: #e00000; }
.btn-small { min-height: 24px; padding: 2px 8px; }
.btn-danger { color: #b00000; }

input, select, textarea {
  border: 1px solid #7a7a7a; background: var(--white); padding: 3px 5px; min-height: 24px;
}
input:disabled, select:disabled, textarea:disabled { background: #e9e9e9; color: var(--muted); }
textarea { resize: vertical; width: 100%; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 1px solid var(--btn-hover-border); }

/* ---------- каркас ---------- */
.app { display: flex; flex-direction: column; height: 100vh; min-width: 1000px; }
.menubar { display: flex; align-items: stretch; gap: 2px; background: var(--white); border-bottom: 1px solid #ccc; font-size: 12px; padding: 0 4px; }
.modes { margin-left: 4px; display: flex; gap: 2px; align-items: center; }
.mode { border: 1px solid transparent; background: none; padding: 2px 10px; cursor: pointer; }
.login-info { margin-left: auto; padding: 2px 10px; align-self: center; }
.mode.active { border-color: var(--btn-hover-border); background: var(--btn-hover); font-weight: bold; }

.frame { flex: 1; display: flex; flex-direction: column; gap: 6px; padding: 8px; min-height: 0; border: 3px ridge #d8d8d8; margin: 4px; }
.top, .bottom { display: grid; grid-template-columns: 300px 1fr 260px; gap: 6px; align-items: center; }
.top .btn, .bottom .btn { width: 100%; }
.status { text-align: center; font-size: 15px; }
.status.ok { color: var(--green-text); }
.status.bad { color: var(--red); }
.clock { text-align: center; font-size: 15px; }
.clock .sep { margin: 0 12px; color: var(--muted); }
.mid { flex: 1; display: grid; grid-template-columns: 300px 1fr; gap: 6px; min-height: 0; }
.panel { border: 2px groove #e0e0e0; background: var(--panel); min-height: 0; }
.left { display: flex; flex-direction: column; gap: 6px; min-height: 0; }

/* режим пульта: без боковых колонок и кнопок приказов */
.pult-mode .mid { grid-template-columns: 1fr; }
.pult-mode .left { display: none; }
.pult-mode .top .btn, .pult-mode .bottom .btn { visibility: hidden; }

/* ---------- категории ---------- */
.cats { flex: 1; overflow-y: auto; padding: 4px; display: flex; flex-direction: column; gap: 4px; }
.cat {
  text-align: left; padding: 10px 8px; border: 1px solid #8a8a8a; background: #ececec; cursor: pointer;
  box-shadow: inset -1px -1px 0 #a0a0a0, inset 1px 1px 0 #fff;
}
.cat:hover:not(:disabled) { background: #f6f6f6; }
.cat.sel { background: var(--yellow); }
.cat.alarm { background: var(--red); }
.cat.alarm.sel { background: linear-gradient(90deg, var(--yellow) 0 85%, var(--red) 85%); }
.cat:disabled { color: var(--disabled); cursor: default; }
.subs { border: 1px solid #b5b5b5; padding: 6px; display: flex; flex-direction: column; gap: 3px; background: #ececec; }
.sub {
  text-align: left; padding: 6px 8px; background: var(--blue-item); border: 1px solid #0a6aa0; cursor: pointer;
  box-shadow: inset -1px -1px 0 #0479b5, inset 1px 1px 0 #66d0ff;
}
.sub:disabled { color: #48607a; cursor: default; opacity: .85; }
.sub.cur { outline: 2px solid #000; outline-offset: -3px; }

.free { color: var(--muted) !important; font-weight: normal !important; }

/* ---------- центр: приказ ---------- */
.center { display: flex; flex-direction: column; overflow: hidden; }
.doc { flex: 1; overflow: auto; padding: 12px 14px; }
.empty { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--muted); text-align: center; padding: 20px; }
.order-head { font-size: 15px; font-weight: bold; display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.numbox { display: inline-block; min-width: 30px; padding: 2px 8px; background: var(--white); border: 1px solid #999; text-align: center; font-weight: normal; }
.otitle { color: #0033cc; }
.tsrow { display: flex; align-items: center; gap: 6px; background: #d6d6d6; padding: 6px 10px; margin: 6px 0; flex-wrap: wrap; }
.tsrow input { width: 38px; text-align: center; padding: 2px; }
.tsrow input.w-month { width: 90px; }
.tsrow input.w-year { width: 52px; }
.tsrow .ic { width: 24px; height: 24px; min-height: 24px; padding: 0; background: var(--btn); border: 1px solid #888; cursor: pointer; font-size: 11px; }
.tsrow .ic.on { background: #9fd3ff; }
.box { border-top: 1px solid #c7c7c7; border-bottom: 1px solid #c7c7c7; padding: 10px 6px; margin: 6px 0; display: flex; flex-direction: column; gap: 8px; }
.field { display: flex; flex-direction: column; gap: 3px; }
.field > label { font-size: 12px; }
.field.req > label::after { content: " *"; color: var(--red); }
.field input, .field select { max-width: 420px; }
.sentence { line-height: 2.1; white-space: pre-line; }
.sentence select.inl { width: auto; }
.sentence .opt { border-bottom: 1px dashed var(--muted); }
.sentence .mirror { font-weight: bold; }
.upper { text-transform: uppercase; }
.sentence .inl { width: 220px; margin: 0 3px; padding: 1px 5px; min-height: 22px; }
.sentence .inl.inl-s { width: 90px; }
/* несколько маршрутов галочками */
.sentence .multi { display: inline-block; position: relative; vertical-align: middle; line-height: 1.4; white-space: normal; }
.sentence .multi summary { display: inline-block; min-width: 160px; cursor: pointer; background: var(--white); border: 1px solid #7a7a7a; list-style: none; }
.sentence .multi summary::-webkit-details-marker { display: none; }
.sentence .multi summary::after { content: " ▾"; color: var(--muted); }
.sentence .multi-list { position: absolute; z-index: 5; left: 0; top: 100%; min-width: 220px; max-height: 260px; overflow-y: auto;
  background: var(--white); border: 1px solid #7a7a7a; box-shadow: 0 4px 12px rgba(0,0,0,.2); padding: 4px; display: flex; flex-direction: column; gap: 2px; }
.sentence .multi-list label { display: flex; gap: 6px; align-items: center; padding: 2px 4px; cursor: pointer; }
.sentence .multi-list label:hover { background: var(--btn-hover); }
.sign { margin-top: 4px; }
.recip { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.recip input { width: 260px; }
.opts label { display: flex; gap: 6px; align-items: center; cursor: pointer; }
.preview { background: var(--white); border: 1px dashed #b0b0b0; padding: 8px; white-space: pre-wrap; font-family: inherit; margin: 6px 0; }
.approve {
  margin: 4px; height: 52px; border: 1px solid #0a5a00; background: var(--green); color: var(--blue-text); font-size: 22px; font-weight: bold;
  letter-spacing: 10px; cursor: pointer;
}
.approve:hover:not(:disabled) { filter: brightness(1.1); }
.approve:disabled { background: #7aa874; color: #3d4f8a; cursor: default; }
.note { color: var(--muted); font-size: 12px; }
.warn { color: #b00000; font-size: 12px; }

/* просмотр приказа */
.docview { background: var(--white); border: 1px solid #bdbdbd; padding: 14px 16px; line-height: 1.5; }
.dv-date { margin-bottom: 6px; }
.dv-head { font-weight: bold; font-size: 15px; }
.dv-meta { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.dv-text { white-space: pre-wrap; margin: 8px 0; }
.dv-sign { margin-top: 8px; }
.dv-back { margin-top: 6px; }
.dv-closed { margin-top: 8px; color: #8a5a00; }
.dv-game { margin-top: 8px; font-size: 12px; }
.dv-game .ok { color: var(--green-text); }
.dv-game .err { color: #b00000; }
.dv-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }

/* ---------- пульт ---------- */
.pult { display: flex; flex-direction: column; height: 100%; }
.ptabs { display: flex; flex-wrap: wrap; gap: 2px; padding: 6px 6px 0; border-bottom: 1px solid #999; }
.ptab { padding: 6px 12px; border: 1px solid #999; border-bottom: 0; background: #e3e3e3; cursor: pointer; }
.ptab.active { background: var(--white); font-weight: bold; position: relative; top: 1px; }
.pbody { flex: 1; overflow: auto; padding: 12px; background: var(--white); }
.pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.card { border: 1px solid #bdbdbd; padding: 10px; display: flex; flex-direction: column; gap: 6px; background: #fafafa; }
.card h3 { margin: 0 0 4px; font-size: 14px; }
.card .who { font-size: 13px; }
.card .row2 { display: flex; gap: 6px; }
.card .row2 > * { flex: 1; }
.card select, .card input { width: 100%; }
table.t { border-collapse: collapse; width: 100%; font-size: 12px; }
table.t th, table.t td { border: 1px solid #c4c4c4; padding: 4px 6px; text-align: left; }
table.t th { background: #e8e8e8; position: sticky; top: 0; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover { background: #eef5ff; }
table.archive td.clip { max-width: 420px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
table.archive td.nowrap { white-space: nowrap; }
.arc-bar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.link { color: var(--link); text-decoration: underline; cursor: pointer; }
.iv-ok { color: var(--green-text); }
.iv-mid { color: #c27c00; font-weight: bold; }
.iv-bad { color: #d00000; font-weight: bold; }
.lst { border: 1px solid #999; overflow-y: auto; background: var(--white); height: 320px; }
.lst div { padding: 3px 8px; cursor: pointer; }
.lst div:hover { background: #eef5ff; }
.lst div.sel { background: #3399ff; color: #fff; }
.col { display: flex; flex-direction: column; gap: 6px; }
.hint { font-size: 12px; color: var(--muted); }

/* ---------- модалки и тосты ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: flex; align-items: center; justify-content: center; z-index: 100; }
.mwin { background: var(--bg); border: 1px solid #6d6d6d; box-shadow: 0 6px 24px rgba(0,0,0,.35); width: min(1100px, 96vw); max-height: 92vh; display: flex; flex-direction: column; }
.mwin.small { width: min(460px, 96vw); }
.mhead { background: var(--white); padding: 6px 10px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid #ccc; }
.mhead button { background: none; border: 0; font-size: 18px; cursor: pointer; padding: 0 6px; }
.mhead button:hover { background: #e81123; color: #fff; }
.mbody { padding: 12px; overflow: auto; display: flex; flex-direction: column; gap: 10px; }
.mfoot { padding: 8px 12px; display: flex; justify-content: flex-end; gap: 6px; border-top: 1px solid #ccc; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; }
.filters label { display: flex; flex-direction: column; font-size: 12px; gap: 2px; }
.split { display: grid; grid-template-columns: 1.2fr 1fr; gap: 10px; min-height: 0; }
.split > div { overflow: auto; max-height: 66vh; }

/* потеря связи с сервером АСРП — заглушка поверх всей страницы */
.offline { position: fixed; inset: 0; z-index: 300; background: var(--bg); display: flex; align-items: center; justify-content: center; padding: 16px; }
.offline-box { display: flex; flex-direction: column; align-items: center; gap: 16px; font-size: 18px; text-align: center; }
.spinner { width: 36px; height: 36px; border: 4px solid var(--line); border-top-color: var(--btn-hover-border); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

.toasts { position: fixed; right: 12px; bottom: 64px; display: flex; flex-direction: column; gap: 6px; z-index: 200; max-width: 420px; }
.toast { background: var(--white); border: 1px solid #888; border-left: 5px solid #0078d7; padding: 8px 10px; box-shadow: 0 2px 8px rgba(0,0,0,.25); white-space: pre-wrap; }
.toast.ok { border-left-color: #138a00; }
.toast.err { border-left-color: #d00000; }
.toast.game { border-left-color: #e0a000; }

/* ---------- вход ---------- */
.login { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: #dcdcdc; }
.login-box { background: var(--bg); border: 3px ridge #d8d8d8; padding: 30px 40px; text-align: center; display: flex; flex-direction: column; gap: 14px; width: min(420px, 92vw); }
.login-title { font-size: 26px; font-weight: bold; color: #0033cc; }
.btn.vodka { font-size: 15px; padding: 12px; }
.login-error { color: #b00000; white-space: pre-wrap; }

/* ---------- тёмная тема ---------- */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1e2023;
  --panel: #24272b;
  --white: #2c3035;
  --line: #4a4f56;
  --line-dark: #6b717a;
  --btn: #33373d;
  --btn-border: #4f555d;
  --btn-hover: #2a3b4f;
  --btn-hover-border: #4da3ff;
  --text: #e3e5e8;
  --muted: #9aa1a9;
  --disabled: #6a7078;
  --green-text: #5fd068;
  --blue-text: #8fb0ff;
  --link: #7fa8ff;
}
[data-theme="dark"] .blue { color: #7fa8ff; }
[data-theme="dark"] .btn:active:not(:disabled) { background: #22476b; }
[data-theme="dark"] .btn-red { color: #ff6b6b; }
[data-theme="dark"] .btn-danger, [data-theme="dark"] .warn, [data-theme="dark"] .dv-game .err { color: #ff7a7a; }
[data-theme="dark"] input, [data-theme="dark"] select, [data-theme="dark"] textarea { border-color: #5a6068; }
[data-theme="dark"] input:disabled, [data-theme="dark"] select:disabled, [data-theme="dark"] textarea:disabled { background: #26292d; }
[data-theme="dark"] .menubar { border-bottom-color: #3a3f45; }
[data-theme="dark"] .frame { border-color: #3a3f45; }
[data-theme="dark"] .panel { border-color: #3a3f45; }
[data-theme="dark"] .cat { background: #2f3338; border-color: #4a4f56; box-shadow: inset -1px -1px 0 #1a1c1f, inset 1px 1px 0 #44494f; }
[data-theme="dark"] .cat:hover:not(:disabled) { background: #383d43; }
[data-theme="dark"] .cat.sel, [data-theme="dark"] .cat.alarm { color: #000; }
[data-theme="dark"] .cat.sel { background: var(--yellow); }
[data-theme="dark"] .cat.alarm { background: var(--red); }
[data-theme="dark"] .cat.alarm.sel { background: linear-gradient(90deg, var(--yellow) 0 85%, var(--red) 85%); }
[data-theme="dark"] .subs { background: #2a2d31; border-color: #43484e; }
[data-theme="dark"] .sub { color: #000; }
[data-theme="dark"] .sub:disabled { color: #1d3a55; opacity: .6; }
[data-theme="dark"] .sub.cur { outline-color: #fff; }
[data-theme="dark"] .numbox { border-color: #5a6068; }
[data-theme="dark"] .otitle, [data-theme="dark"] .login-title { color: #7fa8ff; }
[data-theme="dark"] .tsrow { background: #33373d; }
[data-theme="dark"] .tsrow .ic { border-color: #5a6068; }
[data-theme="dark"] .tsrow .ic.on { background: #2f6aa8; }
[data-theme="dark"] .box { border-color: #3d4248; }
[data-theme="dark"] .preview { border-color: #50565e; }
[data-theme="dark"] .approve { color: #c9d8ff; }
[data-theme="dark"] .approve:disabled { background: #34503a; color: #7d8bb0; }
[data-theme="dark"] .docview { border-color: #43484e; }
[data-theme="dark"] .dv-closed { color: #e0b060; }
[data-theme="dark"] .ptabs { border-bottom-color: #4a4f56; }
[data-theme="dark"] .ptab { background: #2a2d31; border-color: #4a4f56; }
[data-theme="dark"] .card { background: #26292d; border-color: #43484e; }
[data-theme="dark"] table.t th, [data-theme="dark"] table.t td { border-color: #43484e; }
[data-theme="dark"] table.t th { background: #33373d; }
[data-theme="dark"] table.t tr.click:hover, [data-theme="dark"] .lst div:hover { background: #2f3a48; }
[data-theme="dark"] .lst { border-color: #4a4f56; }
[data-theme="dark"] .iv-mid { color: #f0a830; }
[data-theme="dark"] .iv-bad { color: #ff6b6b; }
[data-theme="dark"] .mwin { border-color: #4a4f56; }
[data-theme="dark"] .mhead, [data-theme="dark"] .mfoot { border-color: #3d4248; }
[data-theme="dark"] .toast { background: #2c3035; border-top-color: #4a4f56; border-right-color: #4a4f56; border-bottom-color: #4a4f56; box-shadow: 0 2px 8px rgba(0,0,0,.6); }
[data-theme="dark"] .login { background: #17191b; }
[data-theme="dark"] .login-box { border-color: #3a3f45; }

@media print {
  body * { visibility: hidden; }
  .printable, .printable * { visibility: visible; }
  .printable { position: absolute; left: 0; top: 0; width: 100%; border: 0; }
}
