/* Прототип «Почтовик»: светлая и тёмная темы через переменные */
:root {
  --bg: #f4f6f9; --panel: #ffffff; --panel2: #f8fafc; --text: #1c2430; --muted: #6b7686;
  --line: #dde3ea; --accent: #2563eb; --accent-text: #ffffff; --sel: #e6efff; --hover: #eff3f8;
  --ok: #16803c; --ok-bg: #e4f5ea; --bad: #c0261d; --bad-bg: #fde8e6; --warn: #a15c00; --warn-bg: #fff2d9;
  --new: #2563eb; --work: #d98a00; --done: #16803c; --err: #c0261d; --late: #e8590c;
  --shadow: 0 8px 30px rgba(15, 23, 42, .18); color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #12161c; --panel: #1b212a; --panel2: #202733; --text: #e6ebf2; --muted: #93a0b2;
  --line: #2f3846; --accent: #4f8cff; --accent-text: #0b1220; --sel: #243553; --hover: #262e3b;
  --ok: #4cc47a; --ok-bg: #173325; --bad: #ff7b72; --bad-bg: #3b1d1b; --warn: #f0b04a; --warn-bg: #3a2c12;
  --new: #6aa0ff; --work: #f0b04a; --done: #4cc47a; --err: #ff7b72; --late: #ff9440;
  --shadow: 0 8px 30px rgba(0, 0, 0, .55); color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, "Segoe UI", Roboto, sans-serif; }
button, select, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* Тестовая плашка */
.testbar { background: var(--warn-bg); color: var(--warn); text-align: center; padding: 4px 12px; font-size: 12.5px; border-bottom: 1px solid var(--line); }
.app { display: flex; flex-direction: column; height: 100vh; }

/* Шапка */
.top { display: flex; align-items: center; gap: 10px; padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.logo { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 6px; margin-right: 6px; }
.search { flex: 1 1 220px; min-width: 140px; max-width: 420px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel2); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 3px 9px; border-radius: 999px; font-size: 12px; border: 1px solid var(--line); background: var(--panel2); white-space: nowrap; }
.chip b { font-weight: 700; }
.chip.new b { color: var(--new); } .chip.work b { color: var(--work); } .chip.error b { color: var(--err); }
.spacer { flex: 1; }
.btn { padding: 7px 12px; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; }
.btn:hover:not(:disabled) { background: var(--hover); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 3px 8px; font-size: 12.5px; }
.onec { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel2); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.onec.on .dot { background: var(--ok); } .onec.off .dot { background: var(--bad); }
.onec.off { color: var(--bad); border-color: var(--bad); }

/* Три панели */
.main { flex: 1; display: grid; grid-template-columns: 220px minmax(300px, 400px) 1fr; min-height: 0; }
.pane { min-height: 0; overflow: auto; background: var(--panel); }
.folders { border-right: 1px solid var(--line); padding: 8px 0; }
.list { border-right: 1px solid var(--line); background: var(--panel); }
.detail { background: var(--bg); padding: 14px; }

