:root {
  color-scheme: dark;
  --bg: #0d1117;
  --rail: #111722;
  --surface: #151b26;
  --surface-muted: #101620;
  --surface-hover: #1a2230;
  --line: #263142;
  --line-strong: #344155;
  --text: #f4f7fb;
  --muted: #9ca8b8;
  --soft: #738093;
  --accent: #7dd3fc;
  --accent-strong: #38bdf8;
  --accent-text: #062335;
  --danger: #fb7185;
  --danger-bg: rgba(251, 113, 133, 0.1);
  --green: #5eead4;
  --amber: #fbbf24;
  --orange: #fb923c;
  --blue: #60a5fa;
  --red: #f87171;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.24);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background: var(--bg);
  overflow-x: hidden;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  min-height: 100vh;
}

.rail {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 100vh;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: var(--rail);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 4px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--accent);
  background: var(--surface);
  font-weight: 800;
  letter-spacing: 0;
}

.brand strong,
.workspace-card strong {
  display: block;
  font-size: 1rem;
}

.brand span,
.workspace-card span,
.note,
.panel-heading p,
.section-title p,
#envMeta {
  color: var(--muted);
  font-size: 0.86rem;
}

.auth-panel,
.workspace-card,
.surface {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.auth-panel,
.surface {
  padding: 18px;
}

.panel-heading h1,
.topbar h1,
.section-title h2,
.empty-state h2,
.dialog-card h2 {
  margin: 0;
  letter-spacing: 0;
}

.panel-heading h1 {
  font-size: 1.25rem;
}

.stack,
.diff-controls,
.history-list {
  display: grid;
  gap: 12px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin: 16px 0;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
}

.segment,
.ghost,
.primary,
.danger,
.icon-button {
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  color: var(--text);
  background: transparent;
  transition:
    border-color 140ms ease,
    background 140ms ease,
    color 140ms ease;
}

.segment:hover,
.ghost:hover,
.danger:hover,
.icon-button:hover,
.tiny:hover,
.env-tab:hover {
  border-color: var(--accent-strong);
  background: var(--surface-hover);
}

.segment.active,
.primary {
  border-color: var(--accent-strong);
  color: var(--accent-text);
  background: var(--accent);
  font-weight: 700;
}

.primary:hover {
  background: var(--accent-strong);
}

.danger {
  border-color: rgba(251, 113, 133, 0.45);
  color: var(--danger);
  background: var(--danger-bg);
}

.full {
  width: 100%;
}

.compact {
  min-height: 36px;
  padding: 0 12px;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  min-height: 34px;
  font-size: 1.2rem;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 650;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  background: var(--surface-muted);
  outline: none;
}

input,
select {
  min-height: 42px;
  padding: 0 12px;
}

textarea {
  min-height: 180px;
  padding: 12px;
  resize: vertical;
  line-height: 1.45;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent-strong);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.14);
}

.workspace-card {
  padding: 14px;
  margin-bottom: 10px;
}

.eyebrow {
  display: block;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.section-title h2 {
  font-size: 1rem;
}

.list {
  display: grid;
  gap: 8px;
}

.list-item,
.env-tab,
.history-item {
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  background: var(--surface-muted);
}

.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 44px;
  padding: 0 12px;
}

.list-item.active,
.env-tab.active {
  border-color: var(--accent-strong);
  background: rgba(56, 189, 248, 0.1);
}

.main {
  min-width: 0;
  padding: 28px;
}

.loading-state,
.empty-state {
  display: grid;
  place-items: center;
  align-content: center;
  min-height: calc(100vh - 56px);
  text-align: center;
  color: var(--muted);
}

.loading-state h2,
.empty-state h2 {
  max-width: 620px;
  color: var(--text);
  font-size: clamp(1.8rem, 4vw, 3.25rem);
  line-height: 1.05;
}

.loading-state p,
.empty-state p {
  max-width: 520px;
  font-size: 0.98rem;
}

.spinner {
  width: 48px;
  height: 48px;
  margin-bottom: 22px;
  border: 3px solid var(--line-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 780ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.signal {
  width: 64px;
  height: 64px;
  margin-bottom: 22px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background:
    linear-gradient(90deg, transparent 47%, var(--accent) 47%, var(--accent) 53%, transparent 53%),
    linear-gradient(0deg, transparent 47%, var(--accent) 47%, var(--accent) 53%, transparent 53%),
    var(--surface);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.topbar h1 {
  font-size: clamp(1.85rem, 3vw, 3rem);
  line-height: 1.05;
}

.toolbar,
.button-pair {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.env-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 14px;
}

.env-tab {
  min-width: 108px;
  min-height: 40px;
  padding: 0 14px;
}

.env-tab.env-dev {
  border-color: rgba(96, 165, 250, 0.5);
  color: #bfdbfe;
  background: rgba(96, 165, 250, 0.09);
}

.env-tab.env-dev.active {
  border-color: var(--blue);
  background: rgba(96, 165, 250, 0.22);
}

.env-tab.env-staging {
  border-color: rgba(251, 146, 60, 0.5);
  color: #fed7aa;
  background: rgba(251, 146, 60, 0.09);
}

.env-tab.env-staging.active {
  border-color: var(--orange);
  background: rgba(251, 146, 60, 0.22);
}

.env-tab.env-prod {
  border-color: rgba(248, 113, 113, 0.5);
  color: #fecaca;
  background: rgba(248, 113, 113, 0.09);
}

.env-tab.env-prod.active {
  border-color: var(--red);
  background: rgba(248, 113, 113, 0.22);
}

.work-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.surface {
  min-width: 0;
  box-shadow: var(--shadow);
}

.variable-form {
  display: grid;
  grid-template-columns: minmax(150px, 0.8fr) minmax(180px, 1fr) auto auto;
  gap: 10px;
  margin-bottom: 14px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
}

table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

th {
  color: var(--soft);
  font-size: 0.72rem;
  text-transform: uppercase;
}

td code,
.diff-key {
  color: var(--accent);
  font-family: "SFMono-Regular", Consolas, monospace;
}

.masked {
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, monospace;
}

.revealed-value {
  color: var(--text);
  font-family: "SFMono-Regular", Consolas, monospace;
  overflow-wrap: anywhere;
}

.row-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.tiny {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: transparent;
  transition:
    border-color 140ms ease,
    background 140ms ease;
}

.history-item {
  padding: 12px;
}

.history-item strong {
  display: block;
}

.history-item span {
  color: var(--muted);
  font-size: 0.82rem;
}

.history-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.diff-result {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.diff-row {
  display: grid;
  gap: 4px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-muted);
}

.diff-row.added {
  border-left: 3px solid var(--green);
}

.diff-row.removed {
  border-left: 3px solid var(--danger);
}

.diff-row.changed {
  border-left: 3px solid var(--amber);
}

.diff-values {
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.82rem;
  overflow-wrap: anywhere;
}

.hidden {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

dialog {
  border: none;
  padding: 0;
  background: transparent;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.64);
}

.dialog-card {
  display: grid;
  gap: 16px;
  width: min(420px, calc(100vw - 36px));
  padding: 20px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.modal-card {
  width: min(680px, calc(100vw - 36px));
  max-height: min(760px, calc(100vh - 36px));
  overflow: auto;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 3;
  max-width: 360px;
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  transition: 160ms ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .rail {
    position: static;
    min-height: auto;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }

  .work-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .main,
  .rail {
    padding: 16px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .toolbar,
  .button-pair {
    justify-content: flex-start;
  }

  .section-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .variable-form {
    grid-template-columns: 1fr;
  }
}
