:root {
  --bg: #f4f7f6;
  --surface: #ffffff;
  --surface-2: #eef7f5;
  --text: #12211f;
  --muted: #61736f;
  --line: #d8e5e2;
  --primary: #0f766e;
  --primary-dark: #0b4f49;
  --danger: #b42318;
  --warning: #9a6700;
  --success: #067647;
  --shadow: 0 14px 40px rgba(15, 76, 70, .12);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--text); background: var(--bg); }
button, input, select, textarea { font: inherit; }
button { border: 0; cursor: pointer; }
button:disabled, input:disabled, select:disabled, textarea:disabled { opacity: .62; cursor: not-allowed; }
.app-shell { max-width: 1080px; margin: 0 auto; min-height: 100vh; padding: 18px 14px 96px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 14px; }
.top-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.session-area { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.user-pill { display: grid; gap: 1px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 8px 10px; box-shadow: 0 8px 24px rgba(15, 76, 70, .08); }
.user-pill span { font-size: 13px; font-weight: 900; }
.user-pill em { font-size: 11px; color: var(--muted); font-style: normal; text-transform: capitalize; }
.eyebrow { margin: 0 0 3px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
h1 { margin: 0; font-size: clamp(26px, 8vw, 42px); line-height: 1.05; }
h2 { margin: 0 0 12px; font-size: 22px; }
h3 { margin: 0 0 8px; font-size: 16px; }
p { line-height: 1.55; }
.toolbar { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: end; margin-bottom: 14px; }
.field { display: grid; gap: 6px; }
.field span { color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--text); padding: 11px 12px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15, 118, 110, .16); }
textarea { min-height: 78px; resize: vertical; }
.primary, .ghost, .danger { border-radius: 14px; padding: 12px 14px; font-weight: 800; }
.primary { background: var(--primary); color: white; box-shadow: var(--shadow); }
.ghost { background: var(--surface); color: var(--primary-dark); border: 1px solid var(--line); }
.danger { background: #fee4e2; color: var(--danger); }
.small-button { padding: 8px 10px; font-size: 12px; border-radius: 12px; }
.hidden { display: none !important; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 24px; padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.card.soft { background: var(--surface-2); box-shadow: none; }
.grid { display: grid; gap: 12px; }
.kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 14px; }
.kpi span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.kpi strong { font-size: clamp(18px, 5vw, 28px); }
.kpi.danger strong { color: var(--danger); }
.kpi.warning strong { color: var(--warning); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); }
table { width: 100%; border-collapse: collapse; min-width: 850px; }
th, td { border-bottom: 1px solid var(--line); padding: 9px 8px; text-align: left; vertical-align: top; }
th { position: sticky; top: 0; background: #f8fbfa; z-index: 1; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
td input, td textarea, td select { min-width: 92px; padding: 8px; border-radius: 10px; }
td textarea { min-width: 180px; min-height: 40px; }
td.readonly, .readonly { color: var(--muted); background: #fbfcfc; font-variant-numeric: tabular-nums; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.inline-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.chart-card svg { width: 100%; height: 220px; display: block; }
.chart-labels { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 12px; margin-top: 6px; }
.notice { background: #fffaeb; border: 1px solid #fedf89; color: #7a4d00; border-radius: 18px; padding: 12px 14px; }
.split { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.total-line { display: flex; justify-content: space-between; gap: 14px; border-top: 1px solid var(--line); padding-top: 12px; margin-top: 12px; font-weight: 900; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.section-title h2 { margin-bottom: 0; }
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 6px 9px; font-size: 12px; font-weight: 900; }
.badge.ok { color: var(--success); background: #dcfae6; }
.badge.muted { color: var(--muted); background: #eef2f1; }
.bottom-nav { position: fixed; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; padding: 8px max(8px, env(safe-area-inset-left)) calc(8px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-right)); background: rgba(255,255,255,.94); backdrop-filter: blur(12px); border-top: 1px solid var(--line); z-index: 9; }
.bottom-nav button { background: transparent; color: var(--muted); border-radius: 14px; padding: 9px 4px; font-size: 11px; font-weight: 800; }
.bottom-nav button.active { background: var(--primary); color: #fff; }
.backup-buttons { display: grid; gap: 10px; }
pre.raw { white-space: pre-wrap; word-break: break-word; background: #0b1f1c; color: #eafff9; padding: 14px; border-radius: 16px; max-height: 280px; overflow: auto; }
.small { color: var(--muted); font-size: 13px; }
.auth-wrap { min-height: 64vh; display: grid; place-items: center; }
.login-card { width: min(100%, 460px); }
.login-form { display: grid; gap: 12px; margin-top: 12px; }
.admin-form { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: end; }
.admin-form button { align-self: end; }
.checkline { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.checkline input { width: auto; }
.logged-out .app-shell { padding-bottom: 24px; }

@media (min-width: 720px) {
  .kpi-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .backup-buttons { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .topbar { align-items: flex-start; }
  .session-area { justify-content: flex-start; }
  .admin-form { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  .toolbar { grid-template-columns: 1fr; }
  .split { grid-template-columns: 1fr; }
  .card { border-radius: 20px; padding: 14px; }
  .bottom-nav { grid-template-columns: repeat(4, 1fr); }
  .bottom-nav button { font-size: 10px; padding: 8px 3px; }
}
