/* Стиль в духе интерфейса Битрикс24 */
:root {
    --text: #333;
    --muted: #828b95;
    --line: #e6e9ec;
    --bg-soft: #f5f7f8;
    --accent: #2fc6f6;
    --accent-dark: #11a9d8;
    --old: #c0392b;
    --old-bg: #fdf0ef;
    --new: #1e8e3e;
    --new-bg: #eef8f0;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
    margin: 0;
    font: 14px/1.45 "Open Sans", "Helvetica Neue", Arial, sans-serif;
    color: var(--text);
    background: #fff;
}
h1 { font-size: 22px; font-weight: 600; margin: 0 0 12px; }
h2 { font-size: 16px; font-weight: 600; margin: 24px 0 8px; }
.page { max-width: 760px; padding: 24px; }
.muted { color: var(--muted); }
.error { color: var(--old); }
.card { background: var(--bg-soft); border-radius: 8px; padding: 12px 16px; }
.card p { margin: 4px 0; }

.tab { padding: 16px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; }
.toolbar .spacer { flex: 1; }
select, input[type=search] {
    height: 34px; padding: 0 10px; border: 1px solid #c6cdd3; border-radius: 4px;
    font: inherit; background: #fff; color: var(--text); min-width: 150px;
}
input[type=search] { min-width: 200px; }
.btn {
    height: 34px; padding: 0 16px; border: 1px solid #c6cdd3; border-radius: 4px;
    background: #fff; color: var(--text); font: inherit; cursor: pointer;
}
.btn:hover { border-color: var(--accent); color: var(--accent-dark); }
#summary { margin: 4px 0 10px; font-size: 13px; }
.state { padding: 32px; text-align: center; color: var(--muted); background: var(--bg-soft); border-radius: 8px; }

table.history { width: 100%; border-collapse: collapse; table-layout: fixed; }
.history th {
    text-align: left; font-weight: 600; font-size: 12px; color: var(--muted);
    text-transform: uppercase; letter-spacing: .02em; padding: 8px 10px; border-bottom: 1px solid var(--line);
}
.history td { padding: 7px 10px; vertical-align: top; word-wrap: break-word; white-space: pre-wrap; }
.history tr.group-start td { border-top: 1px solid var(--line); }
.history tbody tr:first-child td { border-top: 0; }
.c-time { width: 140px; color: var(--muted); white-space: nowrap; }
.c-user { width: 170px; }
.c-field { width: 190px; font-weight: 600; }
td.old { color: var(--old); background: var(--old-bg); text-decoration: line-through; text-decoration-color: rgba(192,57,43,.4); }
td.new { color: var(--new); background: var(--new-bg); }
td.event { font-style: italic; color: var(--muted); }
td.event.create { color: var(--new); }
td.event.delete { color: var(--old); }

@media (max-width: 720px) {
    .c-time, .c-user, .c-field { width: auto; }
    table.history, .history tbody, .history tr, .history td { display: block; width: 100%; }
    .history thead { display: none; }
    .history tr { padding: 6px 0; }
    .history td { padding: 2px 6px; }
    .history td:empty { display: none; }
    .history tr.group-start td { border-top: 0; }
    .history tr.group-start { border-top: 1px solid var(--line); margin-top: 6px; }
}

/* Юридические страницы */
.doc { max-width: 820px; }
.doc p, .doc li { line-height: 1.6; }
.doc h2 { margin-top: 28px; }
.doc a { color: var(--accent-dark); }

