:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #999999);
  --section: var(--tg-theme-secondary-bg-color, #f1f1f4);
  --button: var(--tg-theme-button-color, #2481cc);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #2481cc);
  --ok: #2e8b4f; --warn: #b26a00; --bad: #c0492a;
}
* { box-sizing: border-box; }
body { margin: 0 auto; max-width: 900px; padding: 16px 16px 40px; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); font-size: 16px; }
h1 { font-size: 18px; margin: 0 0 16px; }
h2 { font-size: 15px; margin: 22px 0 8px; }
h3 { font-size: 14px; margin: 14px 0 6px; color: var(--hint); font-weight: 600; }
.hidden { display: none !important; }
.hint { color: var(--hint); font-size: 13px; margin: 8px 0; }
a { color: var(--link); text-decoration: none; }

.menu-btn { display: block; width: 100%; padding: 18px 16px; margin-bottom: 10px; border-radius: 14px; background: var(--section); color: var(--text); border: none; text-align: left; cursor: pointer; font-size: 17px; font-weight: 600; }
.menu-btn small { display: block; font-weight: 400; color: var(--hint); font-size: 13px; margin-top: 4px; }

label { display: block; font-size: 13px; color: var(--hint); margin: 12px 0 6px; }
input { width: 100%; padding: 11px 12px; font-size: 16px; border: 1px solid var(--section); border-radius: 10px; background: var(--section); color: var(--text); -webkit-appearance: none; appearance: none; }
.row { display: flex; gap: 10px; }
.row > div { flex: 1; min-width: 0; }
.row > .narrow { flex: 0 0 auto; align-self: flex-end; }
.presets { display: flex; flex-wrap: wrap; gap: 8px; }
.preset { flex: 1 1 calc(50% - 8px); padding: 11px 8px; text-align: center; border-radius: 10px; background: var(--section); color: var(--text); border: 1.5px solid transparent; cursor: pointer; font-size: 14px; }
.preset.active { border-color: var(--button); color: var(--button); font-weight: 600; }
.range { display: none; gap: 10px; }
.range.show { display: flex; }
.range > div { flex: 1; min-width: 0; }
.range label { margin-top: 10px; }
input[type=date] { min-width: 0; width: 100%; }
button.primary { display: block; width: 100%; margin-top: 16px; padding: 13px; border-radius: 12px; border: none; background: var(--button); color: var(--button-text); font-size: 16px; font-weight: 600; cursor: pointer; }
button.primary:disabled { opacity: .6; }
.toggle { display: block; width: 100%; padding: 11px; margin-top: 12px; text-align: center; border-radius: 10px; background: var(--section); color: var(--text); border: 1.5px solid transparent; cursor: pointer; font-size: 15px; }
.toggle.active { border-color: var(--button); color: var(--button); font-weight: 600; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.chip { background: var(--section); border-radius: 10px; padding: 8px 12px; font-size: 14px; }
.chip b { display: block; font-size: 20px; }
.chip small { display: block; font-size: 11px; color: var(--hint); margin-top: 2px; }
.chip.filt { cursor: pointer; border: 1.5px solid transparent; }
/* Широкие плашки: одна на строку, число слева, полный заголовок */
.chips.wide .chip { flex: 1 1 100%; display: flex; align-items: baseline; gap: 12px; padding: 10px 14px; }
.chips.wide .chip b { display: inline; font-size: 18px; min-width: 34px; text-align: right; }
.chip.filt.active { border-color: var(--button); }
.vz-mark.dim { opacity: .25; }
.filter-head { font-size: 14px; margin: 4px 0 8px; color: var(--hint); }
.filter-head b { color: var(--text); }
.filter-head a { margin-left: 8px; }
.filter-list { background: var(--section); border-radius: 10px; padding: 4px 12px; }
.chip.ok b { color: var(--ok); } .chip.warn b { color: var(--warn); } .chip.bad b { color: var(--bad); }

.tbl-wrap { overflow-x: auto; margin: 8px -16px; padding: 0 16px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 7px 8px; text-align: right; border-bottom: 1px solid var(--section); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--hint); font-weight: 600; }
tr.total td { font-weight: 700; }
tr.click { cursor: pointer; }
tr.click.active td { background: var(--section); }

details { background: var(--section); border-radius: 10px; padding: 10px 12px; margin: 8px 0; }
summary { cursor: pointer; font-weight: 600; font-size: 14px; }
summary small { color: var(--hint); font-weight: 400; }
.deal { padding: 7px 0; border-bottom: 1px solid var(--bg); font-size: 14px; line-height: 1.35; }
.deal:last-child { border-bottom: none; }
.deal .meta { color: var(--hint); font-size: 12px; }
.inline a { margin-right: 8px; white-space: nowrap; }

.card { background: var(--section); border-radius: 12px; padding: 12px 14px; margin: 10px 0; font-size: 14px; }
.card .t { font-weight: 600; margin-bottom: 4px; }
.card .m { color: var(--hint); font-size: 12px; }

.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--hint); border-top-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }
#status { margin-top: 12px; font-size: 14px; }
#status.err { color: var(--bad); }
#stub { text-align: center; padding: 60px 20px; }
.stub-login { margin-top: 18px; display: flex; justify-content: center; }
.stub-icon { font-size: 48px; } .stub-title { font-size: 20px; font-weight: 600; margin: 12px 0 8px; } .stub-text { color: var(--hint); }

.bar { height: 8px; border-radius: 4px; background: var(--bg); margin: 10px 0 4px; overflow: hidden; }
.bar div { height: 100%; width: 0; background: var(--button); transition: width .4s ease; }

.back { cursor: pointer; color: var(--link); margin-right: 6px; font-weight: 400; }

