:root {
  color-scheme: light;
  --ink: #1c2526;
  --muted: #657071;
  --line: #d9dfdc;
  --panel: #ffffff;
  --soft: #eef3f0;
  --accent: #1f7a5c;
  --accent-2: #c7532b;
  --blue: #2d6cdf;
  --gold: #b88a1d;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: #f6f7f4;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(246, 247, 244, 0.96);
}

.auth-overlay.hidden { display: none; }

.auth-card {
  width: min(460px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 24px;
  box-shadow: 0 18px 60px rgba(28, 37, 38, 0.12);
}

.auth-card h1 { margin-bottom: 10px; }

.auth-message {
  min-height: 20px;
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.auth-message.error { color: var(--accent-2); }
.auth-message.ok { color: var(--accent); }

.auth-form {
  display: grid;
  gap: 12px;
}

.auth-form label { margin-top: 0; }

.setup-box {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.setup-box summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.app-shell {
  display: grid;
  grid-template-columns: 390px minmax(0, 1fr);
  min-height: 100vh;
}

.panel {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 24px;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
}

.brand-actions {
  display: grid;
  gap: 8px;
  min-width: 92px;
}

.user-badge {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1, h2 { margin: 0; letter-spacing: 0; }
h1 { font-size: 28px; line-height: 1.05; }
h2 { font-size: 16px; }

section { margin-bottom: 28px; }

label {
  display: grid;
  gap: 7px;
  margin-top: 14px;
  color: #334041;
  font-size: 13px;
  font-weight: 650;
}

input, select {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}

input[type="file"] {
  height: auto;
  padding: 9px;
}

.grid { display: grid; gap: 10px; }
.two { grid-template-columns: 1fr 1fr; }

.switch {
  display: flex;
  align-items: center;
  gap: 10px;
}

.switch input { width: 18px; height: 18px; }

button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 14px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.primary {
  background: var(--accent);
  color: white;
}

.secondary {
  background: #e8f1ed;
  color: #155a43;
  border-color: #cbe0d7;
}

.ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--line);
}

.button-row {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.status {
  margin: 0;
  padding: 12px;
  border-radius: 6px;
  background: var(--soft);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.backend-status {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.backend-status.online { color: var(--accent); }
.backend-status.offline { color: var(--accent-2); }

.mini-kpis {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.mini-kpis div {
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px;
  background: #fbfcfa;
}

.mini-kpis span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  margin-bottom: 6px;
}

.mini-kpis strong {
  display: block;
  font-size: 15px;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.workspace {
  padding: 26px;
  overflow: auto;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.kpi-grid article {
  min-height: 96px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 16px;
}

.kpi-grid span {
  display: block;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.kpi-grid strong {
  font-size: 28px;
  line-height: 1;
}

.tabs {
  display: flex;
  gap: 8px;
  margin: 0 0 18px;
  border-bottom: 1px solid var(--line);
}

.tab {
  border-radius: 6px 6px 0 0;
  background: transparent;
  color: var(--muted);
  border-color: transparent;
  border-bottom-color: var(--line);
}

.tab.active {
  background: white;
  color: var(--accent);
  border-color: var(--line);
  border-bottom-color: white;
  margin-bottom: -1px;
}

.tab-view { display: none; }
.tab-view.active { display: block; }

.chart-panel, .table-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 16px;
}

.section-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 8px;
}

canvas {
  width: 100%;
  max-width: 100%;
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 500px;
  gap: 18px;
  margin-top: 18px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: right;
  white-space: nowrap;
}

th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-size: 12px; }

.hourly-panel { margin-top: 0; }

.pager {
  display: flex;
  align-items: end;
  gap: 8px;
}

.hourly-actions {
  display: flex;
  align-items: end;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.pager label {
  width: 132px;
  margin-top: 0;
}

.table-note {
  margin: 2px 0 12px;
  color: var(--muted);
  font-size: 13px;
}

.table-scroll {
  overflow: auto;
  max-height: 620px;
}

.table-scroll table {
  min-width: 1180px;
}

@media (max-width: 1040px) {
  .app-shell { grid-template-columns: 1fr; }
  .panel { border-right: 0; border-bottom: 1px solid var(--line); }
  .split, .kpi-grid { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .two { grid-template-columns: 1fr; }
  .brand, .section-title { align-items: stretch; flex-direction: column; }
  .workspace, .panel { padding: 16px; }
}
