:root {
  color-scheme: dark;
  --bg: #080b10;
  --surface: #0e141d;
  --surface-2: #141c28;
  --line: #263347;
  --text: #eef4ff;
  --muted: #93a4bd;
  --brand: #4c82ff;
  --brand-strong: #2d72ff;
  --pass: #36d399;
  --warn: #fbbf24;
  --fail: #fb7185;
  --pending: #60a5fa;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-2: #edf2f9;
  --line: #7b8799;
  --text: #152033;
  --muted: #60708a;
  --brand: #245edb;
  --brand-strong: #174fca;
  --pass: #087f5b;
  --warn: #7a4b00;
  --fail: #be123c;
  --pending: #1d4ed8;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); }
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
button { color: inherit; }
code { font-family: "SFMono-Regular", Consolas, monospace; overflow-wrap: anywhere; }
:where(a, button, input, select, summary):focus-visible { outline: 3px solid var(--brand); outline-offset: 3px; }
.skip-link { position: fixed; z-index: 100; top: 8px; left: 8px; padding: 10px 14px; border-radius: 9px; background: var(--brand-strong); color: #fff; transform: translateY(calc(-100% - 16px)); transition: transform .15s ease; }
.skip-link:focus { transform: translateY(0); }

.boot-loading, .session-loading {
  min-height: 100vh; display: grid; place-content: center; justify-items: center; gap: 12px;
  background: radial-gradient(circle at 50% 30%, #172338 0, var(--bg) 55%);
}
.boot-loading > span, .session-loading > span { display: grid; place-items: center; width: 54px; height: 54px; border-radius: 16px; background: var(--brand); font-size: 26px; font-weight: 900; }
.boot-loading small, .session-loading p { color: var(--muted); }

.portal-app { min-height: 100vh; display: grid; grid-template-columns: 238px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 24px; padding: 24px 18px; border-right: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 94%, transparent); }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { flex: 0 0 auto; display: grid; place-items: center; width: 42px; height: 42px; border-radius: 12px; background: linear-gradient(145deg, var(--brand), #724cff); color: white; font-weight: 900; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 13px; letter-spacing: .05em; }
.brand small { margin-top: 3px; color: var(--muted); font-size: 9px; letter-spacing: .13em; }
.module-nav { display: grid; gap: 7px; }
.module-nav a { display: grid; grid-template-columns: 34px 1fr; align-items: center; gap: 10px; min-height: 44px; padding: 7px 10px; border-radius: 11px; color: var(--muted); }
.module-nav a:hover, .module-nav a.active { color: var(--text); background: var(--surface-2); }
.module-nav i { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; border: 1px solid var(--line); color: var(--brand); font-style: normal; font-weight: 800; }
.sidebar-footer { margin-top: auto; display: grid; gap: 8px; }
.sidebar-footer a { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; color: var(--muted); }
.sidebar-footer a[aria-current="page"] { color: var(--text); border-color: var(--brand); background: var(--surface-2); }

.workspace { min-width: 0; }
.topbar { position: sticky; z-index: 5; top: 0; min-height: 68px; padding: 12px clamp(18px, 3vw, 42px); display: flex; align-items: center; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(18px); }
.breadcrumb span, .eyebrow { display: block; color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; }
.breadcrumb strong { display: block; margin-top: 3px; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.control, .icon-button, .user-button, .button { min-height: 38px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--text); }
.control { padding: 0 10px; }
.icon-button, .user-button, .button { cursor: pointer; padding: 8px 12px; }
.icon-button:hover, .user-button:hover, .button:hover { border-color: var(--brand); }
.button.primary { border-color: transparent; background: var(--brand-strong); color: #fff; }
.button.danger { border-color: color-mix(in srgb, var(--fail) 55%, var(--line)); color: var(--fail); }
.button:disabled { opacity: .55; cursor: wait; }
.user-button { display: flex; align-items: center; gap: 8px; }
.user-button i { display: grid; place-items: center; width: 23px; height: 23px; border-radius: 50%; background: var(--brand); color: white; font-style: normal; font-size: 12px; font-weight: 800; }

.page { padding: 32px clamp(18px, 3vw, 42px) 64px; }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 26px; }
.page-heading h1 { margin: 8px 0 6px; font-size: clamp(29px, 4vw, 48px); line-height: 1; letter-spacing: -.04em; }
.page-heading p { margin: 0; color: var(--muted); max-width: 760px; }
.page-actions { display: flex; gap: 8px; align-items: center; }
.notice { margin-bottom: 18px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--muted); }
.notice.fail { border-color: color-mix(in srgb, var(--fail) 55%, var(--line)); color: var(--fail); }
.notice.warn { border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); color: var(--warn); }
.notice.pass { border-color: color-mix(in srgb, var(--pass) 45%, var(--line)); color: var(--pass); }
.empty-state { margin: 0; padding: 18px; border: 1px dashed var(--line); border-radius: 12px; color: var(--muted); background: var(--surface-2); }
.contract-notice > strong, .contract-notice > span { display: block; }
.contract-notice > span { margin-top: 4px; font-size: 12px; }
.contract-notice details { margin-top: 10px; }
.contract-notice ul { margin: 10px 0 0; padding-left: 22px; color: var(--muted); }
.contract-notice li + li { margin-top: 7px; }
.contract-notice li span { margin-left: 8px; }
.repair-action { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.repair-action > div { min-width: 240px; margin-right: auto; }
.repair-action strong, .repair-action span { display: block; }
.repair-action span { margin-top: 4px; font-size: 12px; }

.state { display: inline-flex; align-items: center; gap: 7px; width: fit-content; color: var(--muted); font-size: 12px; font-weight: 750; text-transform: uppercase; }
.state::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 4px color-mix(in srgb, currentColor 14%, transparent); }
.state.pass { color: var(--pass); }
.state.warn { color: var(--warn); }
.state.fail { color: var(--fail); }
.state.pending { color: var(--pending); }

.overview-hero { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(260px, .7fr); gap: 16px; margin-bottom: 18px; }
.overview-hero > article, .overview-hero > aside, .panel, .module-card, .fact, .wall-card { border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.overview-hero > article { min-height: 220px; padding: 28px; display: flex; flex-direction: column; justify-content: space-between; background: linear-gradient(145deg, color-mix(in srgb, var(--brand) 16%, var(--surface)), var(--surface)); }
.overview-hero h2 { margin: 12px 0; font-size: clamp(28px, 4vw, 52px); }
.overview-hero p { max-width: 700px; color: var(--muted); }
.overview-hero dl { margin: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.overview-hero dl div { padding-top: 12px; border-top: 1px solid var(--line); }
.overview-hero dt { color: var(--muted); font-size: 11px; }
.overview-hero dd { margin: 5px 0 0; font-weight: 750; overflow-wrap: anywhere; }
.attention { padding: 24px; display: flex; flex-direction: column; gap: 12px; justify-content: center; }
.attention strong { font-size: 25px; }
.attention p { color: var(--muted); }

.module-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.module-card { min-height: 235px; padding: 22px; display: flex; flex-direction: column; transition: transform .18s ease, border-color .18s ease; }
.module-card:hover { transform: translateY(-2px); border-color: var(--brand); }
.module-card header { display: flex; gap: 12px; align-items: center; }
.module-card header > i { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 12px; background: var(--surface-2); color: var(--brand); font-style: normal; font-size: 20px; font-weight: 900; }
.module-card h2 { margin: 0 0 5px; }
.module-card > p { color: var(--muted); }
.module-card .sparkline { margin-top: auto; }
.module-card footer { margin-top: 14px; display: flex; align-items: end; justify-content: space-between; gap: 12px; }
.module-card footer strong { font-size: 24px; }

.sparkline { min-height: 48px; padding: 10px 12px; display: flex; align-items: end; gap: 2px; border-radius: 10px; background: var(--surface-2); color: var(--brand); font-family: monospace; font-size: 19px; letter-spacing: -2px; overflow: hidden; }
.sparkline.empty { color: var(--muted); font: inherit; font-size: 12px; letter-spacing: normal; align-items: center; }

.facts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.fact { min-height: 126px; padding: 18px; }
.fact span, .fact small { display: block; color: var(--muted); }
.fact strong { display: block; margin: 14px 0 6px; font-size: clamp(22px, 3vw, 34px); overflow-wrap: anywhere; }
.panel { padding: 22px; margin-bottom: 16px; }
.panel > header { display: flex; align-items: start; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.panel h2, .panel h3 { margin: 5px 0; }
.panel p { color: var(--muted); }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.detail-grid article { padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); }
.detail-grid span, .detail-grid small { display: block; color: var(--muted); }
.detail-grid strong { display: block; margin: 8px 0; font-size: 19px; overflow-wrap: anywhere; }
.json-details summary { cursor: pointer; color: var(--muted); }
.json-details pre { max-height: 420px; overflow: auto; white-space: pre-wrap; word-break: break-word; color: var(--muted); }

.quick-connect { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.connect-item { padding: 15px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); }
.connect-item span, .connect-item code { display: block; }
.connect-item span { color: var(--muted); font-size: 12px; }
.connect-item code { margin: 9px 0; }

.login-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(360px, .8fr); background: radial-gradient(circle at 20% 30%, color-mix(in srgb, var(--brand) 18%, var(--bg)) 0, var(--bg) 48%); }
.login-context { padding: clamp(30px, 6vw, 92px); display: flex; flex-direction: column; justify-content: space-between; }
.login-context h1 { max-width: 730px; margin: 18px 0; font-size: clamp(42px, 7vw, 88px); line-height: .94; letter-spacing: -.055em; }
.login-context > div > p { max-width: 720px; color: var(--muted); font-size: 17px; line-height: 1.7; }
.login-context dl { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.login-context dl div { padding-top: 14px; border-top: 1px solid var(--line); }
.login-context dt { font-weight: 800; }
.login-context dd { margin: 7px 0 0; color: var(--muted); }
.login-panel { padding: clamp(24px, 5vw, 72px); display: grid; place-items: center; border-left: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 92%, transparent); }
.login-panel form { width: min(100%, 440px); display: grid; gap: 16px; }
.login-panel h2 { margin: 5px 0; font-size: 34px; }
.login-panel label { display: grid; gap: 7px; }
.login-panel input, .admin-form input, .admin-form select { width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text); }
.remember { display: flex !important; grid-template-columns: auto 1fr; align-items: center; }
.remember input { width: 18px; min-height: 18px; }
.login-preferences { position: absolute; top: 20px; right: 20px; display: flex; gap: 8px; }

.admin-grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(310px, .7fr); gap: 16px; }
.user-list { display: grid; gap: 10px; }
.user-row { display: grid; grid-template-columns: minmax(170px, 1fr) auto; gap: 14px; padding: 15px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); }
.user-row header strong, .user-row header code { display: block; }
.user-row header code { margin-top: 4px; color: var(--muted); }
.user-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.reset-row { grid-column: 1 / -1; display: grid; grid-template-columns: minmax(220px, 1fr) auto; gap: 8px; padding-top: 12px; border-top: 1px solid var(--line); }
.reset-row input { min-height: 40px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text); }
.admin-form { display: grid; gap: 12px; }
.audit-list { display: grid; gap: 8px; }
.audit-row { display: grid; grid-template-columns: 150px 140px 1fr; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.audit-row time, .audit-row code { color: var(--muted); }
.mihomo-frame { width: 100%; min-height: 620px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.repair-grid { display: grid; grid-template-columns: minmax(300px, .9fr) minmax(320px, 1.1fr); gap: 16px; }
.repair-safety { padding: 18px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); }
.repair-safety h3 { margin-top: 0; }
.repair-safety li { margin-bottom: 10px; color: var(--muted); }

.wall { min-height: 100vh; display: grid; grid-template-rows: auto 1fr auto; background: radial-gradient(circle at 70% 15%, color-mix(in srgb, var(--brand) 18%, transparent), transparent 40%), var(--bg); }
.wall > header, .wall > footer { padding: 14px 22px; display: flex; align-items: center; justify-content: space-between; gap: 20px; border-color: var(--line); background: color-mix(in srgb, var(--surface) 88%, transparent); }
.wall > header { border-bottom: 1px solid var(--line); }
.wall > footer { border-top: 1px solid var(--line); }
.wall-nav, .wall-actions { display: flex; flex-wrap: wrap; gap: 7px; }
.wall-nav button, .wall-actions button, .wall-actions a { min-height: 34px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); cursor: pointer; }
.wall-nav button.active { border-color: var(--brand); background: var(--brand); color: white; }
.wall-stage { padding: clamp(20px, 3vw, 46px); display: grid; align-content: center; }
.wall-title { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin-bottom: 24px; }
.wall-title > div:last-child { display: flex; align-items: center; gap: 14px; }
.wall-title h1 { margin: 8px 0 0; font-size: clamp(42px, 6vw, 80px); line-height: .94; }
.wall-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.wall-card { min-height: 270px; padding: 20px; display: flex; flex-direction: column; }
.wall-card h2 { font-size: 25px; }
.wall-card strong { margin-top: auto; font-size: clamp(28px, 4vw, 52px); }
.wall-card p { color: var(--muted); }
.wall-time { font-variant-numeric: tabular-nums; font-size: 24px; }

