:root {
  --bg: #eef1f6;
  --surface: #fff;
  --ink: #1a1a2e;
  --muted: #5f6368;
  --accent: #1a73e8;
  --accent-soft: #e8f0fe;
  --teal: #0d9488;
  --warn: #b06000;
  --warn-bg: #fef7e0;
  --danger: #d93025;
  --ok: #188038;
  --line: #dadce0;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(26, 26, 46, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Hiragino Sans', sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
}

/* Header */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 14px 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.04);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.header-back {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--muted);
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}

.header-back:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

header h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

header .sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.user-chip {
  font-size: 13px;
  color: var(--muted);
  padding: 6px 12px;
  background: var(--bg);
  border-radius: 999px;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Main */
main {
  max-width: 1040px;
  margin: 0 auto;
  padding: 20px 16px 48px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.panel.center { text-align: center; }

.panel-title {
  margin: 0 0 8px;
  font-size: 18px;
  font-weight: 700;
}

.panel-desc {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover {
  background: var(--bg);
  border-color: #c5c9d0;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: #1557b0;
  border-color: #1557b0;
}

.btn-ghost {
  background: transparent;
}

.auth-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 20px;
}

/* Dashboard controls */
.dashboard-controls {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.status-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.status-chip {
  padding: 10px 12px;
  background: var(--accent-soft);
  border-radius: 8px;
  border: 1px solid #c6dafc;
}

.status-chip.warn {
  background: var(--warn-bg);
  border-color: #f9e6a8;
}

.status-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 2px;
}

.status-chip strong {
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
}

.toolbar-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tab {
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  transition: all 0.15s;
}

.tab:hover {
  border-color: #c5c9d0;
  color: var(--ink);
}

.tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.filters label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.filters select {
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  font-size: 14px;
  font-weight: 500;
  min-width: 240px;
  background: var(--surface);
  color: var(--ink);
}

/* KPI */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.kpi-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}

.kpi-value {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.kpi-value.accent { color: var(--accent); }
.kpi-value.ok { color: var(--ok); }
.kpi-value.warn { color: var(--warn); }

.kpi-hint {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
}

/* Chart cards */
.charts-stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px 20px;
  box-shadow: var(--shadow);
}

.chart-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.chart-card h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.chart-subtitle {
  font-size: 12px;
  color: var(--muted);
}

.chart-wrap {
  position: relative;
  height: 300px;
}

.chart-wrap.tall {
  height: auto;
  min-height: 180px;
}

.chart-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 14px;
  pointer-events: none;
}

/* Callouts */
.callout {
  font-size: 13px;
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 8px;
  line-height: 1.45;
}

.callout-warn {
  background: var(--warn-bg);
  border: 1px solid #f9e6a8;
  color: #7a5200;
}

.callout-info {
  background: var(--accent-soft);
  border: 1px solid #c6dafc;
  color: #174ea6;
}

.badge-ref {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  background: var(--warn-bg);
  color: var(--warn);
  border: 1px solid #f9e6a8;
  border-radius: 4px;
  padding: 2px 7px;
  margin-left: 6px;
  vertical-align: middle;
}

.note {
  font-size: 13px;
  color: var(--warn);
  margin: 4px 0 12px;
}

/* Loading */
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 20px auto;
}

.loading-panel {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}

@keyframes spin { to { transform: rotate(360deg); } }

.hidden { display: none !important; }

/* Alerts */
.alert {
  padding: 14px 16px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 12px;
  line-height: 1.5;
}

.alert-warn { background: var(--warn-bg); border: 1px solid #f9e6a8; color: #7a5200; }
.alert-error { background: #fce8e6; border: 1px solid #f5c4c0; color: #a50e0e; }
.alert-info { background: var(--accent-soft); border: 1px solid #c6dafc; color: #174ea6; }

/* Footer */
footer {
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  padding: 28px 20px 36px;
  border-top: 1px solid var(--line);
  margin-top: 8px;
}

footer a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

footer a:hover { text-decoration: underline; }

footer p {
  margin: 10px auto 0;
  max-width: 520px;
  font-size: 12px;
  line-height: 1.5;
}

@media (max-width: 600px) {
  header h1 { font-size: 15px; }

  .filters select { min-width: 100%; }

  .toolbar-row {
    flex-direction: column;
    align-items: stretch;
  }

  .tabs { justify-content: center; }

  .kpi-value { font-size: 22px; }

  .chart-wrap { height: 260px; }
}
