/* Rebuildy Studio stylesheet */
:root {
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --topbar: #0b1120;
  --topbar-border: #1e293b;
  --brand: #10b981;
  --brand-dark: #059669;
  --brand-soft: #ecfdf5;
  --ok-bg: #ecfdf5;
  --ok-fg: #047857;
  --ok-bd: #a7f3d0;
  --warn-bg: #fffbeb;
  --warn-fg: #b45309;
  --warn-bd: #fde68a;
  --fail-bg: #fff1f2;
  --fail-fg: #be123c;
  --fail-bd: #fecdd3;
  --info-bg: #f0f9ff;
  --info-fg: #0369a1;
  --info-bd: #bae6fd;
  --neutral-bg: #f1f5f9;
  --neutral-fg: #475569;
  --neutral-bd: #cbd5e1;
  --radius: 8px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
  --font-sans: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: 52px;
  background: var(--topbar);
  border-bottom: 1px solid var(--topbar-border);
  color: #f8fafc;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  gap: 16px;
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #ffffff;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.02em;
  text-decoration: none;
}
.brand:hover { text-decoration: none; opacity: 0.92; }
.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--brand);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.22);
}
.brand-sub {
  color: #64748b;
  font-weight: 500;
  font-size: 12px;
}

.nav {
  display: flex;
  align-items: center;
  gap: 4px;
}
.nav a {
  color: #cbd5e1;
  font-size: 13px;
  font-weight: 500;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: background 0.12s, color 0.12s;
}
.nav a:hover { background: rgba(255, 255, 255, 0.08); color: #ffffff; }
.nav a.active { background: rgba(16, 185, 129, 0.16); color: #6ee7b7; }

.pulse-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: #94a3b8;
  font-family: var(--font-mono);
}
.pulse-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: #cbd5e1;
  white-space: nowrap;
}
.pulse-chip strong { color: #ffffff; font-weight: 600; }
.pulse-chip.live { background: rgba(16, 185, 129, 0.18); color: #6ee7b7; }

.btn-logout {
  background: transparent;
  border: 1px solid #334155;
  color: #cbd5e1;
  font-size: 12px;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.btn-logout:hover { border-color: #64748b; color: #ffffff; }

/* Page shell */
.container {
  max-width: 1440px;
  margin: 0 auto;
  padding: 20px 22px 48px;
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.page-head h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.page-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

/* Metric cards */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.metric-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow-sm);
}
.metric-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
}
.metric-value {
  font-size: 22px;
  font-weight: 700;
  margin-top: 4px;
  font-family: var(--font-mono);
  letter-spacing: -0.02em;
}
.metric-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

/* Filter bar */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}
.pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink-2);
  text-decoration: none;
  transition: border-color 0.12s, background 0.12s;
}
.pill:hover { border-color: var(--line-strong); text-decoration: none; color: var(--ink); }
.pill.active {
  background: var(--ink);
  border-color: var(--ink);
  color: #ffffff;
}
.pill .cnt {
  font-family: var(--font-mono);
  font-size: 11px;
  opacity: 0.8;
}

