/*
 * Proposal Studio — slate & ice-cyan theme (light + dark), from Dopely palette #554:
 * #000000 · #323E4F · #3B495D · #ADEEFC.
 *
 * Slate carries text and structure, ice cyan is the single accent; muted teal/coral
 * for status. Every text/background pair below was checked with the a11y-audit
 * contrast_checker: body text ≥ 10:1, muted/accent text ≥ 4.5:1, UI borders ≥ 3:1.
 *
 * Dark mode follows the OS by default; html[data-theme] (set by theme.js from the
 * sidebar/login toggle) overrides it. The proposal sheet itself keeps its own brand colours.
 */

:root {
  color-scheme: light;

  /* Surfaces */
  --bg: #EDF1F5;               /* page background */
  --surface: #F7F9FB;          /* header, editor pane, cards */
  --surface-sunken: #E7ECF1;   /* inputs, checkboxes, rows */
  --preview-bg: #DCE3EA;       /* backdrop behind the A4 sheet */
  --paper: #F8F4EC;            /* the sheet itself (matches the proposal) */

  /* Sidebar & preview toolbar */
  --sidebar-bg: #E3E9F0;
  --sidebar-text: #323E4F;
  --sidebar-muted: #5A6778;
  --sidebar-active-bg: #CFE9F2;
  --sidebar-border: #D3DBE4;
  --toolbar-bg: #323E4F;
  --toolbar-text: #E6EEF4;

  /* Text */
  --text: #263040;
  --text-strong: #323E4F;
  --text-muted: #5A6778;

  /* Lines */
  --border: #D3DBE4;
  --border-subtle: #E3E9F0;

  /* Accent: warm clay */
  --accent: #323E4F;
  --accent-hover: #3B495D;
  --on-accent: #ADEEFC;
  --accent-text: #3B495D;
  --accent-soft: rgba(173, 238, 252, 0.45);
  --accent-ring: rgba(59, 73, 93, 0.22);

  /* Status: muted sage / terracotta */
  --success: #3E8A76;
  --success-text: #2F6B5E;
  --success-soft: rgba(62, 138, 118, 0.14);
  --danger: #C0504B;
  --danger-text: #A8423F;
  --danger-soft: rgba(192, 80, 75, 0.10);

  /* States & effects */
  --disabled-bg: rgba(50, 62, 79, 0.08);
  --disabled-text: rgba(50, 62, 79, 0.40);
  --hover-tint: rgba(50, 62, 79, 0.05);
  --scrim: rgba(237, 241, 245, 0.88);
  --overlay: rgba(0, 0, 0, 0.55);
  --overlay-text: #E6EEF4;
  --switch-off: rgba(173, 238, 252, 0.25);
  --knob: #FFFFFF;
  --logo-chip: transparent;

  /* Fixed chip over the (always light) A4 sheet */
  --chip-bg: rgba(50, 62, 79, 0.90);
  --chip-text: #ADEEFC;

  --shadow-soft: 0 10px 30px rgba(50, 62, 79, 0.07);
  --shadow-strong: 0 20px 40px rgba(50, 62, 79, 0.12);
  --radius: 12px;
  --transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

/* Dark: warm charcoal, never pure black. Defined twice: once for the OS preference,
   once for the explicit toggle. Keep both blocks identical. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #1E2632;
    --surface: #323E4F;
    --surface-sunken: #2A3443;
    --preview-bg: #141A22;
    --sidebar-bg: #171D26;
    --sidebar-text: #E6EEF4;
    --sidebar-muted: #9AA8B9;
    --sidebar-active-bg: #3B495D;
    --sidebar-border: #2A3443;
    --toolbar-bg: #3B495D;
    --toolbar-text: #E6EEF4;
    --text: #E6EEF4;
    --text-strong: #F2F7FA;
    --text-muted: #A9B6C6;
    --border: #46556B;
    --border-subtle: #3B495D;
    --accent: #ADEEFC;
    --accent-hover: #C6F4FD;
    --on-accent: #0F141B;
    --accent-text: #ADEEFC;
    --accent-soft: rgba(173, 238, 252, 0.12);
    --accent-ring: rgba(173, 238, 252, 0.28);
    --success: #8FD9C4;
    --success-text: #8FD9C4;
    --success-soft: rgba(143, 217, 196, 0.14);
    --danger: #F4A6A1;
    --danger-text: #F4A6A1;
    --danger-soft: rgba(244, 166, 161, 0.14);
    --disabled-bg: rgba(230, 238, 244, 0.08);
    --disabled-text: rgba(230, 238, 244, 0.35);
    --hover-tint: rgba(230, 238, 244, 0.05);
    --scrim: rgba(30, 38, 50, 0.88);
    --overlay: rgba(0, 0, 0, 0.65);
    --overlay-text: #E6EEF4;
    --switch-off: rgba(230, 238, 244, 0.18);
    --knob: #E6EEF4;
    --logo-chip: #E7ECF1;
    --shadow-soft: 0 10px 30px rgba(0, 0, 0, 0.35);
    --shadow-strong: 0 20px 40px rgba(0, 0, 0, 0.45);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1E2632;
  --surface: #323E4F;
  --surface-sunken: #2A3443;
  --preview-bg: #141A22;
  --sidebar-bg: #171D26;
  --sidebar-text: #E6EEF4;
  --sidebar-muted: #9AA8B9;
  --sidebar-active-bg: #3B495D;
  --sidebar-border: #2A3443;
  --toolbar-bg: #3B495D;
  --toolbar-text: #E6EEF4;
  --text: #E6EEF4;
  --text-strong: #F2F7FA;
  --text-muted: #A9B6C6;
  --border: #46556B;
  --border-subtle: #3B495D;
  --accent: #ADEEFC;
  --accent-hover: #C6F4FD;
  --on-accent: #0F141B;
  --accent-text: #ADEEFC;
  --accent-soft: rgba(173, 238, 252, 0.12);
  --accent-ring: rgba(173, 238, 252, 0.28);
  --success: #8FD9C4;
  --success-text: #8FD9C4;
  --success-soft: rgba(143, 217, 196, 0.14);
  --danger: #F4A6A1;
  --danger-text: #F4A6A1;
  --danger-soft: rgba(244, 166, 161, 0.14);
  --disabled-bg: rgba(230, 238, 244, 0.08);
  --disabled-text: rgba(230, 238, 244, 0.35);
  --hover-tint: rgba(230, 238, 244, 0.05);
  --scrim: rgba(30, 38, 50, 0.88);
  --overlay: rgba(0, 0, 0, 0.65);
  --overlay-text: #E6EEF4;
  --switch-off: rgba(230, 238, 244, 0.18);
  --knob: #E6EEF4;
  --logo-chip: #E7ECF1;
  --shadow-soft: 0 10px 30px rgba(0, 0, 0, 0.35);
  --shadow-strong: 0 20px 40px rgba(0, 0, 0, 0.45);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background-color: var(--bg);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  min-height: 100vh;
  display: flex;
  overflow: hidden;
}

/* CUSTOM SCROLLBARS */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}

