:root {
  --sidebar-bg: #0f1117;
  --sidebar-hover: #1e293b;
  --sidebar-active: #1e3a5f;
  --sidebar-text: #94a3b8;
  --sidebar-text-active: #f1f5f9;
  --sidebar-accent: #3b82f6;
  --main-bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-soft: #64748b;
  --text-mute: #94a3b8;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --ok: #16a34a;
  --warn: #d97706;
  --radius: 10px;
  --font: "IBM Plex Sans", system-ui, -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", "Courier New", monospace;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 14px; }

body {
  font-family: var(--font);
  background: var(--main-bg);
  color: var(--text);
  min-height: 100vh;
}

a { color: var(--sidebar-accent); }

/* ── Auth gate ── */
#auth-gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 36px;
  max-width: 400px;
  width: 100%;
  text-align: center;
}

.auth-card h1 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 8px;
}

.auth-card p {
  color: var(--text-soft);
  font-size: 13px;
  line-height: 1.6;
  margin-bottom: 24px;
}

.btn-primary {
  display: inline-block;
  background: var(--sidebar-accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 11px 22px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

.btn-primary:hover { opacity: 0.9; }

.badge-internal {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 3px 8px;
  background: var(--danger-bg);
  color: var(--danger);
  border-radius: 999px;
}

/* ── App shell ── */
#app-shell {
  display: none;
  min-height: 100vh;
}

#app-shell.visible {
  display: flex;
}

#sidebar {
  width: 240px;
  min-width: 240px;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 100;
}

.sidebar-brand {
  padding: 20px 16px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.sidebar-brand-name {
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.3px;
}

.sidebar-brand-name span { color: var(--sidebar-accent); }

.sidebar-brand-sub {
  font-size: 10px;
  color: var(--sidebar-text);
  margin-top: 4px;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.sidebar-user {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  font-size: 12px;
  color: var(--sidebar-text);
}

.sidebar-user strong { color: var(--sidebar-text-active); display: block; margin-bottom: 2px; }

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.nav-group-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--sidebar-text);
  padding: 12px 16px 6px;
  opacity: 0.7;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--sidebar-text);
  font-family: inherit;
  font-size: 13px;
  padding: 9px 16px;
  cursor: pointer;
  text-decoration: none;
  border-left: 3px solid transparent;
}

.nav-item:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-text-active);
}

.nav-item.active {
  background: var(--sidebar-active);
  color: var(--sidebar-text-active);
  border-left-color: var(--sidebar-accent);
}

.nav-item.planned {
  opacity: 0.45;
  cursor: not-allowed;
}

.nav-item .badge-planned {
  font-size: 9px;
  padding: 1px 5px;
  background: rgba(255,255,255,0.08);
  border-radius: 4px;
  margin-left: auto;
}

.nav-item.external::after {
  content: "↗";
  font-size: 11px;
  margin-left: auto;
  opacity: 0.6;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,0.06);
}

.btn-logout {
  width: 100%;
  background: none;
  border: 1px solid rgba(255,255,255,0.12);
  color: var(--sidebar-text);
  border-radius: 6px;
  padding: 8px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
}

.btn-logout:hover { background: var(--sidebar-hover); color: #fff; }

/* ── Main ── */
#main {
  margin-left: 240px;
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

#main-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}

#main-header h2 {
  font-size: 16px;
  font-weight: 600;
}

#main-header .module-hint {
  font-size: 12px;
  color: var(--text-mute);
  font-family: var(--font-mono);
}

#panel-host {
  flex: 1;
  position: relative;
  min-height: calc(100vh - 53px);
}

#panel-host iframe {
  display: block;
  width: 100%;
  height: calc(100vh - 53px);
  border: none;
  background: var(--main-bg);
}

.panel-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-mute);
  font-size: 13px;
  background: var(--main-bg);
}

.panel-builtin {
  padding: 24px;
  max-width: 1200px;
}

/* ── Home KPI ── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}

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

.kpi-card strong {
  display: block;
  font-size: 28px;
  font-weight: 700;
  color: var(--sidebar-accent);
  line-height: 1;
  margin-bottom: 6px;
}

.kpi-card span {
  font-size: 12px;
  color: var(--text-soft);
}

.link-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.link-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.15s;
}

.link-card:hover { border-color: var(--sidebar-accent); }

.link-card h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
}

.link-card p {
  font-size: 12px;
  color: var(--text-soft);
  line-height: 1.5;
}

.link-card .arrow {
  font-size: 12px;
  color: var(--sidebar-accent);
  margin-top: 8px;
}

.section-title {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-mute);
  margin-bottom: 14px;
}

@media (max-width: 768px) {
  #sidebar { width: 100%; height: auto; position: relative; }
  #main { margin-left: 0; }
  #app-shell.visible { flex-direction: column; }
}
