:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1c2330;
  --muted: #6b7584;
  --muted-2: #c3cad4;
  --line: #e5e9ef;
  --accent: #2f6fed;
  --accent-soft: #e8f0fe;
  --accent-2: #f29d38;
  --good: #1f9d61;
  --bad: #d64545;
  --gold: #f5c542;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 2px 8px rgba(20, 30, 50, .04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151c;
    --card: #1a2029;
    --text: #e6e9ee;
    --muted: #8d97a5;
    --muted-2: #4a5462;
    --line: #2a313c;
    --accent: #5b8ff9;
    --accent-soft: #1f2c44;
    --accent-2: #f2a54a;
    --good: #3bbf7f;
    --bad: #f06c6c;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; font-weight: 650; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 14px; margin: 20px 0 8px; }
code { background: var(--accent-soft); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
.muted { color: var(--muted); font-weight: normal; }
.small { font-size: 12.5px; }
.b { font-weight: 650; }
.r { text-align: right; }
.nowrap { white-space: nowrap; }
.good { color: var(--good); }
.neg, .neg .kpi-value { color: var(--bad) !important; }

/* --- шапка --- */
.topbar { background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topbar-inner { max-width: 1400px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 20px; min-height: 56px; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 16px; color: var(--text); }
.nav { display: flex; gap: 2px; flex-wrap: wrap; flex: 1; }
.nav a { color: var(--muted); padding: 8px 12px; border-radius: 8px; }
.nav a:hover { background: var(--bg); text-decoration: none; color: var(--text); }
.nav a.active { color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.topbar-right form { margin: 0; }
.who { color: var(--muted); }
.demo-banner { background: #fff4d6; color: #6b5200; text-align: center; padding: 8px 16px; font-size: 13px; }
@media (prefers-color-scheme: dark) { .demo-banner { background: #3a3014; color: #f1d98a; } }

.container { max-width: 1400px; margin: 0 auto; padding: 20px 16px 48px; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }

/* --- период --- */
.period { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.seg { display: inline-flex; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 3px; flex-wrap: wrap; }
.seg a { padding: 6px 11px; border-radius: 7px; color: var(--muted); font-size: 13px; }
.seg a:hover { text-decoration: none; color: var(--text); }
.seg a.active { background: var(--accent); color: #fff; }
.custom-period { display: flex; gap: 6px; align-items: center; margin: 0; }
@media (max-width: 700px) {
  .period, .seg, .custom-period { width: 100%; }
  .seg a { flex: 1 0 auto; text-align: center; padding: 6px 8px; }
  .custom-period input { flex: 1; min-width: 0; }
  .topbar-inner { gap: 8px; padding: 6px 16px; }
  .nav a { padding: 6px 9px; }
}

/* --- формы и кнопки --- */
input, select {
  font: inherit; color: var(--text); background: var(--card);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px;
}
input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input.num { width: 120px; text-align: right; }
input.num.short { width: 70px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; font-size: 14px; color: var(--text); margin-bottom: 12px; }
.btn {
  font: inherit; font-weight: 550; cursor: pointer; border-radius: 8px; padding: 8px 14px;
  border: 1px solid var(--line); background: var(--card); color: var(--text); display: inline-block;
}
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.danger { color: var(--bad); }
.btn.wide { width: 100%; }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.form-row .grow { flex: 1; min-width: 200px; }
form.inline { display: flex; gap: 6px; margin: 0; }

.alert { padding: 10px 14px; border-radius: 10px; margin-bottom: 16px; }
.alert.error { background: #fde8e8; color: #8a1f1f; }
.alert.success { background: #e3f6ec; color: #145c38; }
.alert.info { background: var(--accent-soft); color: var(--text); }
@media (prefers-color-scheme: dark) {
  .alert.error { background: #3d1d1d; color: #f6b4b4; }
  .alert.success { background: #173626; color: #9fe0bd; }
}

/* --- карточки и сетки --- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; border: 1px solid var(--line); }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-2.wide-left { grid-template-columns: 2fr 1fr; }
.grid-2.wide-right { grid-template-columns: 1fr 2fr; }
.grid-2 > .card { margin-bottom: 0; }
.grid-2 + * { margin-top: 16px; }
@media (max-width: 900px) { .grid-2, .grid-2.wide-left, .grid-2.wide-right { grid-template-columns: 1fr; } }
.scroll-x { overflow-x: auto; }
.chart-box { position: relative; height: 300px; }

/* --- KPI --- */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi-label { color: var(--muted); font-size: 12.5px; }
.kpi-value { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.kpi-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.kpi.accent { border-color: var(--good); }
.kpi.accent .kpi-value { color: var(--good); }

/* --- таблицы --- */
.table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table th { text-align: left; font-weight: 550; color: var(--muted); font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: bottom; }
.table th.r { text-align: right; }
.table td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tfoot td { font-weight: 650; border-top: 2px solid var(--line); border-bottom: none; }
.table.narrow { max-width: 700px; }
.table tr.me td { background: var(--accent-soft); }
.table tr.add-row td { background: var(--bg); }
.table.inner { margin: 4px 0 8px; }
.table.inner td, .table.inner th { padding: 5px 8px; font-size: 13px; }
tr.expandable { cursor: pointer; }
tr.expandable:hover td { background: var(--bg); }
tr.details { display: none; }
tr.details.open { display: table-row; }
.pnl td.indent, td.indent { padding-left: 26px; }
tr.child td { font-size: 13px; background: var(--bg); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs a { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a:hover { text-decoration: none; color: var(--text); }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.form-row.card { align-items: flex-end; }
.pnl tr.subtotal td { font-weight: 650; background: var(--bg); }
.pnl tr.total td { font-weight: 750; font-size: 15px; border-top: 2px solid var(--text); }

.mini-bar { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; width: 60px; display: inline-block; vertical-align: middle; margin-right: 6px; }
.mini-bar.wide { display: block; width: 100%; margin-top: 5px; }
.mini-bar span { display: block; height: 100%; background: var(--accent); }

.tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 10px; background: var(--accent); color: #fff; vertical-align: middle; }
.tag.ok { background: var(--good); }
.tag.warn { background: var(--accent-2); }

/* --- кабинет сотрудника --- */
.hero {
  display: flex; justify-content: space-between; align-items: center; gap: 24px; flex-wrap: wrap;
  background: linear-gradient(135deg, var(--accent), #6a4cf0); color: #fff;
  border-radius: 16px; padding: 24px 28px; margin-bottom: 16px;
}
.hero-label { opacity: .85; }
.hero-value { font-size: 44px; font-weight: 800; letter-spacing: -.5px; line-height: 1.1; margin: 4px 0; white-space: nowrap; }
.hero-sub { opacity: .85; font-size: 13px; }
.hero-rank { display: flex; align-items: center; gap: 14px; background: rgba(255, 255, 255, .14); padding: 12px 18px; border-radius: 12px; }
.hero-rank .muted { color: rgba(255, 255, 255, .85); }
.hero-rank .good { color: #b9f5d2; }
.rank-badge { font-size: 34px; min-width: 48px; text-align: center; font-weight: 800; }
@media (max-width: 600px) { .hero-value { font-size: 34px; } .hero { padding: 20px; } }

.progress { position: relative; height: 14px; background: var(--line); border-radius: 8px; overflow: hidden; margin: 6px 0 10px; }
.progress.big { height: 26px; border-radius: 13px; }
.progress span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), #6a4cf0); border-radius: inherit; transition: width .6s; }
.progress span.done { background: linear-gradient(90deg, var(--good), #5fd39a); }
.progress em { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); font-style: normal; font-weight: 700; font-size: 13px; }

.today-card { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.today-main { display: flex; align-items: center; gap: 16px; }
.today-num { font-size: 44px; font-weight: 800; color: var(--good); min-width: 64px; text-align: center; font-variant-numeric: tabular-nums; }
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 50;
  background: var(--good); color: #fff; font-weight: 650; padding: 14px 22px; border-radius: 12px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .2); max-width: calc(100% - 32px); text-align: center;
}
.leaderboard td.place { font-size: 18px; width: 36px; text-align: center; }

.steps li { margin-bottom: 8px; }

/* --- вход --- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.login-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { font-size: 20px; }
.login-card p { margin: 0; }
.login-card .alert { margin: 0; font-size: 13px; }