/* SIDEBAR */
.sidebar {
  width: 280px;
  background-color: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 32px 24px;
  border-right: 1px solid var(--sidebar-border);
  flex-shrink: 0;
  z-index: 10;
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 48px;
  text-align: center;
}

.brand img {
  height: 48px;
  width: auto;
  margin-bottom: 16px;
  /* In dark mode the logo sits on a light chip so its dark lettering stays readable. */
  background: var(--logo-chip);
  border-radius: 8px;
}

:root[data-theme="dark"] .brand img,
:root[data-theme="dark"] .login-card img { padding: 6px 10px; height: 60px; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .brand img,
  :root:not([data-theme="light"]) .login-card img { padding: 6px 10px; height: 60px; }
}

.brand-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.15em;
  color: var(--accent-text);
  text-transform: uppercase;
  line-height: 1.2;
}

.brand-sub {
  font-family: 'JetBrains Mono', monospace;
  font-size: 8px;
  letter-spacing: 0.2em;
  color: var(--sidebar-muted);
  margin-top: 6px;
  text-transform: uppercase;
}

.nav-menu {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  border-radius: var(--radius);
  color: var(--sidebar-muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  border: 1px solid transparent;
  background: transparent;
  text-align: left;
  width: 100%;
}

.nav-item:hover {
  background: var(--hover-tint);
  color: var(--sidebar-text);
}

.nav-item.active {
  background: var(--sidebar-active-bg);
  border-color: var(--border);
  color: var(--sidebar-text);
}

.nav-item svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* MAIN CONTAINER */
.main-content {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.top-header {
  height: 80px;
  background-color: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 40px;
  flex-shrink: 0;
}

.header-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: 24px;
  font-weight: 500;
  color: var(--text-strong);
  letter-spacing: 0.02em;
}

.header-actions {
  display: flex;
  gap: 16px;
}

/* WORKSPACE */
.workspace {
  flex-grow: 1;
  display: flex;
  height: calc(100vh - 80px);
  max-height: calc(100vh - 80px);
  overflow: hidden;
}

/* TAB CONTENTS */
.tab-content {
  width: 100%;
  height: 100%;
  display: none;
}

.tab-content.active {
  display: flex;
}

/* EDITOR PANES */
.editor-pane {
  width: 55%;
  height: 100%;
  max-height: calc(100vh - 80px);
  overflow-y: auto;
  padding: 40px;
  background-color: var(--surface);
  border-right: 1px solid var(--border);
  position: relative; /* anchors the lock overlay */
}

.preview-pane {
  width: 45%;
  height: 100%;
  background-color: var(--preview-bg);
  display: flex;
  flex-direction: column;
  position: relative;
}

/* EDITOR FORM STYLES */
.form-section {
  margin-bottom: 36px;
  padding-bottom: 24px;
  border-bottom: 1px dashed var(--border);
}

.form-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
}

