:root {
  --bg: #faf9f7;
  --surface: #ffffff;
  --surface-2: #f4f2ee;
  --border: #e4e0d9;
  --border-strong: #d3cec4;
  --text: #1d1b18;
  --text-dim: #6b655c;
  --text-faint: #948d82;
  --accent: #b8563a;
  --accent-soft: #f7ece8;
  --ok: #3f7d58;
  --ok-soft: #e8f2ec;
  --warn: #a8761f;
  --warn-soft: #f8efdd;
  --bad: #b23b3b;
  --bad-soft: #fbeaea;
  --info: #3f6ea8;
  --info-soft: #e9f0f8;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(28, 26, 22, .05), 0 8px 24px -12px rgba(28, 26, 22, .18);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16151a;
    --surface: #1d1c22;
    --surface-2: #24232a;
    --border: #2f2d36;
    --border-strong: #3d3a45;
    --text: #ece9e4;
    --text-dim: #a49e97;
    --text-faint: #726d78;
    --accent: #e0805f;
    --accent-soft: #2e211c;
    --ok: #6cbb8b;
    --ok-soft: #1c2a22;
    --warn: #d6a55a;
    --warn-soft: #2b2419;
    --bad: #e07a7a;
    --bad-soft: #2c1d1d;
    --info: #79a6dc;
    --info-soft: #1b2430;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px -14px rgba(0, 0, 0, .7);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- layout ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .7rem 1.4rem;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  font-weight: 620;
  letter-spacing: -.01em;
  color: var(--text);
}
.brand:hover { text-decoration: none; }
.brand .mark {
  display: grid;
  place-items: center;
  width: 26px; height: 26px;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}
.brand small { color: var(--text-faint); font-weight: 400; }

.spacer { flex: 1; }

.user {
  display: flex;
  align-items: center;
  gap: .5rem;
  color: var(--text-dim);
  font-size: .86rem;
}
.avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: grid; place-items: center;
  font-size: .72rem; font-weight: 600; color: var(--text-dim);
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

main { max-width: 1180px; margin: 0 auto; padding: 1.6rem 1.4rem 4rem; }

.page-head {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.2rem;
  flex-wrap: wrap;
}
.page-head h1 { margin: 0; font-size: 1.35rem; letter-spacing: -.015em; }
.page-head p { margin: .2rem 0 0; color: var(--text-dim); font-size: .88rem; }

/* ---------- controls ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .45rem .85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: .87rem;
  cursor: pointer;
  transition: background .12s, border-color .12s, opacity .12s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--border)); }
.btn.danger:hover { background: var(--bad-soft); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-dim); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.sm { padding: .28rem .6rem; font-size: .8rem; }

input[type=text], input[type=number], input[type=password], select, textarea {
  width: 100%;
  padding: .45rem .6rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: .88rem;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent);
  outline-offset: 1px;
  border-color: var(--accent);
}
input::placeholder { color: var(--text-faint); }
input[type=checkbox] { accent-color: var(--accent); width: 15px; height: 15px; }
label { font-size: .82rem; color: var(--text-dim); display: block; margin-bottom: .25rem; }
.hint { font-size: .76rem; color: var(--text-faint); margin-top: .25rem; }

/* Shrinks before the buttons do, so the action row survives a narrow window. */
.search {
  flex: 1 1 150px;
  min-width: 130px;
  max-width: 320px;
}

/* ---------- cards & tables ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 1rem; }
.card h2 {
  margin: 0;
  padding: .85rem 1.1rem;
  font-size: .95rem;
  letter-spacing: -.005em;
  border-bottom: 1px solid var(--border);
}
.card .body { padding: 1.1rem; }

table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-faint);
  font-weight: 600;
  padding: .55rem 1.1rem;
  border-bottom: 1px solid var(--border);
}
td {
  padding: .7rem 1.1rem;
  border-bottom: 1px solid var(--border);
  font-size: .88rem;
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tbody tr.row { cursor: pointer; }
tbody tr.row:hover { background: var(--surface-2); }

.app-name { font-weight: 570; }
.app-sub { color: var(--text-faint); font-size: .78rem; font-family: var(--mono); }

/* ---------- pills ---------- */

.pill {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .12rem .5rem;
  border-radius: 999px;
  font-size: .74rem;
  font-weight: 560;
  white-space: nowrap;
  border: 1px solid transparent;
}
.pill .dot { width: 6px; height: 6px; 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.mute { background: var(--surface-2); color: var(--text-dim); border-color: var(--border); }
.pill.progress .dot { animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1 } 50% { opacity: .25 } }

