:root {
  --bg: #eef1f6;
  --card: #ffffff;
  --text: #1f2733;
  --muted: #6b7785;
  --accent: #d6202a;
  --accent-dark: #b01821;
  --accent-soft: #fbe7e8;
  --info: #3b6ef5;
  --success: #1faa6e;
  --warn: #e0961a;
  --danger: #d6202a;
  --border: #e2e7ef;
  --shadow: 0 1px 3px rgba(20, 30, 50, .07), 0 6px 18px rgba(20, 30, 50, .05);
  --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { overflow-x: clip; }

body {
  font-family: "Segoe UI", Roboto, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}

/* ───────── Topbar ───────── */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px 18px; padding: 11px 28px; flex-wrap: wrap;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(20, 30, 50, .03);
}
.topbar__left { display: flex; align-items: center; gap: 15px; }
.brand { display: flex; align-items: center; gap: 9px; text-decoration: none; }
.brand__icon { height: 34px; width: auto; display: block; }
.brand__name {
  font-family: "Arial Black", "Segoe UI", Roboto, sans-serif;
  font-weight: 900; font-size: 17px; letter-spacing: .2px;
  color: var(--text); line-height: 1; white-space: nowrap;
}
.brand__red { color: var(--accent); }
.topbar__divider { width: 1px; height: 32px; background: var(--border); }
.topbar__title { font-size: 17px; font-weight: 700; }

.seg {
  display: inline-flex; background: var(--bg); border: 1px solid var(--border);
  border-radius: 9px; padding: 2px; gap: 2px;
}
.seg__btn {
  border: 0; background: transparent; color: var(--muted);
  font-size: 12.5px; font-weight: 600; padding: 5px 12px; border-radius: 7px;
  cursor: pointer; transition: background .14s, color .14s;
}
.seg__btn:hover { color: var(--text); }
.seg__btn.is-active { background: var(--accent); color: #fff; }
.topbar__crumbs { font-size: 13px; color: var(--muted); margin-top: 1px; }
.topbar__crumbs a { color: var(--accent); text-decoration: none; }
.topbar__crumbs a:hover { text-decoration: underline; }
.topbar__right { display: flex; align-items: center; gap: 14px; }
.topbar__updated { font-size: 12px; color: var(--muted); }

.year-select { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 7px; }
.year-select select {
  font-size: 14px; padding: 6px 10px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  cursor: pointer;
}
.btn {
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  width: 36px; height: 34px; border-radius: 9px; cursor: pointer;
  font-size: 16px; transition: background .15s;
}
.btn:hover { background: var(--accent-soft); }

/* ───────── Layout ───────── */
main { padding: 24px 28px 48px; max-width: 1500px; margin: 0 auto; }
.loader { padding: 60px; text-align: center; color: var(--muted); }
.section-title {
  font-size: 15px; font-weight: 700; margin: 26px 0 14px;
  display: flex; align-items: center; gap: 8px;
}
.section-title .hint { font-weight: 400; font-size: 12px; color: var(--muted); }
.error-box {
  background: #fdecee; border: 1px solid #f3c0c6; color: #a32636;
  padding: 16px 20px; border-radius: var(--radius); margin-top: 20px;
}

/* ───────── KPI tiles ───────── */
.kpi-row {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}
.kpi {
  background: var(--card); border-radius: var(--radius); padding: 16px 18px;
  box-shadow: var(--shadow); border-left: 4px solid var(--accent);
}
.kpi--work { border-color: var(--accent); }
.kpi--revision { border-color: var(--warn); }
.kpi--paused { border-color: var(--muted); }
.kpi--month { border-color: #8b5cf6; }
.kpi--year { border-color: var(--success); }
.kpi__label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi__value { font-size: 30px; font-weight: 700; margin-top: 6px; line-height: 1.1; }
.kpi__sub { font-size: 13px; color: var(--muted); margin-top: 4px; }
.kpi__sub b { color: var(--text); font-weight: 600; }

/* ───────── Charts ───────── */
.chart-grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
}
.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px;
  min-width: 0; /* позволяет карточке сжиматься в grid, таблица скроллится внутри */
}
.card__title { font-size: 14px; font-weight: 600; margin-bottom: 12px; }
.card__title .hint { font-weight: 400; font-size: 12px; color: var(--muted); }
.card__title--row { display: flex; align-items: center; gap: 10px; }
.card__title--row .seg { margin-left: auto; }
.chart-wrap { position: relative; height: 300px; }
.chart-wrap--tall { height: 380px; }

