:root {
  --bg: #f4f1ec;
  --surface: #fffdfa;
  --surface-2: #ffffff;
  --text: #191713;
  --muted: #6f675d;
  --line: #d8d0c4;
  --accent: #d55322;
  --good: #0f7f69;
  --warn: #b86406;
  --bad: #b32222;
  --radius: 14px;
}

html[data-theme="dark"] {
  --bg: #15171a;
  --surface: #1d2127;
  --surface-2: #252b34;
  --text: #edf2f7;
  --muted: #9aa5b1;
  --line: #313844;
  --accent: #ef7a4a;
  --good: #41bd8f;
  --warn: #f0a42f;
  --bad: #ef5b5b;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: "Manrope", sans-serif; color: var(--text); background: var(--bg); }

h1, h2, h3 { margin: 0; font-family: "Space Grotesk", sans-serif; letter-spacing: -0.02em; }
.container { width: min(1240px, calc(100% - 2rem)); margin: 0 auto; }

.topbar { border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 40; }
.topbar-inner { min-height: 66px; display: flex; align-items: center; justify-content: space-between; }
.brand { color: var(--text); text-decoration: none; font-weight: 700; font-size: 1.1rem; }

.app-layout { display: grid; grid-template-columns: 240px 1fr; gap: 1rem; padding: 1rem 0 2rem; }
.sidebar {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  align-self: start;
  position: sticky;
  top: 84px;
}
.nav-item {
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  border-radius: 10px;
  padding: 0.62rem 0.7rem;
  cursor: pointer;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--surface-2); color: var(--text); border-color: var(--line); }

.content { min-width: 0; }
.view { display: none; }
.view.active { display: block; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.04);
}

.eyebrow { margin: 0 0 0.4rem; text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.74rem; color: var(--good); }
.subtitle { color: var(--muted); margin: 0.55rem 0 0; }
.oauth-status { color: var(--muted); margin-top: 0.6rem; font-size: 0.9rem; }

.flash { margin-bottom: 0.8rem; padding: 0.65rem 0.82rem; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font-weight: 600; }

.kpis { margin-top: 1rem; display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 0.65rem; }
.kpi { border: 1px solid var(--line); border-radius: 12px; padding: 0.65rem; background: var(--surface-2); }
.kpi strong { display: block; font-size: 1.2rem; line-height: 1.1; }
.kpi span { color: var(--muted); font-size: 0.82rem; }

.toolbar { margin-top: 0.9rem; display: flex; flex-wrap: wrap; gap: 0.55rem; }
.btn {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 10px;
  padding: 0.55rem 0.8rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
}
.btn-primary { border: 0; color: #fff; background: linear-gradient(120deg, var(--accent), #f08b58); }
.btn-danger { border-color: #c97f7f; color: #b12424; }
.btn.oauth { background: #1f6feb; color: #fff; border: 0; }

.form-grid { margin-top: 0.85rem; display: grid; gap: 0.55rem; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.grid-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }

.form-grid input, .form-grid select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.6rem;
  background: var(--surface-2);
  color: var(--text);
}

.table-wrap { margin-top: 0.8rem; overflow: auto; border: 1px solid var(--line); border-radius: 12px; }
.table-wrap.slim { max-height: 260px; }
table { width: 100%; min-width: 840px; border-collapse: collapse; }
th, td { padding: 0.6rem; border-bottom: 1px solid var(--line); text-align: left; font-size: 0.88rem; vertical-align: top; }
th { background: var(--surface-2); font-size: 0.77rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
td a { color: #3182ce; text-decoration: none; }

.badge { padding: 0.2rem 0.45rem; border-radius: 999px; font-size: 0.75rem; font-weight: 700; }
.b-ok { background: rgba(22, 163, 109, 0.15); color: var(--good); }
.b-warn { background: rgba(255, 168, 0, 0.16); color: var(--warn); }
.b-bad { background: rgba(232, 72, 72, 0.16); color: var(--bad); }
.mini { color: var(--muted); font-size: 0.8rem; }
.subhead { margin-top: 1rem; }

.wizard {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 80;
}
.wizard-card {
  width: min(560px, calc(100% - 1rem));
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem;
}

@media (max-width: 1120px) {
  .app-layout { grid-template-columns: 1fr; }
  .sidebar { position: static; flex-direction: row; overflow: auto; }
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-4, .grid-5, .grid-6 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 740px) {
  .container { width: min(1240px, calc(100% - 1rem)); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-4, .grid-5, .grid-6 { grid-template-columns: 1fr; }
  table { min-width: 680px; }
}

.wizard-command {
  width: 100%;
  margin-top: 0.6rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.6rem;
  background: var(--surface-2);
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
}
