:root {
  color-scheme: dark;
  --bg: #0b0f14;
  --surface: #131a22;
  --surface-2: #1a2330;
  --border: #253040;
  --text: #e6edf3;
  --text-dim: #9aa9b8;
  --accent: #4d8dff;
  --danger: #ff5d5d;
  --up: #3ecf6f;
  --degraded: #f5a623;
  --down: #ff5d5d;
  --unknown: #7b8a99;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  padding-bottom: env(safe-area-inset-bottom);
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

#app-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 700;
  font-size: 1.05rem;
}

#main-nav {
  display: flex;
  gap: 0.4rem;
}

.nav-btn {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
  font-size: 0.85rem;
  min-height: 40px;
}

.nav-btn.active {
  color: var(--text);
  border-color: var(--accent);
}

#main {
  flex: 1;
  padding: 1rem;
  padding-inline: max(1rem, env(safe-area-inset-left)) max(1rem, env(safe-area-inset-right));
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

.view[hidden] {
  display: none !important;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  max-width: 360px;
  margin: 3rem auto 0;
  padding: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.login-form h1 {
  margin: 0 0 0.5rem;
  font-size: 1.3rem;
  text-align: center;
}

.login-form label {
  font-size: 0.8rem;
  color: var(--text-dim);
}

input[type="password"],
input[type="text"] {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.65rem 0.7rem;
  font-size: 1rem;
  min-height: 44px;
}

button {
  font-family: inherit;
  cursor: pointer;
}

.primary-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.7rem 1rem;
  font-size: 1rem;
  min-height: 44px;
  font-weight: 600;
}

.secondary-btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.7rem 1rem;
  font-size: 1rem;
  min-height: 44px;
}

.danger-btn {
  background: var(--danger);
}

.error-text {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 0.85rem;
}

.card-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}

.card-title {
  font-weight: 700;
  font-size: 1.05rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.pill::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: currentColor;
}

.pill-up {
  background: rgba(62, 207, 111, 0.15);
  color: var(--up);
}

.pill-degraded {
  background: rgba(245, 166, 35, 0.15);
  color: var(--degraded);
}

.pill-down {
  background: rgba(255, 93, 93, 0.15);
  color: var(--down);
}

.pill-unknown {
  background: rgba(123, 138, 153, 0.15);
  color: var(--unknown);
}

.meta-line {
  font-size: 0.82rem;
  color: var(--text-dim);
  margin: 0.15rem 0;
}

.rung-warning {
  color: var(--degraded);
  font-weight: 600;
}

.container-row,
.result-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.82rem;
  padding: 0.3rem 0;
  border-top: 1px solid var(--border);
}

.container-row:first-of-type,
.result-row:first-of-type {
  border-top: none;
}

.dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-ok {
  background: var(--up);
}

.dot-bad {
  background: var(--down);
}

.card-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}

.card-actions button {
  flex: 1 1 auto;
  min-width: 80px;
}

.jobs-strip {
  margin-bottom: 0.85rem;
}

.job-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem 0.8rem;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
}

.job-row-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  cursor: pointer;
}

.job-log {
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 0.5rem;
  max-height: 240px;
  overflow-y: auto;
}

.sheet {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 20;
}

.sheet[hidden] {
  display: none !important;
}

.sheet-content {
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  padding: 1.25rem 1rem calc(1.25rem + env(safe-area-inset-bottom));
  width: 100%;
  max-width: 720px;
}

.sheet-actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 1rem;
}

.sheet-actions button {
  flex: 1;
}

.logs-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.logs-header select {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem;
  min-height: 40px;
}

.logs-output {
  background: #05070a;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 65vh;
  overflow-y: auto;
}

.incident-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
}

.rebuild-sheet-content {
  max-height: 85vh;
  overflow-y: auto;
}

.host-actions-list {
  flex-direction: column;
}

.host-actions-list button {
  flex: none;
  width: 100%;
  text-align: left;
}

#host-actions-sheet-content input[type="text"] {
  width: 100%;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem;
  font-size: 1rem;
  margin: 0.5rem 0;
}

.rebuild-commit-list {
  margin-top: 0.4rem;
  max-height: 180px;
  overflow-y: auto;
}

.rebuild-commit-row {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  padding: 0.3rem 0;
  border-top: 1px solid var(--border);
}

.rebuild-commit-row:first-of-type {
  border-top: none;
}

.rebuild-sha {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
  color: var(--accent);
}

.rebuild-changed-files {
  margin-top: 0.6rem;
  font-size: 0.85rem;
}

.rebuild-changed-files summary {
  cursor: pointer;
  color: var(--text-dim);
}

.rebuild-guards {
  margin-top: 0.6rem;
}

.rebuild-force-label {
  display: block;
  margin-top: 0.4rem;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.rebuild-outcome {
  margin-top: 0.4rem;
  padding: 0.4rem 0.5rem;
  background: var(--surface-2);
  border-radius: 8px;
}

.jobs-filters {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
  flex-wrap: wrap;
}

.jobs-filters select {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem;
  min-height: 40px;
  flex: 1 1 auto;
}

.empty-note {
  color: var(--text-dim);
  font-size: 0.85rem;
  text-align: center;
  padding: 1.5rem 0;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
  }
}
