:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-muted: #f8f9fb;
  --border: #dde1e7;
  --text: #1d2430;
  --text-muted: #5d6676;
  --accent: #1f5fbf;
  --accent-strong: #174a96;
  --accent-soft: #e7effb;
  --ok: #1c7c45;
  --ok-soft: #e3f4ea;
  --warn: #9a5b00;
  --warn-soft: #fdf1dc;
  --danger: #b42318;
  --danger-soft: #fde8e6;
  --neutral-soft: #eceef2;
  --mono: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --radius: 8px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161d;
    --surface: #1a2029;
    --surface-muted: #202733;
    --border: #2f3846;
    --text: #e6e9ef;
    --text-muted: #9aa4b5;
    --accent: #7aa7ff;
    --accent-strong: #a5c3ff;
    --accent-soft: #1f2d48;
    --ok: #5fd08f;
    --ok-soft: #173525;
    --warn: #f0b354;
    --warn-soft: #3a2c12;
    --danger: #ff8a80;
    --danger-soft: #3d1d1b;
    --neutral-soft: #262e3b;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Hiragino Kaku Gothic ProN",
    "Yu Gothic UI", Meiryo, sans-serif;
  font-size: 14px;
  line-height: 1.55;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }

/* Top bar ------------------------------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 24px;
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-weight: 700; color: var(--text); white-space: nowrap; }
.topbar nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.topbar nav a {
  padding: 6px 10px;
  border-radius: 6px;
  color: var(--text-muted);
  white-space: nowrap;
}
.topbar nav a:hover { background: var(--surface-muted); text-decoration: none; color: var(--text); }
.topbar nav a.active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
.account { display: flex; align-items: center; gap: 12px; color: var(--text-muted); white-space: nowrap; }
.account form { margin: 0; }

/* Page layout --------------------------------------------------------------------------------- */
.page { max-width: 1320px; margin: 0 auto; padding: 24px; }
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.page-header h1 { margin: 0; font-size: 20px; }
.page-header p { margin: 4px 0 0; color: var(--text-muted); }
h2 { font-size: 15px; margin: 0 0 12px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.card.flush { padding: 0; overflow: hidden; }
.card.flush > h2 { padding: 14px 16px 0; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid .card { margin-bottom: 0; }
.stack > * + * { margin-top: 8px; }

.notice, .error-box, .warning-box, .info-box {
  border-radius: var(--radius);
  padding: 10px 14px;
  margin: 0 0 16px;
  border: 1px solid transparent;
}
.notice { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.error-box { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.warning-box { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
.info-box { background: var(--accent-soft); color: var(--accent-strong); }

/* Tables -------------------------------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
th { font-size: 12px; font-weight: 600; color: var(--text-muted); background: var(--surface-muted); white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: color-mix(in srgb, var(--accent-soft) 35%, transparent); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.nowrap, th.nowrap { white-space: nowrap; }
.kv th { width: 180px; background: transparent; }
.kv td, .kv th { border-bottom: 1px dashed var(--border); }
.truncate { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.empty { padding: 24px; text-align: center; color: var(--text-muted); }

/* Badges -------------------------------------------------------------------------------------- */
.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--neutral-soft);
  color: var(--text-muted);
  white-space: nowrap;
}
.state-running, .badge.ok { background: var(--ok-soft); color: var(--ok); }
.state-partial, .state-restarting, .badge.warn { background: var(--warn-soft); color: var(--warn); }
.state-missing, .state-unknown, .badge.danger { background: var(--danger-soft); color: var(--danger); }
.code { font-family: var(--mono); font-weight: 600; }
.code-2xx { color: var(--ok); }
.code-3xx { color: var(--accent); }
.code-4xx { color: var(--warn); }
.code-5xx { color: var(--danger); }

/* Forms and buttons --------------------------------------------------------------------------------- */
button, .button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}
button:hover, .button:hover { background: var(--surface-muted); text-decoration: none; }
button:disabled { opacity: 0.55; cursor: not-allowed; }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-strong); }
button.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }
button.danger:hover { background: var(--danger-soft); }
button.link { border: none; background: none; padding: 0; color: var(--accent); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }
.actions select { width: auto; }
td .actions { flex-wrap: nowrap; }

label { display: block; font-weight: 600; margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.field .hint { font-weight: 400; color: var(--text-muted); font-size: 12px; margin-top: 2px; }
input[type="text"], input[type="search"], input[type="password"], select, textarea {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.inline-choices { display: flex; flex-wrap: wrap; gap: 12px; }
.inline-choices label { font-weight: 400; display: inline-flex; gap: 6px; align-items: center; }
.form-grid { display: grid; gap: 12px 16px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); align-items: end; }
.filters { display: grid; gap: 8px 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); align-items: end; }
.filters .wide { grid-column: span 2; }
.filters label { font-size: 12px; color: var(--text-muted); }

/* Logs ---------------------------------------------------------------------------------------- */
.live-bar { display: flex; align-items: center; gap: 12px; justify-content: space-between; padding: 10px 16px; border-bottom: 1px solid var(--border); }
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); margin-right: 6px; }
.live-dot.on { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.live-dot.error { background: var(--danger); }
tr.fresh td { animation: fresh 2s ease-out; }
@keyframes fresh { from { background: var(--accent-soft); } to { background: transparent; } }
.body-preview { font-family: var(--mono); font-size: 12px; color: var(--text-muted); max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
pre.block {
  margin: 0;
  padding: 12px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 480px;
  overflow: auto;
}
pre.logs { max-height: 560px; font-size: 12px; }

/* Login --------------------------------------------------------------------------------------- */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 32px; }
.auth-card h1 { margin: 0 0 4px; font-size: 20px; }
.auth-card p.lead { margin: 0 0 24px; color: var(--text-muted); }
.auth-card button.primary { width: 100%; justify-content: center; padding: 10px; font-size: 15px; }
.auth-message { min-height: 1.5em; margin-top: 12px; }
.auth-message.error { color: var(--danger); }

meter { width: 120px; height: 10px; vertical-align: middle; }

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 12px; gap: 8px; }
  .page { padding: 12px; }
  .filters .wide { grid-column: auto; }
}
