:root {
  color-scheme: dark;
  --bg: #0f1014;
  --panel: #17191f;
  --panel-2: #1e2129;
  --line: #2d313b;
  --text: #f5f7fb;
  --muted: #9aa3b2;
  --green: #22c55e;
  --green-bg: #12351f;
  --red: #ef4444;
  --red-bg: #3b161a;
  --blue: #60a5fa;
  --violet: #8b5cf6;
  --amber: #f59e0b;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, Segoe UI, Arial, sans-serif;
  letter-spacing: 0;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }

.shell {
  min-height: 100vh;
  padding: 20px;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1240px;
  margin: 0 auto 18px;
  gap: 16px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: linear-gradient(135deg, #22c55e, #2563eb);
  color: white;
}
.nav {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
}
.user-pill {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #13151a;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.login-layout, .center-state {
  min-height: calc(100vh - 100px);
  display: grid;
  place-items: center;
}
.login-card, .state-card {
  width: min(520px, 100%);
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}
.login-card h1, .state-card h1 {
  margin: 8px 0 10px;
  font-size: 34px;
  line-height: 1.1;
}
.login-card p, .state-card p, .section-head p, .hero-band p {
  color: var(--muted);
  line-height: 1.55;
}
.login-actions {
  display: grid;
  gap: 10px;
  margin-top: 24px;
}
.state-icon {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--amber);
  font-weight: 900;
}
.state-card.danger .state-icon { color: var(--red); }
.eyebrow {
  color: var(--blue);
  text-transform: uppercase;
  font-weight: 800;
  font-size: 12px;
}

.dashboard, .admin-layout {
  max-width: 1240px;
  margin: 0 auto;
}
.hero-band {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: linear-gradient(135deg, #161a22, #111318);
}
.hero-band h1 {
  margin: 6px 0;
  font-size: 30px;
}
.tabs {
  display: flex;
  gap: 8px;
  margin: 18px 0;
  overflow-x: auto;
}
.tab {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  border-radius: 8px;
  padding: 10px 14px;
}
.tab.active {
  color: white;
  border-color: #3b82f6;
  background: #172033;
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.section-head {
  margin: 16px 0;
}
.section-head-actions {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
}
.section-head h1, .section-head h2 {
  margin: 0 0 6px;
}
.section-head p { margin: 0; }
.muted-line {
  min-height: 20px;
}
.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 220px));
  gap: 14px;
  padding-bottom: 86px;
}
.preset-card, .pod-card, .group-card, .preset-form, .preset-edit, .admin-row {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}
.preset-card {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.preset-art {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  overflow: hidden;
}
.preset-art img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.preset-card h3, .pod-card h3 {
  margin: 0;
  font-size: 18px;
}
.preset-card h3 {
  text-align: center;
  min-height: 44px;
  display: grid;
  place-items: center;
}
.preset-card .meta {
  text-align: center;
  min-height: 19px;
}
.preset-icon-preview {
  display: flex;
  gap: 10px;
  align-items: center;
}
.preset-icon-preview img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
}
.meta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}
.pod-list {
  display: grid;
  gap: 14px;
}
.pod-card {
  padding: 18px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
}
.pod-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  align-content: start;
}
.status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 8px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--muted);
  background: #12141a;
  border: 1px solid var(--line);
}
.status.running { color: #bbf7d0; border-color: #166534; background: var(--green-bg); }
.status.deploying { color: #bfdbfe; border-color: #1d4ed8; background: #111f3a; }
.status.failed, .status.stopped { color: #fecaca; border-color: #7f1d1d; background: var(--red-bg); }

.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 8px;
  align-items: start;
}
.result-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  margin: 0;
}
.result-thumb {
  position: relative;
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: #11141b;
  overflow: hidden;
  aspect-ratio: 1 / 1;
}
.result-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;
  transition: opacity .18s ease;
}
.result-thumb.thumb-loaded img {
  opacity: 1;
}
.thumb-shimmer {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, transparent, rgba(255,255,255,.08), transparent),
    #141720;
  background-size: 180% 100%;
  animation: thumb-shimmer 1.1s infinite linear;
}
.result-thumb.thumb-loaded .thumb-shimmer,
.result-thumb.thumb-error .thumb-shimmer {
  display: none;
}
.result-thumb.thumb-error::after {
  content: "preview error";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 11px;
}
@keyframes thumb-shimmer {
  from { background-position: 180% 0; }
  to { background-position: -180% 0; }
}
.result-card figcaption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 7px;
  min-width: 0;
}
.result-card figcaption span {
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.result-card figcaption a {
  flex: 0 0 auto;
  color: #bfdbfe;
  font-size: 12px;
}
.result-viewer {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: rgba(5, 6, 9, .94);
  padding: 16px;
}
.viewer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0 14px;
}
.viewer-toolbar strong {
  display: block;
  max-width: 70vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.viewer-actions {
  display: flex;
  gap: 8px;
}
.viewer-progress {
  width: min(420px, 70vw);
  height: 5px;
  margin-top: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: #242833;
}
.viewer-progress span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #22c55e, #60a5fa);
  transition: width .18s ease;
}
.viewer-stage {
  display: grid;
  place-items: center;
  min-height: 0;
}
.viewer-stage img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
}
.modal-open {
  overflow: hidden;
}
.event-log {
  display: grid;
  gap: 8px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 13px;
}
.event {
  display: grid;
  grid-template-columns: 190px 70px minmax(0, 1fr);
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0c0d11;
}
.event p { margin: 0; }
.event time, .event span { color: var(--muted); }
.event.success span { color: var(--green); }
.event.warn span { color: var(--amber); }
.event.error span { color: var(--red); }

