:root,
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c1219;
  --panel: #15202b;
  --border: #2a3a4d;
  --text: #e8eef6;
  --muted: #8b9cb3;
  --accent: #2dd4bf;
  --accent-fg: #042f2e;
  --ok: #34d399;
  --bad: #f87171;
  --warn: #fbbf24;
  --repo: #60a5fa;
  --thin: #2dd4bf;
  --shadow: rgba(0, 0, 0, 0.4);
  --modal-scrim: rgba(0, 0, 0, 0.55);
  --mono: ui-monospace, Menlo, Consolas, monospace;
  --sans: "Segoe UI", system-ui, sans-serif;
  --font-display: "Segoe UI", system-ui, sans-serif;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f7fb;
  --panel: #ffffff;
  --border: #d0dae6;
  --text: #0f172a;
  --muted: #5b6b7f;
  --accent: #0d9488;
  --accent-fg: #ffffff;
  --ok: #059669;
  --bad: #dc2626;
  --warn: #d97706;
  --repo: #2563eb;
  --thin: #0d9488;
  --shadow: rgba(15, 23, 42, 0.12);
  --modal-scrim: rgba(15, 23, 42, 0.4);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    color-scheme: light;
    --bg: #f4f7fb;
    --panel: #ffffff;
    --border: #d0dae6;
    --text: #0f172a;
    --muted: #5b6b7f;
    --accent: #0d9488;
    --accent-fg: #ffffff;
    --ok: #059669;
    --bad: #dc2626;
    --warn: #d97706;
    --repo: #2563eb;
    --thin: #0d9488;
    --shadow: rgba(15, 23, 42, 0.12);
    --modal-scrim: rgba(15, 23, 42, 0.4);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  min-height: 100vh;
}
header {
  padding: 0.75rem 1.5rem 0.4rem;
  border-bottom: 1px solid var(--border);
}
.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 0.65rem; min-width: 0; }
.brand-mark {
  width: 2.15rem; height: 2.15rem; border-radius: 0.7rem;
  background: var(--text); color: var(--bg);
  display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 600; font-size: 1.15rem;
  letter-spacing: -0.04em; flex-shrink: 0;
}
.brand-title {
  margin: 0; font-family: var(--font-display); font-size: 1.35rem;
  font-weight: 600; letter-spacing: -0.04em; line-height: 1.1;
}
.brand-instance {
  margin: 0.2rem 0 0; font-family: var(--font-display);
  font-size: 0.95rem; font-weight: 600; letter-spacing: -0.02em;
}
.header-actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-left: auto; }
.sub { margin: 0.25rem 0 0.35rem; color: var(--muted); font-size: 0.85rem; }
.muted { color: var(--muted); font-size: 0.85rem; }
.mono { font-family: var(--mono); }

.tabs { display: flex; gap: 0.35rem; }
.tab-btn {
  background: transparent; color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 0.35rem 0.7rem; cursor: pointer; font: inherit;
}
.tab-btn.active { outline: 2px solid var(--accent); }
.tab { display: none; padding: 1.25rem 1.5rem 2.5rem; }
.tab.active { display: block; }
#tab-home.active { padding: 2rem 1.25rem 3rem; }
#tab-settings.active { padding: 0; min-height: calc(100vh - 5.5rem); }

