:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f1f3;
  --text: #17181a;
  --muted: #6e7279;
  --border: #e2e4e8;
  --accent: #ff6b00;
  --accent-text: #ffffff;
  --success: #18794e;
  --warning: #a15c00;
  --danger: #b42318;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.04);
}

[data-theme="dark"] {
  --bg: #0f1012;
  --surface: #17181b;
  --surface-2: #202227;
  --text: #f3f4f6;
  --muted: #9da2aa;
  --border: #2b2e34;
  --accent: #ff7a1a;
  --accent-text: #ffffff;
  --success: #4cc38a;
  --warning: #e7a13b;
  --danger: #ff7b72;
  --shadow: none;
}

* { box-sizing: border-box; }
html { background: var(--bg); color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }
body { margin: 0; font: 14px/1.5 system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif; background: var(--bg); color: var(--text); }
a { color: inherit; text-decoration: none; }
button,input { font: inherit; }
button { cursor: pointer; }
code { font-family: ui-monospace,SFMono-Regular,Consolas,monospace; font-size: .9em; }
h1,h2,p { margin-top: 0; }
h1 { font-size: 24px; margin-bottom: 6px; }
h2 { font-size: 16px; margin-bottom: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 220px 1fr; }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 20px 14px; border-right: 1px solid var(--border); background: var(--surface); display:flex; flex-direction:column; }
.brand { display:flex; align-items:center; gap:10px; padding:0 8px 20px; }
.brand-mark { width:34px; height:34px; border-radius:9px; display:grid; place-items:center; font-weight:800; background:var(--accent); color:var(--accent-text); }
.brand strong,.brand span { display:block; }
.brand span { color:var(--muted); font-size:12px; }
.nav { display:grid; gap:4px; }
.nav a { padding:10px 12px; border-radius:8px; color:var(--muted); }
.nav a:hover { background:var(--surface-2); color:var(--text); }
.nav a.active { background:var(--surface-2); color:var(--text); font-weight:600; }
.sidebar-footer { margin-top:auto; padding:8px; }
.link-button { border:0; background:none; color:var(--muted); padding:0; }
.main { min-width:0; }
.topbar { height:58px; position:sticky; top:0; z-index:5; display:flex; align-items:center; justify-content:space-between; padding:0 24px; background:color-mix(in srgb,var(--bg) 92%,transparent); backdrop-filter:blur(8px); border-bottom:1px solid var(--border); }
.content { max-width:1180px; margin:0 auto; padding:28px 24px 48px; }
.page-intro { margin-bottom:20px; }
.section { margin-top:24px; }
.section-title { display:flex; align-items:center; justify-content:space-between; margin-bottom:12px; }
.section-title a { color:var(--muted); font-size:13px; }
.grid { display:grid; gap:14px; }
.cards-3 { grid-template-columns:repeat(3,minmax(0,1fr)); }
.cards-4 { grid-template-columns:repeat(4,minmax(0,1fr)); }
.split { grid-template-columns:1fr 1fr; }
.card,.panel,.mini-card,.service-row { background:var(--surface); border:1px solid var(--border); box-shadow:var(--shadow); border-radius:var(--radius); }
.card { padding:18px; }
.card-head,.mini-card { display:flex; justify-content:space-between; align-items:center; gap:12px; }
.metric { font-size:26px; font-weight:700; margin:18px 0 2px; }
.mini-card { padding:14px; }
.panel { padding:18px; }
.status { display:inline-flex; align-items:center; width:max-content; padding:3px 8px; border-radius:999px; font-size:11px; font-weight:650; background:var(--surface-2); color:var(--muted); text-transform:capitalize; }
.status.online,.status.connected,.status.completed,.status.configured { color:var(--success); }
.status.degraded,.status.timeout,.status.not-configured { color:var(--warning); }
.status.offline,.status.error,.status.failed { color:var(--danger); }
.data-list { margin:0; display:grid; gap:2px; }
.data-list div { display:flex; justify-content:space-between; gap:18px; padding:9px 0; border-bottom:1px solid var(--border); }
.data-list div:last-child { border-bottom:0; }
.data-list dt { color:var(--muted); }
.data-list dd { margin:0; text-align:right; }
.data-list.wide div { padding:12px 0; }
.activity-list { display:grid; }
.activity-list div { display:grid; grid-template-columns:145px 1fr; gap:12px; padding:8px 0; border-bottom:1px solid var(--border); }
.activity-list div:last-child { border-bottom:0; }
.activity-list time { color:var(--muted); font-size:12px; }
.icon-button { width:36px; height:36px; border:1px solid var(--border); background:var(--surface); color:var(--text); border-radius:9px; }
.mobile-only { display:none; }
.service-table { display:grid; gap:8px; }
.service-row { padding:14px 16px; display:grid; grid-template-columns:minmax(220px,1fr) 120px 100px auto; align-items:center; gap:16px; }
.service-row > div:first-child { display:grid; }
.primary-button,.secondary-button { border-radius:9px; padding:9px 13px; border:1px solid var(--border); }
.primary-button { background:var(--accent); color:var(--accent-text); border-color:var(--accent); font-weight:650; }
.primary-button.inline { display:inline-block; }
.secondary-button { background:var(--surface); color:var(--text); }
button:disabled { opacity:.6; cursor:default; }
.action-result { margin-top:12px; min-height:22px; }
.table-wrap { overflow:auto; }
table { width:100%; border-collapse:collapse; }
th,td { padding:11px 10px; text-align:left; border-bottom:1px solid var(--border); vertical-align:top; white-space:nowrap; }
th { color:var(--muted); font-size:12px; }
td code { white-space:normal; }
.endpoint { display:grid; grid-template-columns:minmax(260px,.8fr) 1fr; gap:20px; padding:11px 0; border-bottom:1px solid var(--border); }
.endpoint:last-child { border-bottom:0; }
.login-page { min-height:100vh; display:grid; place-items:center; padding:20px; }
.login-card { width:min(380px,100%); padding:28px; background:var(--surface); border:1px solid var(--border); border-radius:16px; box-shadow:var(--shadow); }
.login-brand { padding-left:0; }
.stack { display:grid; gap:14px; }
label { display:grid; gap:6px; font-weight:600; }
input { width:100%; padding:10px 11px; color:var(--text); background:var(--bg); border:1px solid var(--border); border-radius:9px; outline:none; }
input:focus { border-color:var(--accent); }
.alert { padding:10px 12px; border-radius:9px; margin:12px 0; }
.alert.error { background:color-mix(in srgb,var(--danger) 12%,var(--surface)); color:var(--danger); }
.error-code { font-size:42px; font-weight:800; color:var(--accent); }

