:root {
  --bg: #100f0e;
  --bg-soft: #171513;
  --panel: #1c1a18;
  --panel-2: #24211e;
  --line: #342f2a;
  --line-strong: #4a423b;
  --text: #f4efe9;
  --muted: #a79e94;
  --faint: #756d65;
  --accent: #ff5a45;
  --accent-soft: rgba(255, 90, 69, 0.14);
  --green: #52d18e;
  --green-soft: rgba(82, 209, 142, 0.12);
  --yellow: #f3c467;
  --red: #ff7468;
  --blue: #76a9ff;
  --radius: 16px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1200px 480px at 80% -10%, rgba(255, 90, 69, 0.1), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
code, .mono { font-family: var(--mono); }
code { background: rgba(255,255,255,.06); border: 1px solid var(--line); border-radius: 6px; padding: 1px 5px; font-size: .92em; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(30px, 4vw, 52px); line-height: 1.04; letter-spacing: -0.045em; }
h2 { margin-bottom: 6px; font-size: 22px; letter-spacing: -0.025em; }
h3 { font-size: 16px; margin-bottom: 8px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.eyebrow { margin: 0 0 8px; color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: .19em; }
.mono { font-family: var(--mono); }

.login-shell {
  display: grid;
  grid-template-columns: minmax(360px, 520px) minmax(360px, 620px);
  gap: clamp(40px, 8vw, 120px);
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 48px;
}
.login-card {
  display: grid;
  gap: 28px;
  padding: 38px;
  background: linear-gradient(160deg, rgba(35,31,28,.96), rgba(20,18,17,.98));
  border: 1px solid var(--line);
  border-radius: 26px;
  box-shadow: 0 40px 100px rgba(0,0,0,.45);
}
.login-card h1 { font-size: 42px; }
.brand-mark {
  display: grid;
  width: 58px;
  height: 58px;
  place-items: center;
  border-radius: 17px;
  background: var(--accent);
  color: #fff;
  font-size: 32px;
  font-weight: 900;
  line-height: 1;
  box-shadow: 0 12px 30px rgba(255,90,69,.22);
}
.brand-mark.small { width: 38px; height: 38px; border-radius: 11px; font-size: 20px; }
.login-aside { max-width: 620px; }
.login-aside h2 { font-size: clamp(36px, 5vw, 64px); line-height: 1.03; letter-spacing: -.055em; margin: 24px 0; }
.login-aside > p:not(.eyebrow) { max-width: 500px; color: var(--muted); font-size: 16px; }
.login-foot { color: var(--faint); font-size: 12px; margin: 0; }
.feature-row { display: grid; grid-template-columns: 34px 160px 1fr; gap: 16px; align-items: baseline; padding: 18px 0; border-top: 1px solid var(--line); }
.feature-row span { color: var(--accent); font-family: var(--mono); font-size: 12px; }
.feature-row small { color: var(--muted); }

.app-shell { min-height: 100vh; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 28px;
  min-height: 72px;
  padding: 0 clamp(20px, 4vw, 56px);
  background: rgba(16,15,14,.88);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 230px; }
.brand > span:last-child { display: grid; line-height: 1.2; }
.brand small { color: var(--muted); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; }
.topnav { display: flex; gap: 6px; }
.nav-item {
  padding: 9px 14px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 10px;
  font-weight: 600;
}
.nav-item:hover { color: var(--text); background: rgba(255,255,255,.04); }
.nav-item.active { color: var(--text); background: var(--panel-2); }
.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.admin-chip { color: var(--muted); font-family: var(--mono); font-size: 12px; margin-right: 6px; }
main { max-width: 1520px; margin: 0 auto; padding: clamp(34px, 6vw, 78px) clamp(20px, 4vw, 56px) 100px; }
.page { display: none; }
.page.active { display: block; animation: page-in .22s ease; }
@keyframes page-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.page-head { display: flex; gap: 24px; justify-content: space-between; align-items: flex-end; margin-bottom: 34px; }
.page-head > div:first-child { max-width: 800px; }
.page-head h1 { font-size: clamp(36px, 5vw, 58px); }
.section-heading { display: flex; justify-content: space-between; align-items: flex-end; margin: 44px 0 18px; }
.section-heading h2 { margin: 0; }
.section-heading p { margin: 2px 0 0; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.stat-card { padding: 21px 22px; background: var(--bg-soft); border: 1px solid var(--line); border-radius: var(--radius); }
.stat-card .value { display: block; margin-top: 16px; font-size: 32px; font-weight: 760; letter-spacing: -.04em; }
.stat-card .label { color: var(--muted); font-size: 12px; }
.stat-card .sub { color: var(--faint); font-size: 11px; margin-top: 4px; }

.tenant-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.tenant-card {
  position: relative;
  display: grid;
  gap: 18px;
  min-height: 230px;
  padding: 22px;
  text-align: left;
  color: var(--text);
  background: linear-gradient(155deg, var(--panel), var(--bg-soft));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: transform .16s ease, border-color .16s ease, box-shadow .16s ease;
}
.tenant-card:hover { transform: translateY(-2px); border-color: var(--line-strong); box-shadow: 0 20px 42px rgba(0,0,0,.24); }
.tenant-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.tenant-card h3 { margin: 4px 0 0; font-size: 20px; letter-spacing: -.025em; }
.tenant-card .slug { color: var(--faint); font-family: var(--mono); font-size: 11px; }
.tenant-card .url { overflow: hidden; color: var(--muted); font-family: var(--mono); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.tenant-meta { display: flex; flex-wrap: wrap; gap: 7px; align-self: end; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px; color: var(--muted); background: rgba(255,255,255,.04); border: 1px solid var(--line); border-radius: 999px; font-size: 10px; font-weight: 650; }
.pill.accent { color: #ffb0a4; background: var(--accent-soft); border-color: rgba(255,90,69,.25); }
.pill.green { color: #91e6b8; background: var(--green-soft); border-color: rgba(82,209,142,.2); }
.pill.yellow { color: var(--yellow); background: rgba(243,196,103,.08); border-color: rgba(243,196,103,.2); }
.status-dot { display: inline-block; width: 9px; height: 9px; flex: 0 0 auto; border-radius: 50%; background: var(--faint); box-shadow: 0 0 0 4px rgba(255,255,255,.03); }
.status-dot.running { background: var(--green); box-shadow: 0 0 0 4px var(--green-soft); }
.status-dot.provisioning, .status-dot.starting, .status-dot.queued { background: var(--yellow); box-shadow: 0 0 0 4px rgba(243,196,103,.1); animation: pulse 1.4s infinite ease-in-out; }
.status-dot.error, .status-dot.unhealthy { background: var(--red); box-shadow: 0 0 0 4px rgba(255,116,104,.1); }
.status-dot.stopped, .status-dot.deleted { background: var(--faint); }
@keyframes pulse { 50% { opacity: .42; transform: scale(.82); } }

.notice { margin: 20px 0; padding: 15px 17px; color: var(--muted); background: rgba(255,255,255,.03); border: 1px solid var(--line); border-radius: 12px; }
.notice.warning { color: #f2d7a2; background: rgba(243,196,103,.07); border-color: rgba(243,196,103,.24); }
.notice.success { color: #b6ebd0; background: var(--green-soft); border-color: rgba(82,209,142,.22); }
.notice.error { color: #ffc0ba; background: rgba(255,116,104,.08); border-color: rgba(255,116,104,.24); }

.list-stack { display: grid; gap: 12px; }
.list-row { display: flex; align-items: center; gap: 16px; padding: 16px 18px; background: var(--bg-soft); border: 1px solid var(--line); border-radius: 12px; }
.list-row > div:first-child { min-width: 0; flex: 1; }
.list-row h3 { margin: 0 0 2px; }
.list-row p { margin: 0; color: var(--muted); font-size: 12px; }
.row-actions { display: flex; gap: 7px; flex-wrap: wrap; justify-content: flex-end; }
.empty-state { padding: 42px 20px; text-align: center; color: var(--muted); border: 1px dashed var(--line-strong); border-radius: var(--radius); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 38px; padding: 8px 14px; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; font-weight: 650; transition: .14s ease; }
.btn:hover { border-color: var(--line-strong); background: #2d2925; }
.btn:disabled { cursor: not-allowed; opacity: .45; }
.btn.primary { color: #fff; background: var(--accent); border-color: var(--accent); box-shadow: 0 8px 24px rgba(255,90,69,.15); }
.btn.primary:hover { background: #ff6d5a; border-color: #ff6d5a; }
.btn.ghost { background: transparent; }
.btn.danger { color: #ffb5ae; background: rgba(255,116,104,.08); border-color: rgba(255,116,104,.23); }
.btn.small { min-height: 31px; padding: 5px 10px; font-size: 12px; }
.btn.wide { width: 100%; min-height: 44px; }
.icon-button { display: grid; width: 34px; height: 34px; place-items: center; color: var(--muted); background: transparent; border: 1px solid var(--line); border-radius: 9px; font-size: 21px; line-height: 1; }
.icon-button:hover { color: var(--text); border-color: var(--line-strong); }

.stack { display: grid; gap: 15px; }
label { display: grid; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 650; }
input, textarea, select {
  width: 100%;
  padding: 10px 12px;
  color: var(--text);
  background: #12110f;
  border: 1px solid var(--line);
  border-radius: 9px;
  outline: none;
}
textarea { resize: vertical; font-family: var(--mono); font-size: 12px; line-height: 1.55; }
input:focus, textarea:focus, select:focus { border-color: rgba(255,90,69,.68); box-shadow: 0 0 0 3px var(--accent-soft); }
input::placeholder, textarea::placeholder { color: #5e5751; }
input[type="checkbox"] { width: auto; accent-color: var(--accent); }
.check-line { display: flex; align-items: center; gap: 8px; color: var(--text); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-error { min-height: 18px; margin: 0; color: var(--red); font-size: 12px; }
.inline-hint { color: var(--faint); font-size: 11px; }

.dialog { width: min(620px, calc(100vw - 28px)); max-height: calc(100vh - 32px); padding: 0; color: var(--text); background: transparent; border: 0; overflow: visible; }
.dialog::backdrop { background: rgba(5,4,4,.72); backdrop-filter: blur(8px); }
.dialog-card { width: 100%; max-height: calc(100vh - 32px); padding: 26px; overflow: auto; background: var(--panel); border: 1px solid var(--line-strong); border-radius: 18px; box-shadow: 0 38px 100px rgba(0,0,0,.52); }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.dialog-head h2 { margin: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.wide-dialog { width: min(920px, calc(100vw - 28px)); }
.safe-clone-note { display: grid; grid-template-columns: 80px 1fr; gap: 8px 12px; padding: 14px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; font-size: 12px; }
.safe-clone-note b { color: var(--accent); }
.safe-clone-note span { color: var(--muted); }

.detail-dialog { width: min(1280px, calc(100vw - 22px)); height: min(900px, calc(100vh - 24px)); max-height: none; }
.detail-card { display: flex; flex-direction: column; height: 100%; background: var(--panel); border: 1px solid var(--line-strong); border-radius: 18px; overflow: hidden; box-shadow: 0 40px 120px rgba(0,0,0,.58); }
.detail-head { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 19px 22px; border-bottom: 1px solid var(--line); }
.detail-title { display: flex; align-items: center; gap: 13px; }
.detail-title h2 { margin: 0; }
.detail-title p { margin: 0; font-size: 11px; }
.detail-layout { display: grid; grid-template-columns: 186px 1fr; min-height: 0; flex: 1; }
.detail-tabs { display: flex; flex-direction: column; gap: 4px; padding: 16px 12px; background: var(--bg-soft); border-right: 1px solid var(--line); }
.detail-tab { padding: 9px 11px; text-align: left; color: var(--muted); background: transparent; border: 0; border-radius: 8px; font-weight: 620; }
.detail-tab:hover { color: var(--text); background: rgba(255,255,255,.035); }
.detail-tab.active { color: var(--text); background: var(--panel-2); }
.detail-tab.danger-link { color: #e7958d; margin-top: auto; }
.detail-body { min-width: 0; padding: 26px; overflow: auto; }
.detail-body h3 { margin-top: 0; }
.panel { padding: 18px; background: var(--bg-soft); border: 1px solid var(--line); border-radius: 13px; }
.panel + .panel { margin-top: 14px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.panel-head h3, .panel-head p { margin: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.overview-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(280px, .8fr); gap: 14px; }
.kv { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 10px 18px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.code-line { display: flex; gap: 8px; align-items: center; min-width: 0; }
.code-line code { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.action-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.op-row { display: flex; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); font-size: 12px; }
.op-row:first-child { border-top: 0; }
.op-status { width: 7px; height: 7px; border-radius: 50%; margin-top: 6px; background: var(--faint); }
.op-status.running { background: var(--yellow); }
.op-status.succeeded { background: var(--green); }
.op-status.failed { background: var(--red); }
.op-message { color: var(--muted); white-space: pre-wrap; word-break: break-word; }

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); }
th { color: var(--muted); background: var(--bg-soft); font-size: 11px; letter-spacing: .04em; }
tr:last-child td { border-bottom: 0; }
td { color: var(--muted); font-size: 12px; }

.qr-panel { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(230px, .8fr); gap: 16px; }
.qr-screen { min-height: 380px; padding: 16px; overflow: auto; color: #f8f8f8; background: #000; border: 1px solid var(--line); border-radius: 12px; }
.qr-screen pre { margin: 0; font-family: var(--mono); font-size: 7px; line-height: .72; white-space: pre; }
.qr-empty { display: grid; height: 100%; min-height: 340px; place-items: center; color: #8d8d8d; text-align: center; }
.log-output { min-height: 420px; max-height: 560px; margin: 0; padding: 16px; overflow: auto; color: #c8d0d4; background: #080909; border: 1px solid var(--line); border-radius: 11px; font-family: var(--mono); font-size: 11px; line-height: 1.55; white-space: pre-wrap; word-break: break-word; }
.skill-editor { font-size: 12px; }
.provider-card { border-color: rgba(255,255,255,.09); }
.provider-card.enabled { border-color: rgba(82,209,142,.24); }
.provider-title-line { display: flex; align-items: center; gap: 8px; }
.provider-title-line h3 { margin: 0; }
.provider-config { margin-top: 14px; display: grid; gap: 12px; }
.clone-box { border-color: rgba(255,90,69,.24); }
.danger-zone { border-color: rgba(255,116,104,.22); background: rgba(255,116,104,.035); }

.toast-root { position: fixed; right: 22px; bottom: 22px; z-index: 100; display: grid; gap: 9px; width: min(380px, calc(100vw - 32px)); pointer-events: none; }
.toast { padding: 13px 15px; color: var(--text); background: #2a2521; border: 1px solid var(--line-strong); border-radius: 11px; box-shadow: 0 16px 36px rgba(0,0,0,.35); font-size: 12px; animation: toast-in .18s ease; }
.toast.success { border-color: rgba(82,209,142,.35); }
.toast.error { border-color: rgba(255,116,104,.4); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 1120px) {
  .tenant-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .login-shell { grid-template-columns: minmax(360px, 560px); }
  .login-aside { display: none; }
}
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; gap: 12px; padding: 13px 16px; }
  .brand { min-width: 0; }
  .topnav { order: 3; width: 100%; overflow-x: auto; }
  .topbar-actions { gap: 5px; }
  .admin-chip { display: none; }
  main { padding: 28px 16px 70px; }
  .page-head { align-items: flex-start; flex-direction: column; }
  .stats-grid, .tenant-grid, .grid-2, .grid-3, .overview-grid, .qr-panel { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .detail-layout { grid-template-columns: 1fr; }
  .detail-tabs { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 9px; }
  .detail-tab { white-space: nowrap; }
  .detail-tab.danger-link { margin-top: 0; }
  .detail-body { padding: 18px; }
  .detail-dialog { width: calc(100vw - 10px); height: calc(100vh - 10px); }
  .kv { grid-template-columns: 95px minmax(0, 1fr); }
  .login-shell { padding: 18px; }
  .login-card { padding: 25px; }
}