button, .btn {
  font: inherit; cursor: pointer;
  background: var(--accent); color: var(--accent-fg);
  border: 0; border-radius: 8px; padding: 0.5rem 0.9rem; font-weight: 600;
}
button.ghost, .ghost {
  background: transparent; color: var(--text); border: 1px solid var(--border);
}
button.danger { background: var(--bad); color: #fff; }
button.secondary {
  background: transparent; color: var(--text); border: 1px solid var(--border);
}
button.linkish {
  background: none; border: none; color: var(--accent); cursor: pointer;
  padding: 0; font: inherit; text-decoration: underline; font-weight: 500;
}
.theme-toggle {
  display: inline-flex; align-items: center; gap: 0.35rem;
  background: transparent; color: var(--text); border: 1px solid var(--border);
  padding: 0.35rem 0.6rem; font-weight: 500;
}
input, textarea, select {
  font: inherit; width: 100%;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 0.45rem 0.6rem;
}
label { display: block; font-size: 0.85rem; color: var(--muted); }
label > input, label > select, label > textarea { margin-top: 0.25rem; }

.user-chrome { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; }
.badge {
  display: inline-block; font-size: 0.7rem; font-weight: 600;
  padding: 0.1rem 0.4rem; border-radius: 999px;
}
.badge.su { background: #7c3aed33; color: #c4b5fd; border: 1px solid #7c3aed66; }
.brand-badge {
  display: inline-block; font-family: var(--mono); font-size: 0.65rem; font-weight: 600;
  letter-spacing: 0.08em; padding: 0.15rem 0.45rem; border-radius: 0.35rem;
  background: var(--text); color: var(--bg); vertical-align: middle; margin-left: 0.35rem;
}

.group { margin-bottom: 2rem; }
.group-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 0.75rem; margin-bottom: 0.85rem;
}
.group-head h2 { margin: 0; font-size: 1.15rem; font-family: var(--font-display); }
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0.85rem;
}
.home-wrap {
  max-width: 68rem;
  margin: 0 auto;
}
.home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
  justify-content: center;
}
.home-empty { text-align: center; margin: 3rem 0; }
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 1rem 1.05rem 1.05rem;
  box-shadow: 0 8px 24px var(--shadow);
  display: flex; flex-direction: column; gap: 0.35rem; min-height: 8.25rem;
}
a.card-launch {
  text-decoration: none; color: inherit; cursor: pointer;
  transition: border-color 0.12s ease, transform 0.12s ease;
}
a.card-launch:hover { border-color: var(--accent); transform: translateY(-1px); }
.card-kind {
  font-size: 0.68rem; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted);
}
.card-kind.repo { color: var(--repo); }
.card-kind.thin { color: var(--thin); }
.card-name {
  margin: 0.15rem 0 0; font-size: 1.2rem; letter-spacing: -0.03em;
  font-weight: 700; font-family: var(--font-display); word-break: break-word;
}
.card-title { margin: 0; font-size: 0.88rem; }
.card .host { font-size: 0.78rem; word-break: break-all; }
.card-actions { display: flex; gap: 0.4rem; margin-top: auto; padding-top: 0.55rem; flex-wrap: wrap; }
.card-actions .open { flex: 1; }

.settings-layout {
  display: grid;
  grid-template-columns: 12.5rem minmax(0, 1fr);
  min-height: calc(100vh - 5.5rem);
}
.settings-side {
  border-right: 1px solid var(--border);
  padding: 1rem 0.65rem;
  display: flex; flex-direction: column; gap: 0.3rem;
  background: color-mix(in srgb, var(--panel) 70%, var(--bg));
}
.settings-nav {
  text-align: left; width: 100%;
  background: transparent; color: var(--text);
  border: 0; border-radius: 8px; padding: 0.55rem 0.75rem; font-weight: 500;
}
.settings-nav:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.settings-nav.active {
  background: color-mix(in srgb, var(--accent) 18%, var(--panel));
  outline: 1px solid color-mix(in srgb, var(--accent) 45%, var(--border));
}
.settings-main { padding: 1.25rem 1.5rem 2.5rem; }
.settings-pane[hidden] { display: none !important; }
.apps-list { list-style: none; margin: 0.75rem 0 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.apps-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.65rem; align-items: center;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; padding: 0.65rem 0.75rem;
}
.apps-row.dragging { opacity: 0.55; }
.apps-row.drag-over { border-color: var(--accent); }
.apps-drag { cursor: grab; color: var(--muted); letter-spacing: -0.15em; user-select: none; }
.apps-meta { display: flex; flex-direction: column; gap: 0.1rem; min-width: 0; }
.apps-actions { display: flex; flex-wrap: wrap; gap: 0.3rem; justify-content: flex-end; }
@media (max-width: 720px) {
  .settings-layout { grid-template-columns: 1fr; }
  .settings-side { flex-direction: row; border-right: 0; border-bottom: 1px solid var(--border); }
  .apps-row { grid-template-columns: auto 1fr; }
  .apps-actions { grid-column: 1 / -1; }
}

.auth-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 2rem; }
.auth-shell:has(.login-wrap) { display: block; padding: 0; }
.auth-card {
  max-width: 28rem; width: 100%; background: var(--panel);
  border: 1px solid var(--border); border-radius: 12px; padding: 1.5rem;
  box-shadow: 0 8px 24px var(--shadow);
}
.auth-card.wide { max-width: 36rem; }
.auth-card h1 { margin: 0 0 0.5rem; font-size: 1.35rem; }
.auth-card .field { margin: 0.75rem 0; }
.auth-card .field label { display: block; margin-bottom: 0.25rem; }
.auth-card .field label.inline { display: flex; align-items: center; gap: 0.4rem; margin: 0.35rem 0; color: var(--text); }

