:root {
  color-scheme: dark;
  --bg: #0f1419;
  --panel: #1a2332;
  --panel-border: #2a3544;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --blocked: #6b7280;
  --row-valid: rgba(34, 197, 94, 0.08);
  --row-blocked: rgba(107, 114, 128, 0.12);
  --row-invalid: rgba(239, 68, 68, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  border-bottom: 1px solid var(--panel-border);
  background: var(--panel);
  gap: 16px;
}

.topbar-title h1 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 600;
}

.topbar-title p {
  margin: 2px 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}

.env-switch {
  display: flex;
  padding: 3px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--panel-border);
}

.env-btn {
  padding: 6px 14px;
  border: none;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  color: var(--muted);
  width: auto;
  margin: 0;
}

.env-btn.active {
  background: rgba(59, 130, 246, 0.2);
  color: var(--accent);
}

.env-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.user-slot.authenticated {
  opacity: 1;
  border-style: solid;
}

.user-slot.authenticated .user-avatar {
  background: var(--accent-dim, #1a3d2e);
  color: var(--accent, #3ecf8e);
  font-weight: 600;
  font-size: 0.65rem;
}

.user-slot.authenticated .user-label {
  color: var(--text, #e8eaed);
  max-width: 10rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-logout {
  margin-left: 2px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.7rem;
  color: var(--muted);
  text-decoration: none;
  border: 1px solid transparent;
  background: transparent;
  font: inherit;
  cursor: pointer;
}

.login-callback {
  display: grid;
  place-items: center;
  min-height: 60vh;
  color: var(--muted);
}

.auth-pending .layout,
.auth-pending .topbar {
  visibility: hidden;
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  background: var(--bg, #0f1114);
  color: var(--muted);
  padding: 1.5rem;
  text-align: center;
}

.auth-gate[hidden] {
  display: none;
}

.auth-gate-error {
  color: #ffb4ab;
  max-width: 36rem;
}

.user-logout:hover {
  color: var(--text, #e8eaed);
  border-color: var(--panel-border);
  background: rgba(255, 255, 255, 0.04);
}

.user-slot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 4px;
  border-radius: 999px;
  border: 1px dashed var(--panel-border);
  opacity: 0.7;
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--panel-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  color: var(--muted);
}

.user-label {
  font-size: 0.75rem;
  color: var(--muted);
}

.layout {
  display: grid;
  grid-template-columns: minmax(300px, 24rem) minmax(360px, 1fr) minmax(240px, 18rem);
  gap: 0;
  height: calc(100vh - 57px);
  max-width: 1680px;
  margin: 0 auto;
}

.panel {
  border-right: 1px solid var(--panel-border);
  overflow: hidden;
  min-height: 0;
}

.panel:last-child {
  border-right: none;
}

.panel h2 {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}

/* ── Source panel ── */

.source-panel {
  display: flex;
  flex-direction: column;
  background: var(--panel);
}

.panel-head {
  flex-shrink: 0;
  padding: 18px 18px 12px;
  border-bottom: 1px solid var(--panel-border);
}

.panel-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.panel-head-row h2 {
  margin: 0;
}

.btn-text {
  width: auto;
  margin: 0;
  padding: 4px 8px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  border-radius: 4px;
}

.btn-text:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.panel-head h2 {
  margin-bottom: 0;
}

.flow-steps {
  display: flex;
  gap: 0;
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.7rem;
  color: var(--muted);
}

.flow-steps li {
  display: flex;
  align-items: center;
  gap: 6px;
}

.flow-steps li:not(:last-child)::after {
  content: "›";
  margin: 0 8px;
  opacity: 0.4;
}

.flow-steps li.active {
  color: var(--accent);
  font-weight: 600;
}

.flow-steps li.done {
  color: var(--success);
}

.source-form {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.source-scroll {
  flex: 0 0 auto;
  padding: 12px 18px 0;
}

.source-section {
  margin-bottom: 14px;
}

.source-section--last {
  margin-bottom: 0;
}

.field--tight {
  margin-bottom: 0;
}

.section-title {
  margin: 0 0 10px;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  opacity: 0.85;
}

.field {
  display: block;
  margin-bottom: 12px;
}

.field-label {
  display: block;
  margin-bottom: 5px;
  font-size: 0.78rem;
  color: var(--muted);
}

.source-panel label.field {
  margin-bottom: 12px;
}

.source-actions {
  flex: 0 0 auto;
  margin-top: 14px;
  padding: 14px 18px 14px;
  border-top: 1px solid var(--panel-border);
  background: color-mix(in srgb, var(--bg) 35%, var(--panel));
}

.action-status {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 0.78rem;
  line-height: 1.4;
  margin-bottom: 10px;
  min-height: auto;
}

.status-dot {
  flex-shrink: 0;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-top: 5px;
  background: var(--muted);
  opacity: 0.5;
}

.action-status.ready .status-dot {
  background: var(--success);
  opacity: 1;
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.5);
}

.action-status.warn .status-dot {
  background: var(--warn);
  opacity: 1;
}

.action-buttons {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 8px;
}

.action-footnote {
  margin: 10px 0 0;
  font-size: 0.7rem;
  color: var(--muted);
  text-align: center;
}

.action-footnote code {
  font-size: 0.68rem;
  color: var(--text);
  opacity: 0.7;
}

.kbd-hint {
  opacity: 0.55;
}

.history-panel h2 {
  margin-bottom: 14px;
}

.chip input {
  width: auto;
  margin: 0;
}

.label-hint {
  font-weight: 400;
  opacity: 0.7;
}

input,
select,
textarea,
button {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  font: inherit;
  font-size: 0.85rem;
  background: var(--bg);
  color: var(--text);
}

textarea {
  resize: vertical;
  min-height: 72px;
  font-family: ui-monospace, monospace;
  font-size: 0.78rem;
}

.source-toggle {
  border: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 0;
  padding: 6px 10px;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  font-size: 0.78rem;
  cursor: pointer;
  background: var(--bg);
}

.chip:has(input:checked) {
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.12);
  color: var(--accent);
}

.checkbox-label {
  display: flex !important;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--text);
  margin-bottom: 4px;
}

.checkbox-label input {
  width: auto;
  margin: 0;
}

.field-hint {
  margin: 0 0 12px;
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.4;
}

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.btn {
  font-weight: 600;
  cursor: pointer;
  border: none;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.84rem;
  transition: background 0.15s, opacity 0.15s;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-primary:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--panel-border);
  color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
  background: #3a4556;
}

.btn-danger {
  background: rgba(239, 68, 68, 0.85);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  border: none;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.84rem;
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger);
}

.revert-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin: 0 0 12px;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid rgba(239, 68, 68, 0.4);
  background: rgba(239, 68, 68, 0.08);
  flex-shrink: 0;
}