.section-headline {
  font-family: 'Cormorant Garamond', serif;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-strong);
  margin-bottom: 20px;
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  gap: 12px;
}

.section-headline::after {
  content: "";
  flex-grow: 1;
  height: 1px;
  background-color: var(--border-subtle);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

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

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
}

.form-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-strong);
  font-family: 'JetBrains Mono', monospace;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.form-input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  color: var(--text);
  background-color: var(--surface-sunken);
  transition: var(--transition);
  outline: none;
}

.form-input::placeholder { color: var(--text-muted); opacity: 0.8; }

.form-input:focus {
  border-color: var(--accent);
  background-color: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.form-input[readonly] { color: var(--text-muted); }

.form-input.warning {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-soft);
}

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

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background-color: var(--surface-sunken);
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: var(--transition);
  font-size: 12.5px;
  user-select: none;
}

.checkbox-item:hover {
  border-color: var(--accent);
  background-color: var(--surface);
}

.checkbox-item.checked {
  border-color: var(--accent);
  background-color: var(--accent-soft);
  color: var(--text-strong);
  font-weight: 500;
}

.checkbox-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

.input-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.4;
}

.input-hint strong {
  color: var(--accent-text);
  font-weight: 500;
}

/* PREVIEW CONTAINER */
.preview-header {
  height: 60px;
  background: var(--toolbar-bg);
  color: var(--toolbar-text);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 24px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.preview-frame-container {
  flex-grow: 1;
  padding: 24px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow-y: auto;
  position: relative;
}

.preview-shadow-wrapper {
  width: 210mm;
  height: fit-content;
  box-shadow: var(--shadow-strong);
  background-color: var(--paper);
  position: relative;
}

.preview-iframe {
  width: 210mm;
  height: 297mm; /* resized to the document height once the preview loads */
  border: none;
  display: block;
  background-color: var(--paper);
}

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 24px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  transition: var(--transition);
  border: none;
  outline: none;
  text-decoration: none;
}

.btn:focus-visible { box-shadow: 0 0 0 3px var(--accent-ring); }

.btn-primary {
  background-color: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 4px 14px var(--accent-soft);
}

.btn-primary:hover {
  background-color: var(--accent-hover);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(1px);
}

.btn-secondary {
  background-color: var(--surface-sunken);
  color: var(--text-strong);
}

.btn-secondary:hover {
  background-color: var(--accent-soft);
  color: var(--accent-text);
}

.btn-outline {
  background-color: transparent;
  border: 1px solid var(--border);
  color: var(--text-strong);
}

.btn-outline:hover {
  border-color: var(--accent);
  color: var(--accent-text);
  background-color: var(--accent-soft);
}

.btn:disabled {
  background-color: var(--disabled-bg);
  color: var(--disabled-text);
  border-color: transparent;
  box-shadow: none;
  cursor: not-allowed;
  transform: none !important;
}

/* HISTORY VIEW */
.history-pane {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  padding: 40px;
  background-color: var(--bg);
}

.history-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  padding: 32px;
  border: 1px solid var(--border);
  max-width: 1000px;
  margin: 0 auto;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.history-title h2 {
  font-family: 'Cormorant Garamond', serif;
  font-size: 28px;
  font-weight: 500;
  color: var(--text-strong);
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.history-table th {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 500;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  letter-spacing: 0.05em;
}

.history-table td {
  padding: 16px;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 13.5px;
}

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

.history-table tr:hover td {
  background-color: var(--hover-tint);
}

.file-name {
  font-family: 'Inter', sans-serif;
  font-weight: 600;
  color: var(--text-strong);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.file-date {
  color: var(--text-muted);
}

/* EMPTY STATE */
.empty-state {
  text-align: center;
  padding: 48px 0;
  color: var(--text-muted);
}

.empty-state svg {
  width: 48px;
  height: 48px;
  color: var(--border);
  margin-bottom: 16px;
}

/* LOADER OVERLAY */
.loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--overlay);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: none;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  color: var(--overlay-text);
  gap: 16px;
  transition: opacity 0.3s ease;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 3px solid rgba(173, 238, 252, 0.25);   /* on the dark overlay in both themes */
  border-top-color: #ADEEFC;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.loading-text {
  font-family: 'Cormorant Garamond', serif;
  font-size: 20px;
  letter-spacing: 0.05em;
}

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