.login-wrap {
  min-height: 100vh; width: 100%; display: grid; place-items: center;
  padding: 1.5rem 1rem 2rem;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 55%),
    var(--bg);
}
.login-stage { width: min(520px, 100%); display: flex; flex-direction: column; gap: 1.1rem; }
.login-hero { text-align: center; padding: 0.35rem 0.5rem 0.15rem; }
.login-mark {
  width: 3.25rem; height: 3.25rem; margin: 0 auto 0.85rem; border-radius: 0.9rem;
  background: var(--text); color: var(--bg); display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 600; font-size: 1.55rem;
}
.login-wordmark { display: flex; align-items: center; justify-content: center; gap: 0.45rem; flex-wrap: wrap; }
.login-name { font-family: var(--font-display); font-size: 1.35rem; font-weight: 600; letter-spacing: -0.04em; }
.login-instance-name {
  margin: 0.75rem 0 0; font-family: var(--font-display);
  font-size: clamp(1.65rem, 5vw, 2.2rem); font-weight: 700; letter-spacing: -0.045em; line-height: 1.12;
}
.login-tagline { margin: 0.55rem 0 0; color: var(--muted); font-size: 0.9rem; }
.login-card { width: 100%; max-width: none; }
.login-card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.75rem; margin-bottom: 1rem; }
.login-heading { margin: 0; font-size: 1.35rem; font-family: var(--font-display); }
.login-sub { margin: 0.2rem 0 0; font-size: 0.88rem; }
.login-tabs { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.login-tabs button { flex: 1; }
.login-tabs button.active { outline: 2px solid var(--accent); }
button.login-primary {
  display: inline-flex; align-items: center; justify-content: center;
  width: 100%; margin-top: 0.25rem; padding: 0.65rem 1rem; border-radius: 10px;
  font-weight: 600; background: #fff; color: #0f172a; border: 1px solid var(--border);
}
.login-foot { text-align: center; font-size: 0.75rem; margin: 0; }
.idp-continue { margin-top: 0.5rem; }
.idp-continue-label { margin: 0 0 0.45rem; font-size: 0.8rem; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.idp-continue-btn { display: flex; flex-direction: column; align-items: center; gap: 0.45rem; min-height: 4.5rem; }
.idp-continue-logo { max-width: 72px; max-height: 72px; object-fit: contain; }
.idp-continue-name { font-size: 1rem; }

.setup-question { margin: 1.25rem 0 0.5rem; font-size: 1.05rem; }
.setup-choice-row { display: flex; flex-direction: column; gap: 0.65rem; margin-top: 1.25rem; }
.btn-choice {
  display: block; width: 100%; text-align: left;
  padding: 0.85rem 1rem; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font: inherit; cursor: pointer;
}
.btn-choice.primary { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 18%, var(--panel)); font-weight: 600; }
.btn-choice:hover { border-color: var(--accent); }
.setup-path { margin: 0 0 1rem; }
.app-rows { display: flex; flex-direction: column; gap: 0.65rem; }
.app-row {
  border: 1px solid var(--border); border-radius: 10px; padding: 0.7rem;
  background: var(--bg); display: grid; gap: 0.45rem;
}
.app-row-head { display: flex; justify-content: space-between; align-items: center; }

.modal-root { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; }
.modal-backdrop { position: absolute; inset: 0; background: var(--modal-scrim); }
.modal {
  position: relative; width: min(28rem, calc(100% - 2rem));
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 16px 40px var(--shadow); z-index: 1;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 0.85rem 1rem 0; }
.modal-head h3 { margin: 0; }
.modal-x { background: transparent; color: var(--text); border: 0; font-size: 1.4rem; padding: 0 0.25rem; }
.modal-body { padding: 0.85rem 1rem 1.1rem; display: flex; flex-direction: column; gap: 0.65rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.35rem; }

#toast {
  position: fixed; bottom: 1.1rem; left: 50%; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  padding: 0.55rem 0.9rem; border-radius: 8px; box-shadow: 0 8px 24px var(--shadow);
  z-index: 50; display: none; max-width: min(32rem, 92vw);
}
#toast.show { display: block; }
#toast.err { border-color: var(--bad); }
.err { color: var(--bad); font-size: 0.9rem; margin: 0.5rem 0; }

.access-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 1rem; margin: 0.75rem 0;
}
.access-list { list-style: none; padding: 0; margin: 0.5rem 0 0; }
.access-list li {
  display: flex; justify-content: space-between; align-items: center;
  gap: 0.5rem; padding: 0.4rem 0; border-bottom: 1px solid var(--border);
}