.folder { display: flex; align-items: center; gap: 8px; padding: 8px 14px; cursor: pointer; border-left: 3px solid transparent; }
.folder.child { padding-left: 30px; }
.folder:hover { background: var(--hover); }
.folder.sel { background: var(--sel); border-left-color: var(--accent); font-weight: 600; }
.folder .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { min-width: 22px; text-align: center; padding: 1px 7px; border-radius: 999px; background: var(--accent); color: var(--accent-text); font-size: 12px; font-weight: 600; }
.badge.warn { background: var(--bad); color: #fff; }
.badge.q { background: var(--panel2); color: var(--muted); border: 1px dashed var(--muted); cursor: help; }
.fnote { margin: 10px 14px; font-size: 12px; color: var(--muted); }

/* Список писем */
.lhead { position: sticky; top: 0; z-index: 2; background: var(--panel); border-bottom: 1px solid var(--line); padding: 8px 12px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.lhead .ttl { font-weight: 600; margin-right: auto; }
.fchip { padding: 2px 9px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel2); font-size: 12px; }
.fchip.sel { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.row { display: grid; grid-template-columns: 12px 1fr auto; gap: 4px 10px; padding: 9px 12px; border-bottom: 1px solid var(--line); cursor: pointer; border-left: 3px solid transparent; }
.row:hover { background: var(--hover); }
.row.sel { background: var(--sel); border-left-color: var(--accent); }
.row.err { background: var(--bad-bg); }
.row.err.sel { background: var(--sel); border-left-color: var(--bad); }
.row .st { grid-row: 1 / span 3; margin-top: 6px; }
.row .from { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.read .from, .row.read .subj { font-weight: 400; }
.row .date { color: var(--muted); font-size: 12px; white-space: nowrap; }
.row .subj { grid-column: 2 / span 2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .meta { grid-column: 2 / span 2; display: flex; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); }
.st.new { background: var(--new); } .st.work { background: var(--work); } .st.done { background: var(--done); } .st.error { background: var(--err); }
.pill { padding: 1px 8px; border-radius: 999px; font-size: 11.5px; border: 1px solid var(--line); background: var(--panel2); white-space: nowrap; }
.pill.new { color: var(--new); border-color: var(--new); } .pill.work { color: var(--work); border-color: var(--work); }
.pill.done { color: var(--done); border-color: var(--done); } .pill.error { color: var(--err); border-color: var(--err); background: var(--bad-bg); }
.pill.scen { background: var(--panel2); color: var(--text); }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

/* Просмотр письма */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin-bottom: 12px; }
.card h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.mhead h2 { margin: 0 0 4px; font-size: 18px; line-height: 1.3; word-break: break-word; }
.mhead .sub { color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; }
.back { display: none; margin-bottom: 8px; }

.prop { border: 2px solid var(--accent); }
.prop .scen { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.scenbadge { width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; font-weight: 800; font-size: 17px; flex: none; }
.scenbadge.x { background: var(--muted); }
.checks { list-style: none; margin: 8px 0; padding: 0; }
.checks li { display: grid; grid-template-columns: 26px 1fr; gap: 8px; padding: 6px 8px; border-radius: 8px; margin-bottom: 4px; }
.checks .ic { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 700; margin-top: 1px; }
.checks .ok { background: var(--ok-bg); } .checks .ok .ic { background: var(--ok); color: #fff; }
.checks .fail { background: var(--bad-bg); } .checks .fail .ic { background: var(--bad); color: #fff; }
.checks .warn { background: var(--warn-bg); } .checks .warn .ic { background: var(--warn); color: #fff; }
.checks .skip { background: var(--panel2); color: var(--muted); } .checks .skip .ic { background: var(--muted); color: #fff; }
.checks .tt { font-weight: 600; } .checks .dd { font-size: 13px; color: var(--muted); }
.checks .ok .dd, .checks .fail .dd, .checks .warn .dd { color: var(--text); opacity: .85; }
.default { background: var(--sel); border-radius: 8px; padding: 8px 10px; margin: 8px 0; }
.act { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
.act .resp { display: flex; align-items: center; gap: 6px; margin-right: auto; }
select { padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel2); max-width: 100%; }
.hint { font-size: 12.5px; color: var(--bad); margin-top: 6px; }
.doneBox { background: var(--ok-bg); color: var(--ok); padding: 8px 10px; border-radius: 8px; font-weight: 600; }

table.tbl, table.data { border-collapse: collapse; width: 100%; }
table.tbl th, table.tbl td, table.data th, table.data td { border: 1px solid var(--line); padding: 5px 8px; text-align: left; font-size: 13px; }
table.tbl th, table.data th { background: var(--panel2); font-weight: 600; }
.tablewrap { overflow-x: auto; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 4px 12px; margin-bottom: 8px; }
.kv .k { color: var(--muted); }
.conf { display: inline-block; height: 8px; width: 80px; background: var(--line); border-radius: 4px; vertical-align: middle; margin-right: 6px; overflow: hidden; }
.conf i { display: block; height: 100%; background: var(--ok); }
.conf.mid i { background: var(--warn); } .conf.low i { background: var(--bad); }
.body { word-break: break-word; }
.body ul { padding-left: 20px; }
.att { display: inline-flex; gap: 6px; align-items: center; padding: 4px 10px; border: 1px solid var(--line); border-radius: 8px; margin: 0 6px 6px 0; background: var(--panel2); }
.hist { list-style: none; margin: 0; padding: 0; }
.hist li { display: grid; grid-template-columns: 90px 1fr; gap: 8px; padding: 4px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.hist .t { color: var(--muted); }

/* Модальные окна */
.ovl { position: fixed; inset: 0; background: rgba(8, 12, 20, .55); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: var(--panel); border-radius: 14px; box-shadow: var(--shadow); width: min(680px, 100%); max-height: 92vh; display: flex; flex-direction: column; }
.modal.wide { width: min(860px, 100%); }
.mh { padding: 14px 18px; border-bottom: 1px solid var(--line); font-weight: 700; font-size: 16px; display: flex; justify-content: space-between; align-items: center; }
.mb { padding: 14px 18px; overflow: auto; }
.mf { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.letter { border: 1px solid var(--line); border-radius: 10px; background: var(--panel2); padding: 10px 12px; margin-bottom: 10px; white-space: pre-wrap; font-size: 13.5px; }
.letter .lh { color: var(--muted); font-size: 12.5px; white-space: normal; margin-bottom: 6px; }
.testnote { background: var(--warn-bg); color: var(--warn); padding: 6px 10px; border-radius: 8px; font-size: 12.5px; margin-bottom: 10px; }
.tabs { display: flex; gap: 4px; padding: 0 18px; border-bottom: 1px solid var(--line); }
.tab { padding: 10px 14px; border: 0; background: none; border-bottom: 3px solid transparent; }
.tab.sel { border-bottom-color: var(--accent); font-weight: 600; }
.toggle { position: relative; width: 40px; height: 22px; border-radius: 999px; background: var(--line); border: 0; padding: 0; flex: none; }
.toggle::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: left .15s; }
.toggle.on { background: var(--ok); } .toggle.on::after { left: 21px; }
.arow { display: grid; grid-template-columns: 1fr auto 52px; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.arow .st2 { font-size: 12px; color: var(--muted); text-align: right; }
.arow .st2.full { color: var(--ok); font-weight: 600; }
.form { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; margin: 10px 0; }
.form label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 2px; flex: 1 1 160px; }
.form input { padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel2); }
.tag { padding: 1px 8px; border-radius: 999px; font-size: 11.5px; }
.tag.ok { background: var(--ok-bg); color: var(--ok); } .tag.bad { background: var(--bad-bg); color: var(--bad); }
.toast { position: fixed; right: 16px; bottom: 16px; background: var(--ok); color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); z-index: 60; max-width: 80vw; }
.kbd { font-size: 11px; color: var(--muted); }

/* Адаптивность */
@media (max-width: 1100px) { .main { grid-template-columns: 180px minmax(260px, 340px) 1fr; } }
@media (max-width: 860px) {
  .main { grid-template-columns: minmax(0, 1fr); }
  .top { padding: 8px 10px; } .testbar { font-size: 11.5px; }
  .folders { display: none; border-right: 0; border-bottom: 1px solid var(--line); max-height: 45vh; }
  .app.showFolders .folders { display: block; }
  .list { border-right: 0; }
  .detail { display: none; padding: 10px; }
  .app.showDetail .list { display: none; }
  .app.showDetail .detail { display: block; }
  .back { display: inline-block; }
  .app.showDetail .folders { display: none; }
  .kv { grid-template-columns: 100px 1fr; }
}
@media (min-width: 861px) { .menu { display: none; } }

[hidden] { display: none !important; }
.main > * { min-width: 0; }
.mhead .sub, .checks .dd, .default { overflow-wrap: anywhere; }

/* ===== Рабочее место специалиста ===== */
.qblock { margin: 10px 0; }
.qh { margin: 0 0 6px; font-size: 13px; color: var(--warn); }
.qh.ok { color: var(--ok); }
.qcard { border: 1px solid var(--warn); background: var(--warn-bg); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; }
.qcard .qt { font-weight: 700; margin-bottom: 2px; }
.qtext { margin-bottom: 6px; }
.qopt { display: flex; gap: 8px; align-items: flex-start; padding: 5px 6px; border-radius: 8px; cursor: pointer; }
.qopt:hover { background: var(--hover); }
.qopt input[type=radio] { margin-top: 3px; }
.qcust { width: 80px; padding: 2px 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }
.rem { display: flex; gap: 8px 12px; flex-wrap: wrap; align-items: center; margin: 8px 0 4px; padding-top: 8px; border-top: 1px dashed var(--line); }
.rem select:disabled { opacity: .5; }
.qact { margin-top: 6px; }
.applied, .qdone { display: flex; gap: 8px; align-items: flex-start; padding: 7px 10px; border-radius: 8px; margin-bottom: 6px; background: var(--ok-bg); overflow-wrap: anywhere; }
.applied a { color: var(--accent); font-weight: 600; }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.store { border: 1px solid var(--line); font-size: 11px; }
.tag.s1c { background: var(--sel); color: var(--accent); }
.tag.spm { background: var(--panel2); color: var(--muted); }
.data tr.off td { opacity: .5; text-decoration: line-through; }
.data td.num { text-align: center; }
.data td.acts { white-space: nowrap; }
.editbox { border: 2px solid var(--accent); border-radius: 10px; padding: 10px 12px; margin: 10px 0; background: var(--panel2); }
.form label.chk { flex: 0 0 auto; justify-content: end; }
.statgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; margin: 10px 0 14px; }
.stat { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--panel2); }
.stat b { display: block; font-size: 24px; color: var(--accent); }
.stat span { font-size: 12.5px; color: var(--muted); }
.arow2 { display: grid; grid-template-columns: 1fr minmax(150px, 230px) 52px; gap: 12px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--line); }
.arow2 .astat { font-size: 12.5px; color: var(--muted); text-align: right; }
.bar { height: 6px; background: var(--line); border-radius: 3px; margin-top: 5px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--ok); }
.bar i.part { background: var(--warn); }
.toggle:disabled { opacity: .4; cursor: not-allowed; }
@media (max-width: 860px) { .arow2 { grid-template-columns: 1fr 52px; } .arow2 .astat { grid-column: 1; text-align: left; grid-row: 2; } .arow2 .toggle { grid-row: 1 / span 2; grid-column: 2; } }

/* ===== Рабочая версия: добавки к прототипу ===== */
.testbar.live { background: var(--bad-bg); color: var(--bad); }
.testbar.ro { background: var(--ok-bg); color: var(--ok); font-weight: 600; }
.testbar small { opacity: .8; }
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: sp .8s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes sp { to { transform: rotate(360deg); } }
.banner { padding: 8px 12px; border-radius: 8px; margin-bottom: 10px; font-size: 13px; }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.bad { background: var(--bad-bg); color: var(--bad); }
.banner.info { background: var(--sel); }
.bodytext { white-space: pre-wrap; word-break: break-word; font-size: 13.5px; max-height: 420px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; background: var(--panel2); }
iframe.htmlbody { width: 100%; height: 420px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; cursor: pointer; font-size: 12.5px; }
.folder .nm { white-space: nowrap; }
.more { margin: 10px 12px; }
.summaryGrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 12px; }
.row2 { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
textarea.txt { width: 100%; min-height: 70px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel2); }
.form select { padding: 6px 8px; }
.tag.dis { background: var(--panel2); color: var(--muted); }
td.wrap { max-width: 280px; overflow-wrap: anywhere; }
.actrow { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.stale { color: var(--warn); }
.toast.bad { background: var(--bad); }
@media (max-width: 860px) { .modal, .modal.wide { width: 100%; } }
/* ---------- Вход (авторизация, app/auth.py) ---------- */
.login-ovl { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; background: var(--bg); padding: 16px; }
.login-box { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 22px 22px 18px; }
.login-box h2 { margin: 0 0 6px; font-size: 20px; }
.login-box p { margin: 0 0 12px; color: var(--muted); font-size: 13px; }
.login-box input { width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel2); color: var(--text); margin-bottom: 10px; }
.login-box .err { color: var(--bad); min-height: 18px; font-size: 13px; margin-bottom: 8px; }
.chip.user { font-weight: 600; }

/* Иконка «письмо»: наведение (или закрепление кликом) прячет блоки действий, письмо оказывается наверху */
.mhead { position: relative; }
.peekbtn { position: absolute; top: 10px; left: 12px; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; width: 34px; height: 30px; font-size: 16px; cursor: pointer; }
.peekbtn:hover, .peeking .peekbtn { background: var(--accent); }
.mhead h2 { padding-left: 44px; }
.detailwrap:has(.peekbtn:hover) .actblock, .detailwrap.peeking .actblock, .detailwrap:has(.peekbtn:focus-visible) .actblock { display: none; }
#detail { scrollbar-gutter: stable; }

/* Задачи 1С у письма: просрочено (оранжевый), цвет ответственного слева, ссылка на задачу */
.st.late { background: var(--late); }
.pill.late { color: var(--late); border-color: var(--late); background: var(--warn-bg); }
.row.late { background: var(--warn-bg); }
.row.late.sel { background: var(--sel); border-left-color: var(--late); }
.tasklink { color: var(--accent); font-weight: 600; text-decoration: none; border-bottom: 1px dotted currentColor; }
.tasklink:hover { text-decoration: underline; }
.taskinfo { margin-top: 4px; }
.cdot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.lhead select.respf { max-width: 180px; }

/* Дерево папок: стрелка сворачивания слева, отступ по глубине задаётся inline */
.folder { padding-left: 10px; gap: 6px; }
.folder .chev { width: 14px; flex: none; text-align: center; color: var(--muted); font-size: 11px; }
.folder .chev[data-a] { cursor: pointer; }
.folder .chev[data-a]:hover { color: var(--text); }
