:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e5ea;
  --text: #171b23;
  --muted: #667085;
  --accent: #4f46e5;
  --accent-soft: #eef0ff;
  --accent-text: #ffffff;
  --ok: #12805c;
  --ok-soft: #e3f6ee;
  --warn: #b25e09;
  --warn-soft: #fdf1e1;
  --bad: #c4321c;
  --bad-soft: #fde9e6;
  --info: #2563eb;
  --info-soft: #e6efff;
  --code-bg: #0f1420;
  --code-text: #d7deea;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --radius: 12px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1017;
    --surface: #151a23;
    --surface-2: #1b212c;
    --border: #262d3a;
    --text: #e7eaf0;
    --muted: #8d96a8;
    --accent: #8b8cf8;
    --accent-soft: #23264a;
    --accent-text: #0d1017;
    --ok: #3ccf91;
    --ok-soft: #0f2a20;
    --warn: #f0a44b;
    --warn-soft: #2e2212;
    --bad: #ff7a66;
    --bad-soft: #321713;
    --info: #79a6ff;
    --info-soft: #15213a;
    --code-bg: #0a0d13;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 15px; font-weight: 620; }
h3 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 24px; padding: 0 24px; height: 56px;
  background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 600; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.logo { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--accent-text); font-weight: 750; font-size: 15px; }
.brand-sub { color: var(--muted); font-weight: 500; }
.topnav { display: flex; gap: 4px; flex: 1; }
.topnav a { padding: 6px 12px; border-radius: 8px; color: var(--muted); font-weight: 520; }
.topnav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.topnav a.active { background: var(--accent-soft); color: var(--accent); }

main { max-width: 1180px; margin: 0 auto; padding: 28px 24px 64px; }

/* ---------- buttons + forms ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--bad); }
.btn.danger.solid { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn.busy { pointer-events: none; opacity: .7; }
.btn.busy::before { content: ""; width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.field { display: grid; gap: 6px; justify-items: start; font-weight: 550; font-size: 13px; }
.field .hint { font-weight: 400; color: var(--muted); font-size: 12.5px; }
input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%; height: 36px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font: inherit; outline: none; }
textarea { height: auto; min-height: 140px; padding: 10px; font-family: var(--mono); font-size: 12.5px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input.mono { font-family: var(--mono); font-size: 12.5px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.seg { display: inline-flex; padding: 3px; gap: 3px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); }
.seg button { border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 550; padding: 6px 12px; border-radius: 7px; cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

/* ---------- page structure ---------- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head .sub { margin: 6px 0 0; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; }
.title-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.back { display: inline-block; margin-bottom: 14px; color: var(--muted); font-weight: 500; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; align-items: start; }
.stack { display: grid; gap: 16px; }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
.stat { padding: 16px 18px; }
.stat .label { color: var(--muted); font-size: 12.5px; font-weight: 550; }
.stat .value { font-size: 22px; font-weight: 650; margin: 4px 0 10px; letter-spacing: -.01em; }
.stat .value small { font-size: 13px; font-weight: 500; color: var(--muted); }

.bar { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar > span { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--accent); transition: width .4s ease; }
.bar.warn > span { background: var(--warn); }
.bar.bad > span { background: var(--bad); }
.meter { display: grid; gap: 5px; min-width: 120px; }
.meter .nums { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }

/* ---------- project list ---------- */
.list .row { display: grid; grid-template-columns: minmax(220px, 2.2fr) 1.3fr 1.2fr 1.3fr 1.3fr 1fr; gap: 16px; align-items: center;
  padding: 14px 20px; border-top: 1px solid var(--border); color: var(--text); }
.list .row:first-child { border-top: 0; }
.list a.row:hover { background: var(--surface-2); text-decoration: none; }
.list .row.head { padding-top: 10px; padding-bottom: 10px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.pname { display: flex; align-items: center; gap: 12px; min-width: 0; }
.pname strong { display: block; font-weight: 600; }
.pname .muted { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; }
.avatar { flex: none; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); font-weight: 700; text-transform: uppercase; }

.pill { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 99px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.info { background: var(--info-soft); color: var(--info); }
.pill.info::before { animation: pulse 1s ease-in-out infinite; }
.pill.muted { background: var(--surface-2); color: var(--muted); }
@keyframes pulse { 50% { opacity: .25; } }
.tag { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 6px; background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 550; white-space: nowrap; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; }

.empty { padding: 56px 24px; text-align: center; }
.empty h2 { font-size: 18px; margin-bottom: 8px; }
.empty p { color: var(--muted); max-width: 520px; margin: 0 auto 18px; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 20px; overflow-x: auto; }
.tabs a { padding: 10px 14px; color: var(--muted); font-weight: 550; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); }