.tag {
  font-size: .72rem;
  padding: .1rem .4rem;
  border-radius: 5px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: var(--mono);
}

/* ---------- detail ---------- */

.detail-head {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.detail-head h1 { margin: 0; font-size: 1.4rem; letter-spacing: -.02em; }
.detail-meta { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-top: .35rem; }
.actions { display: flex; gap: .45rem; flex-wrap: wrap; }

.tabs {
  display: flex;
  gap: .15rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.1rem;
  overflow-x: auto;
}
.tab {
  padding: .5rem .8rem;
  border: none;
  background: none;
  color: var(--text-dim);
  font: inherit;
  font-size: .87rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 550; }

.grid { display: grid; gap: 1rem; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

.kv { display: grid; grid-template-columns: minmax(120px, auto) 1fr; gap: .5rem 1rem; font-size: .86rem; }
.kv dt { color: var(--text-dim); }
.kv dd { margin: 0; word-break: break-word; }
.mono { font-family: var(--mono); font-size: .82rem; }

/* ---------- forms ---------- */

.field { margin-bottom: .9rem; }
.field.row { display: flex; align-items: center; gap: .5rem; }
.field.row label { margin: 0; }
fieldset { border: none; margin: 0 0 1.4rem; padding: 0; }
fieldset > legend {
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-faint);
  font-weight: 600;
  padding: 0 0 .6rem;
}

/* Free label plus the tenant zone, which is fixed and shown as plain text. */
.host-field { display: flex; align-items: center; gap: .1rem; }
.host-field input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.host-field .suffix {
  flex: none;
  padding: .45rem .55rem;
  border: 1px solid var(--border-strong);
  border-left: none;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--surface-2);
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: .8rem;
  white-space: nowrap;
}

.pairs { display: flex; flex-direction: column; gap: .45rem; }
.pair { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr) auto; gap: .45rem; align-items: center; }
.pair input { font-family: var(--mono); font-size: .82rem; }

.empty {
  padding: 2.4rem 1rem;
  text-align: center;
  color: var(--text-faint);
  font-size: .9rem;
}
.empty strong { display: block; color: var(--text-dim); font-size: 1rem; margin-bottom: .3rem; }

/* ---------- logs ---------- */

.logs {
  background: #16151a;
  color: #d8d4cd;
  font-family: var(--mono);
  font-size: .78rem;
  line-height: 1.5;
  padding: .9rem 1rem;
  border-radius: var(--radius-sm);
  max-height: 60vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
.logs .ts { color: #6f6a63; }

/* ---------- dialog ---------- */

dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 0;
  width: min(760px, calc(100vw - 2rem));
  max-height: calc(100vh - 4rem);
  box-shadow: 0 24px 60px -20px rgba(0, 0, 0, .35);
}
dialog::backdrop { background: rgba(20, 18, 16, .45); backdrop-filter: blur(2px); }
dialog header {
  display: flex; align-items: center; gap: 1rem;
  padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--border);
}
dialog header h2 { margin: 0; font-size: 1.05rem; }
dialog .content { padding: 1.2rem; overflow: auto; max-height: calc(100vh - 14rem); }
dialog footer {
  display: flex; justify-content: flex-end; gap: .5rem;
  padding: .9rem 1.2rem;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 var(--radius) var(--radius);
}

/* ---------- toast ---------- */

#toasts {
  position: fixed;
  right: 1.1rem; bottom: 1.1rem;
  display: flex; flex-direction: column; gap: .5rem;
  z-index: 100;
  max-width: min(420px, calc(100vw - 2rem));
}
.toast {
  padding: .7rem .9rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: .86rem;
  animation: slide .18s ease-out;
}
.toast.err { border-color: color-mix(in srgb, var(--bad) 45%, var(--border)); background: var(--bad-soft); color: var(--bad); }
.toast.ok { border-color: color-mix(in srgb, var(--ok) 40%, var(--border)); background: var(--ok-soft); color: var(--ok); }
@keyframes slide { from { opacity: 0; transform: translateY(6px) } }

.loading { padding: 3rem; text-align: center; color: var(--text-faint); font-size: .9rem; }

.banner {
  padding: .7rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .85rem;
  margin-bottom: 1rem;
  border: 1px solid;
}
.banner.warn { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, var(--border)); }
.banner.bad { background: var(--bad-soft); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, var(--border)); }

@media (max-width: 680px) {
  .hide-sm { display: none; }
  main { padding: 1rem .8rem 3rem; }
  .pair { grid-template-columns: 1fr; }
}