.search-form {
  display: flex;
  align-items: center;
  gap: 6px;
}
.input, select, textarea {
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  outline: none;
}
.input:focus, select:focus, textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover { background: #f8fafc; border-color: #94a3b8; text-decoration: none; }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn-primary { background: var(--ink); border-color: var(--ink); color: #ffffff; }
.btn-primary:hover { background: #1e293b; border-color: #1e293b; color: #ffffff; }
.btn-approve { background: var(--brand-dark); border-color: var(--brand-dark); color: #ffffff; }
.btn-approve:hover { background: #047857; border-color: #047857; color: #ffffff; }
.btn-hold { background: var(--fail-bg); border-color: var(--fail-bd); color: var(--fail-fg); }
.btn-hold:hover { background: #ffe4e6; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--neutral-bg); }
.btn.is-active {
  background: var(--ink);
  border-color: var(--ink);
  color: #ffffff;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
  font-family: var(--font-mono);
}
.badge-pass, .badge-approved, .badge-ok, .badge-done {
  background: var(--ok-bg); color: var(--ok-fg); border-color: var(--ok-bd);
}
.badge-warn, .badge-flag, .badge-drafted, .badge-check, .badge-running, .badge-queued {
  background: var(--warn-bg); color: var(--warn-fg); border-color: var(--warn-bd);
}
.badge-fail, .badge-hold, .badge-error, .badge-stopped {
  background: var(--fail-bg); color: var(--fail-fg); border-color: var(--fail-bd);
}
.badge-info, .badge-sent {
  background: var(--info-bg); color: var(--info-fg); border-color: var(--info-bd);
}
.badge-none, .badge-neutral {
  background: var(--neutral-bg); color: var(--neutral-fg); border-color: var(--neutral-bd);
}

/* Cards & Tables */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.card-head {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.card-head h2, .card-head h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}
.card-body { padding: 14px 16px; }

.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th {
  text-align: left;
  padding: 9px 12px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  background: #f8fafc;
  border-bottom: 1px solid var(--line);
  font-weight: 600;
  white-space: nowrap;
}
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }

.biz-title {
  font-weight: 600;
  color: var(--ink);
  display: block;
}
.biz-meta {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}
.gate-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.mono { font-family: var(--font-mono); font-size: 12px; }
.muted { color: var(--muted); }

/* Split Review Studio */
body.studio-page { overflow: hidden; }
.studio-wrap {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 52px);
}
.studio-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 8px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}
.studio-ident {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.studio-ident h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.studio-nav {
  display: flex;
  align-items: center;
  gap: 6px;
}

.studio-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 400px;
  flex: 1;
  min-height: 0;
}

.studio-stage {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: #e2e8f0;
  border-right: 1px solid var(--line-strong);
}
.stage-bar {
  background: #f8fafc;
  border-bottom: 1px solid var(--line);
  padding: 6px 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}
.stage-tabs, .stage-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}
.stage-body {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: auto;
  display: flex;
  flex-direction: column;
}
.stage-pane {
  display: none;
  flex: 1;
  min-height: 0;
  width: 100%;
  height: 100%;
}
.stage-pane.active { display: flex; flex-direction: column; }

.iframe-shell {
  flex: 1;
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: 0;
  background: #cbd5e1;
  overflow: auto;
}
.iframe-shell.phone-mode {
  padding: 18px;
  align-items: flex-start;
}
.preview-frame {
  width: 100%;
  height: 100%;
  border: none;
  background: #ffffff;
}
.iframe-shell.phone-mode .preview-frame {
  width: 390px;
  height: 844px;
  flex-shrink: 0;
  border-radius: 22px;
  border: 6px solid #0f172a;
  box-shadow: var(--shadow-md);
}

.compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  padding: 14px;
  overflow: auto;
  height: 100%;
  background: var(--bg);
}
.compare-col {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 460px;
}
.compare-col-head {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  font-weight: 600;
  background: #f8fafc;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.compare-shots {
  padding: 12px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.compare-shots img {
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  display: block;
}

.pdf-head {
  padding: 8px 12px;
  background: #f8fafc;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
}
.pdf-frame {
  flex: 1;
  width: 100%;
  border: none;
  background: #334155;
}

/* Right audit rail */
.studio-rail {
  background: var(--bg);
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.rail-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow-sm);
}
.rail-card.alert-card {
  border-color: var(--warn-bd);
  background: #fffdf5;
}
.rail-title {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.decision-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}
.decision-row:last-child { border-bottom: none; padding-bottom: 0; }
.decision-btns { display: flex; gap: 5px; }

.flag-list {
  margin: 0;
  padding-left: 16px;
  font-size: 12.5px;
  color: var(--ink-2);
}
.flag-list li { margin-bottom: 5px; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}
.form-grid .full { grid-column: 1 / -1; }
.field label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 3px;
}
.field .input, .field select, .field textarea { width: 100%; }

details.audit-item {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  background: #fcfcfd;
}
details.audit-item summary {
  padding: 7px 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12.5px;
  font-weight: 600;
  list-style: none;
}
details.audit-item summary::-webkit-details-marker { display: none; }
.audit-body {
  padding: 8px 10px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--ink-2);
}
.audit-body ul { margin: 4px 0 6px; padding-left: 16px; }
.audit-body li { margin-bottom: 3px; }

.empty-state {
  padding: 36px 20px;
  text-align: center;
  color: var(--muted);
}

/* Login */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at top, #1e293b 0%, #0b1120 65%);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: #ffffff;
  border-radius: 12px;
  padding: 28px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.35);
}
.login-card h1 {
  margin: 0 0 4px;
  font-size: 20px;
  letter-spacing: -0.02em;
}
.login-card p {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 13px;
}
.login-err {
  background: var(--fail-bg);
  color: var(--fail-fg);
  border: 1px solid var(--fail-bd);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 12.5px;
  margin-bottom: 12px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 18px;
  right: 18px;
  z-index: 90;
  background: var(--topbar);
  color: #ffffff;
  padding: 9px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.16s, transform 0.16s;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* Queue & Ops grids */
.two-col {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
  align-items: start;
}
.thumb-sm {
  width: 44px;
  height: 70px;
  object-fit: cover;
  object-position: top;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: #f1f5f9;
}
.meter {
  height: 8px;
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
  margin: 8px 0;
}
.meter > span {
  display: block;
  height: 100%;
  background: var(--brand);
}
.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  font-size: 13px;
}

@media (max-width: 1080px) {
  body.studio-page { overflow: auto; }
  .studio-wrap { height: auto; }
  .studio-split { grid-template-columns: 1fr; }
  .studio-stage { height: 72vh; border-right: none; border-bottom: 1px solid var(--line-strong); }
  .two-col { grid-template-columns: 1fr; }
  .pulse-strip { display: none; }
}
