:root {
  color-scheme: light;
  --background: #f8fafc;
  --foreground: #102846;
  --card: #ffffff;
  --sidebar: #0d1522;
  --sidebar-soft: #132238;
  --border: #e2e8f0;
  --muted: #64748b;
  --muted-bg: #f1f5f9;
  --brand: #fb4818;
  --brand-hover: #d63a0f;
  --brand-soft: rgba(251, 72, 24, 0.1);
  --danger: #b42318;
  --warning: #a15c07;
  --ok: #087443;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--background);
  color: var(--foreground);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

h1, h2, p { margin: 0; }

button, input, textarea {
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
}

button {
  min-height: 36px;
  padding: 0 12px;
  background: #ffffff;
  color: var(--foreground);
  cursor: pointer;
}

button:hover { border-color: var(--brand); color: var(--brand); }
button:disabled { cursor: wait; opacity: 0.65; }

input, textarea {
  width: 100%;
  min-width: 0;
  padding: 0 11px;
  background: #ffffff;
  color: var(--foreground);
}

input { height: 38px; }
textarea { padding-top: 10px; resize: vertical; }

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

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 18px 14px;
  background: var(--sidebar);
  color: #f8fafc;
  border-right: 1px solid rgba(255, 255, 255, 0.07);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 6px 14px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: var(--brand);
  color: #ffffff;
  font-weight: 800;
}

.brand strong, .brand span { display: block; }
.brand strong { font-size: 15px; }
.brand span { margin-top: 2px; color: #9fb0c7; font-size: 12px; }

.module-badge {
  margin: 2px 6px 18px;
  padding: 8px 10px;
  border: 1px solid rgba(251, 72, 24, 0.3);
  border-radius: 8px;
  background: rgba(251, 72, 24, 0.11);
  color: #ff8b6b;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
}

.nav { display: grid; gap: 4px; }
.nav-item {
  justify-content: flex-start;
  width: 100%;
  min-height: 40px;
  border: 0;
  background: transparent;
  color: #c6d1e1;
  text-align: left;
}
.nav-item:hover { background: var(--sidebar-soft); color: #ffffff; }
.nav-item.active { background: var(--brand-soft); color: #ff8b6b; }

.auth-card {
  display: grid;
  gap: 8px;
  margin-top: auto;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
}
.auth-card label { color: #9fb0c7; font-size: 12px; }
.token-row { display: grid; grid-template-columns: 1fr 54px; gap: 8px; }
.token-row input { background: #09111f; border-color: rgba(255, 255, 255, 0.1); color: #ffffff; }
.token-row button { background: var(--brand); border-color: var(--brand); color: #ffffff; }

.workspace { min-width: 0; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 68px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
}

h1 { font-size: 22px; line-height: 1.15; }
h2 { font-size: 15px; line-height: 1.25; }
.topbar p, .panel-head p { margin-top: 4px; color: var(--muted); font-size: 13px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.status-pill, .badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--muted-bg);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.status-pill[data-status="ok"], .badge.ok { background: #e7f6ee; color: var(--ok); }
.status-pill[data-status="warning"], .badge.warning { background: #fff4df; color: var(--warning); }
.status-pill[data-status="error"], .badge.failed, .badge.error { background: #fdecec; color: var(--danger); }

.primary-action, .stack-form button, .action-grid button:first-child {
  background: var(--brand);
  border-color: var(--brand);
  color: #ffffff;
}
.primary-action:hover, .stack-form button:hover, .action-grid button:first-child:hover { background: var(--brand-hover); border-color: var(--brand-hover); color: #ffffff; }

main { padding: 22px 24px 34px; }
.page { display: none; }
.page.active { display: block; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}
.metric, .panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.metric { padding: 16px; }
.metric span { color: var(--muted); font-size: 12px; text-transform: uppercase; }
.metric strong { display: block; margin-top: 10px; font-size: 30px; line-height: 1; }

.dashboard-grid, .section-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.span-2 { grid-column: span 2; }
.panel { min-width: 0; overflow: hidden; }
.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.list { display: grid; max-height: 360px; overflow: auto; }
.list-row {
  display: grid;
  grid-template-columns: 150px 92px 1fr;
  gap: 12px;
  align-items: center;
  padding: 11px 16px;
  border-bottom: 1px solid #edf0f4;
  font-size: 13px;
}
.list-row:last-child { border-bottom: 0; }
.muted { color: var(--muted); }

.action-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding: 16px; }
.summary-card { padding: 16px; color: var(--muted); font-size: 13px; }
.summary-card strong { display: block; margin-bottom: 6px; color: var(--foreground); font-size: 16px; }

.stack-form { display: grid; gap: 10px; padding: 16px; }
.workflow { display: grid; gap: 12px; padding: 16px; }
.workflow div { display: grid; grid-template-columns: 30px 1fr; gap: 10px; align-items: center; }
.workflow strong { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); }
.workflow span { color: var(--foreground); font-size: 14px; }

.bundle-list { display: grid; }
.bundle-row {
  display: grid;
  grid-template-columns: 1fr 110px 130px 70px;
  gap: 10px;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid #edf0f4;
  font-size: 13px;
}
.bundle-row:last-child { border-bottom: 0; }
.mini { min-height: 30px; padding: 0 10px; font-size: 12px; }

.table-wrap { max-height: 580px; overflow: auto; }
table { width: 100%; border-collapse: collapse; table-layout: fixed; }
th, td { padding: 11px 12px; border-bottom: 1px solid #edf0f4; text-align: left; vertical-align: top; font-size: 13px; overflow-wrap: anywhere; }
th { position: sticky; top: 0; background: #f8fafc; color: var(--muted); font-weight: 700; }

pre {
  min-height: 110px;
  max-height: 300px;
  margin: 0;
  padding: 14px 16px;
  overflow: auto;
  background: #080e1a;
  color: #d8e7ed;
  font-size: 12px;
}

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .auth-card { margin-top: 14px; }
  .topbar { position: static; align-items: stretch; flex-direction: column; }
  .topbar-actions { align-items: stretch; flex-wrap: wrap; }
  .metric-grid, .dashboard-grid, .section-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .list-row, .bundle-row { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  main, .topbar { padding-left: 16px; padding-right: 16px; }
  .action-grid, .nav { grid-template-columns: 1fr; }
}
