:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --fg: #172033;
  --card: #ffffff;
  --muted: #667085;
  --border: #d9e0ea;
  --soft: #eef3f8;
  --primary: #1155cc;
  --primary-strong: #0b3f98;
  --success: #12805c;
  --warning: #b25e09;
  --danger: #c93434;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
  --radius: 8px;
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html,
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button { border: 0; cursor: pointer; }
h1, h2, p { margin: 0; }
h1 { font-size: 20px; line-height: 1.35; font-weight: 700; }
h2 { font-size: 14px; line-height: 1.4; font-weight: 700; }
p { color: var(--muted); }

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  width: min(100%, 390px);
  display: grid;
  gap: 16px;
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: #fbfcfe;
}

.sidebar-header { padding: 16px; }

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

.brand-button {
  width: 100%;
  padding: 0;
  background: transparent;
  color: var(--fg);
  text-align: left;
}

.brand-row strong {
  display: block;
  font-weight: 750;
}

.brand-row small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.brand-mark {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--primary);
  font-size: 11px;
  font-weight: 800;
  box-shadow: var(--shadow);
}

.sidebar-nav {
  display: grid;
  gap: 2px;
  padding: 0 10px;
}

.nav-item {
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 10px;
  border-radius: var(--radius);
  background: transparent;
  color: #344054;
  text-align: left;
  font-weight: 650;
}

.nav-item:hover,
.nav-item.active {
  background: var(--soft);
  color: var(--fg);
}

.nav-item span {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 10px;
  padding: 14px;
}

.runtime {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--muted);
  font-size: 12px;
}

.workspace { min-width: 0; }

.topbar {
  height: 58px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 22px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar-actions { margin-left: auto; }

.icon-button {
  width: 36px;
  height: 36px;
  display: none;
  place-items: center;
  gap: 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
}

.icon-button span {
  width: 16px;
  height: 2px;
  display: block;
  background: var(--fg);
}

main {
  max-width: 1520px;
  margin: 0 auto;
  padding: 24px;
}

.page-section { display: none; }
.page-section.active { display: grid; gap: 18px; }

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.page-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border-radius: var(--radius);
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  white-space: nowrap;
}

.button:hover { background: var(--primary-strong); }
.button.secondary { background: #e8eef8; color: #153b76; }
.button.ghost { background: transparent; color: var(--fg); border: 1px solid var(--border); }
.button.compact { min-height: 32px; padding: 0 10px; font-size: 13px; }
.button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.notice,
.error-box {
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid #ffd1d1;
  background: #fff5f5;
  color: #8f1f1f;
}

.notice {
  margin-bottom: 18px;
  border-color: #cde1ff;
  background: #f2f7ff;
  color: #163f7b;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
}

.stat-card,
.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}

.stat-card {
  min-height: 94px;
  display: grid;
  align-content: space-between;
  padding: 14px;
}

.stat-card small {
  color: var(--muted);
  font-weight: 650;
}

.stat-card strong {
  font-size: 28px;
  line-height: 1;
}

.two-column {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
}

.source-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.card {
  overflow: hidden;
}

.card-header,
.toolbar {
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.toolbar {
  justify-content: flex-start;
  flex-wrap: wrap;
}

.search-input,
input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--fg);
}

.search-input { width: min(420px, 100%); }
select { width: auto; min-width: 150px; }
textarea { resize: vertical; }

.list-stack {
  display: grid;
  gap: 0;
}

.list-item {
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.list-item:last-child { border-bottom: 0; }

.item-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-weight: 700;
}

.item-meta {
  color: var(--muted);
  font-size: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--soft);
  color: #344054;
  font-size: 12px;
  font-weight: 700;
}

.badge.good { background: #e8f7f1; color: var(--success); }
.badge.warn { background: #fff3e5; color: var(--warning); }
.badge.danger { background: #fff0f0; color: var(--danger); }

.table-wrap {
  width: 100%;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 920px;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

td {
  font-size: 13px;
}

td a {
  color: var(--primary);
  text-decoration: none;
}

.cell-main {
  display: grid;
  gap: 3px;
}

.cell-main strong {
  font-size: 13px;
}

.form-card {
  display: grid;
  gap: 12px;
  padding: 0 14px 14px;
}

.form-card .card-header {
  margin: 0 -14px;
}

.form-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
}

label {
  display: grid;
  gap: 6px;
  color: #344054;
  font-weight: 650;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.check-row input {
  width: auto;
  min-height: auto;
}

.wide-form {
  max-width: 820px;
}

.empty-state {
  padding: 14px;
  color: var(--muted);
}

.json-box {
  width: 100%;
  min-height: 120px;
  margin: 0;
  padding: 14px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #0f172a;
  color: #e5edf7;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
}

@media (max-width: 1080px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 256px;
    transform: translateX(-100%);
    transition: transform 160ms ease;
    z-index: 20;
  }
  .sidebar.open { transform: translateX(0); }
  .icon-button { display: grid; }
  .stats-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .two-column { grid-template-columns: 1fr; }
  .source-grid { grid-template-columns: 1fr; }
}

@media (max-width: 680px) {
  main { padding: 16px; }
  .page-head { display: grid; }
  .page-actions { justify-content: flex-start; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar { padding: 0 14px; }
  .toolbar { align-items: stretch; }
  select { width: 100%; }
  .form-row { grid-template-columns: 1fr; }
}