.warning-bar {
  margin: 14px 0;
  padding: 12px 14px;
  border: 1px solid #92400e;
  border-radius: 8px;
  background: #2c1d0b;
  color: #fde68a;
}
.hidden { display: none !important; }

.primary, .secondary, .ghost, .danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 9px 13px;
  border-radius: 8px;
  border: 1px solid transparent;
  color: white;
}
.primary { background: #2563eb; border-color: #3b82f6; }
.secondary { background: #1d2737; border-color: #334155; }
.ghost { background: transparent; border-color: var(--line); color: var(--muted); }
.danger { background: var(--red-bg); border-color: #7f1d1d; color: #fecaca; }
.wide { width: 100%; }
.link-ok { background: var(--green-bg); border-color: #16a34a; color: #dcfce7; }
.disabled-link {
  pointer-events: none;
  opacity: .55;
}

.flash-stack {
  max-width: 1240px;
  margin: 0 auto 14px;
  display: grid;
  gap: 8px;
}
.flash {
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
}
.flash.error { border-color: #7f1d1d; color: #fecaca; }
.flash.success { border-color: #166534; color: #bbf7d0; }
.hint-line {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 13px;
}
.hint-line.error {
  color: #fecaca;
}

.admin-layout {
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr);
  gap: 18px;
}
.admin-menu {
  position: sticky;
  top: 20px;
  align-self: start;
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}
.admin-menu a {
  padding: 10px;
  border-radius: 7px;
  color: var(--muted);
}
.admin-menu a:hover { background: var(--panel-2); color: white; }
.admin-content {
  min-width: 0;
}
.table-list, .preset-admin-list, .group-list {
  display: grid;
  gap: 12px;
}
.admin-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) repeat(4, minmax(120px, 180px)) auto;
  gap: 10px;
  padding: 12px;
  align-items: center;
}
.admin-row-head {
  background: transparent;
  border-style: dashed;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}
.admin-row span { color: var(--muted); font-size: 13px; display: block; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #101218;
  color: var(--text);
  border-radius: 7px;
  padding: 9px 10px;
}
textarea { min-height: 80px; resize: vertical; }
.preset-form, .preset-edit, .group-card {
  padding: 14px;
}
.preset-edit summary {
  cursor: pointer;
  font-weight: 700;
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.form-grid label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
}
.form-grid .wide { grid-column: 1 / -1; }
.check {
  display: flex !important;
  align-items: center;
  gap: 8px;
}
.check input { width: auto; }
.group-list {
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
}
.output-toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(260px, 1.4fr) auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
}
.output-toolbar label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
}
.output-context {
  display: grid;
  gap: 3px;
  margin: 10px 0 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}
.output-context span {
  color: var(--muted);
  font-size: 13px;
}
.admin-results {
  margin-top: 10px;
}

@media (max-width: 760px) {
  .shell { padding: 12px; }
  .topbar, .hero-band, .pod-card, .section-head-actions { align-items: stretch; flex-direction: column; display: flex; }
  .nav { flex-wrap: wrap; }
  .admin-layout { grid-template-columns: 1fr; }
  .admin-menu { position: static; }
  .admin-row { grid-template-columns: 1fr; }
  .output-toolbar { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .event { grid-template-columns: 1fr; }
}