/* ---------- key/value + tables ---------- */
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 10px 16px; align-items: baseline; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
table.t { width: 100%; border-collapse: collapse; }
table.t th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 10px 20px; border-bottom: 1px solid var(--border); }
table.t td { padding: 12px 20px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.t tr:last-child td { border-bottom: 0; }
table.t td.right, table.t th.right { text-align: right; }
.status-line { display: inline-flex; align-items: center; gap: 6px; }
.status-line .ic { width: 16px; height: 16px; border-radius: 50%; display: grid; place-items: center; font-size: 10px; font-weight: 800; color: #fff; flex: none; }
.ic.ok { background: var(--ok); } .ic.bad { background: var(--bad); } .ic.warn { background: var(--warn); }

.codebox { display: flex; align-items: flex-start; gap: 8px; padding: 10px 12px; border-radius: 8px; background: var(--code-bg); color: var(--code-text); }
.codebox code { flex: 1; white-space: pre-wrap; word-break: break-all; color: inherit; }
.codebox .btn { height: 24px; padding: 0 8px; font-size: 12px; background: transparent; color: var(--code-text); border-color: #2c3445; flex: none; }
.codebox + .codebox { margin-top: 8px; }

pre.log { margin: 0; padding: 14px 16px; min-height: 360px; max-height: 64vh; overflow: auto; background: var(--code-bg); color: var(--code-text);
  border-radius: 0 0 var(--radius) var(--radius); white-space: pre-wrap; word-break: break-word; line-height: 1.55; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar select { width: auto; min-width: 140px; }

.deploys { list-style: none; margin: 0; padding: 0; }
.deploys li { display: flex; gap: 12px; align-items: flex-start; padding: 12px 20px; border-top: 1px solid var(--border); }
.deploys li:first-child { border-top: 0; }
.deploys .msg { flex: 1; min-width: 0; overflow-wrap: anywhere; }

.env-row { display: grid; grid-template-columns: minmax(160px, 1fr) 2fr auto; gap: 8px; margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips code { padding: 2px 7px; border-radius: 6px; background: var(--surface-2); color: var(--muted); }

.danger-zone { border-color: color-mix(in srgb, var(--bad) 40%, var(--border)); }
.notice { padding: 12px 14px; border-radius: 10px; background: var(--info-soft); color: var(--text); font-size: 13px; }
.notice.warn { background: var(--warn-soft); }

/* ---------- modal + toasts ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: rgba(9, 12, 18, .55); }
.modal { width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal header { padding: 18px 22px 0; }
.modal .body { padding: 16px 22px; display: grid; gap: 16px; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 22px 18px; }
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 60; display: grid; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast { padding: 12px 14px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--ok); box-shadow: 0 8px 24px rgba(0,0,0,.18); animation: rise .2s ease; overflow-wrap: anywhere; white-space: pre-wrap; }
.toast.bad { border-left-color: var(--bad); }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: min(380px, 100%); padding: 28px; display: grid; gap: 16px; }
.login .brand { margin-bottom: 4px; }
.login .error { color: var(--bad); font-size: 13px; min-height: 18px; }

/* ---------- guide ---------- */
.guide { max-width: 820px; }
.guide h2 { font-size: 17px; margin: 30px 0 10px; }
.guide p, .guide li { color: var(--text); }
.guide .say { padding: 12px 16px; border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: 0 10px 10px 0; margin: 10px 0; font-weight: 500; }
.guide ul { padding-left: 20px; }

/* ---------- small screens ---------- */
@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .list .row { grid-template-columns: 1fr auto; gap: 10px; }
  .list .row .hide-sm, .list .row.head { display: none; }
}
@media (max-width: 640px) {
  .topbar { padding: 0 16px; gap: 12px; }
  .brand-sub { display: none; }
  main { padding: 20px 16px 48px; }
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .grid-2 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 10px; }
  .env-row { grid-template-columns: 1fr; }
  table.t th, table.t td { padding: 10px 14px; }
  table.t .hide-sm { display: none; }
}
.top-gap { margin-top: 16px; }
.bar.ok > span { background: var(--ok); }
.field > input, .field > select, .field > textarea { justify-self: stretch; }
details summary { cursor: pointer; margin-bottom: 12px; }
