:root,
[data-theme="light"] {
  --bg: #e8ebef;
  --panel: #fff;
  --text: #1a1a1e;
  --muted: #5c5c66;
  --border: #c8ced6;
  --accent: #0d7dd8;
  --danger: #c00;
  --ok: #1a7f37;
  --topbar-bg: #0d7dd8;
  --topbar-fg: #ffffff;
  --sidebar-bg: #f2f5f8;
  --sidebar-border: #dce3eb;
  --sidebar-active-bg: #d6e8fc;
  --sidebar-active-fg: #0851a8;
  --widget-hd-bg: #e4e8ed;
  --widget-hd-fg: #0d6abc;
  --main-canvas: #e8ebef;
}
[data-theme="dark"] {
  --bg: #12141a;
  --panel: #1c2128;
  --text: #e8eaed;
  --muted: #9aa0a6;
  --border: #3d454e;
  --accent: #5eb0ff;
  --danger: #ff6b6b;
  --ok: #3fb950;
  --topbar-bg: #0a3d6b;
  --topbar-fg: #e8f1ff;
  --sidebar-bg: #1a1f27;
  --sidebar-border: #2a323c;
  --sidebar-active-bg: #243447;
  --sidebar-active-fg: #8ec5ff;
  --widget-hd-bg: #252b35;
  --widget-hd-fg: #7eb8ff;
  --main-canvas: #12141a;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", ui-sans-serif, system-ui, -apple-system, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}
body.layout-sbc {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--main-canvas);
}

/* —— Dinstar-style shell (astTECS SBC) —— */
.app-topbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem 1rem;
  min-height: 46px;
  padding: 0 14px;
  background: var(--topbar-bg);
  color: var(--topbar-fg);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  z-index: 10;
}
.app-topbar-brand {
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 4px 0;
  margin-right: 0.5rem;
}
.app-topbar-nav {
  display: flex;
  align-items: stretch;
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.app-topnav-item {
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.88);
  font: inherit;
  font-size: 0.88rem;
  padding: 10px 16px;
  cursor: pointer;
  border-radius: 4px 4px 0 0;
}
.app-topnav-item:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}
.app-topnav-item.active {
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
  font-weight: 600;
}
[data-theme="dark"] .app-topnav-item {
  color: rgba(232, 241, 255, 0.9);
}
[data-theme="dark"] .app-topnav-item.active {
  background: rgba(255, 255, 255, 0.15);
}
.app-topbar-right {
  margin-left: auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
}
.topbar-stat {
  font-size: 0.72rem;
  padding: 3px 8px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  color: var(--topbar-fg);
  white-space: nowrap;
}
.topbar-stat.ok { background: rgba(40, 180, 90, 0.35); border-color: rgba(180, 255, 200, 0.5); }
.topbar-stat.bad { background: rgba(200, 60, 60, 0.4); border-color: rgba(255, 180, 180, 0.55); }
.app-topbar .topbar-theme {
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.4);
  color: #fff;
  font-size: 0.8rem;
  padding: 5px 12px;
}
.app-topbar .topbar-theme:hover {
  background: rgba(255, 255, 255, 0.24);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.55);
}
.app-topbar .topbar-link {
  color: #fff;
  font-size: 0.85rem;
  padding: 4px 2px;
  opacity: 0.95;
}
.app-topbar .topbar-link:hover {
  color: #fff;
  opacity: 1;
  text-decoration: underline;
}

.app-shell {
  display: flex;
  flex: 1;
  min-height: 0;
  align-items: stretch;
}
.app-sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  padding: 8px 0;
  overflow-y: auto;
}
.app-side-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  border: none;
  border-bottom: 1px solid var(--sidebar-border);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.86rem;
  padding: 11px 14px;
  cursor: pointer;
}
.app-side-item:hover {
  background: rgba(13, 125, 216, 0.06);
}
.app-side-item.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-fg);
  font-weight: 600;
}
.side-ic {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  border-radius: 3px;
  background: currentColor;
  opacity: 0.28;
}
.app-side-item.active .side-ic { opacity: 0.45; }

.app-main {
  flex: 1;
  min-width: 0;
  padding: 16px 20px 28px;
  overflow-x: auto;
}

.d-widget {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 2px;
  margin-bottom: 16px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}
.d-widget-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  background: var(--widget-hd-bg);
  color: var(--widget-hd-fg);
  font-size: 0.82rem;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}
.d-widget-bd {
  padding: 14px 16px 16px;
}
.btn-widget {
  font: inherit;
  font-size: 0.78rem;
  padding: 4px 10px;
  border-radius: 3px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--widget-hd-fg);
  cursor: pointer;
}
.btn-widget:hover {
  filter: brightness(0.97);
}