@media (max-width: 900px) {
  .app-shell { grid-template-columns:1fr; }
  .sidebar { position:fixed; left:-240px; z-index:20; width:220px; transition:left .15s ease; }
  .sidebar.open { left:0; }
  .mobile-only { display:inline-grid; place-items:center; }
  .cards-3,.cards-4 { grid-template-columns:repeat(2,minmax(0,1fr)); }
  .split { grid-template-columns:1fr; }
  .service-row { grid-template-columns:1fr auto; }
  .service-row > :nth-child(3) { display:none; }
}

@media (max-width: 560px) {
  .content { padding:20px 14px 36px; }
  .topbar { padding:0 14px; }
  .cards-3,.cards-4 { grid-template-columns:1fr; }
  .endpoint { grid-template-columns:1fr; gap:4px; }
  .activity-list div { grid-template-columns:1fr; gap:2px; }
}

/* Lightweight skeleton loading */
.skeleton {
  display: block;
  border-radius: 7px;
  background: linear-gradient(90deg, var(--surface-2) 25%, color-mix(in srgb, var(--surface-2) 55%, var(--border)) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.15s linear infinite;
}
.skeleton-card { min-height: 92px; }
.skeleton-card > .skeleton + .skeleton { margin-top: 12px; }
.sk-line { height: 12px; }
.sk-metric { width: 88px; height: 31px; margin-top: 18px !important; }
.sk-pill { width: 72px; height: 22px; border-radius: 999px; }
.sk-button { width: 96px; height: 36px; }
.sk-w-30 { width: 30%; }
.sk-w-45 { width: 45%; }
.sk-w-70 { width: 70%; }
.load-error { margin-top: 14px; color: var(--danger); }
@keyframes skeleton-shimmer { to { background-position: -200% 0; } }

/* Chat API */
.chat-intro { display:flex; align-items:flex-start; justify-content:space-between; gap:16px; }
.chat-panel { padding:0; overflow:hidden; }
.chat-messages { min-height:420px; max-height:62vh; overflow:auto; padding:20px; display:flex; flex-direction:column; gap:12px; }
.chat-empty { min-height:330px; display:grid; place-items:center; align-content:center; text-align:center; gap:5px; }
.chat-message { max-width:min(78%,760px); padding:11px 13px; border:1px solid var(--border); border-radius:12px; white-space:pre-wrap; overflow-wrap:anywhere; }
.chat-message.user { align-self:flex-end; background:var(--accent); color:var(--accent-text); border-color:var(--accent); }
.chat-message.assistant { align-self:flex-start; background:var(--surface-2); }
.chat-message.error { align-self:center; max-width:100%; color:var(--danger); background:color-mix(in srgb,var(--danger) 8%,var(--surface)); }
.chat-loading { width:88px; display:flex; gap:6px; align-items:center; }
.chat-loading .skeleton { width:10px; height:10px; border-radius:999px; }
.chat-composer { border-top:1px solid var(--border); padding:14px; background:var(--surface); }
.chat-composer textarea { width:100%; min-height:58px; max-height:180px; resize:vertical; padding:11px 12px; color:var(--text); background:var(--bg); border:1px solid var(--border); border-radius:9px; outline:none; font:inherit; }
.chat-composer textarea:focus { border-color:var(--accent); }
.chat-actions { margin-top:10px; display:flex; align-items:center; justify-content:space-between; gap:12px; }
.chat-actions > div { display:flex; gap:8px; }

@media (prefers-reduced-motion: reduce) {
  .skeleton { animation:none; }
}

@media (max-width: 560px) {
  .chat-message { max-width:92%; }
  .chat-actions { align-items:flex-start; flex-direction:column; }
  .chat-actions > div { width:100%; }
  .chat-actions button { flex:1; }
  .chat-intro { align-items:center; }
}
.service-row .skeleton + .skeleton { margin-top:8px; }
.status.checking,.status.refreshing { color:var(--muted); }

/* v0.4 headnode */
.row-between { display:flex; justify-content:space-between; align-items:flex-start; gap:14px; }
.service-row.simple { grid-template-columns:1fr auto; }
.service-table.compact .service-row { padding:10px 12px; }
.status.warning { color:var(--warning); }
.status.critical { color:var(--danger); font-weight:750; }
.status.error,.status.inactive,.status.failed,.status.offline { color:var(--danger); }
.status.active,.status.ready,.status.enabled,.status.online,.status.lite-safe { color:var(--success); }
.status.approval-required { color:var(--warning); }
@media (max-width:560px) { .row-between { flex-direction:column; } }