.revert-bar[hidden] {
  display: none !important;
}

.revert-bar-text {
  font-size: 0.82rem;
  line-height: 1.4;
}

.revert-bar-text strong {
  display: block;
  color: var(--danger);
  margin-bottom: 2px;
}

.revert-bar-text span {
  color: var(--muted);
}

.revert-bar-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.revert-bar-actions .btn {
  width: auto;
  white-space: nowrap;
}

.preview-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 18px 20px;
  overflow-y: auto;
}

.history-panel {
  padding: 18px;
  overflow-y: auto;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  gap: 12px;
  flex-wrap: wrap;
}

.preview-stats {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.stat-chip {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
}

.stat-chip.valid {
  background: rgba(34, 197, 94, 0.15);
  color: var(--success);
}

.stat-chip.blocked {
  background: rgba(107, 114, 128, 0.2);
  color: var(--blocked);
}

.stat-chip.invalid {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
}

.preview-banner {
  margin: 0 0 10px;
  font-size: 0.82rem;
  padding: 8px 12px;
  border-radius: 6px;
  background: var(--bg);
  border: 1px solid var(--panel-border);
}

.preview-banner.ready {
  border-color: rgba(34, 197, 94, 0.3);
  color: var(--success);
  background: rgba(34, 197, 94, 0.06);
}

.preview-banner.warn {
  border-color: rgba(245, 158, 11, 0.35);
  color: var(--warn);
  background: rgba(245, 158, 11, 0.06);
}

.table-wrap {
  flex: 0 1 auto;
  overflow: auto;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: var(--bg);
  max-height: min(60vh, 520px);
}

.table-wrap.has-rows {
  flex: 1;
  min-height: 120px;
}

.preview-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

.preview-table th {
  position: sticky;
  top: 0;
  background: var(--panel);
  text-align: left;
  padding: 8px 10px;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 1px solid var(--panel-border);
}

.preview-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--panel-border);
  vertical-align: top;
  word-break: break-word;
}

.preview-table td.path-cell {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-table tr.row-valid {
  background: var(--row-valid);
}

.preview-table tr.row-blocked {
  background: var(--row-blocked);
  color: var(--muted);
}

.preview-table tr.row-invalid {
  background: var(--row-invalid);
}

.status-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
}

.status-pill.valid {
  background: rgba(34, 197, 94, 0.2);
  color: var(--success);
}