/* ───────── Department cards ───────── */
.dept-grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
}
.dept-card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; cursor: pointer; border: 1px solid transparent;
  transition: transform .12s, border-color .12s, box-shadow .12s;
  display: flex; flex-direction: column; gap: 14px;
}
.dept-card:hover { transform: translateY(-3px); border-color: var(--accent); }
.dept-card__head { display: flex; justify-content: space-between; gap: 10px; }
.dept-card__name { font-size: 15px; font-weight: 700; line-height: 1.3; }
.dept-card__parent { font-size: 11.5px; color: var(--accent); margin-top: 2px; }
.dept-card__meta { font-size: 12px; color: var(--muted); margin-top: 3px; }
.badge {
  font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 20px;
  background: var(--accent-soft); color: var(--accent); white-space: nowrap; height: fit-content;
}
.badge--prod { background: #e6f7ef; color: var(--success); }

.dept-card__stats { display: flex; gap: 8px; }
.stat {
  flex: 1; text-align: center; padding: 8px 4px; border-radius: 10px; background: var(--bg);
}
.stat__num { font-size: 20px; font-weight: 700; }
.stat__lbl { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.stat--work .stat__num { color: var(--accent); }
.stat--revision .stat__num { color: var(--warn); }
.stat--paused .stat__num { color: var(--muted); }

.dept-card__foot {
  display: flex; justify-content: space-between; align-items: baseline;
  border-top: 1px dashed var(--border); padding-top: 10px;
}
.dept-card__foot .lbl { font-size: 12px; color: var(--muted); }
.dept-card__foot .val { font-size: 15px; font-weight: 700; color: var(--success); }
.loadbar { height: 6px; border-radius: 4px; background: var(--bg); overflow: hidden; display: flex; }
.loadbar > span { display: block; height: 100%; }

/* ───────── Tables ───────── */
.tbl-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th {
  text-align: left; padding: 9px 12px; color: var(--muted); font-weight: 600;
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em;
  border-bottom: 2px solid var(--border);
}
table.data th.num, table.data td.num { text-align: right; }
table.data td { padding: 9px 12px; border-bottom: 1px solid var(--border); }
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: var(--bg); }
.crown { color: var(--warn); }
.rest { color: var(--accent); font-weight: 600; }

.pill {
  font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 20px;
  display: inline-block;
}
.pill--green { background: #e6f7ef; color: var(--success); }
.pill--amber { background: #fdf0db; color: var(--warn); }
.pill--red { background: #fdecee; color: var(--danger); }
.pill--grey { background: var(--bg); color: var(--muted); }
.pill--blue { background: var(--accent-soft); color: var(--accent); }

.back-link {
  display: inline-flex; align-items: center; gap: 6px; font-size: 13px;
  color: var(--accent); text-decoration: none; margin-bottom: 6px;
}
.back-link:hover { text-decoration: underline; }
.dept-title { font-size: 22px; font-weight: 700; margin: 4px 0; }
.dept-subtitle { font-size: 13px; color: var(--muted); margin-bottom: 18px; }

.empty { padding: 28px; text-align: center; color: var(--muted); font-size: 13px; }

/* ───────── Сортируемые таблицы ───────── */
.data--sortable th { cursor: pointer; user-select: none; white-space: nowrap; transition: color .12s; }
.data--sortable th:hover { color: var(--text); }
.data--sortable th.is-sorted { color: var(--accent); }
.th-arrow { font-size: 9px; margin-left: 3px; }

/* Строка итогов над заголовком таблицы */
.tbl-summary td {
  background: var(--bg); font-weight: 700; font-size: 12.5px;
  color: var(--text); padding: 8px 12px; white-space: nowrap;
  border-bottom: 2px solid var(--border);
}
.tbl-summary td.num { text-align: right; }
.muted { color: var(--muted); }
.section-title .seg { margin-left: auto; }

/* ───────── Маленький сегмент-контрол (в графике) ───────── */
.seg--sm { padding: 2px; }
.seg--sm .seg__btn { padding: 3px 10px; font-size: 11.5px; }

/* ───────── Карточка сотрудника ───────── */
.emp-link { color: var(--accent); text-decoration: none; }
.emp-link:hover { text-decoration: underline; }
.emp-info {
  font-size: 13px; color: var(--muted); margin: -8px 0 18px;
  display: flex; flex-wrap: wrap; align-items: center;
}
.emp-info .dot { margin: 0 9px; color: var(--border); }
.badge--off { background: #eef0f3; color: var(--muted); }

/* ───────── Подсказки (tooltip при наведении) ───────── */
.info-dot {
  display: inline-flex; align-items: center; justify-content: center;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--border); color: var(--muted);
  font-size: 9px; font-weight: 700; font-style: normal;
  vertical-align: middle; margin-left: 4px; transition: background .14s, color .14s;
}
.kpi:hover .info-dot { background: var(--accent); color: #fff; }
.stat:hover .info-dot { background: var(--accent); color: #fff; }

[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip);
  position: absolute; left: 12px; top: calc(100% + 9px);
  width: 250px; background: #222b38; color: #fff;
  font-size: 12px; font-weight: 400; line-height: 1.45; text-transform: none;
  letter-spacing: normal; text-align: left;
  padding: 9px 12px; border-radius: 9px;
  box-shadow: 0 8px 24px rgba(20, 30, 50, .25);
  opacity: 0; visibility: hidden; transform: translateY(-4px);
  transition: opacity .14s, transform .14s; z-index: 200; pointer-events: none;
}
[data-tip]::before {
  content: ''; position: absolute; left: 22px; top: calc(100% + 3px);
  border: 6px solid transparent; border-bottom-color: #222b38;
  opacity: 0; visibility: hidden; transition: opacity .14s; z-index: 201; pointer-events: none;
}
[data-tip]:hover::after, [data-tip]:hover::before { opacity: 1; visibility: visible; transform: translateY(0); }
.stat[data-tip]::after { width: 188px; left: 50%; margin-left: -94px; }
.stat[data-tip]::before { left: 50%; margin-left: -6px; }

@media (max-width: 640px) {
  main { padding: 16px 14px 40px; }
  .topbar { padding: 10px 14px; }
  .brand__icon { height: 28px; }
  .brand__name { font-size: 15px; }
  .topbar__title { font-size: 15px; }
  .kpi__value { font-size: 24px; }
  [data-tip]::after { width: 210px; }
}
