:root {
  --bg: #f3f3ef;
  --panel: #fbfbf8;
  --fg: #1b1e23;
  --muted: #6c7077;
  --border: #d5d5cd;
  --hairline: #e3e3dc;
  --primary: #1b1e23;
  --primary-fg: #fbfbf8;
  --danger: #b4433a;
  --ok: #2e7d46;

  --font-sans: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', Roboto, 'Noto Color Emoji', sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, 'Noto Color Emoji', monospace;

  --c-default: #8b9099;
  --c-prepare: #c98a1b;
  --c-permit: #2f6fd6;
  --c-updating: #0a9cb8;
  --c-finished: #2e9e5b;
  --c-canceled: #b4554d;
}

[data-theme="dark"] {
  --bg: #101113;
  --panel: #17181c;
  --fg: #e6e4de;
  --muted: #8a8f96;
  --border: #2a2c31;
  --hairline: #202227;
  --primary: #e6e4de;
  --primary-fg: #101113;
  --danger: #e06a5e;
  --ok: #4fbc7c;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.45;
  min-height: 100vh;
  transition: background-color .2s ease, color .2s ease;
}

.hidden { display: none !important; }

/* ---------- buttons ---------- */
.btn {
  font: inherit;
  font-weight: 400;
  border-radius: 4px;
  border: 1px solid transparent;
  padding: 7px 14px;
  cursor: pointer;
  background: transparent;
  color: var(--fg);
  transition: background-color .15s ease, border-color .15s ease, opacity .15s ease;
}
.btn:focus-visible { outline: 2px solid var(--c-permit); outline-offset: 2px; }
.btn-primary { background: var(--primary); color: var(--primary-fg); }
.btn-primary:hover { opacity: .85; }
.btn-block { width: 100%; }
.btn-ghost { border-color: var(--border); background: var(--panel); }
.btn-ghost:hover { border-color: var(--fg); }
.btn-danger-ghost { border-color: var(--border); background: var(--panel); color: var(--danger); }
.btn-danger-ghost:hover { border-color: var(--danger); }

/* ---------- login ---------- */
.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 340px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 32px 28px;
}
.login-title { margin: 0 0 2px; font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
.login-sub { margin: 0 0 24px; color: var(--muted); font-size: 13px; }
.login-error { color: var(--danger); font-size: 13px; margin: 12px 0 0; }
.login-foot { margin-top: 20px; }

/* ---------- fields ---------- */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
.field input {
  width: 100%;
  font: inherit;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 10px;
}
.field input:focus { outline: 2px solid var(--c-permit); outline-offset: 0; border-color: transparent; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; margin-bottom: 18px; }
.check input { accent-color: var(--primary); }

/* ---------- topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand-title { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -.01em; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.current-user {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--muted);
  padding: 0 8px;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.env-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
}

/* ---------- content ---------- */
.content { max-width: fit-content; margin: 0 auto; padding: 24px 20px 60px; }
.toolbar { display: flex; justify-content: flex-end; margin-bottom: 16px; }

.table-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow-x: auto;
}
table.services { width: 100%; border-collapse: collapse; }
table.services th, table.services td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--hairline);
  vertical-align: middle;
}
table.services thead th {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.services tbody tr:last-child td { border-bottom: none; }
table.services tbody tr:hover { background: var(--bg); }
table.services td { font-size: 14px; }

.td-name { font-weight: 600; }
.td-mono { font-family: var(--font-mono); font-size: 12.5px; }
.td-time { font-family: var(--font-mono); font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.td-actions { white-space: nowrap; }
.td-actions .btn { margin-right: 6px; padding: 5px 10px; font-size: 13px; }
.td-actions .btn:last-child { margin-right: 0; }

.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.loading { padding: 40px 20px; text-align: center; color: var(--muted); }

/* ---------- state badge + track ---------- */
.state-cell { display: flex; flex-direction: column; gap: 6px; min-width: 150px; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  width: fit-content;
  white-space: nowrap;
}
.badge::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}
.badge.State-Default { color: var(--c-default); background: color-mix(in srgb, var(--c-default) 14%, transparent); }
.badge.State-PrepareForUpdate { color: var(--c-prepare); background: color-mix(in srgb, var(--c-prepare) 14%, transparent); }
.badge.State-DeploymentIsPermitted { color: var(--c-permit); background: color-mix(in srgb, var(--c-permit) 14%, transparent); }
.badge.State-Updating { color: var(--c-updating); background: color-mix(in srgb, var(--c-updating) 14%, transparent); }
.badge.State-Updating::before { animation: pulse 1.4s ease-in-out infinite; }
.badge.State-UpdateFinished { color: var(--c-finished); background: color-mix(in srgb, var(--c-finished) 14%, transparent); }
.badge.State-UpdateCanceled { color: var(--c-canceled); background: color-mix(in srgb, var(--c-canceled) 14%, transparent); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .25; }
}

.track { display: flex; gap: 3px; max-width: 240px; }
.track-seg {
  flex: 1;
  height: 8px;
  border-radius: 2px;
  background: var(--hairline);
  transition: background-color .2s ease;
}
.track-seg.done { background: var(--c-default); opacity: .45; }
.track-seg.current { background: var(--state-color, var(--c-default)); }
.track-seg.current.pulse { animation: pulse 1.4s ease-in-out infinite; }

/* ---------- dialog ---------- */
dialog {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--fg);
  padding: 24px;
  width: min(400px, calc(100vw - 32px));
}
dialog::backdrop { background: rgb(0 0 0 / .45); }
dialog h2 { margin: 0 0 18px; font-size: 17px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--fg);
  color: var(--bg);
  font-size: 14px;
  font-weight: 500;
  padding: 10px 18px;
  border-radius: 6px;
  box-shadow: 0 4px 16px rgb(0 0 0 / .2);
  z-index: 100;
  max-width: calc(100vw - 40px);
}
.toast.error { background: var(--danger); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }

/* ---------- responsive ---------- */
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; }
  .state-cell { min-width: 0; }
}
