:root {
  --bg: #0D1117;
  --bg-soft: #111827;
  --bg2: #161B22;
  --surface: #21262D;
  --surface-2: #1B222C;
  --border: #30363D;
  --border-soft: rgba(139, 148, 158, .18);
  --blue: #58A6FF;
  --blue-2: #2F81F7;
  --green: #7EE787;
  --amber: #F0883E;
  --red: #F85149;
  --text: #E6EDF3;
  --muted: #8B949E;
  --ash: #6E7681;
  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 22px;
  --shadow: 0 20px 70px rgba(0, 0, 0, .35);
  --shadow-soft: 0 14px 34px rgba(0, 0, 0, .24);
  --spring: cubic-bezier(.34, 1.56, .64, 1);
  --container: 1180px;
  --safe-x: clamp(14px, 3.6vw, 32px);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
img, svg, canvas { max-width: 100%; }
:focus-visible { outline: 3px solid rgba(88, 166, 255, .45); outline-offset: 2px; }

.bg-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -2;
  background-image:
    radial-gradient(#1a2332 1px, transparent 1px),
    linear-gradient(rgba(88,166,255,.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(88,166,255,.035) 1px, transparent 1px);
  background-size: 18px 18px, 72px 72px, 72px 72px;
  mask-image: linear-gradient(to bottom, #000 0%, rgba(0,0,0,.92) 48%, rgba(0,0,0,.25) 100%);
}
body::before {
  content: "";
  position: fixed;
  inset: -20%;
  z-index: -3;
  background:
    radial-gradient(circle at 16% 12%, rgba(88,166,255,.15), transparent 28%),
    radial-gradient(circle at 86% 6%, rgba(126,231,135,.11), transparent 24%),
    radial-gradient(circle at 48% 100%, rgba(240,136,62,.08), transparent 24%);
}

/* Header */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 72px;
  padding: 12px var(--safe-x);
  background: rgba(13, 17, 23, .78);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid rgba(48, 54, 61, .72);
  transition: background .25s ease, box-shadow .25s ease;
}
.topbar.scrolled { background: rgba(13, 17, 23, .96); box-shadow: 0 10px 30px rgba(0,0,0,.28); }
.brand { display: inline-flex; align-items: center; gap: 12px; min-width: max-content; }
.brand-icon, .brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(88,166,255,.24), rgba(126,231,135,.12));
  border: 1px solid rgba(88,166,255,.45);
  box-shadow: 0 0 22px rgba(88,166,255,.18);
  color: var(--blue);
  font: 800 14px Space Grotesk, sans-serif;
}
.brand strong { display: block; font-family: Space Grotesk, sans-serif; letter-spacing: .2px; }
.brand small { display: block; color: var(--muted); font-size: 11px; margin-top: 1px; }
.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}
.icon-link, .user-pill {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 9px 12px;
  border-radius: 999px;
  color: var(--muted);
  white-space: nowrap;
  transition: color .15s ease, background .15s ease, border-color .15s ease;
}
.icon-link:hover { color: var(--text); background: rgba(88,166,255,.08); }
.icon-link.admin-only { color: #d6ffe0; border: 1px solid rgba(126,231,135,.28); background: rgba(126,231,135,.06); }
.user-pill { max-width: 150px; overflow: hidden; text-overflow: ellipsis; border: 1px solid var(--border); font-size: 13px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 12px 16px;
  border: 1px solid transparent;
  border-radius: 13px;
  background: transparent;
  color: var(--text);
  font-weight: 800;
  line-height: 1.2;
  text-align: center;
  transition: transform .15s ease-out, box-shadow .15s ease-out, background .15s ease-out, border .15s ease-out;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: scale(.98); }
.btn:disabled, button:disabled { cursor: not-allowed; opacity: .62; transform: none; }
.btn-primary { background: linear-gradient(135deg, var(--blue), var(--blue-2)); color: #fff; box-shadow: 0 0 28px rgba(88,166,255,.22); }
.btn-secondary { background: rgba(88,166,255,.045); border-color: var(--border); color: var(--text); }
.btn-secondary:hover { background: rgba(88,166,255,.1); border-color: rgba(88,166,255,.55); }
.btn-danger { background: rgba(248,81,73,.12); border-color: rgba(248,81,73,.45); color: #ffd8d4; }
.btn.mini { min-height: 36px; padding: 8px 12px; font-size: 13px; }
.btn.full { width: 100%; }

/* Shells and panels */
.page-shell, .studio-shell {
  width: min(var(--container), calc(100% - (var(--safe-x) * 2)));
  margin-inline: auto;
  padding: clamp(22px, 4vw, 42px) 0;
}
.blueprint-panel, .feature-card, .stats-grid > div {
  position: relative;
  background: linear-gradient(180deg, rgba(33,38,45,.92), rgba(22,27,34,.92));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
}
.blueprint-panel::before, .feature-card::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
  background: linear-gradient(135deg, rgba(88,166,255,.08), transparent 34%, rgba(126,231,135,.04));
  opacity: .8;
}
.blueprint-panel > *, .feature-card > * { position: relative; }
.reveal { animation: reveal .45s ease both; }
@keyframes reveal { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

/* Public landing */
.hero { padding: clamp(26px, 5vw, 60px); overflow: hidden; }
.hero::after, .studio-hero::after {
  content: "";
  position: absolute;
  right: -80px;
  top: -80px;
  width: 220px;
  height: 220px;
  border-radius: 32px;
  border: 1px solid rgba(88,166,255,.2);
  transform: rotate(28deg);
  background: linear-gradient(135deg, rgba(88,166,255,.08), transparent);
}
.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(88,166,255,.35);
  background: rgba(88,166,255,.07);
  color: var(--blue);
  font: 800 12px JetBrains Mono, monospace;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.hero h1, .studio-hero h1, .auth-card h1, .install-card h1, .admin-shell h1 {
  margin: 20px 0 14px;
  font-family: Space Grotesk, sans-serif;
  font-size: clamp(34px, 7vw, 72px);
  line-height: 1.02;
  letter-spacing: -.05em;
  background: linear-gradient(135deg, var(--text), var(--blue) 52%, var(--green));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero-subtitle { max-width: 780px; color: var(--muted); font-size: clamp(16px, 2vw, 20px); line-height: 1.7; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; margin: 28px 0; }
.stats-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 28px; }
.stats-grid > div { padding: 18px; min-width: 0; }
.stats-grid strong { display: block; color: var(--green); font: 800 28px Space Grotesk, sans-serif; }
.stats-grid span { color: var(--muted); font-size: 13px; }
.stats-grid small { display: block; margin-top: 8px; color: var(--ash); font-size: 11px; line-height: 1.5; }
.feature-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-top: 16px; }
.feature-card { display: block; min-width: 0; padding: 24px; transition: transform .18s var(--spring), border-color .18s ease, box-shadow .18s ease; }
a.feature-card:hover, .admin-menu-grid a.feature-card:hover { transform: translateY(-4px); border-color: rgba(88,166,255,.58); box-shadow: 0 18px 42px rgba(0,0,0,.28); }
.feature-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  border: 1px solid rgba(88,166,255,.25);
  background: rgba(88,166,255,.08);
  color: var(--blue);
  font-weight: 900;
}
.feature-card h3 { margin: 14px 0 8px; font-family: Space Grotesk, sans-serif; }
.feature-card p, .muted { color: var(--muted); line-height: 1.6; }
.footer {
  width: min(var(--container), calc(100% - (var(--safe-x) * 2)));
  margin: 20px auto 0;
  padding: 24px 0 36px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--ash);
  font-size: 13px;
  border-top: 1px solid rgba(48,54,61,.65);
}