/* TOAST NOTIFICATION */
.toast-container {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  box-shadow: var(--shadow-strong);
  padding: 16px 20px;
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  min-width: 300px;
  transform: translateX(120%);
  transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.toast.show {
  transform: translateX(0);
}

.toast.success {
  border-left-color: var(--success);
}

.toast.error {
  border-left-color: var(--danger);
}

.toast-close {
  cursor: pointer;
  color: var(--text-muted);
  margin-left: 12px;
}

.toast-close:hover {
  color: var(--text);
}

/* ZOOM CONTROLS */
.zoom-controls {
  position: absolute;
  bottom: 24px;
  right: 24px;
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
  z-index: 5;
}

.zoom-btn {
  width: 36px;
  height: 36px;
  display: flex;
  justify-content: center;
  align-items: center;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-strong);
  font-weight: 600;
  transition: var(--transition);
}

.zoom-btn:hover {
  background: var(--accent-soft);
  color: var(--accent-text);
}

.zoom-btn:first-child {
  border-right: 1px solid var(--border);
}

/* RESPONSIVE DESIGN ADJUSTMENT */
@media (max-width: 1200px) {
  .workspace {
    flex-direction: column;
    overflow-y: auto;
  }
  .editor-pane, .preview-pane {
    width: 100%;
    height: auto;
  }
  .editor-pane {
    max-height: none;
    overflow-y: visible;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .preview-pane {
    height: 600px;
    flex-shrink: 0;
  }
}

/* TOGGLE SWITCH */
.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--switch-off);
  transition: .3s cubic-bezier(0.25, 0.8, 0.25, 1);
  border-radius: 22px;
  border: 1px solid var(--border);
}
.slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background-color: var(--knob);
  transition: .3s cubic-bezier(0.25, 0.8, 0.25, 1);
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
/* The switch lives on the slate toolbar in both themes, so "on" is always ice cyan. */
.switch input:checked + .slider {
  background-color: #ADEEFC;
  border-color: #ADEEFC;
}
.switch input:checked + .slider:before { background-color: #323E4F; }
.switch input:checked + .slider:before {
  transform: translateX(18px);
}

/* EDITOR LOCK OVERLAY */
.editor-lock-overlay {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--scrim);
  backdrop-filter: blur(2px);
  z-index: 100;
  justify-content: center;
  align-items: center;
  padding: 40px;
  text-align: center;
  flex-direction: column;
  animation: fadeIn 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.editor-lock-card {
  max-width: 380px;
  background: var(--surface);
  padding: 32px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-strong);
  transform: scale(0.95);
  animation: scaleUp 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes scaleUp {
  to { transform: scale(1); }
}

/* BANNERS, VALIDATION, BADGES */
.banner {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  margin-bottom: 20px;
  border-radius: var(--radius);
  font-size: 12.5px;
  line-height: 1.45;
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  color: var(--accent-text);
}
.banner.show { display: flex; }
.banner.locked { border-color: var(--border); background: var(--surface-sunken); color: var(--text-strong); }
.banner.conflict { border-color: var(--danger); background: var(--danger-soft); color: var(--danger-text); }
.banner .btn { padding: 6px 12px; font-size: 11.5px; flex-shrink: 0; }
.banner-actions { display: flex; gap: 8px; flex-shrink: 0; }

.field-error { font-size: 11px; color: var(--danger-text); margin-top: 4px; display: none; }
.field-error.show { display: block; }

.badge {
  display: inline-block;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  vertical-align: middle;
}
.badge.draft { background: var(--accent-soft); color: var(--accent-text); }
.badge.sent { background: var(--surface-sunken); color: var(--text-strong); border: 1px solid var(--border); }
.badge.legacy { background: var(--disabled-bg); color: var(--text-muted); }
.badge.new { background: var(--success-soft); color: var(--success-text); }

.header-ref { font-family: 'JetBrains Mono', monospace; font-size: 12px; color: var(--text-muted); margin-left: 12px; }

.lib-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.lib-actions .btn { padding: 5px 10px; font-size: 11.5px; }
.lib-sub { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.versions-row td { background: var(--surface-sunken); padding-top: 8px; padding-bottom: 12px; }
.versions-list { display: flex; flex-wrap: wrap; gap: 8px; }
.versions-list a { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--accent-text); }

.form-locked .form-section { opacity: 0.6; pointer-events: none; }

/* SIDEBAR FOOTER: theme toggle + user */
.sidebar-footer { margin-top: auto; padding-top: 20px; border-top: 1px solid var(--sidebar-border); display: flex; flex-direction: column; gap: 14px; }
.sidebar-user { font-size: 12px; color: var(--sidebar-text); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sidebar-user button,
.theme-toggle { background: none; border: 1px solid var(--border); color: var(--sidebar-text); border-radius: 6px; padding: 4px 10px; font-size: 11px; cursor: pointer; font-family: 'Inter', sans-serif; transition: var(--transition); }
.sidebar-user button:hover,
.theme-toggle:hover { border-color: var(--accent); color: var(--accent-text); }
.theme-toggle { display: inline-flex; align-items: center; gap: 8px; align-self: flex-start; }
.theme-toggle svg { width: 14px; height: 14px; }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: inline; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: inline; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
}

.preview-message { padding: 60px 40px; text-align: center; color: var(--text-muted); font-size: 13px; line-height: 1.6; }

/* LOGIN */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); width: 100%; position: relative; }
.login-card { background: var(--surface); padding: 40px; border-radius: 12px; border: 1px solid var(--border); box-shadow: var(--shadow-strong); width: 360px; max-width: calc(100vw - 32px); }
.login-card img { height: 48px; margin-bottom: 16px; background: var(--logo-chip); border-radius: 8px; }
.login-card h1 { font-family: 'Cormorant Garamond', serif; color: var(--text-strong); font-size: 26px; margin-bottom: 24px; font-weight: 600; }
.login-card .form-group { margin-bottom: 16px; }
.login-card .btn { width: 100%; justify-content: center; margin-top: 8px; }
.login-error { color: var(--danger-text); font-size: 12.5px; margin-bottom: 14px; }
.login-theme { position: absolute; top: 20px; right: 20px; }
.login-theme .theme-toggle { color: var(--text-strong); }

