:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-muted: #f8fafb;
  --text: #17212b;
  --muted: #64717d;
  --border: #dce2e7;
  --border-strong: #c7d0d8;
  --accent: #176b5b;
  --accent-hover: #105749;
  --accent-soft: #e4f2ee;
  --blue: #276db5;
  --blue-soft: #e7f0fa;
  --amber: #a45c08;
  --amber-soft: #fff2dc;
  --red: #a43a3a;
  --red-soft: #fce8e8;
  --gray-soft: #edf1f4;
  --shadow: 0 12px 30px rgba(26, 39, 52, .12);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 14px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); min-width: 320px; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { color: inherit; }
.auth-screen {
  min-height: 100vh; display: grid; grid-template-columns: minmax(260px, .8fr) minmax(420px, 1.2fr);
  background: var(--surface); align-items: stretch;
}
.auth-brand {
  background: #18232d; color: #eef4f6; padding: 42px; display: flex; align-items: flex-start; gap: 12px;
}
.auth-brand .brand-mark { flex: 0 0 auto; }
.auth-brand strong { display: block; font-size: 19px; margin-top: 2px; }
.auth-brand span:last-child { display: block; color: #9eb0bc; font-size: 12px; margin-top: 5px; }
.auth-panel { width: min(420px, calc(100vw - 32px)); margin: auto; padding: 28px 0; }
.auth-panel h1 { margin: 6px 0 8px; font-size: 25px; letter-spacing: 0; }
.auth-message { min-height: 20px; margin: 0 0 18px; color: var(--muted); }
.auth-message.error { color: var(--red); }
.auth-fields { display: grid; gap: 14px; }
.auth-submit { width: 100%; min-height: 42px; margin-top: 18px; }
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 232px minmax(0, 1fr); }
.sidebar {
  background: #18232d;
  color: #eaf0f4;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; height: 42px; padding: 0 8px; }
.brand-mark {
  width: 28px; height: 28px; display: grid; place-items: center;
  background: #52b79f; color: #10231e; font-weight: 700; border-radius: 6px;
}
.brand-name { font-size: 17px; font-weight: 600; }
.env-tag { margin-left: auto; font-size: 10px; color: #9cb1bf; border: 1px solid #3c4a55; padding: 3px 5px; border-radius: 4px; }
.main-nav { display: grid; gap: 4px; margin-top: 26px; }
.nav-item {
  border: 0; background: transparent; color: #b9c6cf; min-height: 42px;
  padding: 0 11px; display: flex; align-items: center; gap: 11px; border-radius: 6px;
  text-align: left; cursor: pointer;
}
.nav-item:hover { background: #24313c; color: #f8fbfc; }
.nav-item.is-active { background: #dff2ec; color: #114d42; font-weight: 600; }
.nav-item svg, .nav-item i { width: 18px; height: 18px; flex: 0 0 auto; font-style: normal; }
.sidebar-status { margin-top: auto; display: flex; gap: 9px; align-items: flex-start; padding: 12px 9px 4px; color: #dbe5ea; }
.sidebar-status small { display: block; color: #8ea2af; margin-top: 3px; font-size: 11px; }
.status-dot { width: 8px; height: 8px; background: #55c59c; border-radius: 50%; margin-top: 5px; box-shadow: 0 0 0 4px rgba(85,197,156,.12); }
.workspace { min-width: 0; }
.topbar {
  min-height: 82px; padding: 16px 28px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
}
.topbar h1 { margin: 2px 0 0; font-size: 21px; line-height: 1.25; font-weight: 600; }
.breadcrumb, .eyebrow { margin: 0; font-size: 11px; color: var(--muted); text-transform: uppercase; }
.topbar-actions, .dialog-actions, .inline-actions { display: flex; align-items: center; gap: 8px; }
.account-button {
  border: 0; background: transparent; min-height: 36px; padding: 2px 8px; text-align: right; cursor: pointer;
}
.account-button:hover { background: var(--surface-muted); border-radius: 6px; }
.account-name { display: block; font-weight: 600; font-size: 12px; }
.account-role { display: block; color: var(--muted); font-size: 10px; margin-top: 2px; }
#app-content { padding: 24px 28px 48px; max-width: 1480px; margin: 0 auto; }
.loading-state, .empty-state { min-height: 280px; display: grid; place-items: center; color: var(--muted); text-align: center; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin-right: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }
.btn, .icon-btn {
  border: 1px solid var(--border-strong); background: var(--surface); border-radius: 6px;
  min-height: 36px; display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 0 12px; cursor: pointer; font-weight: 500;
}
.btn:hover, .icon-btn:hover { background: var(--surface-muted); border-color: #aeb9c2; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--red); }
.btn-sm { min-height: 30px; padding: 0 9px; font-size: 12px; }
.icon-btn { width: 36px; padding: 0; position: relative; }
.icon-btn svg, .btn svg, .icon-btn i, .btn i { width: 16px; height: 16px; font-style: normal; }
[data-tooltip]::after {
  content: attr(data-tooltip); position: absolute; z-index: 20; top: calc(100% + 7px); left: 50%;
  transform: translateX(-50%); background: #17212b; color: #fff; font-size: 11px; white-space: nowrap;
  padding: 5px 7px; border-radius: 4px; opacity: 0; pointer-events: none; transition: opacity .15s;
}
[data-tooltip]:hover::after, [data-tooltip]:focus-visible::after { opacity: 1; }
.metrics-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.metric-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 7px; padding: 15px 16px;
  min-height: 112px; display: flex; flex-direction: column; justify-content: space-between;
}
.metric-head { display: flex; justify-content: space-between; color: var(--muted); }
.metric-icon { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 6px; background: var(--gray-soft); color: var(--text); }
.metric-icon.green { background: var(--accent-soft); color: var(--accent); }
.metric-icon.blue { background: var(--blue-soft); color: var(--blue); }
.metric-icon.amber { background: var(--amber-soft); color: var(--amber); }
.metric-icon svg { width: 17px; }
.metric-value { font-size: 28px; line-height: 1; font-weight: 600; font-variant-numeric: tabular-nums; }
.metric-context { color: var(--muted); font-size: 12px; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(280px, .8fr); gap: 24px; margin-top: 25px; }
.section { min-width: 0; }
.section + .section-stack, .section-stack + .section { margin-top: 26px; }
.section-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 10px; }
.section-header h2 { margin: 0; font-size: 15px; font-weight: 600; }
.section-header p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 7px; }
table { width: 100%; border-collapse: collapse; min-width: 680px; }
.dashboard-grid table { min-width: 600px; }
th, td { padding: 11px 13px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-size: 11px; font-weight: 600; background: var(--surface-muted); text-transform: uppercase; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfcfd; }
.primary-cell { font-weight: 600; }
.secondary-line { display: block; color: var(--muted); font-size: 11px; margin-top: 3px; font-weight: 400; }
.mono { font-family: "Cascadia Mono", Consolas, monospace; font-size: 12px; }
.payload-preview {
  display: block; max-width: 290px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--text); font-family: "Cascadia Mono", Consolas, monospace; font-size: 11px;
}
.payload-error { color: var(--red); }
.badge { display: inline-flex; align-items: center; min-height: 23px; padding: 0 8px; border-radius: 999px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.badge-online, .badge-active, .badge-completed, .badge-updated, .badge-ready { background: var(--accent-soft); color: var(--accent); }
.badge-offline, .badge-closed { background: var(--gray-soft); color: #596773; }
.badge-pending, .badge-waiting, .badge-queued, .badge-metadata_only { background: var(--amber-soft); color: var(--amber); }
.badge-deploying, .badge-dispatching, .badge-downloading, .badge-sent,
.badge-preparing, .badge-verifying, .badge-installing, .badge-rolling_back { background: var(--blue-soft); color: var(--blue); }
.badge-isolated, .badge-retired, .badge-revoked, .badge-disabled, .badge-deleted, .badge-failed, .badge-timed_out,
.badge-rollback_detected, .badge-rollback_failed { background: var(--red-soft); color: var(--red); }
.runtime { display: inline-flex; align-items: center; gap: 5px; }
.runtime::before { content: ""; width: 7px; height: 7px; border-radius: 2px; background: var(--blue); }
.runtime.tai::before { background: var(--amber); }
.audit-list { background: var(--surface); border: 1px solid var(--border); border-radius: 7px; }
.audit-item { padding: 11px 13px; border-bottom: 1px solid var(--border); display: grid; grid-template-columns: 9px minmax(0,1fr); gap: 9px; }
.audit-item:last-child { border-bottom: 0; }
.audit-pin { width: 7px; height: 7px; border-radius: 50%; background: var(--blue); margin-top: 5px; }
.audit-item p { margin: 0; }
.audit-item time { display: block; color: var(--muted); margin-top: 3px; font-size: 11px; }
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.filter-control { min-height: 34px; border: 1px solid var(--border-strong); background: var(--surface); border-radius: 6px; padding: 0 9px; }
.filter-toggle { min-height: 34px; display: inline-flex; align-items: center; gap: 7px; padding: 0 9px; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--surface); cursor: pointer; }
.filter-toggle input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
.progress-track { width: 120px; height: 7px; border-radius: 999px; background: var(--gray-soft); overflow: hidden; }
.progress-bar { height: 100%; background: var(--blue); }
.progress-value { margin-top: 4px; color: var(--muted); font-size: 11px; }
.split-sections { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.dialog { width: min(520px, calc(100vw - 28px)); border: 0; padding: 0; border-radius: 8px; box-shadow: var(--shadow); color: var(--text); }
.dialog-wide { width: min(720px, calc(100vw - 28px)); }
.dialog::backdrop { background: rgba(17, 28, 38, .48); }
.dialog-header { padding: 18px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; }
.dialog-header h2 { font-size: 18px; margin: 3px 0 0; }
.dialog-body { padding: 18px 20px; display: grid; gap: 15px; max-height: 68vh; overflow-y: auto; }
.dialog-actions { padding: 13px 20px; border-top: 1px solid var(--border); justify-content: flex-end; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field { display: grid; gap: 6px; }
.field-full { grid-column: 1 / -1; }
.field label, .fieldset-label { font-size: 12px; font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%; min-height: 38px; border: 1px solid var(--border-strong); border-radius: 6px; padding: 8px 10px;
  background: var(--surface); color: var(--text); outline: none;
}
.field textarea { min-height: 76px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(23,107,91,.11); }
.field-help { color: var(--muted); font-size: 11px; }
.choice-list { display: grid; gap: 7px; border: 1px solid var(--border); border-radius: 6px; padding: 9px; max-height: 190px; overflow-y: auto; }
.choice-item { display: flex; align-items: center; gap: 8px; min-height: 32px; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 0; border: 1px solid var(--border-strong); border-radius: 6px; overflow: hidden; }
.segmented label { min-height: 38px; display: grid; place-items: center; cursor: pointer; background: var(--surface); }
.segmented label + label { border-left: 1px solid var(--border-strong); }
.segmented input { position: absolute; opacity: 0; }
.segmented label:has(input:checked) { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.credential-block { background: var(--surface-muted); border: 1px solid var(--border); border-radius: 6px; padding: 12px; }
.credential-block h3 { margin: 0 0 8px; font-size: 12px; }
.credential-block code { display: block; overflow-wrap: anywhere; color: var(--text); }
.credential-warning { border-left: 3px solid var(--amber); background: var(--amber-soft); color: #71420b; padding: 10px 12px; }
.toast-region { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 8px; z-index: 100; }
.toast { min-width: 260px; max-width: 380px; padding: 11px 13px; border-radius: 6px; box-shadow: var(--shadow); background: #17212b; color: #fff; }
.toast.error { background: #8e3030; }
.relay-note { display:inline-flex; align-items:center; gap:6px; color:var(--green); font-size:11px; }
.relay-note svg { width:14px; height:14px; }

@media (max-width: 1050px) {
  .metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .split-sections { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .auth-screen { display: block; background: var(--surface); }
  .auth-brand { min-height: 86px; padding: 24px 20px; }
  .auth-panel { padding: 34px 0; }
  .app-shell { display: block; }
  .sidebar { min-height: 0; padding: 10px 12px 8px; }
  .brand { height: 36px; }
  .main-nav { margin-top: 8px; display: flex; overflow-x: auto; padding-bottom: 3px; }
  .nav-item { flex: 0 0 auto; min-height: 36px; padding: 0 9px; }
  .nav-item span { display: none; }
  .sidebar-status { display: none; }
  .topbar { min-height: 72px; padding: 13px 16px; }
  .topbar h1 { font-size: 19px; }
  .account-role { display: none; }
  #app-content { padding: 16px 14px 36px; }
  .metrics-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .metric-card { min-height: 102px; padding: 12px; }
  .form-grid { grid-template-columns: 1fr; }
  .field-full { grid-column: auto; }
}
@media (max-width: 440px) {
  .metrics-grid { grid-template-columns: 1fr; }
  .topbar-actions .btn span { display: none; }
  .topbar-actions .btn { width: 36px; padding: 0; }
  .account-button { max-width: 96px; }
  .account-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
