/* Торг-Трейд — Учёт по офисам. Корпоративный стиль. */
:root {
  --brand: #0b5cad;
  --brand-dark: #08457f;
  --brand-light: #e8f1fb;
  --accent: #f5a623;
  --bg: #f3f6fa;
  --surface: #ffffff;
  --text: #1c2733;
  --muted: #6b7a8c;
  --border: #dde4ed;
  --green: #148a4b;
  --green-bg: #e5f5ec;
  --red: #c8372d;
  --red-bg: #fbeaea;
  --amber-bg: #fff6e5;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 38, 66, .06), 0 2px 8px rgba(16, 38, 66, .05);
  --sidebar: 236px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.45;
}
a { color: var(--brand); text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 600; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.muted { color: var(--muted); }
.pos { color: var(--green); }
.neg { color: var(--red); }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar); flex-shrink: 0; background: var(--brand-dark); color: #fff;
  position: fixed; inset: 0 auto 0 0; display: flex; flex-direction: column; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 20px 18px 18px; border-bottom: 1px solid rgba(255,255,255,.12); }
.brand-mark {
  width: 38px; height: 38px; border-radius: 9px; background: #fff; color: var(--brand);
  display: grid; place-items: center; font-weight: 800; font-size: 17px; letter-spacing: -.5px;
}
.brand-name { font-weight: 700; font-size: 15px; line-height: 1.15; }
.brand-sub { font-size: 12px; opacity: .7; }
.nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; }
.nav a {
  color: rgba(255,255,255,.82); padding: 9px 12px; border-radius: 8px; display: flex; align-items: center; gap: 10px;
}
.nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav a.active { background: #fff; color: var(--brand-dark); font-weight: 600; }
.nav svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-sep { height: 1px; background: rgba(255,255,255,.12); margin: 8px 6px; }
.sidebar-foot { margin-top: auto; padding: 14px 18px; font-size: 12px; }
.user-box { background: rgba(255,255,255,.08); border-radius: 9px; padding: 10px 12px; }
.user-name { color: #fff; font-weight: 600; font-size: 13.5px; display: block; }
.user-role { opacity: .7; margin: 2px 0 6px; }
.user-logout { color: #cfe0f5; font-size: 12.5px; }
.user-logout:hover, .user-name:hover { text-decoration: underline; }

.main { margin-left: var(--sidebar); flex: 1; min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 10; background: rgba(243,246,250,.94); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 16px 28px; border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 21px; }
.period { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.month-switch { display: flex; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
.month-switch button { border: 0; background: none; padding: 7px 10px; cursor: pointer; color: var(--muted); font-size: 15px; }
.month-switch button:hover { color: var(--brand); }
.month-switch span { min-width: 120px; text-align: center; font-weight: 600; }
.content { padding: 24px 28px 48px; max-width: 1400px; }
.topbar .menu-btn { display: none; }
.grid > *, .kpis > *, .deal-layout > * { min-width: 0; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid transparent; border-radius: 8px;
  padding: 8px 14px; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; transition: .15s;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { border-color: var(--brand); color: var(--brand); }
.btn-danger { background: var(--red); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.icon-btn {
  border: 0; background: none; cursor: pointer; padding: 5px 7px; border-radius: 6px; color: var(--muted); font-size: 15px; line-height: 1;
}
.icon-btn:hover { background: var(--brand-light); color: var(--brand); }
.icon-btn.del:hover { background: var(--red-bg); color: var(--red); }

input, select, textarea {
  font: inherit; color: var(--text); background: #fff; border: 1px solid var(--border); border-radius: 7px;
  padding: 7px 10px; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(11,92,173,.2); border-color: var(--brand); }
input[type=checkbox] { width: auto; }
.period select { width: auto; min-width: 160px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); font-weight: 600; }
label.field.req > span::after { content: " *"; color: var(--red); }
.check { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; font-size: 13px; color: var(--text); }

.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .grow { flex: 1; }
.toolbar input[type=search] { max-width: 300px; }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-head h2 { font-size: 15px; }
.card-body { padding: 16px 18px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: 1.6fr 1fr; }
.mt { margin-top: 16px; }

.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 16px; }
.kpi { padding: 16px 18px; border-top: 3px solid var(--brand); }
.kpi.k-amber { border-top-color: var(--accent); }
.kpi.k-green { border-top-color: var(--green); }
.kpi.k-red { border-top-color: var(--red); }
.kpi-label { font-size: 12.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .3px; }
.kpi-value { font-size: 25px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi-note { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .2px; color: var(--muted); font-weight: 600; background: #f8fafc; white-space: nowrap; }
tbody tr:hover { background: #f8fbff; }
tfoot td { font-weight: 700; background: #f8fafc; border-bottom: 0; }
td.actions { white-space: nowrap; text-align: right; width: 1%; }
tr.clickable { cursor: pointer; }
.empty { text-align: center; color: var(--muted); padding: 36px 12px !important; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-blue { background: var(--brand-light); color: var(--brand); }
.badge-amber { background: var(--amber-bg); color: #9a6200; }
.badge-gray { background: #eef1f5; color: var(--muted); }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,30,50,.45); z-index: 100; display: flex; align-items: flex-start;
  justify-content: center; padding: 32px 16px; overflow-y: auto;
}
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 560px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { max-width: 1080px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 17px; }
.modal-body { padding: 18px 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); background: #fafbfd; border-radius: 0 0 12px 12px; }
.form-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px 14px; }
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-4 { grid-column: 1 / -1; }
.section-title { display: flex; align-items: center; justify-content: space-between; margin: 20px 0 8px; }
.section-title h3 { font-size: 14px; }
.lines td { padding: 5px 6px; }
.lines th { padding: 7px 6px; }
.lines input, .lines select { padding: 6px 8px; }
.lines .w-qty { width: 68px; }
.lines .w-money { width: 108px; }
.lines .w-nds { width: 78px; }
.lines .w-type { width: 210px; }
.lines .i-name { min-width: 180px; }
.lines .e-desc { min-width: 220px; }
td.client { min-width: 170px; }

.deal-layout { display: grid; grid-template-columns: 1fr 290px; gap: 20px; }
.calc-box { background: #f6f9fd; border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; align-self: start; position: sticky; top: 0; }
.calc-box h3 { font-size: 14px; margin-bottom: 10px; }
.calc-row { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; font-size: 13.5px; }
.calc-row.total { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 10px; font-weight: 700; font-size: 16px; }
.calc-note { font-size: 12px; color: var(--muted); margin-top: 10px; }
.hint { font-size: 12px; color: var(--muted); }

/* ---------- toast ---------- */
#toasts { position: fixed; right: 20px; bottom: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--text); color: #fff; padding: 11px 16px; border-radius: 8px; box-shadow: var(--shadow); max-width: 380px; animation: slide .2s ease-out; }
.toast.success { background: var(--green); }
.toast.error { background: var(--red); }
@keyframes slide { from { transform: translateY(10px); opacity: 0; } }

/* ---------- chart ---------- */
.chart svg { width: 100%; height: 220px; display: block; }
.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

.office-group { margin-bottom: 16px; }
.vat-list .calc-row { font-size: 14px; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .deal-layout { grid-template-columns: 1fr; }
  .calc-box { position: static; }
}
@media (max-width: 800px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s; }
  body.nav-open .sidebar { transform: none; }
  .main { margin-left: 0; }
  .topbar .menu-btn { display: inline-flex; }
  .topbar { padding: 12px 16px; }
  .content { padding: 16px; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .kpi-value { font-size: 20px; }
}

@media print {
  .sidebar, .topbar .period, .toolbar, .actions, .menu-btn { display: none !important; }
  .main { margin: 0; }
  .card { box-shadow: none; }
  body { background: #fff; }
}

/* ---------- Битрикс24 ---------- */
.b24-quick { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.b24-quick .grow, .modal-foot .grow { flex: 1; }
.modal-foot { align-items: center; }
.b24-table select { min-width: 130px; }
tr.muted td { color: var(--muted); }
.notice { background: var(--amber-bg); border: 1px solid #f3d08a; color: #6d4a00; padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 13.5px; }
select.invalid, input.invalid { border-color: var(--red); background: var(--red-bg); }

/* ---------- вход ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px;
  background: linear-gradient(160deg, var(--brand-dark) 0%, var(--brand) 55%, #2d7fd0 100%); }
.login-card { background: var(--surface); width: 100%; max-width: 380px; border-radius: 14px; padding: 26px 26px 22px;
  box-shadow: 0 20px 50px rgba(0,0,0,.25); display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { font-size: 20px; margin-top: 4px; }
.login-brand { border: 0; padding: 0; color: var(--text); }
.login-brand .brand-mark { background: var(--brand); color: #fff; }
.login-brand .brand-sub { color: var(--muted); opacity: 1; }
.login-btn { justify-content: center; padding: 11px; font-size: 15px; margin-top: 4px; }
.login-error { background: var(--red-bg); color: var(--red); padding: 9px 12px; border-radius: 8px; font-size: 13.5px; }

/* ---------- премия в списке ---------- */
.bonus-input { width: 96px; text-align: right; padding: 5px 8px; font-variant-numeric: tabular-nums; }
.bonus-input.saved { border-color: var(--green); background: var(--green-bg); }
.bonus-input.multi { background: #f3f5f8; color: var(--muted); cursor: pointer; }
.margin-pill { display: inline-block; min-width: 54px; text-align: center; padding: 2px 7px; border-radius: 12px; font-weight: 700; font-size: 12.5px; }
.m-good { background: var(--green-bg); color: var(--green); }
.m-mid { background: var(--amber-bg); color: #9a6200; }
.m-bad { background: var(--red-bg); color: var(--red); }
.b24-box { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-top: 12px; background: #fafcff; font-size: 13px; }
.b24-box .row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.readonly { background: #f3f5f8; color: var(--muted); }
.company-suggest { position: relative; }
.suggest-list { position: absolute; z-index: 5; top: 100%; left: 0; right: 0; background: #fff; border: 1px solid var(--border);
  border-radius: 8px; box-shadow: var(--shadow); max-height: 220px; overflow-y: auto; margin-top: 2px; }
.suggest-list div { padding: 7px 10px; cursor: pointer; font-size: 13.5px; color: var(--text); font-weight: 400; }
.suggest-list div:hover, .suggest-list div.active { background: var(--brand-light); }
.suggest-list .new { color: var(--brand); border-top: 1px solid var(--border); }

/* ---------- журнал ---------- */
.log-row { border-left: 3px solid var(--brand-light); padding: 6px 10px; margin-bottom: 8px; background: #fafcff; border-radius: 0 6px 6px 0; }
.log-head { font-size: 12.5px; margin-bottom: 2px; }
.log-line { font-size: 13px; color: var(--text); }

/* ---------- инструкция ---------- */
.help-tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.help-tab { border: 1px solid var(--border); background: var(--surface); padding: 8px 16px; border-radius: 20px; font: inherit; font-weight: 600; cursor: pointer; color: var(--muted); }
.help-tab.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.help-hero { display: grid; grid-template-columns: 1.4fr 1fr; gap: 24px; padding: 22px 24px; margin-bottom: 16px;
  background: linear-gradient(135deg, #fff 55%, var(--brand-light)); border-top: 3px solid var(--brand); }
.help-hero h2 { font-size: 20px; margin: 4px 0 8px; }
.help-hero p { margin: 0; color: var(--muted); max-width: 560px; }
.help-kicker { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--brand); font-weight: 700; }
.help-flow { display: flex; flex-direction: column; align-items: stretch; gap: 2px; justify-content: center; }
.flow-step { background: #fff; border: 1px solid var(--border); border-radius: 9px; padding: 8px 12px; font-size: 13.5px; display: flex; align-items: center; gap: 10px; }
.flow-num { width: 22px; height: 22px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-size: 12px; font-weight: 700; flex-shrink: 0; }
.flow-arrow { text-align: center; color: var(--muted); font-size: 12px; line-height: 1; }
.help-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 16px; }
.help-grid > * { min-width: 0; }
.help-card, .help-wide { padding: 18px 20px; position: relative; }
.help-wide { margin-bottom: 16px; }
.help-card h3, .help-wide h3 { font-size: 15.5px; margin: 0 0 8px; padding-right: 36px; }
.help-card p, .help-wide p { margin: 6px 0; font-size: 13.5px; }
.help-card ul, .help-card ol, .help-wide ul { margin: 6px 0; padding-left: 18px; font-size: 13.5px; }
.help-card li, .help-wide li { margin: 3px 0; }
.help-wide h4 { font-size: 13.5px; margin: 12px 0 2px; color: var(--brand-dark); }
.help-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; }
.help-cols > * { min-width: 0; }
.help-step { position: absolute; top: 14px; right: 16px; width: 28px; height: 28px; border-radius: 8px; background: var(--brand-light); color: var(--brand); font-weight: 800; display: grid; place-items: center; }
.mock-notify { background: #f4f7fb; border: 1px solid var(--border); border-left: 3px solid var(--brand); border-radius: 8px; padding: 9px 12px; font-size: 13px; margin: 8px 0; }
.mock-notify .link { color: var(--brand); text-decoration: underline; }
.formula { background: #f6f9fd; border: 1px solid var(--border); border-radius: 10px; padding: 12px 16px; font-size: 14px; display: flex; flex-direction: column; gap: 6px; margin: 4px 0 8px; }
.f-label { display: inline-block; min-width: 170px; font-weight: 700; color: var(--brand-dark); }
@media (max-width: 1100px) { .help-grid { grid-template-columns: 1fr 1fr; } .help-hero { grid-template-columns: 1fr; } }
@media (max-width: 800px) { .help-grid, .help-cols { grid-template-columns: 1fr; } .f-label { min-width: 0; display: block; } }
@media print {
  .help-tabs { display: none; }
  .help-page.hidden { display: block !important; break-before: page; }
  .help-card, .help-wide, .help-hero { break-inside: avoid; }
}

/* ---------- статусы ---------- */
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-green { background: var(--green-bg); color: var(--green); }
.btn-green { background: var(--green); color: #fff; }
.btn-green:hover { background: #0f6e3b; }
.rework-box { padding: 12px 20px; border-top: 1px solid var(--border); background: #fff8f7; }

.report-filters { display: flex; flex-wrap: wrap; gap: 12px 16px; padding: 14px 18px; margin-bottom: 16px; align-items: end; }
.report-filters .field { min-width: 160px; }