/* ---------- Время на стадиях ---------- */
.seg { display: inline-flex; border: 1px solid #c6cdd3; border-radius: 4px; overflow: hidden; }
.seg button { height: 32px; padding: 0 14px; border: 0; background: #fff; font: inherit; color: var(--text); cursor: pointer; }
.seg button + button { border-left: 1px solid #c6cdd3; }
.seg button.on { background: var(--accent); color: #fff; }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin: 12px 0 14px; }
.kpi { background: var(--bg-soft); border-radius: 8px; padding: 10px 12px; min-width: 0; }
.kpi-label { font-size: 12px; color: var(--muted); }
.kpi-value { font-size: 18px; font-weight: 600; margin-top: 2px; overflow-wrap: anywhere; }
.kpi-note { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi-note.warn, td.warn { color: #d35400; font-weight: 600; }

.bar { display: flex; height: 18px; border-radius: 9px; overflow: hidden; gap: 2px; background: var(--bg-soft); margin-bottom: 6px; }
.seg-part { min-width: 4px; }
.seg-part.open { background-image: repeating-linear-gradient(45deg, rgba(255,255,255,.35) 0 6px, transparent 6px 12px); }

table.grid { width: 100%; border-collapse: collapse; margin-bottom: 6px; }
.grid th { text-align: left; font-weight: 600; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .02em; padding: 7px 10px; border-bottom: 1px solid var(--line); }
.grid td { padding: 7px 10px; border-bottom: 1px solid var(--line); }
.grid .num { text-align: right; white-space: nowrap; }
.grid tr.current td { background: #f0fafe; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 8px; vertical-align: 0; }
.small { font-size: 12px; }

@media (max-width: 720px) {
    .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid th:nth-child(3), .grid td:nth-child(3) { display: none; }
}
.stage { display: inline-flex; align-items: center; }
.stage .dot { flex: none; }

/* ---------- Активность менеджеров ---------- */
.dash { padding: 20px; }
.dash-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 10px; }
.dash-head h1 { margin: 0; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.kpis { grid-template-columns: repeat(7, minmax(0, 1fr)); }
.kpi-value.bad, td.bad { color: #d35400; }
.notice { background: #fff6e5; color: #8a5a00; border-radius: 6px; padding: 8px 12px; font-size: 13px; }
.table-wrap { overflow-x: auto; margin-bottom: 8px; }
.sortable th { cursor: pointer; user-select: none; white-space: nowrap; }
.sortable th.asc::after { content: ' ▲'; font-size: 9px; }
.sortable th.desc::after { content: ' ▼'; font-size: 9px; }
.grid td.zero { color: #c3cad1; }
.grid td.who { min-width: 170px; }
.who-name { font-weight: 600; }
.badge { display: inline-block; font-size: 11px; color: #8a5a00; background: #fff1d6; border-radius: 10px; padding: 1px 8px; margin-top: 2px; }
.grid tr.idle td.who-name, .grid tr.idle .who-name { color: var(--muted); }
.grid tfoot td { font-weight: 600; border-top: 2px solid var(--line); border-bottom: 0; }
.grid tfoot tr.unassigned td { font-weight: 400; border-top: 1px solid var(--line); }
@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (max-width: 720px) {
    .dash { padding: 12px; }
    .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid th:nth-child(3), .grid td:nth-child(3) { display: table-cell; }
}

/* ---------- График платежей ---------- */
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); color: #fff; }
.btn.small { height: 28px; padding: 0 10px; font-size: 12px; }
.btn.link { border: 0; background: none; color: var(--muted); padding: 0 6px; }
.btn.link:hover { color: var(--old); }
.ps-title { font-size: 16px; font-weight: 600; }
.prog { height: 12px; border-radius: 6px; background: #eef1f3; overflow: hidden; display: flex; margin: 4px 0 16px; }
.prog .paid { background: #2fb35a; } .prog .over { background: #e8590c; }
.kpi-value.ok { color: #1e8e3e; }
.st { display: inline-block; font-size: 12px; border-radius: 10px; padding: 2px 10px; font-weight: 600; white-space: nowrap; }
.st.paid { background: #e6f6ea; color: #1e8e3e; }
.st.upcoming, .st.due { background: #eef2f4; color: #5b6670; }
.st.due { background: #e1f5fe; color: #0277bd; }
.st.overdue { background: #fdeee6; color: #c2410c; }
.st.partial { background: #fff4dc; color: #8a5a00; }
.grid tr.overdue td { background: #fff8f4; }
.grid td .sub { font-size: 12px; color: var(--muted); }
.act { white-space: nowrap; text-align: right; }
.act .btn { margin-left: 4px; }
.panel { border: 1px dashed #9dd9ef; background: #f6fcfe; border-radius: 8px; padding: 10px 14px; margin: 0 0 14px; font-size: 13px;
         display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.panel input, .panel select { height: 30px; min-width: 0; font-size: 13px; }
.panel .err { color: var(--old); width: 100%; }
.panel .grow { flex: 1; }
.w-num { width: 120px; } .w-pct { width: 56px; } .w-cnt { width: 52px; } .w-date { width: 140px; } .w-title { width: 200px; }
.reminders { background: var(--bg-soft); border-radius: 8px; padding: 10px 14px; font-size: 13px; margin-top: 14px; color: var(--muted); }
.form-row { display: flex; gap: 10px; align-items: center; margin: 8px 0; flex-wrap: wrap; }
.form-row label { min-width: 280px; }
.form-row input[type=number] { width: 70px; height: 32px; }

/* ---------- Реестр договоров ---------- */
.panel.form-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px 12px; align-items: start; }
.form-grid label, .form-grid .field { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); min-width: 0; }
.form-grid label.check { flex-direction: row; align-items: center; color: var(--text); font-size: 13px; }
.form-grid input:not([type=checkbox]) { width: 100%; height: 30px; padding: 0 8px; border: 1px solid #c6cdd3; border-radius: 4px; font: inherit; font-size: 13px; color: var(--text); }
.form-grid input.w-cnt { width: 60px; }
.form-grid .wide { grid-column: span 2; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid .hint { font-size: 11px; }
.form-grid .pick { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 13px; min-height: 30px; flex-wrap: wrap; }
.form-grid .row-btns { display: flex; gap: 8px; align-items: center; }
.grid tr.muted-row td { color: var(--muted); }
.file-link { display: inline-block; font-size: 12px; color: var(--accent-dark); margin-top: 2px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0 12px; }
@media (max-width: 720px) {
    .panel.form-grid { grid-template-columns: 1fr 1fr; }
    .form-grid .wide { grid-column: 1 / -1; }
}
.grid.contracts { min-width: 760px; }
.grid.contracts td:first-child { min-width: 200px; }

/* ---------- Сделки без следующего шага ---------- */
.grid tr.clickable { cursor: pointer; }
.grid tr.clickable:hover td { background: #f0fafe; }
.cats { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.toolbar select { min-width: 200px; }
.form-row .cats label { min-width: 0; }
.kpis.k4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 720px) { .kpis.k4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpis.k3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 720px) { .kpis.k3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* ---------- Командировки ---------- */
.head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.head h1 { margin: 0; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs button { border: 0; background: none; padding: 9px 14px; font: inherit; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.tabs .cnt { display: inline-block; min-width: 18px; padding: 0 6px; border-radius: 9px; background: #ff5752; color: #fff; font-size: 11px; margin-left: 4px; }
.st.draft, .st.cancelled { background: #eef2f4; color: #5b6670; }
.st.pending { background: #fff4dc; color: #8a5a00; }
.st.approved, .st.upcoming, .st.travelling { background: #e1f5fe; color: #0277bd; }
.st.report_wait, .st.report { background: #f1e8ff; color: #6b3fb3; }
.st.report_overdue, .st.rejected { background: #fdeee6; color: #c2410c; }
.st.closed { background: #e6f6ea; color: #1e8e3e; }
.info { display: grid; grid-template-columns: 180px 1fr; gap: 6px 14px; margin: 8px 0 16px; }
.info dt { color: var(--muted); }
.info dd { margin: 0; overflow-wrap: anywhere; }
.box { border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; margin: 0 0 14px; }
.box h3 { margin: 0 0 10px; font-size: 15px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0 16px; }
.fgrid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px 12px; }
.fgrid label, .fgrid .field { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); min-width: 0; }
.fgrid label.check { flex-direction: row; align-items: center; gap: 6px; color: var(--text); font-size: 13px; }
.fgrid input:not([type=checkbox]):not([type=file]), .fgrid select, .fgrid textarea { width: 100%; min-width: 0; height: 32px; padding: 0 8px; border: 1px solid #c6cdd3; border-radius: 4px; font: inherit; font-size: 13px; color: var(--text); background: #fff; }
.fgrid textarea { height: 60px; padding: 6px 8px; resize: vertical; }
.fgrid .w2 { grid-column: span 2; } .fgrid .w4 { grid-column: 1 / -1; }
.fgrid .pick { display: flex; align-items: center; gap: 8px; min-height: 32px; color: var(--text); font-size: 13px; flex-wrap: wrap; }
.err { color: var(--old); margin-top: 8px; }
.ok-msg { color: var(--new); }
.totals { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.calc td { padding: 4px 10px 4px 0; }
.hist { list-style: none; padding: 0; margin: 0; font-size: 13px; }
.hist li { padding: 5px 0; border-bottom: 1px dashed var(--line); }
.hist .when { color: var(--muted); margin-right: 8px; }
a.file { font-size: 12px; cursor: pointer; color: var(--accent-dark); }
.back { margin-bottom: 10px; }
@media (max-width: 720px) {
    .fgrid, .totals { grid-template-columns: 1fr 1fr; }
    .fgrid .w2 { grid-column: 1 / -1; }
    .info { grid-template-columns: 1fr; gap: 0 0; }
    .info dt { margin-top: 8px; }
}
.st.issued { background: #e1f5fe; color: #0277bd; }

/* ---------- Кадровые сроки ---------- */
.st.month { background: #fff4dc; color: #8a5a00; }
.st.soon { background: #e1f5fe; color: #0277bd; }
.kpi.clickable { cursor: pointer; border: 1px solid transparent; }
.kpi.clickable:hover { border-color: #9dd9ef; }
.kpi.on { border-color: var(--accent); background: #f0fafe; }
.kpi-value.bad { color: #c2410c; }
.tag { display: inline-flex; align-items: center; gap: 2px; background: #eef2f4; border-radius: 12px; padding: 2px 4px 2px 10px; font-size: 13px; }
.tag .btn.link { height: 22px; padding: 0 4px; }
.grid.terms { min-width: 720px; }
.grid.types { min-width: 860px; }
.grid.types input[type=text], .grid.types input[type=number], .grid.types select { height: 30px; padding: 0 8px; border: 1px solid #c6cdd3; border-radius: 4px; font: inherit; font-size: 13px; width: 100%; min-width: 0; }
.grid.types td:first-child { min-width: 320px; }
.grid.types input.w-cnt { width: 64px; } .grid.types input.w-rem { width: 100px; }
.grid td.c { text-align: center; }
.toolbar select { max-width: 280px; }
@media (max-width: 600px) {
    .grid.terms.mine { min-width: 0; }
    .grid.terms.mine th:nth-child(2), .grid.terms.mine td:nth-child(2), .grid.terms.mine th:nth-child(5), .grid.terms.mine td:nth-child(5) { display: none; }
}

/* ---------- Пени и проценты ---------- */
.pays { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.pay { display: flex; gap: 8px; align-items: center; }
.pay input { height: 32px; padding: 0 8px; border: 1px solid #c6cdd3; border-radius: 4px; font: inherit; font-size: 13px; }
.pay input[type=text] { width: 140px; }
textarea.calc-text { width: 100%; min-height: 150px; box-sizing: border-box; padding: 8px 10px; border: 1px solid #c6cdd3; border-radius: 4px; font: 13px/1.5 inherit; resize: vertical; }
ol.steps { margin: 0; padding-left: 20px; } ol.steps li { margin: 0 0 10px; }
.fgrid [hidden] { display: none; }

/* ---------- Порядок стадий ---------- */
.flow { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 6px 0; }
.flow .arrow { color: #a8b3bc; }
.stage { border: 1px solid #c6cdd3; background: #fff; border-radius: 14px; padding: 4px 12px; font: inherit; font-size: 13px; color: var(--text); cursor: pointer; }
.stage.req { border-color: #ff8a1a; background: #fff4e8; font-weight: 600; }
.stage.win { border-color: #2fb35a; }
.stage.win.req { background: #e6f6ea; }
.stage.fail { background: #fdeee6; border-color: #f3c3ad; color: #c2410c; cursor: default; }
.fails { flex-basis: 100%; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 4px; }
.modes { display: flex; flex-direction: column; gap: 6px; }
.box.rule.off { opacity: .6; }
.rule-head { display: flex; gap: 10px; align-items: center; margin-bottom: 4px; flex-wrap: wrap; }
.fgrid .modes input[type=radio] { width: auto; height: auto; padding: 0; margin: 0; flex: none; }
.fgrid .modes label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 13px; }

/* ---------- Калькулятор полей ---------- */
textarea.formula { font: 13px/1.5 ui-monospace, Menlo, Consolas, monospace; height: auto !important; min-height: 80px; }
.rule { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.rule:first-child { border-top: 0; }
.rule.off { opacity: .55; }
.rule-main { min-width: 0; }
.rule code, .grid code, .small code { background: #f2f5f7; border-radius: 4px; padding: 1px 6px; font: 12.5px ui-monospace, Menlo, Consolas, monospace; overflow-wrap: anywhere; }
.fgrid .pick select { width: auto; max-width: 320px; }
.fgrid .pick input[type=number] { width: 140px; }