@media (max-width: 1040px) {
  .portal-app { grid-template-columns: 88px minmax(0, 1fr); }
  .sidebar { padding-inline: 12px; }
  .brand > div, .module-nav a span, .sidebar-footer a span { display: none; }
  .module-nav a { grid-template-columns: 1fr; justify-items: center; }
  .brand { justify-content: center; }
  .facts, .wall-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .admin-grid, .repair-grid { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .portal-app { display: block; }
  .sidebar { position: static; width: auto; height: auto; padding: 12px; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar .brand, .sidebar-footer { display: none; }
  .module-nav { display: flex; overflow-x: auto; }
  .module-nav a { flex: 0 0 auto; grid-template-columns: 30px auto; }
  .module-nav a span { display: block; }
  .topbar { position: static; padding: 10px 14px; }
  .breadcrumb { display: none; }
  .top-actions { width: 100%; justify-content: flex-end; }
  .user-button b { display: none; }
  .page { padding: 24px 14px 48px; }
  .page-heading { align-items: start; flex-direction: column; }
  .overview-hero, .module-grid, .quick-connect, .detail-grid { grid-template-columns: 1fr; }
  .facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .login-shell { display: block; }
  .login-context { min-height: 48vh; padding: 28px 20px; }
  .login-context dl { display: none; }
  .login-panel { min-height: 52vh; padding: 70px 20px 28px; border-left: 0; border-top: 1px solid var(--line); }
  .wall > header, .wall > footer { align-items: flex-start; flex-direction: column; }
  .wall-title { align-items: flex-start; flex-direction: column; }
  .wall-grid { grid-template-columns: 1fr; }
  .wall-card { min-height: 180px; }
  .user-row { grid-template-columns: 1fr; }
  .audit-row { grid-template-columns: 1fr; }
  .reset-row { grid-template-columns: 1fr; }
  .control, .icon-button, .user-button, .button, .wall-nav button, .wall-actions button, .wall-actions a, .remember { min-height: 44px; }
}

@media (max-width: 480px) {
  .product-harness .facts { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
