* { box-sizing: border-box; margin: 0; }
:root {
  --bg: #f4f6fa; --panel: #fff; --ink: #17233d; --muted: #67718a;
  --line: #e6eaf2;
  --blue-1: #3b74f2; --blue-2: #2857c9; --blue-3: #1c3f9e; --blue-4: #142e78; --blue-5: #0d1f54;
  --green: #1fa365; --red: #d64550; --amber: #d98a1f;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(18,32,66,.06), 0 8px 24px rgba(18,32,66,.05);
}
body { font: 14px/1.45 -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); }

.topbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; padding: 13px 22px; background: var(--panel); box-shadow: var(--shadow); position: sticky; top: 0; z-index: 5; }
.brand { font-size: 21px; font-weight: 800; letter-spacing: -.4px; }
.brand span { color: var(--blue-1); }
.brand em { font-style: normal; font-weight: 500; color: var(--muted); font-size: 12px; margin-left: 6px; text-transform: uppercase; letter-spacing: .8px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-left: auto; }
.filters label { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 4px; }
.filters input[type=date], .filters select { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; background: #fff; font: inherit; color: var(--ink); max-width: 168px; }
.filters button { background: var(--blue-1); color: #fff; border: 0; border-radius: 8px; padding: 7px 18px; font: inherit; font-weight: 650; cursor: pointer; }
.filters button:hover { background: var(--blue-2); }

main { max-width: 1280px; margin: 20px auto 60px; padding: 0 20px; }

/* --- карточки-статы --- */
.money-row, .kpi-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 14px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.stat-t { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.stat-v { font-size: 26px; font-weight: 780; margin-top: 4px; letter-spacing: -.4px; }
.stat-s { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat.sm .stat-v { font-size: 22px; }
.accent-green { color: var(--green); }
.accent-red { color: var(--red); }
.stat.mroi { background: linear-gradient(135deg, var(--blue-2), var(--blue-4)); border: 0; color: #fff; }
.stat.mroi .stat-t, .stat.mroi .stat-s { color: rgba(255,255,255,.75); }
.stat.mroi .stat-v { font-size: 32px; }
.stat.mroi.neg { background: linear-gradient(135deg, #b23a44, #7c232b); }

/* --- воронка --- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin: 14px 0; }
.panel-h { font-size: 15px; font-weight: 750; margin-bottom: 14px; color: var(--ink); }
.funnel-wrap { display: grid; grid-template-columns: 1fr 260px; gap: 24px; align-items: start; }
.funnel { display: flex; flex-direction: column; align-items: center; gap: 0; }
.fstage { color: #fff; border-radius: 9px; padding: 9px 16px; display: flex; justify-content: space-between; align-items: baseline; gap: 14px; min-width: 220px; transition: width .4s; }
.fstage .fname { font-size: 13px; font-weight: 600; opacity: .92; white-space: nowrap; }
.fstage .fval { font-size: 19px; font-weight: 780; white-space: nowrap; }
.fstage .fval small { font-size: 12px; font-weight: 600; opacity: .8; margin-left: 6px; }
.fconv { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12.5px; font-weight: 650; padding: 3px 0; }
.fconv::before { content: "↓"; color: var(--blue-1); font-size: 14px; }
.funnel-side { display: flex; flex-direction: column; gap: 8px; }
.chip { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; font-size: 13px; color: var(--muted); background: #fafbfe; }
.chip b { color: var(--ink); font-size: 15px; margin-right: 6px; }
.chip span { float: right; font-weight: 650; color: var(--blue-2); }
.chip.warn { background: #fff8ec; border-color: #f2dfba; color: #8a6414; }
.chip.warn b { color: var(--amber); }

/* --- табы и таблицы --- */
.tabs { display: flex; gap: 6px; margin-top: 18px; }
.tabs button { border: 1px solid var(--line); border-bottom: 0; background: #fff; color: var(--muted); border-radius: 10px 10px 0 0; padding: 9px 18px; font: inherit; font-weight: 650; cursor: pointer; }
.tabs button.active { background: var(--blue-1); border-color: var(--blue-1); color: #fff; }
.table-panel { margin-top: 0; border-top-left-radius: 0; max-height: 560px; overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 10px; text-align: right; border-bottom: 1px solid #eef1f7; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; max-width: 380px; white-space: normal; }
th { color: var(--muted); font-weight: 650; cursor: pointer; user-select: none; position: sticky; top: -18px; background: #fff; z-index: 1; }
tr:hover td { background: #f6f8fd; }
td.pos { color: var(--green); font-weight: 650; } td.neg { color: var(--red); font-weight: 650; }
.table-note { color: var(--muted); font-size: 12px; margin-bottom: 8px; }

/* --- вход --- */
.login-body { display: grid; place-items: center; min-height: 100vh; background: var(--bg); }
.login-card { background: var(--panel); padding: 36px; border-radius: 18px; box-shadow: var(--shadow); border: 1px solid var(--line); width: 320px; display: flex; flex-direction: column; gap: 14px; }
.login-logo { font-size: 30px; font-weight: 800; text-align: center; }
.login-logo span { color: var(--blue-1); }
.login-card h1 { font-size: 14px; font-weight: 500; color: var(--muted); text-align: center; }
.login-card input { border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; font: inherit; }
.login-card button { background: var(--blue-1); color: #fff; border: 0; border-radius: 10px; padding: 11px; font: inherit; font-weight: 700; cursor: pointer; }
.login-err { color: var(--red); text-align: center; font-size: 13px; min-height: 18px; }

@media (max-width: 900px) {
  .money-row, .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .funnel-wrap { grid-template-columns: 1fr; }
  .fstage { min-width: 180px; }
}