@media (max-width: 760px) {
  .app-shell { flex-direction: column; }
  .app-sidebar {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    padding: 6px;
    gap: 4px;
    border-right: none;
    border-bottom: 1px solid var(--sidebar-border);
  }
  .app-side-item {
    flex: 1 1 auto;
    min-width: 140px;
    border: 1px solid var(--sidebar-border);
    border-radius: 4px;
  }
}
code { font-size: 0.92em; background: var(--panel); padding: 0.1em 0.35em; border-radius: 4px; }
.wrap { max-width: 52rem; margin: 0 auto; padding: 1.25rem 1rem 2rem; }
h1 { font-size: 1.45rem; margin: 0 0 0.5rem; }
.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem 1rem;
  margin-bottom: 1rem;
}
.site-title {
  font-size: 1.45rem;
  font-weight: 600;
  margin: 0;
  line-height: 1.2;
}
.site-header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem 0.65rem;
}
.theme-toggle-btn {
  padding: 0.4rem 0.8rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  cursor: pointer;
  white-space: nowrap;
}
.theme-toggle-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.header-signout {
  font-size: 0.9rem;
  padding: 0.35rem 0;
}
.muted, .small { color: var(--muted); font-size: 0.9rem; }
.row { display: flex; gap: 1rem; align-items: flex-start; flex-wrap: wrap; }
.row-between { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.gap { gap: 0.5rem; }
.stack { display: flex; flex-direction: column; gap: 0.75rem; }
.field { margin-bottom: 1rem; }
.field label { display: block; font-weight: 500; margin-bottom: 0.35rem; }
.field label.checkbox-label { display: flex; align-items: center; gap: 0.5rem; font-weight: 500; cursor: pointer; }
.field label.checkbox-label input { width: auto; margin: 0; }
.field input, .field textarea {
  width: 100%;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font: inherit;
}
.field textarea { min-height: 5rem; font-family: ui-monospace, monospace; font-size: 0.85rem; }

.tabs { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 0.75rem; border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; }
.tab {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 0.45rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-color: var(--border); background: var(--panel); }

.panels { position: relative; }
.panel { display: none; padding: 0.25rem 0 1rem; }
.panel.active { display: block; }

.badge-row { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.75rem; }
.badge { font-size: 0.8rem; padding: 0.25rem 0.55rem; border-radius: 6px; border: 1px solid var(--border); }
.badge.ok { border-color: rgba(52,199,89,0.45); color: var(--ok); }
.badge.bad { border-color: rgba(255,100,100,0.45); color: var(--danger); }

.alert { padding: 0.75rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid var(--border); }
.alert.ok { border-color: rgba(52,199,89,0.45); background: rgba(52,199,89,0.08); }
.alert.warn { border-color: rgba(255,180,0,0.45); background: rgba(255,180,0,0.08); }

.actions .primary, .actions .secondary, button.primary, button.secondary {
  cursor: pointer;
  font: inherit;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
}
button.primary, .actions .primary {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}
button.secondary, .actions .secondary { background: var(--panel); color: var(--text); }

.theme-switch { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.theme-switch button { border: none; background: var(--panel); color: var(--muted); padding: 0.35rem 0.65rem; cursor: pointer; font: inherit; }
.theme-switch button[aria-pressed="true"] { color: var(--text); font-weight: 600; }

.login-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.login-brand {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.output {
  margin-top: 0.75rem;
  padding: 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  font-size: 0.8rem;
  overflow: auto;
  max-height: 24rem;
  white-space: pre-wrap;
  word-break: break-word;
}
.output.hidden { display: none; }
.danger { color: var(--danger); }

.quick-save-bar {
  position: sticky;
  bottom: 0;
  z-index: 8;
  margin-top: 0.75rem;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
}
.quick-save-bar.visible {
  display: flex;
}
.quick-save-bar .quick-save-note {
  color: var(--muted);
  font-size: 0.86rem;
}

/* Status dashboard */
.wrap.wide { max-width: 60rem; }
.dash-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
  gap: 1rem;
  margin-top: 1.25rem;
}
.dash-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.1rem;
}
.dash-card h2 {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 0 0 0.75rem;
  color: var(--text);
}
.dash-card .note { font-size: 0.82rem; color: var(--muted); margin-top: 0.5rem; line-height: 1.4; }
.dash-stat {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  font-size: 0.9rem;
  margin: 0.35rem 0;
}
.dash-stat span:first-child { color: var(--muted); }
.dash-stat strong { font-variant-numeric: tabular-nums; }
.bar-wrap {
  height: 8px;
  border-radius: 4px;
  background: var(--border);
  overflow: hidden;
  margin-top: 0.35rem;
}
.bar-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--accent);
  transition: width 0.2s ease;
}
.bar-fill.warn { background: #e6a100; }
.bar-fill.bad { background: var(--danger); }
.dash-table {
  width: 100%;
  font-size: 0.85rem;
  border-collapse: collapse;
}
.dash-table th, .dash-table td {
  text-align: left;
  padding: 0.4rem 0.5rem 0.4rem 0;
  border-bottom: 1px solid var(--border);
}
.dash-table th { color: var(--muted); font-weight: 500; }
.dash-table td { font-variant-numeric: tabular-nums; }
.dash-full { grid-column: 1 / -1; }
.status-alert {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 180, 0, 0.45);
  background: rgba(255, 180, 0, 0.08);
  font-size: 0.9rem;
  margin-top: 0.75rem;
}
#dash-root.loading { opacity: 0.55; }
details.dash-raw { margin-top: 1.25rem; font-size: 0.8rem; }
details.dash-raw summary { cursor: pointer; color: var(--muted); }
details.dash-raw pre { margin: 0.5rem 0 0; }
