:root {
  --bg: #f4f6fa; --panel: #fff; --text: #0f172a; --muted: #64748b; --line: #e2e8f0;
  --primary: #1e40af; --primary-2: #2563eb; --ok: #16a34a; --warn: #d97706; --bad: #dc2626;
  --side: #0f1b3d; --side-text: #cbd5e1; --radius: 10px;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; color: var(--text); background: var(--bg); display: flex; min-height: 100vh; }
a { color: var(--primary-2); }
h1 { font-size: 22px; margin: 0 0 4px; } h2 { font-size: 16px; margin: 0 0 12px; } h3 { font-size: 14px; margin: 16px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.sidebar { width: 230px; background: var(--side); color: var(--side-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; flex-shrink: 0; }
.brand { display: flex; gap: 10px; align-items: center; padding: 18px 16px; border-bottom: 1px solid #1e2b55; }
.brand .logo { width: 40px; height: 40px; border-radius: 9px; background: linear-gradient(135deg, #2563eb, #1e40af); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 13px; }
.brand b { color: #fff; font-size: 17px; display: block; } .brand small { font-size: 11px; color: #94a3b8; }
nav { padding: 10px 8px; flex: 1; }
nav a { display: flex; gap: 10px; padding: 9px 12px; border-radius: 8px; color: var(--side-text); text-decoration: none; margin-bottom: 2px; }
nav a:hover { background: #1a2852; color: #fff; }
nav a.active { background: var(--primary-2); color: #fff; }
.user { padding: 14px 16px; border-top: 1px solid #1e2b55; } .user label { font-size: 11px; color: #94a3b8; display: block; margin-bottom: 4px; }
.user .who b { color: #fff; } .user .who small { color: #94a3b8; }
.user-actions { display: flex; gap: 6px; margin-top: 8px; }
.user-actions button { font: inherit; font-size: 12px; flex: 1; background: #1a2852; color: #cbd5e1; border: 1px solid #2a3a6b; border-radius: 6px; padding: 5px 6px; cursor: pointer; }
.user-actions button:hover { background: #24356b; color: #fff; }
body.anon .sidebar, body.anon main { display: none; }
.login { position: fixed; inset: 0; display: grid; place-items: center; background: linear-gradient(135deg, #0f1b3d, #1e40af); padding: 16px; }
.login-box { background: #fff; border-radius: 14px; padding: 28px; width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.login-box p { margin: 0; }
.brand-big { display: flex; gap: 12px; align-items: center; margin-bottom: 6px; }
.brand-big .logo { width: 48px; height: 48px; border-radius: 11px; background: linear-gradient(135deg, #2563eb, #1e40af); color: #fff; display: grid; place-items: center; font-weight: 800; }
.brand-big b { font-size: 20px; display: block; } .brand-big small { color: var(--muted); }
.pwd { font-family: Consolas, monospace; font-size: 18px; background: #f1f5f9; padding: 8px 12px; border-radius: 8px; display: inline-block; user-select: all; }

main { flex: 1; padding: 24px 28px; min-width: 0; }
.loading { color: var(--muted); padding: 40px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin: 0; color: var(--muted); }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.calc-layout { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(320px, 1fr); gap: 16px; align-items: start; }
.as-layout { grid-template-columns: 280px minmax(0, 1fr); }
@media (max-width: 1100px) { .as-layout { grid-template-columns: 1fr; } .g4 { grid-template-columns: repeat(2, 1fr); } .g3, .calc-layout { grid-template-columns: 1fr; } }
@media (max-width: 760px) { body { flex-direction: column; } .sidebar { width: 100%; height: auto; position: static; } nav { display: flex; flex-wrap: wrap; } nav a span { display: none; } .user { display: none; } .g2, .g4 { grid-template-columns: 1fr; } main { padding: 16px; } }

.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.kpi .l { color: var(--muted); font-size: 12px; } .kpi .v { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; } .kpi .s { font-size: 12px; color: var(--muted); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #f8fafc; position: sticky; top: 0; }
tr.click { cursor: pointer; } tr.click:hover td { background: #f1f5ff; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }

label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
input, select, textarea { font: inherit; padding: 7px 9px; border: 1px solid #cbd5e1; border-radius: 7px; background: #fff; color: var(--text); min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--primary-2); }
textarea { resize: vertical; min-height: 60px; }
label.chk { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--text); cursor: pointer; }
.form { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px 14px; }
.form .wide { grid-column: 1 / -1; }

.btn { font: inherit; border: 1px solid #cbd5e1; background: #fff; color: var(--text); padding: 7px 14px; border-radius: 7px; cursor: pointer; white-space: nowrap; text-decoration: none; display: inline-flex; gap: 6px; align-items: center; }
.btn:hover { background: #f1f5f9; }
.btn.primary { background: var(--primary-2); border-color: var(--primary-2); color: #fff; } .btn.primary:hover { background: var(--primary); }
.btn.danger { color: var(--bad); border-color: #fecaca; } .btn.sm { padding: 4px 9px; font-size: 12px; }
.btn.ghost { border-color: transparent; background: transparent; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; color: #fff; white-space: nowrap; }
.tag { display: inline-block; padding: 1px 7px; border-radius: 6px; font-size: 11px; background: #eef2ff; color: #3730a3; margin: 1px 2px 1px 0; }
.tag.ok { background: #dcfce7; color: #166534; } .tag.warn { background: #fef3c7; color: #92400e; } .tag.bad { background: #fee2e2; color: #991b1b; }
.muted { color: var(--muted); } .small { font-size: 12px; } .pos { color: var(--ok); } .neg { color: var(--bad); }
.right { text-align: right; } .row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; } .spacer { flex: 1; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button { font: inherit; border: none; background: none; padding: 10px 14px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--primary-2); border-bottom-color: var(--primary-2); font-weight: 600; }

/* Калькулятор */
.res-line { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px dashed var(--line); font-variant-numeric: tabular-nums; }
.res-line.total { font-weight: 700; font-size: 16px; border-bottom: none; padding-top: 10px; }
.res-line.sub { color: var(--muted); font-size: 12px; padding-left: 12px; }
.big-box { border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; color: #fff; background: linear-gradient(135deg, #1e40af, #2563eb); }
.big-box .v { font-size: 26px; font-weight: 800; } .big-box.bad { background: linear-gradient(135deg, #991b1b, #dc2626); } .big-box.warn { background: linear-gradient(135deg, #92400e, #d97706); } .big-box.ok { background: linear-gradient(135deg, #166534, #16a34a); }
.costs-row { display: grid; grid-template-columns: 1fr 150px 70px 32px; gap: 6px; margin-bottom: 6px; align-items: center; }
.alert { padding: 10px 12px; border-radius: 8px; margin-bottom: 10px; font-size: 13px; }
.alert.warn { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; } .alert.bad { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; } .alert.info { background: #eff6ff; border: 1px solid #bfdbfe; color: #1e3a8a; }

/* Канбан */
.kanban { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; }
.kcol { background: #eef1f6; border-radius: var(--radius); min-width: 250px; width: 250px; flex-shrink: 0; display: flex; flex-direction: column; max-height: calc(100vh - 150px); }
.kcol .kh { padding: 10px 12px; font-weight: 600; font-size: 13px; display: flex; justify-content: space-between; border-top: 3px solid; border-radius: var(--radius) var(--radius) 0 0; }
.kcol .kb { padding: 0 8px 8px; overflow-y: auto; min-height: 60px; flex: 1; } .kcol.over { background: #dbeafe; }
.kcard { background: #fff; border-radius: 8px; padding: 10px; margin-bottom: 8px; border: 1px solid var(--line); cursor: grab; font-size: 13px; }
.kcard:hover { border-color: var(--primary-2); } .kcard .t { font-weight: 600; margin-bottom: 4px; } .kcard .m { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; gap: 6px; }

.funnel-row { display: grid; grid-template-columns: 170px 1fr 40px; gap: 8px; align-items: center; margin-bottom: 6px; font-size: 13px; }
.funnel-bar { height: 18px; border-radius: 4px; min-width: 2px; }
.timeline { border-left: 2px solid var(--line); margin-left: 6px; padding-left: 16px; }
.timeline .ev { position: relative; margin-bottom: 12px; } .timeline .ev::before { content: ''; position: absolute; left: -22px; top: 5px; width: 10px; height: 10px; border-radius: 50%; background: var(--primary-2); }
.checklist label { display: flex; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); cursor: pointer; } .checklist .done { text-decoration: line-through; color: var(--muted); }

.ent-card { border-left: 4px solid var(--primary-2); } .ent-card.rec { border-left-color: var(--ok); background: #f6fef9; } .ent-card.blocked { border-left-color: var(--bad); opacity: .85; }
.modal { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal-box { background: #fff; border-radius: 12px; padding: 22px; width: min(860px, 100%); max-height: 90vh; overflow: auto; }
.hidden { display: none !important; }
.toast { position: fixed; bottom: 20px; right: 20px; background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 60; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.toast.err { background: var(--bad); }
.empty { text-align: center; padding: 30px; color: var(--muted); }
