:root {
  color-scheme: dark;
  --bg: #0f1115;
  --surface: #161920;
  --surface-raised: #1c2029;
  --border: #272c36;
  --text: #dfe3ea;
  --text-muted: #8b93a1;
  --accent: #5b9cf8;
  --accent-contrast: #0b0d11;
  --danger: #f2777a;
  --warning: #e8c468;
  --success: #7fd18a;
  --radius: 8px;
  --gap: 16px;
  --font: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --font-scale: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: var(--font-scale)/1.5 var(--font);
  background: var(--bg);
  color: var(--text);
}

.app { display: flex; min-height: 100vh; }

/* Navigation is built from the sections a module declared, so a module adds itself to the
   panel's navigation rather than only appending widgets to the bottom of the page. */
.nav {
  width: 208px;
  flex: 0 0 208px;
  border-right: 1px solid var(--border);
  background: var(--surface);
  padding: 16px 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-brand {
  font-weight: 600;
  padding: 0 16px 14px;
  letter-spacing: 0.02em;
}

.nav-item {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  text-align: left;
  padding: 7px 16px;
  cursor: pointer;
  border-left: 2px solid transparent;
}

.nav-item:hover { color: var(--text); background: var(--surface-raised); }
.nav-item[aria-current="true"] {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--surface-raised);
}

.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
}

.topbar h1 { font-size: var(--font-scale); font-weight: 600; margin: 0; }
#status { font-size: 12px; color: var(--text-muted); margin-left: auto; }
#status[data-state="stale"] { color: var(--warning); }
#status[data-state="error"] { color: var(--danger); }

.content { padding: 20px; display: flex; flex-direction: column; gap: var(--gap); }

.widget { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.widget.card { padding: 16px; }
.widget.card > h2 { margin: 0 0 12px; font-size: var(--font-scale); font-weight: 600; }
.widget.card > h2:empty { display: none; }

.widget table { border-collapse: collapse; width: 100%; }
.widget th, .widget td { padding: 7px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.widget th { background: var(--surface-raised); font-weight: 600; color: var(--text-muted); }
.widget tbody tr:last-child td { border-bottom: 0; }
.widget tbody tr:hover td { background: var(--surface-raised); }

.widget.kv dl, .widget.form dl { margin: 0; padding: 12px 16px; display: grid;
  grid-template-columns: minmax(120px, max-content) 1fr; gap: 6px 16px; }
.widget.kv dt, .widget.form dt { color: var(--text-muted); }
.widget.kv dd, .widget.form dd { margin: 0; }

.widget.stats ul { list-style: none; margin: 0; padding: 12px 16px;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.widget.stats li { display: flex; flex-direction: column; gap: 2px; }
.widget.stats .label { color: var(--text-muted); font-size: 12px; }
.widget.stats .value { font-size: 22px; font-weight: 600; }

.widget.text { padding: 12px 16px; }

.widget.chart { padding: 16px; display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.widget.chart .bars rect { fill: var(--accent); }
.widget.chart .legend { list-style: none; margin: 0; padding: 0; display: flex;
  flex-direction: column; gap: 4px; }
.widget.chart .legend .label { color: var(--text-muted); }
.widget.chart .legend .value { margin-left: 8px; font-weight: 600; }

.widget.tabs { background: transparent; border: 0; }
.tab-labels { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: var(--gap); }
.tab-label { padding: 7px 14px; color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; }
.tab-label.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel[hidden] { display: none; }

.widget.button { background: transparent; border: 0; }
.widget.button button {
  appearance: none; font: inherit; cursor: pointer;
  background: var(--accent); color: var(--accent-contrast);
  border: 0; border-radius: var(--radius); padding: 7px 16px; font-weight: 600;
}
.widget.button button:hover { filter: brightness(1.1); }

.empty { color: var(--text-muted); }
.banner { padding: 10px 20px; background: var(--surface-raised);
  border-bottom: 1px solid var(--border); color: var(--warning); font-size: 13px; }

/* Row actions and the action dialog */
.row-actions { white-space: nowrap; text-align: right; }
.row-action {
  appearance: none; font: inherit; font-size: 12px; cursor: pointer;
  background: transparent; color: var(--accent);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 3px 10px; margin-left: 4px;
}
.row-action:hover { background: var(--surface-raised); }

.action-dialog {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); padding: 20px 24px; min-width: min(420px, 92vw);
}
.action-dialog::backdrop { background: rgba(0, 0, 0, 0.55); }
.action-dialog h2 { margin: 0 0 12px; font-size: 18px; }
.action-dialog .warn { margin: 0 0 12px; color: var(--warning); font-size: 13px; }
.action-dialog .fields { display: flex; flex-direction: column; gap: 12px; }
.action-dialog .field { display: flex; flex-direction: column; gap: 4px; }
.action-dialog .field label { font-size: 12px; color: var(--text-muted); }
.action-dialog .req { color: var(--warning); }
.action-dialog input[type="text"], .action-dialog input[type="number"], .action-dialog select {
  font: inherit; color: inherit; background: var(--surface-raised);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 7px 10px;
}
.action-dialog input[readonly] { opacity: 0.75; }
.action-dialog .form-error { color: var(--danger, var(--warning)); font-size: 13px; margin: 10px 0 0; }
.action-dialog .buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.action-dialog .buttons button {
  appearance: none; font: inherit; cursor: pointer; padding: 7px 16px; font-weight: 600;
  background: transparent; color: var(--text); border: 1px solid var(--border); border-radius: var(--radius);
}
.action-dialog .buttons button.primary { background: var(--accent); color: var(--accent-contrast); border-color: transparent; }
.action-dialog .buttons button.primary.danger { background: var(--danger, #ed4245); color: #fff; }

.toast {
  position: fixed; right: 20px; bottom: 20px; max-width: min(460px, 90vw); z-index: 50;
  padding: 12px 16px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface-raised); color: var(--text); box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}
.toast[data-ok="true"] { border-left: 4px solid var(--success, #57f287); }
.toast[data-ok="false"] { border-left: 4px solid var(--danger, #ed4245); }

.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login[hidden], .app[hidden] { display: none; }
.login-card {
  display: flex; flex-direction: column; gap: 10px; width: min(420px, 100%);
  padding: 28px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card p { margin: 0 0 6px; color: var(--text-muted); font-size: 13px; }
.login-card label { font-size: 12px; color: var(--text-muted); }
.login-card input {
  font: inherit; letter-spacing: 0.12em; text-transform: uppercase; color: inherit; background: var(--surface-raised);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px;
}
.login-card button.primary {
  appearance: none; font: inherit; cursor: pointer; padding: 9px 16px; font-weight: 600;
  background: var(--accent); color: var(--accent-contrast); border: 0; border-radius: var(--radius);
}
.login-card .login-error { color: var(--danger, #ed4245); margin: 0; }
.login-providers { display: flex; flex-direction: column; align-items: stretch; gap: 8px; margin-top: 4px; }
.login-providers[hidden], .provider-button[hidden] { display: none; }
.login-or { text-align: center; color: var(--text-muted); font-size: 12px; }
.provider-button {
  display: block; text-align: center; padding: 9px 16px; font-weight: 600; text-decoration: none; cursor: pointer;
  color: #fff; background: #5865f2; border-radius: var(--radius);
}
.provider-button:hover { filter: brightness(1.1); }
.link-button {
  appearance: none; background: none; border: 0; padding: 0 0 0 12px; font: inherit; font-size: 12px;
  color: var(--text-muted); cursor: pointer; text-decoration: underline;
}
