/* Дашборд директора — мобильный первый, без библиотек. */
:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --ink: #17202a;
  --muted: #5c6773;
  --line: #dde3ea;
  --accent: #1a56db;
  --accent-ink: #ffffff;
  --good: #0f7b4f;
  --good-bg: #e7f5ee;
  --warn: #7a4a00;
  --warn-bg: #fff3dc;
  --bad: #b42318;
  --bad-bg: #fde8e6;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419;
    --surface: #161c23;
    --surface-2: #1d242c;
    --ink: #e8edf2;
    --muted: #9aa6b2;
    --line: #2a333d;
    --accent: #6b9bff;
    --accent-ink: #0b1220;
    --good: #4cc38a;
    --good-bg: rgba(76, 195, 138, .15);
    --warn: #e0b341;
    --warn-bg: rgba(224, 179, 65, .16);
    --bad: #ff7b72;
    --bad-bg: rgba(255, 123, 114, .16);
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 22px; }
h2 { font-size: 20px; margin: 18px 0 10px; }
h3 { font-size: 16px; }
a { color: var(--accent); }
code {
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 6px;
  font-size: 14px;
  overflow-wrap: anywhere;
}
.muted { color: var(--muted); }
.neg { color: var(--bad); }
.pos { color: var(--good); }
.empty { color: var(--muted); text-align: center; padding: 28px 8px; }

/* ---------- Вход ---------- */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 24px;
  box-shadow: var(--shadow);
}
.login-card h1 { margin-bottom: 8px; }
.login-card p { margin: 8px 0 16px; }
.login-card label { display: block; font-weight: 600; margin-bottom: 6px; }
input[type="password"] {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  font-size: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
}
input[type="password"]:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 3px solid var(--accent);
  outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent);
  outline-offset: 2px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 10px 18px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); width: 100%; margin-top: 14px; }
.btn:active { transform: translateY(1px); }

.notice {
  border-radius: 10px;
  padding: 10px 12px;
  margin: 10px 0;
  font-size: 14px;
}
.notice.bad { background: var(--bad-bg); color: var(--bad); }
.notice-inline { margin: 16px; }

/* ---------- Шапка ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand {
  font-weight: 700;
  font-size: 17px;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 7px;
}
.brand-mark { color: var(--accent); font-size: 18px; }
.status {
  flex: 1;
  min-width: 0;
  text-align: right;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.status.stale { color: var(--bad); }
.icon-btn {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.icon-btn.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.logout { margin: 0; }
.link-btn {
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  min-height: 44px;
  padding: 0 6px;
  cursor: pointer;
}

/* ---------- Меню ---------- */
.tabs {
  display: flex;
  gap: 4px;
  padding: 6px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative;
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 42px;
  padding: 6px 12px;
  border-radius: 10px;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}
.tab-ico { font-weight: 700; }
.tab:hover { background: var(--surface-2); }
.tab.active { background: var(--surface-2); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
.badge {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--bad);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

/* ---------- Контент ---------- */
.view {
  max-width: 900px;
  margin: 0 auto;
  padding: 4px 14px 28px;
}
.screen-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin: 16px 0 4px;
}
.screen-head h2 { margin: 0; }
.screen-head .muted { font-size: 14px; }

.card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  color: inherit;
  text-decoration: none;
}
a.card { transition: border-color .15s; }
a.card:hover { border-color: var(--accent); }
.card-title { font-weight: 700; font-size: 16px; overflow-wrap: anywhere; }
.card-sub { color: var(--muted); font-size: 14px; margin-top: 2px; overflow-wrap: anywhere; }
.card-note { margin-top: 8px; font-size: 14px; }
.card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  background: var(--surface-2);
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 13px;
  color: var(--muted);
}

/* ---------- Крупные цифры ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.kpi.span-2 { grid-column: span 2; }
.kpi-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.kpi-label { color: var(--muted); font-size: 13px; }
.kpi-num {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
  overflow-wrap: anywhere;
}
.kpi.hero .kpi-num { font-size: 34px; }
.kpi-num small { font-size: 15px; font-weight: 600; color: var(--muted); letter-spacing: 0; }
.kpi-foot { color: var(--muted); font-size: 13px; margin-top: 2px; }

.banner {
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 10px;
  font-size: 14px;
  border: 1px solid transparent;
}
.banner.warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn); }
.banner.bad { background: var(--bad-bg); color: var(--bad); border-color: var(--bad); }

/* ---------- Погода и риск ---------- */
.weather {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}
.weather-main { font-weight: 700; font-size: 18px; }
.risk {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 13px;
  font-weight: 700;
}
.risk-0 { background: var(--good-bg); color: var(--good); }
.risk-1 { background: var(--warn-bg); color: var(--warn); }
.risk-2 { background: var(--bad-bg); color: var(--bad); }
.risk-why { color: var(--muted); font-size: 13px; }

/* ---------- Списки и полоски ---------- */
.seg {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--surface-2);
  border-radius: 10px;
  margin: 4px 0 14px;
  max-width: 100%;
  overflow-x: auto;
}
.seg button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  min-height: 40px;
  padding: 4px 12px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}
.seg button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.bar-row { margin: 10px 0 14px; }
.bar-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; font-size: 14px; }
.bar-head b { font-variant-numeric: tabular-nums; }
.bar-track {
  height: 10px;
  margin-top: 6px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  min-width: 2px;
}
.bar-fill.bad { background: var(--bad); }

.nums {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.num { min-width: 0; }
.num-label { color: var(--muted); font-size: 12px; }
.num-value {
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0;
  font-size: 14px;
}
.detail-row > span:first-child { color: var(--muted); }
.detail-row > span:last-child { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }

.group { margin-top: 22px; }
.group h3 { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.count {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.profit-line { display: flex; align-items: baseline; gap: 8px; margin-top: 6px; }
.profit-big { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.profit-margin { color: var(--muted); font-size: 14px; }

.open-hint { color: var(--accent); font-size: 13px; font-weight: 600; white-space: nowrap; }

/* ---------- Телефон ---------- */
@media (max-width: 720px) {
  .tabs {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    justify-content: space-between;
    gap: 0;
    padding: 5px 2px calc(5px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    border-bottom: 0;
  }
  .tab {
    flex: 1 1 0;
    flex-direction: column;
    gap: 2px;
    justify-content: center;
    min-height: 54px;
    padding: 4px 2px;
    font-size: 10.5px;
    border-radius: 8px;
  }
  .tab-ico { font-size: 17px; }
  .badge {
    position: absolute;
    top: 4px;
    right: calc(50% - 24px);
    min-width: 17px;
    height: 17px;
    font-size: 10px;
  }
  .view { padding-bottom: 86px; }
}

@media (min-width: 721px) {
  .view { padding-left: 20px; padding-right: 20px; }
  .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kpi.span-2 { grid-column: span 1; }
  .kpi.hero { grid-column: span 1; }
}

@media (min-width: 980px) {
  .view { padding-top: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