/* Forms */
.auth-shell, .install-shell { min-height: calc(100vh - 90px); display: grid; place-items: center; padding: 32px var(--safe-x); }
.auth-card, .install-card { width: min(520px, 100%); padding: 28px; }
.install-card { width: min(760px, 100%); }
.form-stack, .install-form, .admin-form { display: grid; gap: 14px; }
label { display: grid; gap: 8px; color: var(--text); font-size: 13px; font-weight: 800; }
input, select, textarea {
  width: 100%;
  min-width: 0;
  padding: 13px 14px;
  outline: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(13,17,23,.75);
  color: var(--text);
  transition: border .15s ease, box-shadow .15s ease, background .15s ease;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 4px rgba(88,166,255,.11); background: rgba(13,17,23,.95); }
select {
  appearance: none;
  padding-right: 36px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 18px, calc(100% - 13px) 18px;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}
.grid-2, .settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
hr { width: 100%; margin: 8px 0; border: 0; border-top: 1px solid var(--border); }
.tiny { color: var(--ash); font-size: 12px; }
.mono { font-family: JetBrains Mono, monospace; }
.auth-switch { color: var(--muted); text-align: center; }
.auth-switch a { color: var(--blue); font-weight: 800; }
.flash {
  margin: 12px 0;
  padding: 12px 14px;
  border-radius: 12px;
  font-weight: 800;
  border: 1px solid transparent;
}
.flash-error { border-color: rgba(248,81,73,.45); background: rgba(248,81,73,.12); color: #ffd8d4; }
.flash-success { border-color: rgba(126,231,135,.35); background: rgba(126,231,135,.1); color: #d6ffe0; }
.flash-info { border-color: rgba(88,166,255,.35); background: rgba(88,166,255,.08); color: #b9d9ff; }
.flash code, .admin-table code { color: var(--green); font-family: JetBrains Mono, monospace; }

/* Studio */
.studio-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 24px;
  padding: clamp(20px, 3vw, 30px);
  margin-bottom: 16px;
  overflow: hidden;
}
.studio-hero h1 { margin: 10px 0; font-size: clamp(32px, 5vw, 54px); }
.public-mode-note {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid rgba(88,166,255,.32);
  background: rgba(88,166,255,.08);
  color: #b9d9ff;
  font-size: 12px;
  font-weight: 900;
}
.live-clock {
  display: grid;
  gap: 4px;
  min-width: 190px;
  padding: 16px;
  border-radius: 16px;
  border: 1px solid rgba(88,166,255,.25);
  background: rgba(88,166,255,.06);
  text-align: right;
}
.live-clock span { color: var(--green); font: 800 28px JetBrains Mono, monospace; }
.live-clock small { color: var(--muted); }
.engine-selector { padding: 20px; margin-bottom: 16px; overflow: hidden; }
.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}
.panel-head h2 { margin: 0 0 4px; font-family: Space Grotesk, sans-serif; }
.panel-head h3 { margin: 0 0 4px; font-family: Space Grotesk, sans-serif; }
.panel-head p { margin: 0; }
.panel-head.compact { margin-bottom: 10px; }
.engine-current {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(126,231,135,.36);
  background: rgba(126,231,135,.08);
  color: #d6ffe0;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}
.engine-choice-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.engine-choice {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: flex-start;
  gap: 10px;
  min-height: 150px;
  padding: 16px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(13,17,23,.78), rgba(33,38,45,.78));
  color: var(--text);
  text-align: left;
  transition: transform .2s var(--spring), border-color .2s ease, box-shadow .2s ease;
}
.engine-choice::before { content: ""; position: absolute; inset: auto -20% -60% -20%; height: 80%; background: radial-gradient(circle, rgba(88,166,255,.18), transparent 60%); opacity: .25; }
.engine-choice:hover { transform: translateY(-4px); border-color: rgba(88,166,255,.58); box-shadow: 0 18px 42px rgba(0,0,0,.28), 0 0 26px rgba(88,166,255,.12); }
.engine-choice.active { border-color: rgba(126,231,135,.78); box-shadow: 0 0 0 1px rgba(126,231,135,.18), 0 0 34px rgba(126,231,135,.12); }
.engine-choice.active::after { content: "✓"; position: absolute; right: 12px; top: 12px; display: grid; place-items: center; width: 26px; height: 26px; border-radius: 999px; background: var(--green); color: #08120b; font-weight: 950; }
.engine-icon { grid-row: span 2; display: grid; place-items: center; width: 48px; height: 48px; border-radius: 16px; border: 1px solid rgba(88,166,255,.35); background: rgba(88,166,255,.08); color: var(--blue); font: 900 13px JetBrains Mono, monospace; box-shadow: 0 0 24px rgba(88,166,255,.12); }
.engine-choice.active .engine-icon { border-color: rgba(126,231,135,.48); background: rgba(126,231,135,.1); color: var(--green); }
.engine-choice b { padding-right: 24px; font: 800 16px/1.2 Space Grotesk, sans-serif; }
.engine-choice small { grid-column: 2; color: var(--muted); font-size: 12px; line-height: 1.55; }

.studio-grid {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 360px;
  gap: 16px;
  align-items: start;
}
.template-panel, .builder-panel, .preview-panel, .history-panel { min-width: 0; padding: 18px; }
.template-grid { display: grid; gap: 12px; }
.template-card {
  position: relative;
  min-width: 0;
  overflow: hidden;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(13,17,23,.5);
  color: var(--text);
  text-align: left;
  transition: transform .18s var(--spring), border-color .18s ease, box-shadow .18s ease;
}
.template-card:hover { transform: translateY(-4px); border-color: rgba(88,166,255,.55); box-shadow: 0 16px 40px rgba(0,0,0,.25); }
.template-card.selected::after { content: "✓"; position: absolute; top: 10px; right: 10px; display: grid; place-items: center; width: 24px; height: 24px; border-radius: 999px; background: var(--green); color: #0D1117; font-weight: 900; }
.template-card small { display: inline-block; margin-bottom: 8px; color: var(--green); font: 800 11px JetBrains Mono, monospace; }
.template-card h3 { margin: 0 0 6px; font-size: 15px; }
.template-card p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.accordion-list { display: grid; gap: 10px; }
.accordion-item { overflow: hidden; border: 1px solid var(--border); border-radius: 14px; background: rgba(13,17,23,.38); }
.accordion-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 56px;
  padding: 0 14px;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
}
.accordion-head span { display: flex; align-items: center; gap: 10px; min-width: 0; font-weight: 900; }
.accordion-head b { color: var(--blue); font: 800 12px JetBrains Mono, monospace; }
.accordion-head i { color: var(--muted); font-style: normal; transition: transform .25s ease, color .25s ease; }
.accordion-body { display: none; gap: 13px; padding: 0 14px 14px; }
.accordion-item.active { border-color: rgba(88,166,255,.45); box-shadow: 0 0 0 1px rgba(88,166,255,.05); }
.accordion-item.active .accordion-body { display: grid; animation: slideDown .28s ease both; }
.accordion-item.active .accordion-head i { transform: rotate(180deg); color: var(--blue); }
@keyframes slideDown { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(13,17,23,.45);
}
.switch { position: relative; display: inline-flex; width: 54px; height: 30px; flex: 0 0 auto; }
.switch input { display: none; }
.switch b { position: absolute; inset: 0; border: 1px solid var(--border); border-radius: 999px; background: #30363D; transition: .2s ease; }
.switch b::after { content: ""; position: absolute; top: 4px; left: 4px; width: 20px; height: 20px; border-radius: 50%; background: var(--muted); transition: .2s var(--spring); }
.switch input:checked + b { border-color: rgba(88,166,255,.65); background: rgba(88,166,255,.35); }
.switch input:checked + b::after { left: 28px; background: var(--blue); box-shadow: 0 0 18px rgba(88,166,255,.45); }
.feature-list { display: grid; gap: 10px; }
.feature-row { display: grid; grid-template-columns: minmax(0, 1fr) 145px 42px; gap: 8px; align-items: center; }
.remove-feature { min-height: 42px; border: 1px solid rgba(248,81,73,.35); border-radius: 12px; background: rgba(248,81,73,.12); color: #ffd8d4; font-weight: 900; }
.preview-panel { position: sticky; top: 88px; }
.sticky-preview-head { margin-bottom: 12px; }
.prompt-preview {
  min-height: 420px;
  max-height: 70vh;
  overflow: auto;
  margin: 0;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #090d13;
  color: #d7e7ff;
  font: 400 13px/1.7 JetBrains Mono, monospace;
  white-space: pre-wrap;
  word-break: break-word;
}
.ai-refine-box { margin: 14px 0 16px; padding: 14px; border: 1px solid rgba(88,166,255,.22); border-radius: 16px; background: linear-gradient(135deg, rgba(88,166,255,.08), rgba(126,231,135,.04)); box-shadow: inset 0 0 0 1px rgba(255,255,255,.025); }
.action-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 12px; }
.action-grid .btn:first-child { grid-column: span 2; }
.history-panel { margin-top: 16px; }
.history-list { display: grid; gap: 10px; }
.history-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 14px; border: 1px solid var(--border); border-radius: 14px; background: rgba(13,17,23,.48); transition: border-color .15s ease, background .15s ease; }
.history-item:hover { border-color: rgba(88,166,255,.45); background: rgba(88,166,255,.06); }
.history-item h3 { margin: 0 0 6px; font-size: 15px; }
.history-item p { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; margin: 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.history-meta { margin-top: 8px; color: var(--ash); font: 800 11px JetBrains Mono, monospace; }
.history-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.empty-state { padding: 28px; border: 1px dashed var(--border); border-radius: 14px; color: var(--muted); text-align: center; }
.toast-host { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 80; display: grid; gap: 10px; width: min(420px, calc(100% - 32px)); pointer-events: none; }
.toast { padding: 13px 14px; border: 1px solid var(--border); border-radius: 14px; background: rgba(22,27,34,.96); box-shadow: var(--shadow); animation: toastIn .25s ease both; font-weight: 800; }
.toast.success { border-color: rgba(126,231,135,.35); color: #d6ffe0; }
.toast.error { border-color: rgba(248,81,73,.4); color: #ffd8d4; }
.toast.info { border-color: rgba(88,166,255,.45); color: #d7e7ff; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: translateY(0) scale(1); } }

/* Admin */
.admin-shell { display: grid; gap: 16px; }
.admin-form { margin-top: 16px; }
.check-row { display: flex; align-items: center; gap: 10px; }
.check-row input { width: auto; }
.compact-checks { align-items: center; }
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 14px; }
.admin-table { width: 100%; min-width: 720px; border-collapse: collapse; }
.admin-table th, .admin-table td { padding: 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.admin-table th { color: var(--blue); font-size: 12px; letter-spacing: .08em; text-transform: uppercase; }
.admin-table small { color: var(--muted); }
.admin-table .mono { max-width: 420px; word-break: break-word; }
.row-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.row-actions form { margin: 0; }
.admin-stats { grid-template-columns: repeat(5, minmax(0, 1fr)); margin-top: 0; }
.analytics-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-top: 0; }
.analytics-stats > div { min-height: 116px; }
.admin-menu-grid .feature-card { min-height: 170px; }
.two-col-admin { grid-template-columns: minmax(0, 1.3fr) minmax(300px, .9fr); }
.status-ok { color: var(--green); font-weight: 900; }
.status-error { color: var(--red); font-weight: 900; }
.storage-badge { display: inline-flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 999px; border: 1px solid rgba(126,231,135,.3); background: rgba(126,231,135,.08); color: #d6ffe0; font-size: 12px; font-weight: 900; }
.security-list { display: grid; gap: 8px; margin: 14px 0; padding: 0; }
.security-list li { list-style: none; padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; background: rgba(13,17,23,.35); }
.event-badge { display: inline-flex; align-items: center; padding: 7px 10px; border-radius: 999px; border: 1px solid rgba(88,166,255,.35); background: rgba(88,166,255,.08); color: #d7e7ff; font-size: 12px; font-weight: 900; white-space: nowrap; }
.ai-test-result { flex-basis: 100%; margin-top: 8px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; background: rgba(13,17,23,.5); color: var(--muted); font-size: 12px; line-height: 1.45; }
.ai-test-result.success { border-color: rgba(126,231,135,.45); background: rgba(126,231,135,.08); color: #d6ffe0; }
.ai-test-result.error { border-color: rgba(248,81,73,.45); background: rgba(248,81,73,.08); color: #ffd8d4; }
.ai-test-result.loading { border-color: rgba(88,166,255,.45); background: rgba(88,166,255,.08); color: #d7e7ff; }
.install-body { background: var(--bg); }
.install-done { display: grid; gap: 12px; }

/* Desktop wide */
@media (min-width: 1280px) {
  :root { --container: 1240px; }
  .studio-grid { grid-template-columns: 300px minmax(0, 1fr) 380px; }
}

/* Tablet landscape and small desktop */
@media (max-width: 1199px) {
  .studio-grid { grid-template-columns: minmax(0, 1fr) minmax(320px, .78fr); }
  .studio-grid > .template-panel { grid-column: 1 / -1; }
  .template-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .preview-panel { position: static; }
  .prompt-preview { min-height: 360px; max-height: none; }
  .engine-choice-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .admin-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .feature-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Tablet portrait */
@media (max-width: 980px) {
  :root { --safe-x: clamp(14px, 3vw, 24px); }
  .topbar { align-items: flex-start; flex-wrap: wrap; gap: 10px; }
  .top-actions { width: 100%; justify-content: flex-start; overflow-x: auto; padding-bottom: 2px; scrollbar-width: thin; }
  .top-actions::-webkit-scrollbar { height: 4px; }
  .top-actions::-webkit-scrollbar-thumb { background: rgba(88,166,255,.35); border-radius: 99px; }
  .studio-hero { grid-template-columns: 1fr; align-items: start; }
  .live-clock { text-align: left; width: 100%; min-width: 0; }
  .engine-choice-grid { grid-template-columns: 1fr; }
  .engine-choice { min-height: auto; }
  .studio-grid, .two-col-admin { grid-template-columns: 1fr; }
  .studio-grid > .template-panel { grid-column: auto; }
  .template-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .analytics-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .admin-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Mobile */
@media (max-width: 720px) {
  body { font-size: 14px; }
  .topbar { min-height: auto; padding: 10px 12px; }
  .brand-icon, .brand-mark { width: 38px; height: 38px; border-radius: 12px; }
  .brand small, .user-pill { display: none; }
  .icon-link { min-height: 36px; padding: 8px 10px; font-size: 13px; }
  .btn { width: 100%; min-height: 44px; padding: 11px 13px; }
  .top-actions .btn { width: auto; }
  .btn.mini { width: auto; padding: 8px 10px; }
  .page-shell, .studio-shell { width: calc(100% - 20px); padding: 20px 0; }
  .hero { padding: 24px 18px; }
  .hero h1, .studio-hero h1, .admin-shell h1 { font-size: clamp(32px, 11vw, 42px); letter-spacing: -.04em; }
  .hero-actions, .row-actions { flex-direction: column; align-items: stretch; }
  .row-actions .btn, .row-actions select, .row-actions form, .row-actions form .btn { width: 100%; }
  .stats-grid, .feature-grid, .grid-2, .settings-grid, .template-grid, .analytics-stats, .admin-stats { grid-template-columns: 1fr; }
  .stats-grid > div, .feature-card, .blueprint-panel { border-radius: 14px; }
  .footer { width: calc(100% - 20px); display: grid; gap: 6px; padding-bottom: 26px; }
  .auth-card, .install-card { padding: 20px; }
  .studio-hero, .engine-selector, .template-panel, .builder-panel, .preview-panel, .history-panel { padding: 16px; }
  .studio-hero::after, .hero::after { display: none; }
  .public-mode-note { border-radius: 14px; }
  .live-clock span { font-size: 24px; }
  .panel-head { display: grid; gap: 10px; }
  .panel-head .btn { width: auto; justify-self: start; }
  .engine-current { width: fit-content; }
  .engine-choice { grid-template-columns: auto minmax(0, 1fr); padding: 14px; }
  .engine-choice small { grid-column: 1 / -1; }
  .engine-icon { width: 42px; height: 42px; border-radius: 14px; }
  .accordion-head { min-height: 54px; padding: 0 12px; }
  .accordion-body { padding: 0 12px 12px; }
  input, select, textarea { padding: 12px 13px; }
  .toggle-row { align-items: flex-start; }
  .feature-row { grid-template-columns: 1fr; }
  .remove-feature { width: 100%; }
  .prompt-preview { min-height: 300px; font-size: 12px; }
  .ai-refine-box .grid-2 { grid-template-columns: 1fr; }
  .action-grid { grid-template-columns: 1fr; }
  .action-grid .btn:first-child { grid-column: auto; }
  .history-item { grid-template-columns: 1fr; }
  .history-actions { justify-content: flex-start; }
  .table-wrap { margin-inline: -4px; width: calc(100% + 8px); }
  .admin-table { min-width: 680px; }
}

/* Small mobile */
@media (max-width: 420px) {
  .brand strong { font-size: 14px; }
  .hero-badge { font-size: 10px; white-space: normal; }
  .hero h1, .studio-hero h1, .admin-shell h1 { font-size: 32px; }
  .stats-grid strong { font-size: 24px; }
  .engine-choice { grid-template-columns: 1fr; }
  .engine-choice b { padding-right: 30px; }
  .engine-choice small { grid-column: auto; }
  .toast-host { width: calc(100% - 20px); bottom: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