.status-pill.blocked {
  background: rgba(107, 114, 128, 0.25);
  color: var(--blocked);
}

.status-pill.invalid {
  background: rgba(239, 68, 68, 0.2);
  color: var(--danger);
}

.action-tag {
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.7rem;
}

.action-tag.add { color: var(--success); }
.action-tag.remove { color: var(--danger); }
.action-tag.replace { color: var(--warn); }

.empty-state {
  padding: 24px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
  margin: 0;
}

.table-wrap:not(.has-rows) {
  min-height: 0;
}

.log-details {
  margin-top: 12px;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.deploy-checklist[hidden],
.verify-section[hidden] {
  display: none !important;
}

.deploy-checklist {
  margin: 0 0 12px;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid rgba(59, 130, 246, 0.35);
  background: rgba(59, 130, 246, 0.06);
  font-size: 0.78rem;
}

.checklist-title {
  margin: 0 0 8px;
  font-weight: 600;
  color: var(--accent);
}

.checklist-steps {
  margin: 0;
  padding-left: 1.2rem;
  color: var(--muted);
  line-height: 1.6;
}

.checklist-steps li.done {
  color: var(--success);
  list-style-type: "✓ ";
}

.checklist-steps code {
  font-size: 0.72rem;
}

.verify-section {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--panel-border);
  flex-shrink: 0;
}

.url-probe-section {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--panel-border);
  flex-shrink: 0;
}

.field--probe {
  margin-bottom: 10px;
}

.field--probe textarea {
  width: 100%;
  min-height: 72px;
  font-family: var(--mono, ui-monospace, monospace);
  font-size: 0.78rem;
}

.verify-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 10px;
}

.verify-title {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.verify-sub {
  margin: 4px 0 0;
  font-size: 0.72rem;
  color: var(--muted);
  opacity: 0.85;
}

.btn-verify {
  width: auto;
  flex-shrink: 0;
  white-space: nowrap;
}

.verify-results {
  font-size: 0.78rem;
}

.verify-table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  overflow: hidden;
}

.verify-table th,
.verify-table td {
  padding: 7px 10px;
  text-align: left;
  border-bottom: 1px solid var(--panel-border);
}

.verify-table th {
  background: var(--panel);
  color: var(--muted);
  font-size: 0.7rem;
  text-transform: uppercase;
}

.verify-table tr:last-child td {
  border-bottom: none;
}

.verify-table tr.pass td:first-child {
  color: var(--success);
}

.verify-table tr.fail td:first-child {
  color: var(--danger);
}

.verify-table a {
  color: var(--accent);
  text-decoration: none;
}

.verify-table a:hover {
  text-decoration: underline;
}

.verify-summary {
  margin: 0 0 8px;
  font-size: 0.8rem;
}

.verify-summary.pass {
  color: var(--success);
}

.verify-summary.fail {
  color: var(--warn);
}

.log-details summary {
  cursor: pointer;
  color: var(--muted);
  margin-bottom: 8px;
}

.output {
  margin: 0;
  max-height: 200px;
  overflow: auto;
  background: #0a0e14;
  color: #94a3b8;
  padding: 12px;
  border-radius: 6px;
  font-size: 0.75rem;
  white-space: pre-wrap;
  border: 1px solid var(--panel-border);
}

.runs-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.run-card {
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: var(--bg);
  overflow: hidden;
}

.run-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.25);
}

.run-card-header {
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
  font: inherit;
}

.run-card-header:hover {
  background: rgba(255, 255, 255, 0.03);
}

.run-time {
  font-size: 0.7rem;
  color: var(--muted);
}

.run-label-text {
  font-size: 0.82rem;
  font-weight: 500;
  margin-top: 2px;
}

.run-badges {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.badge {
  font-size: 0.65rem;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--panel-border);
  color: var(--muted);
}

.badge.changed {
  background: rgba(34, 197, 94, 0.15);
  color: var(--success);
}

.revert-btn {
  width: 100%;
  margin: 0;
  padding: 8px;
  border-top: 1px solid var(--panel-border);
  border-radius: 0;
  background: transparent;
  color: var(--warn);
  font-size: 0.78rem;
  cursor: pointer;
}

.revert-btn:hover:not(:disabled) {
  background: rgba(245, 158, 11, 0.08);
}

.muted {
  color: var(--muted);
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
    height: auto;
    min-height: calc(100vh - 57px);
  }

  .source-panel {
    max-height: none;
  }

  .source-scroll {
    max-height: none;
  }

  .panel {
    border-right: none;
    border-bottom: 1px solid var(--panel-border);
    overflow: visible;
  }

  .preview-panel {
    min-height: 50vh;
  }
}
