* { box-sizing: border-box; }
:root {
  --bg: #f4f5f7;
  --ink: #1a1a1a;
  --muted: #667085;
  --card: #fff;
  --border: #e5e7eb;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --radius: 10px;
  --blue: #2563eb;
  --blue-dark: #1e3a8a;
  --green-bg: #d1fae5; --green-ink: #065f46;
  --amber-bg: #fef3c7; --amber-ink: #92400e;
  --red-bg: #fee2e2; --red-ink: #991b1b;
  --header-h: 56px;
}
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
  overflow-x: hidden;
}
a { color: var(--blue); }

/* ---------- Header / nav ---------- */
header.top {
  background: #1f2937;
  color: #fff;
  padding: 0 16px;
  min-height: var(--header-h);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 30;
}
#nav-toggle { display: none; }
header.top .top-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
header.top .brand { font-weight: 700; font-size: 16px; white-space: nowrap; }
header.top nav.links { display: flex; align-items: center; flex-wrap: wrap; }
header.top nav.links a {
  color: #fff; text-decoration: none; margin-right: 4px; font-size: 14px;
  padding: 8px 10px; border-radius: 6px; white-space: nowrap;
}
header.top nav.links a:hover, header.top nav.links a:active { background: rgba(255,255,255,0.12); }
.user-badge { font-size: 13px; opacity: 0.9; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.user-badge a { color: #fff; }

.nav-toggle-label {
  display: none;
  color: #fff;
  font-size: 22px;
  padding: 6px 10px;
  cursor: pointer;
  line-height: 1;
}

nav.wh-switch {
  background: #111827; color: #cbd5e1; padding: 8px 16px; font-size: 13px;
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  position: sticky; top: var(--header-h); z-index: 29;
}
nav.wh-switch a { color: #cbd5e1; text-decoration: none; padding: 3px 10px; border-radius: 10px; }
nav.wh-switch a.active { background: var(--blue); color: #fff; }

main { max-width: 1300px; margin: 20px auto; padding: 0 16px 60px; }
h1 { font-size: 21px; margin: 4px 0 16px; }
h2 { font-size: 16px; margin-top: 26px; margin-bottom: 10px; }

/* ---------- Tables (desktop default, scroll on mobile) ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius); box-shadow: var(--shadow); background: var(--card); }
.table-wrap table { box-shadow: none; border-radius: 0; }
table { width: 100%; border-collapse: collapse; background: var(--card); box-shadow: var(--shadow); border-radius: var(--radius); overflow: hidden; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); font-size: 13.5px; white-space: nowrap; }
td.wrap, th.wrap { white-space: normal; }
th { background: #f9fafb; font-weight: 600; color: #374151; }
tr:last-child td { border-bottom: none; }
tr.alert-row { background: #fff7f7; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 3px 9px; border-radius: 10px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.ok { background: var(--green-bg); color: var(--green-ink); }
.badge.warn { background: var(--red-bg); color: var(--red-ink); }
.badge.soon { background: var(--amber-bg); color: var(--amber-ink); }
.badge.critical { background: var(--red-bg); color: var(--red-ink); }
.badge.unknown { background: #e5e7eb; color: #4b5563; }
.badge.role { background: #e0e7ff; color: #3730a3; }
.badge.wh { background: #eef2ff; color: #4338ca; }
.badge-dot { display:inline-block; width:8px; height:8px; border-radius:50%; margin-right:6px; }
.badge-dot.ok { background:#059669; } .badge-dot.soon { background:#d97706; } .badge-dot.critical { background:#dc2626; }

/* ---------- Forms ---------- */
form.inline { display: inline; }
.card, form.card {
  background: var(--card);
  padding: 18px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
form.card { max-width: 480px; }
details.card summary { list-style: none; }
details.card summary::-webkit-details-marker { display: none; }
label { display: block; margin-top: 12px; font-size: 13px; font-weight: 600; color: #444; }
input, select, textarea {
  width: 100%; padding: 11px 12px; margin-top: 5px; border: 1px solid #ccc; border-radius: 8px;
  font-size: 16px; /* prevents iOS auto-zoom on focus */
  min-height: 44px; /* touch target */
  background: #fff; color: var(--ink); font-family: inherit;
}
textarea { min-height: 80px; }
label > input[type="checkbox"] { width: auto; min-height: auto; margin: 0; }
button, .btn {
  display: inline-block;
  margin-top: 16px;
  background: var(--blue);
  color: #fff;
  border: none;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  min-height: 44px;
  line-height: 1.2;
  text-align: center;
}
button:active, .btn:active { opacity: 0.85; }
button.danger, .btn.danger { background: #dc2626; }
button.secondary, .btn.secondary { background: #6b7280; }
.flash { padding: 12px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.flash.error { background: var(--red-bg); color: var(--red-ink); }
.flash.ok { background: var(--green-bg); color: var(--green-ink); }

/* ---------- Stat cards / grids ---------- */
.grid, .cards-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stat-card .num { font-size: 24px; font-weight: 700; }
.stat-card .label { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

.login-wrap { display: flex; justify-content: center; align-items: center; min-height: 100vh; padding: 16px; }
.hint { font-size: 12.5px; color: #777; margin-top: 6px; }
nav.tabs { margin-bottom: 16px; }
nav.tabs a { margin-right: 16px; font-size: 14px; color: var(--blue); text-decoration: none; }
nav.tabs a.active { font-weight: 700; text-decoration: underline; }

.bar-row { display: flex; align-items: center; gap: 10px; font-size: 13px; margin: 4px 0; }
.bar-row .bar-label { width: 80px; text-align: right; color: #555; flex-shrink: 0; }
.bar-row .bar-track { flex: 1; background: #eef1f5; border-radius: 4px; overflow: hidden; height: 18px; }
.bar-row .bar-fill { background: var(--blue); height: 100%; }
.bar-row .bar-value { width: 100px; font-weight: 600; flex-shrink: 0; }

/* ---------- Filter bars ---------- */
.filter-bar { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; max-width: 100%; }
.filter-bar > div { min-width: 150px; }
.filter-bar label { margin-top: 0; }

/* ---------- Charts ---------- */
.chart-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 20px; }
.chart-card h2 { margin-top: 0; }
.chart-box { position: relative; width: 100%; height: 260px; }
.chart-box.short { height: 180px; }
.insight {
  margin-top: 10px; padding: 10px 12px; background: #eff6ff; border-left: 3px solid var(--blue);
  border-radius: 0 6px 6px 0; font-size: 13px; color: #1e3a5f;
}
.insight.warn { background: #fffaf0; border-left-color: #d97706; color: #7c4a03; }
.charts-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }

/* ---------- Для Вовы ---------- */
.nav-vova { font-weight: 700; background: rgba(255,255,255,0.14); border-radius: 6px; }
.vova-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; margin-bottom: 16px; }
.vova-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; border-top: 6px solid var(--blue); }
.vova-card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.vova-card-head h2 { margin: 0; font-size: 22px; }
.vova-big { font-size: 46px; font-weight: 800; line-height: 1.05; margin: 6px 0 2px; }
.vova-big .vova-unit { font-size: 15px; font-weight: 500; color: var(--muted); margin-left: 8px; }
.vova-spark-row { display: flex; align-items: center; gap: 10px; margin: 6px 0 14px; }
.vova-metric-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 8px; border-top: 1px solid var(--border); padding-top: 12px; }
.vova-metric-num { font-size: 22px; font-weight: 700; }
.vova-metric-label { font-size: 11.5px; color: var(--muted); }
.vova-profit-today { margin-top: 14px; font-size: 16px; font-weight: 600; border-top: 1px solid var(--border); padding-top: 10px; }
.vova-triage-row { margin-bottom: 8px; }
.vova-ceiling { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 12px; }
.vova-ceiling-head { font-size: 13px; font-weight: 700; margin-bottom: 8px; }
.vova-ceiling-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.vova-ceiling-item { text-align: center; }
.vova-ceiling-num { font-size: 18px; font-weight: 700; }
.vova-scenario { margin-top: 10px; font-size: 13px; }

/* ---------- Responsive ---------- */
@media (max-width: 780px) {
  header.top { flex-direction: column; align-items: stretch; padding: 8px 12px; }
  header.top .top-row { width: 100%; }
  .nav-toggle-label { display: block; }
  header.top nav.links {
    display: none;
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    padding-top: 6px;
  }
  header.top nav.links a { padding: 12px 10px; margin-right: 0; border-top: 1px solid rgba(255,255,255,0.08); border-radius: 0; }
  #nav-toggle:checked ~ nav.links { display: flex; }
  .user-badge { font-size: 12.5px; width: 100%; justify-content: space-between; padding: 8px 0 2px; }
  nav.wh-switch { position: static; overflow-x: auto; }

  main { margin: 12px auto; padding: 0 10px 40px; }
  h1 { font-size: 19px; }

  th, td { padding: 9px 10px; font-size: 13px; }
  form.card { max-width: 100%; padding: 14px; }
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-bar > div { min-width: 0; }
  .filter-bar button, .filter-bar .btn { width: 100%; }

  .grid, .cards-row { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
  .stat-card { padding: 12px; }
  .stat-card .num { font-size: 20px; }

  .chart-box { height: 220px; }
  .charts-grid { grid-template-columns: 1fr; }

  .vova-cards { grid-template-columns: 1fr; }
  .vova-big { font-size: 40px; }
  .vova-metric-grid { grid-template-columns: repeat(3, 1fr); gap: 8px 6px; }
  .vova-metric-num { font-size: 19px; }
}