/* Комбобокс с поиском (как в jira-service) */
.combo { position: relative; }
.combo-list { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 20; max-height: 240px; overflow-y: auto; background: var(--bg); border: 1px solid var(--section); border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.18); }
.combo-opt { padding: 11px 12px; font-size: 15px; cursor: pointer; border-bottom: 1px solid rgba(127,127,127,.12); }
.combo-opt:last-child { border-bottom: none; }
.combo-opt:active { background: var(--section); }
.combo-empty { padding: 11px 12px; color: var(--hint); font-size: 14px; }

/* Модалка подтверждения — для клиентов Telegram без showConfirm и для браузера */
.modal-wrap { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 24px; }
.modal { background: var(--bg); color: var(--text); border-radius: 14px; padding: 18px 16px 12px; width: 100%; max-width: 360px; }
.modal-text { font-size: 15px; line-height: 1.4; margin-bottom: 14px; }
.modal-btns { display: flex; gap: 8px; }
.modal-btns button { flex: 1; padding: 11px; border-radius: 10px; border: none; font-size: 15px; cursor: pointer; }
.modal-cancel { background: var(--section); color: var(--text); }
.modal-ok { background: var(--button); color: var(--button-text); font-weight: 600; }

/* Карточка сделки: страница «Сделка» и шторка по тапу на номер */
.sheet-wrap { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); color: var(--text); width: 100%; max-width: 640px; max-height: 88vh; border-radius: 16px 16px 0 0; display: flex; flex-direction: column; }
@media (min-width: 700px) { .sheet-wrap { align-items: center; padding: 24px; } .sheet { border-radius: 16px; max-height: 85vh; } }
.sheet-head { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--section); font-weight: 600; }
.sheet-title { flex: 1; text-align: center; }
.sheet-back, .sheet-close { font-weight: 400; font-size: 15px; min-width: 56px; }
.sheet-close { text-align: right; font-size: 18px; }
.sheet-body { overflow-y: auto; padding: 4px 16px 24px; -webkit-overflow-scrolling: touch; }
.sheet-body .tbl-wrap { margin: 8px 0; padding: 0; }
body.sheet-open { overflow: hidden; }
.sheet-body .err { color: var(--bad); }

.dc-title { font-size: 16px; font-weight: 600; margin-top: 12px; }
.dc-title a { margin-left: 4px; }
.dc-name { font-weight: 400; margin-top: 2px; }
.dc-meta { font-size: 13px; color: var(--hint); margin: 6px 0 12px; }
.btn-link { display: block; text-align: center; margin: 0 0 6px; padding: 12px; border-radius: 12px; background: var(--button); color: var(--button-text); font-weight: 600; font-size: 15px; }
.badge { display: inline-block; padding: 1px 7px; border-radius: 6px; background: var(--section); color: var(--text); font-size: 12px; font-weight: 600; }
.badge.ok { color: var(--ok); } .badge.bad { color: var(--bad); }
.chain { background: var(--section); border-radius: 12px; padding: 2px 12px; }
.chain-row { display: flex; gap: 10px; align-items: flex-start; padding: 9px 0; border-bottom: 1px solid var(--bg); font-size: 14px; }
.chain-row:last-child { border-bottom: none; }
.chain-row .role { flex: 0 0 84px; color: var(--hint); font-size: 13px; padding-top: 1px; }
.chain-row.current .role { color: var(--text); font-weight: 600; }
.chain-row .body { flex: 1; min-width: 0; line-height: 1.35; }
.chain-row .meta { color: var(--hint); font-size: 12px; margin-top: 3px; }
.chain-row .badge { background: var(--bg); }
.chain-row.empty .body { padding-top: 1px; }
.ext { flex: 0 0 auto; font-size: 16px; padding: 0 2px; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; font-size: 14px; background: var(--section); border-radius: 12px; padding: 10px 12px; }
.kv .k { color: var(--hint); font-size: 13px; }
.kv .v { min-width: 0; overflow-wrap: anywhere; }
.card.dc { padding-top: 2px; }
.card.dc .chain, .card.dc .kv { background: var(--bg); }
.card.dc .chain-row { border-bottom-color: var(--section); }
.card.dc .chain-row .badge { background: var(--section); }

/* Графики: палитра (валидирована в обеих темах), тема Telegram */
:root {
  --v-good: #0ca30c; --v-crit: #d03b3b;
  --v-1: #2a78d6; --v-2: #eb6834; --v-3: #1baf7a; --v-4: #eda100; --v-7: #4a3aa7;
  --v-grid: rgba(127,127,127,.22);
}
body[data-theme="dark"] {
  --v-good: #0ca30c; --v-crit: #e66767;
  --v-1: #3987e5; --v-2: #d95926; --v-3: #199e70; --v-4: #c98500; --v-7: #9085e9;
  --v-grid: rgba(255,255,255,.14);
}
.vz { margin: 8px 0 4px; max-width: 520px; }
.vz svg { display: block; overflow: visible; }
.vz-lbl { font-size: 11px; fill: var(--hint); }
.vz-val { font-size: 11px; fill: var(--text); font-weight: 600; }
.vz-seg { font-size: 10px; fill: #fff; text-anchor: middle; font-weight: 600; pointer-events: none; }
.vz-grid { stroke: var(--v-grid); stroke-width: 1; }
.vz-axis { stroke: var(--hint); stroke-width: 1; }
.vz-mark { cursor: pointer; }
.vz-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 6px; font-size: 12px; color: var(--hint); }
.vz-key i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.vz-tip { position: absolute; z-index: 60; background: var(--text); color: var(--bg); font-size: 12px; padding: 6px 9px; border-radius: 8px; pointer-events: none; white-space: nowrap; }