/* "Remove Page" buttons layered over the (always light) A4 sheet */
.page-ctl {
  position: absolute; right: 20px; z-index: 5;
  background: var(--chip-bg); color: var(--chip-text); border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 8px 14px; font: 500 8pt 'JetBrains Mono', monospace; text-transform: uppercase; letter-spacing: 0.06em;
  border-radius: 6px; cursor: pointer; opacity: 0; transition: opacity 0.2s, background 0.2s;
}
.preview-shadow-wrapper:hover .page-ctl { opacity: 1; }
.page-ctl:hover { background: var(--danger); color: #FFFFFF; }

/* STATE CLASSES (set by studio.js; no inline styles under the CSP) */
[hidden] { display: none !important; }
.loading-overlay.show { display: flex; }
.editor-lock-overlay.show { display: flex; }

.lock-icon { color: var(--accent); margin-bottom: 14px; display: inline-block; }
.lock-title { font-family: 'Cormorant Garamond', serif; font-size: 20px; color: var(--text-strong); margin-bottom: 10px; font-weight: 600; text-transform: none; }
.lock-text { font-size: 12.5px; color: var(--text-muted); line-height: 1.55; margin-bottom: 20px; text-transform: none; }
.lock-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.btn-small { font-size: 11px; padding: 8px 16px; }

.form-grid.spaced { margin-top: 20px; }
.section-hint { margin-top: 10px; }

.phase2-toggle { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; }
.phase2-toggle-main { display: flex; align-items: center; gap: 12px; }
.phase2-toggle-main input { width: 18px; height: 18px; accent-color: var(--accent); }
.phase2-toggle-main label { font-weight: 600; cursor: pointer; color: var(--text-strong); }

.preview-tools { display: flex; align-items: center; gap: 18px; }
.direct-edit-control { display: flex; align-items: center; gap: 8px; }
.direct-edit-label { font-family: 'Inter', sans-serif; font-size: 10px; font-weight: 600; text-transform: uppercase; color: var(--toolbar-text); letter-spacing: 0.05em; }

.col-actions { text-align: right; }

.toast-body { display: flex; align-items: center; gap: 10px; }
.toast.success .toast-icon { color: var(--success); }
.toast.error .toast-icon { color: var(--danger); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* Dark mode: dim the bright A4 sheet on screen so it doesn't glare against the
   charcoal UI. Display only; the generated PDF is unaffected. */
:root[data-theme="dark"] .preview-shadow-wrapper { filter: brightness(0.88); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .preview-shadow-wrapper { filter: brightness(0.88); }
}
