:root {
  color-scheme: light;
  --bg: #f4f6fa;
  --surface: rgba(255, 255, 255, .92);
  --surface-strong: #ffffff;
  --text: #171a22;
  --muted: #6f7583;
  --line: #e5e8ef;
  --accent: #5b68ff;
  --accent-soft: #eef0ff;
  --green: #20a66a;
  --amber: #c77b0a;
  --red: #d04444;
  --shadow: 0 18px 45px rgba(35, 43, 67, .07);
  --radius: 22px;
  --sidebar: 238px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { background: var(--bg); overflow-x: hidden; }
body { margin: 0; min-width: 320px; min-height: 100vh; color: var(--text); background: var(--bg); overflow-x: hidden; }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
a { color: inherit; }
img { max-width: 100%; }

:focus-visible { outline: 3px solid rgba(91, 104, 255, .42); outline-offset: 3px; }
.skip-link { position: fixed; z-index: 100; left: 1rem; top: -5rem; padding: .75rem 1rem; border-radius: 12px; color: #fff; background: #171a22; }
.skip-link:focus { top: 1rem; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.hidden { display: none !important; }

.app-shell { min-height: 100vh; }
.sidebar { display: none; }
.main-content { width: 100%; padding: 1.25rem 1rem calc(6.25rem + env(safe-area-inset-bottom)); }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin: .4rem 0 1.4rem; }
.page-header h1 { margin: .18rem 0 .35rem; font-size: clamp(1.9rem, 7vw, 3.2rem); line-height: 1.02; letter-spacing: -.055em; }
.page-header p:not(.eyebrow) { margin: 0; color: var(--muted); font-size: .93rem; }
.eyebrow { margin: 0; color: #8a91a1; font-size: .66rem; line-height: 1.4; font-weight: 750; letter-spacing: .16em; }
.live-indicator { display: none; align-items: center; gap: .5rem; color: var(--muted); font-size: .8rem; white-space: nowrap; }
.live-indicator span, .privacy-dot, .status-dot { width: .55rem; height: .55rem; border-radius: 999px; background: var(--amber); box-shadow: 0 0 0 4px rgba(199,123,10,.1); }
.live-indicator.ready span, .status-dot.ready { background: var(--green); box-shadow: 0 0 0 4px rgba(32,166,106,.1); }
.live-indicator.error span, .status-dot.error { background: var(--red); box-shadow: 0 0 0 4px rgba(208,68,68,.1); }

.mobile-nav { position: fixed; z-index: 20; inset: auto 0 0; display: grid; grid-template-columns: repeat(5, 1fr); padding: .5rem .35rem calc(.45rem + env(safe-area-inset-bottom)); border-top: 1px solid rgba(220,224,233,.9); background: rgba(250,251,253,.92); backdrop-filter: blur(18px); }
.mobile-nav a { display: grid; justify-items: center; gap: .2rem; min-width: 0; padding: .35rem .15rem; border-radius: 12px; color: var(--muted); text-decoration: none; font-size: .61rem; }
.mobile-nav a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }
.nav-glyph { position: relative; width: 1.25rem; height: 1.25rem; border: 1.7px solid currentColor; border-radius: 7px; }
.glyph-overview::after { content: ""; position: absolute; inset: 3px; border: 1.5px solid currentColor; border-radius: 50%; }
.glyph-theme::after { content: ""; position: absolute; width: 5px; height: 5px; right: 2px; top: 2px; border-radius: 50%; background: currentColor; }
.glyph-device { border-radius: 5px; }
.glyph-device::after { content: ""; position: absolute; inset: 3px; border-radius: 50%; border: 1px solid currentColor; }
.glyph-updates::after { content: "↑"; position: absolute; inset: -3px 0 0; text-align: center; font-weight: 700; }
.glyph-system::after { content: ""; position: absolute; inset: 4px; border-radius: 50%; background: currentColor; }

.hero-grid, .content-grid { display: grid; grid-template-columns: 1fr; gap: .85rem; }
.hero-grid { margin-bottom: .85rem; }
.metric-card, .panel { min-width: 0; border: 1px solid rgba(226,229,237,.9); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.metric-card { position: relative; padding: 1.25rem; overflow: hidden; }
.metric-primary { color: #fff; border-color: transparent; background: linear-gradient(145deg, #5663f3, #737dff); }
.metric-primary::after { content: ""; position: absolute; width: 11rem; height: 11rem; right: -4rem; bottom: -5rem; border: 1px solid rgba(255,255,255,.18); border-radius: 50%; box-shadow: 0 0 0 2rem rgba(255,255,255,.045), 0 0 0 4rem rgba(255,255,255,.025); }
.card-heading, .panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.card-heading { color: inherit; font-size: .82rem; font-weight: 650; }
.metric-value { position: relative; z-index: 1; display: inline-block; margin-top: 1.1rem; font-size: 2.55rem; letter-spacing: -.06em; }
.metric-value.compact { font-size: 2rem; }
.metric-unit { position: relative; z-index: 1; margin-left: .3rem; color: currentColor; opacity: .7; font-size: .76rem; }
.metric-card > p { position: relative; z-index: 1; margin: .75rem 0 0; color: var(--muted); font-size: .76rem; }
.metric-primary > p { color: rgba(255,255,255,.76); }
.status-pill { display: inline-flex; align-items: center; min-height: 1.65rem; padding: .25rem .62rem; border-radius: 999px; color: var(--muted); background: #f0f2f6; font-size: .7rem; white-space: nowrap; }
.metric-primary .status-pill { color: rgba(255,255,255,.88); background: rgba(255,255,255,.14); }
.progress-track { position: relative; z-index: 1; height: 5px; margin-top: 1rem; overflow: hidden; border-radius: 999px; background: rgba(255,255,255,.18); }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: #fff; transition: width .35s ease; }

.panel { padding: 1.2rem; }
.panel-heading { margin-bottom: 1.1rem; }
.panel-heading h2 { margin: .18rem 0 0; font-size: 1.02rem; letter-spacing: -.02em; }
.panel-heading a { color: var(--accent); font-size: .78rem; text-decoration: none; }
.detail-list { margin: 0; }
.detail-list div { display: flex; justify-content: space-between; gap: 1rem; padding: .76rem 0; border-bottom: 1px solid var(--line); }
.detail-list div:last-child { border-bottom: 0; }
.detail-list dt { color: var(--muted); font-size: .78rem; }
.detail-list dd { margin: 0; font-size: .8rem; font-weight: 650; text-align: right; word-break: break-word; }
.event-list { display: grid; gap: .2rem; margin: 0; padding: 0; list-style: none; }
.event-list li { display: grid; grid-template-columns: .55rem 1fr auto; align-items: center; gap: .75rem; padding: .75rem 0; border-bottom: 1px solid var(--line); font-size: .8rem; }
.event-list li::before { content: ""; width: .5rem; height: .5rem; border-radius: 50%; background: var(--accent); }
.event-list li.empty-state::before { display: none; }
.event-list li.empty-state { display: block; }
.event-list time { color: var(--muted); font-size: .7rem; }
.empty-state { color: var(--muted); text-align: center; padding: 1.3rem !important; }
.empty-state strong { display: block; color: var(--text); margin-bottom: .4rem; }
.empty-state p { margin: 0; }

.chain { display: grid; grid-template-columns: 1fr; gap: .55rem; }
.chain div { display: grid; grid-template-columns: 2.1rem 1fr; grid-template-rows: auto auto; column-gap: .7rem; align-items: center; padding: .7rem; border-radius: 16px; background: #f7f8fb; }
.chain-icon { grid-row: 1 / 3; display: grid; place-items: center; width: 2.1rem; height: 2.1rem; border-radius: 11px; color: var(--accent); background: var(--accent-soft); font-size: .72rem; font-weight: 800; }
.chain strong { font-size: .8rem; }
.chain small { color: var(--muted); }
.chain i { display: none; }

.editor-layout { display: grid; gap: 1rem; }
.watch-preview-panel { display: grid; place-items: center; padding: 1.4rem; min-height: 28rem; border-radius: var(--radius); background: radial-gradient(circle at 50% 30%, #eef1f8, #dfe4ed); overflow: hidden; }
.watch-preview { position: relative; width: min(76vw, 310px); aspect-ratio: 1; padding: 7%; border: 10px solid #13151b; border-radius: 50%; background: #191c24; box-shadow: 0 28px 50px rgba(24,29,42,.24), inset 0 0 0 2px #424752; overflow: hidden; }
.watch-preview > img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; }
.watch-preview > img.loaded { opacity: 1; }
.watch-overlay { position: absolute; z-index: 1; left: 13%; right: 13%; display: grid; justify-items: center; color: #fff; text-shadow: 0 2px 10px rgba(0,0,0,.5); }
.watch-overlay.position-top { top: 17%; }
.watch-overlay.position-middle { top: 50%; transform: translateY(-50%); }
.watch-overlay.position-bottom { bottom: 16%; }
.watch-overlay strong { font-size: 3rem; line-height: .95; letter-spacing: -.08em; }
.watch-overlay span { margin-top: .35rem; font-size: .7rem; }
.preview-caption { margin: 1rem 0 0; color: #727989; font-size: .73rem; }
.editor-panel { align-self: start; }
.status-panel { margin-top: 1rem; }

.stack-form { display: grid; gap: .85rem; }
.stack-form label, fieldset legend { color: #4e5565; font-size: .76rem; font-weight: 650; }
.stack-form input:not([type="checkbox"]):not([type="radio"]):not([type="color"]):not([type="file"]), .stack-form select, .stack-form textarea, .danger-action input { width: 100%; border: 1px solid #dfe3eb; border-radius: 13px; padding: .75rem .85rem; color: var(--text); background: #fafbfc; }
.stack-form input.visually-hidden { width: 1px; height: 1px; padding: 0; border: 0; }
.stack-form textarea { resize: vertical; }
.stack-form fieldset { margin: 0; padding: 0; border: 0; }
.file-drop { display: grid; gap: .25rem; padding: 1.1rem; border: 1px dashed #cbd1dd; border-radius: 16px; color: var(--text) !important; background: #f8f9fc; cursor: pointer; text-align: center; }
.file-drop span { color: var(--muted); font-size: .7rem; font-weight: 400; }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: .35rem; padding: .3rem; border-radius: 14px; background: #f0f2f6; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; }
.segmented span { display: block; padding: .58rem; border-radius: 10px; text-align: center; }
.segmented input:checked + span { color: var(--accent); background: #fff; box-shadow: 0 3px 10px rgba(43,52,78,.08); }
.inline-field, .switch-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.inline-field input[type="color"] { width: 3rem; height: 2rem; padding: 0; border: 0; background: none; }
.switch-row { padding: .15rem 0; }
.switch-row span { display: grid; gap: .15rem; }
.switch-row small { color: var(--muted); font-weight: 400; }
.switch-row input { appearance: none; position: relative; width: 2.65rem; height: 1.55rem; border-radius: 999px; background: #ccd1db; transition: background .2s ease; }
.switch-row input::after { content: ""; position: absolute; width: 1.2rem; height: 1.2rem; top: .175rem; left: .18rem; border-radius: 50%; background: #fff; box-shadow: 0 2px 5px rgba(0,0,0,.18); transition: transform .2s ease; }
.switch-row input:checked { background: var(--accent); }
.switch-row input:checked::after { transform: translateX(1.08rem); }
.button-row { display: flex; flex-wrap: wrap; gap: .65rem; }
.primary-button, .secondary-button, .danger-button { min-height: 2.75rem; padding: .65rem 1rem; border: 0; border-radius: 13px; font-weight: 700; font-size: .79rem; }
.primary-button { color: #fff; background: var(--accent); box-shadow: 0 8px 18px rgba(91,104,255,.22); }
.secondary-button { color: #343a49; background: #eef0f5; }
.secondary-button.small { min-height: 2.25rem; padding: .45rem .7rem; }
.danger-button { color: #fff; background: var(--red); }
button:disabled { cursor: wait; opacity: .55; }
.form-message { min-height: 1.2rem; margin: .8rem 0 0; color: var(--muted); font-size: .76rem; }
.form-message.error, .form-error { color: var(--red); }
.job-list { display: grid; gap: .6rem; }
.job-item { display: flex; justify-content: space-between; gap: 1rem; padding: .8rem; border-radius: 14px; background: #f7f8fb; font-size: .78rem; }
.job-item small { color: var(--muted); }

.two-column div { min-width: 0; }
.activation-result { margin-top: 1rem; padding: 1rem; border-radius: 16px; background: var(--accent-soft); }
.activation-result p, .activation-result small { display: block; margin: 0; color: var(--muted); font-size: .72rem; }
.activation-result strong { display: block; margin: .4rem 0 .7rem; font-size: 1.6rem; letter-spacing: .15em; }
.activation-result code { display: block; margin-top: .5rem; padding: .65rem; border-radius: 10px; background: rgba(255,255,255,.7); overflow-wrap: anywhere; font-size: .68rem; }
.danger-panel { display: flex; flex-direction: column; gap: 1rem; border-color: rgba(208,68,68,.17); }
.danger-panel h2 { margin: .2rem 0; font-size: 1rem; }
.danger-panel p:not(.eyebrow) { margin: 0; color: var(--muted); font-size: .76rem; }
.danger-action { display: flex; flex-wrap: wrap; gap: .6rem; }
.danger-action input { flex: 1 1 10rem; }

.field-grid { display: grid; gap: .8rem; }
.field-grid > div { display: grid; gap: .45rem; }
.policy-list { display: grid; gap: .7rem; margin: 0; padding: 0; list-style: none; }
.policy-list li { position: relative; padding-left: 1.4rem; color: #505767; font-size: .78rem; }
.policy-list li::before { content: "✓"; position: absolute; left: 0; color: var(--green); font-weight: 800; }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .76rem; }
th, td { padding: .75rem .6rem; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-size: .67rem; text-transform: uppercase; letter-spacing: .07em; }
.diagnostic-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .65rem; }
.diagnostic-grid div, .operations-grid div { padding: .9rem; border-radius: 15px; background: #f7f8fb; }
.diagnostic-grid span { display: block; margin-bottom: .3rem; color: var(--muted); font-size: .7rem; }
.diagnostic-grid strong { font-size: .78rem; }
.operations-grid { display: grid; gap: .7rem; }
.operations-grid strong { font-size: .8rem; }
.operations-grid p { margin: .35rem 0 0; color: var(--muted); font-size: .74rem; line-height: 1.55; }

.toast-region { position: fixed; z-index: 90; right: 1rem; bottom: calc(5.5rem + env(safe-area-inset-bottom)); display: grid; gap: .5rem; width: min(22rem, calc(100vw - 2rem)); }
.toast { padding: .8rem 1rem; border: 1px solid var(--line); border-radius: 14px; background: #fff; box-shadow: var(--shadow); font-size: .78rem; }
.toast.error { color: var(--red); }

.login-page { display: grid; min-height: 100vh; background: radial-gradient(circle at 50% 10%, #fff 0, #eef2f8 52%, #e8edf5 100%); }
.login-shell { display: grid; place-items: center; padding: 1.2rem; }
.login-card { width: min(100%, 410px); padding: clamp(1.5rem, 6vw, 2.6rem); border: 1px solid rgba(255,255,255,.8); border-radius: 28px; background: rgba(255,255,255,.82); box-shadow: 0 30px 70px rgba(35,43,67,.12); backdrop-filter: blur(22px); }
.login-mark, .brand-mark { display: grid; place-items: center; color: #fff; background: linear-gradient(145deg, #5765f4, #7d86ff); font-weight: 800; box-shadow: 0 8px 20px rgba(91,104,255,.25); }
.login-mark { width: 3rem; height: 3rem; margin-bottom: 1.4rem; border-radius: 15px; }
.login-card h1 { margin: .35rem 0 .55rem; font-size: 1.8rem; letter-spacing: -.045em; }
.login-lead { margin: 0 0 1.5rem; color: var(--muted); font-size: .84rem; }
.security-note { margin: 1.3rem 0 0; color: var(--muted); text-align: center; font-size: .68rem; }
.security-note span { color: var(--green); }
.form-error { padding: .7rem; border-radius: 12px; background: #fff0f0; font-size: .76rem; }

@media (min-width: 600px) {
  .hero-grid { grid-template-columns: repeat(2, 1fr); }
  .metric-primary { grid-column: span 2; }
  .field-grid { grid-template-columns: repeat(2, 1fr); }
  .two-column { display: grid; grid-template-columns: repeat(2, 1fr); column-gap: 1.2rem; }
  .danger-panel { flex-direction: row; align-items: center; justify-content: space-between; }
  .operations-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 768px) {
  .app-shell { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); }
  .sidebar { position: sticky; top: 0; display: flex; flex-direction: column; height: 100vh; padding: 1.4rem 1rem; border-right: 1px solid var(--line); background: rgba(250,251,253,.82); backdrop-filter: blur(18px); }
  .brand { display: flex; align-items: center; gap: .7rem; padding: .4rem; text-decoration: none; }
  .brand-mark { width: 2.25rem; height: 2.25rem; border-radius: 11px; }
  .brand span:last-child { display: grid; }
  .brand strong { font-size: .86rem; }
  .brand small { color: var(--muted); font-size: .62rem; }
  .primary-nav { display: grid; gap: .35rem; margin-top: 2rem; }
  .primary-nav a { display: flex; align-items: center; gap: .75rem; padding: .7rem .75rem; border-radius: 13px; color: var(--muted); text-decoration: none; font-size: .78rem; font-weight: 650; }
  .primary-nav a:hover { color: var(--text); background: #f0f2f6; }
  .primary-nav a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }
  .primary-nav .nav-glyph { width: 1.1rem; height: 1.1rem; }
  .sidebar-footer { display: flex; align-items: center; gap: .55rem; margin-top: auto; padding: .75rem .4rem; color: var(--muted); font-size: .67rem; }
  .privacy-dot { width: .42rem; height: .42rem; background: var(--green); }
  .text-button { margin-left: auto; padding: 0; border: 0; color: var(--muted); background: none; font-size: .67rem; }
  .mobile-nav { display: none; }
  .main-content { padding: 2rem clamp(1.4rem, 4vw, 3.5rem) 3rem; }
  .page-header { margin-bottom: 2rem; }
  .live-indicator { display: flex; }
  .hero-grid { grid-template-columns: repeat(3, 1fr); gap: 1rem; }
  .metric-primary { grid-column: auto; }
  .content-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
  .span-two { grid-column: span 2; }
  .span-three { grid-column: span 3; }
  .editor-layout { grid-template-columns: minmax(290px, .9fr) minmax(330px, 1.1fr); }
  .toast-region { bottom: 1rem; }
}

@media (min-width: 1050px) {
  .chain { grid-template-columns: 1fr auto 1fr auto 1fr auto 1fr; align-items: center; }
  .chain div { grid-template-columns: 2rem 1fr; padding: .65rem; }
  .chain i { display: block; width: 1.2rem; height: 1px; background: #d8dce5; }
  .panel, .metric-card { padding: 1.4rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
