:root {
  color-scheme: dark;
  --bg: #080d13;
  --panel: rgba(16, 24, 34, 0.9);
  --panel-strong: #111b27;
  --line: rgba(156, 185, 205, 0.16);
  --text: #edf6fa;
  --muted: #91a5b2;
  --cyan: #38d4cf;
  --cyan-soft: rgba(56, 212, 207, 0.13);
  --blue: #4f8cff;
  --amber: #f5b94c;
  --red: #ff6b77;
  --green: #57d68d;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

.ambient { position: fixed; z-index: -1; width: 42rem; height: 42rem; border-radius: 999px; filter: blur(100px); opacity: .13; pointer-events: none; }
.ambient-a { top: -18rem; left: -10rem; background: var(--cyan); }
.ambient-b { right: -18rem; bottom: -20rem; background: var(--blue); }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 2rem; }
.login-card { width: min(29rem, 100%); padding: 2.1rem; border: 1px solid var(--line); border-radius: 1.25rem; background: linear-gradient(150deg, rgba(20, 31, 44, .97), rgba(10, 16, 24, .97)); box-shadow: 0 30px 100px rgba(0,0,0,.4); }
.brand-lockup { display: flex; align-items: center; gap: .9rem; }
.brand-lockup.compact { gap: .65rem; }
.brand-mark { width: 3rem; height: 3rem; display: grid; place-items: center; border: 1px solid rgba(56,212,207,.5); border-radius: .8rem; color: var(--cyan); font-weight: 800; font-size: 1.25rem; background: var(--cyan-soft); box-shadow: inset 0 0 30px rgba(56,212,207,.08); }
.compact .brand-mark { width: 2.45rem; height: 2.45rem; border-radius: .65rem; }
.brand-title { font-size: 1.35rem; font-weight: 760; letter-spacing: .08em; }
.eyebrow { color: var(--cyan); font-size: .68rem; font-weight: 750; letter-spacing: .17em; text-transform: uppercase; }
h1 { margin: .1rem 0 0; font-size: 2.2rem; letter-spacing: .08em; }
.login-copy { margin: 1.6rem 0; color: var(--muted); line-height: 1.65; }
.viewer-state { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.viewer-state-card { display: flex; align-items: center; gap: .9rem; max-width: 34rem; padding: 1rem 1.1rem; border: 1px solid var(--line); border-radius: .8rem; background: #0d141d; box-shadow: 0 18px 60px rgba(0,0,0,.28); }
.viewer-state-mark { flex: 0 0 auto; width: 2.2rem; height: 2.2rem; display: grid; place-items: center; border: 1px solid rgba(145,165,178,.34); border-radius: .55rem; color: #c9d7de; font-weight: 750; }
.viewer-state-card strong { font-size: .88rem; font-weight: 650; }
.viewer-state-card p { margin: .25rem 0 0; color: var(--muted); font-size: .75rem; line-height: 1.45; }
.viewer-state-card button { margin-left: .35rem; white-space: nowrap; }
.viewer-state.error .viewer-state-mark { color: #ffd4d8; border-color: rgba(255,107,119,.35); }

label { display: grid; gap: .45rem; color: #c6d5dd; font-size: .82rem; }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: .65rem; padding: .72rem .8rem; color: var(--text); background: rgba(4, 9, 14, .78); outline: none; transition: border-color .15s, box-shadow .15s; }
textarea { resize: vertical; min-height: 7rem; }
input:focus, select:focus, textarea:focus { border-color: rgba(56,212,207,.72); box-shadow: 0 0 0 3px rgba(56,212,207,.1); }

button { border: 1px solid transparent; border-radius: .6rem; padding: .62rem .85rem; color: var(--text); background: rgba(255,255,255,.06); transition: transform .12s, border-color .12s, background .12s; }
button:hover { transform: translateY(-1px); border-color: rgba(255,255,255,.16); }
button:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.primary { background: linear-gradient(120deg, #1ba9a6, #2879df); border-color: rgba(102,226,222,.35); font-weight: 700; }
.wide { width: 100%; margin-top: 1rem; }
.ghost { background: rgba(255,255,255,.035); border-color: var(--line); }
.danger { color: #ffd8dc; border-color: rgba(255,107,119,.28); background: rgba(255,107,119,.1); }
.form-error { min-height: 1.25rem; color: var(--red); font-size: .8rem; }

.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; height: 4.3rem; padding: 0 clamp(1rem, 4vw, 3rem); border-bottom: 1px solid var(--line); background: rgba(8,13,19,.84); backdrop-filter: blur(18px); }
.top-actions { display: flex; align-items: center; gap: .6rem; font-size: .78rem; }
main { width: min(1480px, calc(100% - 2rem)); margin: 0 auto; padding: 2.1rem 0 4rem; }
.hero { display: flex; justify-content: space-between; align-items: end; gap: 2rem; padding: 1.2rem 0 2rem; }
.hero h2 { margin: .35rem 0 .4rem; font-size: clamp(1.8rem, 4vw, 3.25rem); letter-spacing: -.045em; }
.hero p { margin: 0; color: var(--muted); }
.security-note { display: flex; align-items: center; gap: .55rem; padding: .7rem .9rem; border: 1px solid var(--line); border-radius: 999px; color: #c9dae2; font-size: .78rem; white-space: nowrap; }
.pulse { width: .55rem; height: .55rem; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 5px rgba(87,214,141,.11); }

.metric-grid { display: grid; grid-template-columns: repeat(5, minmax(0,1fr)); gap: .85rem; margin-bottom: .85rem; }
.metric { padding: 1.1rem 1.2rem; border: 1px solid var(--line); border-radius: .9rem; background: var(--panel); }
.metric-value { margin-top: .3rem; font-size: 2rem; font-weight: 720; letter-spacing: -.04em; }
.metric-label { color: var(--muted); font-size: .75rem; }

.panel { margin-top: .85rem; border: 1px solid var(--line); border-radius: 1rem; background: var(--panel); overflow: hidden; box-shadow: 0 14px 48px rgba(0,0,0,.14); }
.panel-heading { min-height: 4.7rem; display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.2rem; border-bottom: 1px solid var(--line); }
.panel-heading h3 { margin: .22rem 0 0; font-size: 1.05rem; }
.cell-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(260px,1fr)); gap: .8rem; padding: 1rem; }
.cell-card { padding: 1rem; border: 1px solid var(--line); border-radius: .8rem; background: rgba(5,11,17,.5); }
.cell-card-head { display: flex; justify-content: space-between; gap: 1rem; align-items: start; }
.cell-card h4 { margin: 0; font-size: 1rem; }
.cell-meta { margin-top: .35rem; color: var(--muted); font-size: .75rem; word-break: break-all; }
.node-list { display: grid; gap: .55rem; margin-top: .9rem; }
.node-row { display: grid; grid-template-columns: 1fr auto; gap: .5rem; align-items: center; padding: .62rem; border-radius: .6rem; background: rgba(255,255,255,.035); }
.node-name { font-weight: 650; }
.node-detail { color: var(--muted); font-size: .68rem; margin-top: .15rem; }

.split-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .85rem; }
.form-panel { min-width: 0; }
.stack-form { display: grid; gap: .8rem; padding: 1rem 1.2rem 1.25rem; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 850px; }
th, td { padding: .82rem 1rem; border-bottom: 1px solid rgba(156,185,205,.09); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-size: .68rem; letter-spacing: .08em; text-transform: uppercase; font-weight: 700; }
td { font-size: .79rem; }
tbody tr:hover { background: rgba(255,255,255,.018); }
.primary-cell { display: grid; gap: .18rem; }
.primary-cell strong { font-size: .84rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .7rem; color: var(--muted); }
.badge { display: inline-flex; align-items: center; padding: .28rem .48rem; border-radius: 999px; font-weight: 700; font-size: .66rem; letter-spacing: .04em; background: rgba(255,255,255,.07); }
.badge.RUNNING, .badge.SUCCEEDED { color: #9df4c0; background: rgba(87,214,141,.12); }
.badge.SLEEPING, .badge.QUEUED { color: #b8c9ff; background: rgba(79,140,255,.13); }
.badge.PROVISIONING, .badge.CHECKPOINTING, .badge.RESTORING { color: #ffe0a1; background: rgba(245,185,76,.13); }
.badge.FAILED, .badge.ERROR, .badge.RESTORE_FAILED, .badge.CANCELED { color: #ffc1c7; background: rgba(255,107,119,.13); }
.badge.FIRING { color: #ffc1c7; background: rgba(255,107,119,.13); }
.badge.RESOLVED { color: #9df4c0; background: rgba(87,214,141,.12); }
.action-row { display: flex; flex-wrap: wrap; gap: .35rem; }
.action-row button { padding: .42rem .55rem; font-size: .68rem; }
.empty-row td { padding: 2rem; text-align: center; color: var(--muted); }

.toast { position: fixed; right: 1.2rem; top: 5.2rem; z-index: 50; max-width: min(28rem, calc(100vw - 2.4rem)); padding: .8rem 1rem; border: 1px solid rgba(56,212,207,.3); border-radius: .7rem; color: #dff; background: rgba(13,32,39,.96); box-shadow: 0 18px 50px rgba(0,0,0,.35); }
.toast.error { border-color: rgba(255,107,119,.4); color: #ffe2e5; background: rgba(49,19,25,.97); }
dialog { width: min(900px, calc(100vw - 2rem)); max-height: calc(100vh - 3rem); padding: 0; border: 1px solid var(--line); border-radius: 1rem; color: var(--text); background: #0d151f; box-shadow: 0 30px 120px rgba(0,0,0,.7); }
dialog::backdrop { background: rgba(2,6,10,.77); backdrop-filter: blur(4px); }
.dialog-heading { display: flex; justify-content: space-between; align-items: center; padding: 1rem 1.2rem; border-bottom: 1px solid var(--line); }
.dialog-heading h3 { margin: 0; }
.dialog-content { padding: 1rem 1.2rem 1.3rem; overflow: auto; }
.dialog-content pre { padding: .9rem; overflow: auto; border: 1px solid var(--line); border-radius: .65rem; background: rgba(0,0,0,.24); color: #bdd0da; font-size: .7rem; line-height: 1.5; }
.snapshot-row { display: grid; grid-template-columns: 1fr auto; gap: 1rem; align-items: center; padding: .8rem 0; border-bottom: 1px solid var(--line); }

.browser-dialog { width: min(1440px, calc(100vw - 1.2rem)); max-height: calc(100vh - 1.2rem); }
.browser-heading { gap: 1rem; }
.browser-heading-actions { display: flex; flex-wrap: wrap; gap: .45rem; justify-content: flex-end; }
.browser-status { margin-top: .3rem; color: var(--muted); font-size: .72rem; }
.browser-status.connected { color: var(--green); }
.browser-status.connecting { color: var(--amber); }
.browser-status.disconnected { color: var(--red); }
.browser-toolbar { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: end; gap: .65rem; padding: .75rem 1rem; border-bottom: 1px solid var(--line); background: rgba(0,0,0,.18); }
.browser-location-label { align-self: center; }
.browser-viewport { position: relative; display: grid; place-items: center; min-height: min(65vh, 800px); overflow: auto; background: #020406; outline: none; }
.browser-viewport:focus { box-shadow: inset 0 0 0 2px rgba(56,212,207,.48); }
.browser-viewport img { display: block; width: min(100%, 1280px); height: auto; max-height: calc(100vh - 13.5rem); object-fit: contain; user-select: none; cursor: default; }
.browser-placeholder { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); pointer-events: none; }
.browser-footer { display: flex; justify-content: space-between; gap: 1rem; padding: .65rem 1rem; color: var(--muted); font-size: .72rem; border-top: 1px solid var(--line); }
.browser-viewport:fullscreen { width: 100vw; height: 100vh; background: #000; }
.browser-viewport:fullscreen img { width: 100%; max-width: none; max-height: 100vh; }

html.embedded-viewer, html.embedded-viewer body { width: 100%; height: 100%; overflow: hidden; background: #080c11; }
.embedded-viewer #app, .embedded-viewer #login-screen, .embedded-viewer .ambient { display: none !important; }
.embedded-viewer .browser-dialog[open] { display: flex; flex-direction: column; inset: 0; width: 100vw; max-width: none; height: 100vh; max-height: none; margin: 0; border: 0; border-radius: 0; }
.embedded-viewer .browser-dialog #browser-close { display: none; }
.embedded-viewer .browser-heading { min-height: 3.6rem; padding: .65rem .85rem; background: #0d141d; }
.embedded-viewer .browser-heading h3 { font-size: .82rem; font-weight: 620; color: #d7e1e6; }
.embedded-viewer .browser-heading-actions button { padding: .45rem .65rem; font-size: .72rem; }
.embedded-viewer .browser-toolbar { padding: .55rem .75rem; background: #0a1017; }
.embedded-viewer .browser-toolbar input { padding: .55rem .7rem; border-radius: .5rem; background: #060a0f; }
.embedded-viewer .browser-toolbar .primary { padding: .55rem .75rem; background: #1b2732; border-color: rgba(156,185,205,.18); font-weight: 620; }
.embedded-viewer .browser-viewport { flex: 1; min-height: 0; }
.embedded-viewer .browser-viewport img { max-height: calc(100vh - 7.5rem); }
.embedded-viewer .browser-footer { display: none; }

@media (max-width: 900px) {
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .split-grid { grid-template-columns: 1fr; }
  .hero { align-items: start; flex-direction: column; }
}
@media (max-width: 560px) {
  main { width: min(100% - 1rem, 1480px); padding-top: 1rem; }
  .topbar { padding: 0 .7rem; }
  .top-actions .muted { display: none; }
  .metric-grid, .two-col { grid-template-columns: 1fr; }
  .login-card { padding: 1.35rem; }
  .browser-toolbar { grid-template-columns: 1fr auto; }
  .browser-location-label { display: none; }
  .browser-footer { flex-direction: column; }
}
