@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;600;700&family=DM+Mono:wght@400;500&family=Source+Serif+4:ital,opsz,wght@0,8..60,300;0,8..60,400;0,8..60,600;1,8..60,300&display=swap');

:root {
  color-scheme: light;
  --bg: #f5efe3;
  --bg2: #fffaf1;
  --bg3: #efe4cf;
  --border: #ddcfb4;
  --border2: #c7b692;
  --text: #2f2415;
  --text2: #6d5a38;
  --text3: #a08c69;
  --accent: #bc8a22;
  --accent2: #8f6310;
  --accent-soft: rgba(188, 138, 34, 0.12);
  --green: #2f8a53;
  --green-soft: rgba(47, 138, 83, 0.12);
  --red: #bd5541;
  --red-soft: rgba(189, 85, 65, 0.12);
  --blue: #3d73b0;
  --blue-soft: rgba(61, 115, 176, 0.12);
  --radius: 6px;
  --radius-lg: 10px;
  --font-display: 'Playfair Display', Georgia, serif;
  --font-body: 'Source Serif 4', Georgia, serif;
  --font-mono: 'DM Mono', monospace;
  --shadow: 0 10px 26px rgba(92, 68, 20, 0.08);
  --shadow-lg: 0 18px 44px rgba(92, 68, 20, 0.14);
  --overlay: rgba(62, 44, 14, 0.22);
  --paper-shadow: 0 18px 48px rgba(92, 68, 20, 0.12), 0 0 0 1px rgba(92, 68, 20, 0.08);
}

html[data-theme='dark'] {
  color-scheme: dark;
  --bg: #0e0d0b;
  --bg2: #161512;
  --bg3: #1e1c18;
  --border: #2e2b24;
  --border2: #3d3a30;
  --text: #e8e3d8;
  --text2: #a09880;
  --text3: #5a5548;
  --accent: #c9a84c;
  --accent2: #8b6914;
  --accent-soft: rgba(201, 168, 76, 0.1);
  --green: #4a9e6b;
  --green-soft: rgba(74, 158, 107, 0.12);
  --red: #c0473a;
  --red-soft: rgba(192, 71, 58, 0.12);
  --blue: #4a7fb5;
  --blue-soft: rgba(74, 127, 181, 0.1);
  --shadow: 0 2px 16px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.6);
  --overlay: rgba(0, 0, 0, 0.7);
  --paper-shadow: 0 4px 40px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(0, 0, 0, 0.15);
}

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

html { font-size: 16px; }

body {
  background:
    radial-gradient(circle at top left, rgba(188, 138, 34, 0.12), transparent 28%),
    linear-gradient(180deg, var(--bg) 0%, #fbf7ee 100%);
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.6;
  min-height: 100vh;
  transition: background 0.2s ease, color 0.2s ease;
}

html[data-theme='dark'] body {
  background:
    radial-gradient(circle at top left, rgba(201, 168, 76, 0.08), transparent 24%),
    linear-gradient(180deg, var(--bg) 0%, #14120e 100%);
}

/* NAV */
.nav {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 0 2rem;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 2rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.nav-brand {
  font-family: var(--font-display);
  font-size: 1.1rem;
  color: var(--accent);
  letter-spacing: 0.02em;
  text-decoration: none;
  font-weight: 600;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-left: auto;
}

.nav-link {
  color: var(--text2);
  text-decoration: none;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.05em;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius);
  transition: color 0.15s, background 0.15s;
}

.nav-link:hover, .nav-link.active {
  color: var(--text);
  background: var(--bg3);
}

.theme-toggle {
  background: transparent;
  color: var(--text2);
  border: 1px solid var(--border2);
  border-radius: 999px;
  padding: 0.38rem 0.72rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}

.theme-toggle:hover {
  color: var(--text);
  background: var(--bg3);
  border-color: var(--text3);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* PAGE SHELL */
.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2.5rem 2rem;
}

.page-header {
  margin-bottom: 2rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 1.25rem;
}

.page-title {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.page-subtitle {
  color: var(--text2);
  font-size: 0.9rem;
  margin-top: 0.4rem;
  font-family: var(--font-mono);
}

/* CARDS */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.card + .card {
  margin-top: 1rem;
}

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1.1rem;
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.03em;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #1a1500;
  border-color: var(--accent);
}
.btn-primary:hover { background: #d9b85c; }

.btn-outline {
  background: transparent;
  color: var(--text2);
  border-color: var(--border2);
}
.btn-outline:hover { color: var(--text); border-color: var(--text3); background: var(--bg3); }

.btn-danger {
  background: transparent;
  color: var(--red);
  border-color: var(--red);
}
.btn-danger:hover { background: var(--red-soft); }

.btn-success {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
}
.btn-success:hover { background: #5ab57c; }

.btn-ghost {
  background: transparent;
  color: var(--text3);
  border-color: transparent;
  padding: 0.35rem 0.6rem;
}
.btn-ghost:hover { color: var(--text); background: var(--bg3); }

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.73rem; }
.btn-lg { padding: 0.7rem 1.5rem; font-size: 0.88rem; }

/* FORM ELEMENTS */
.form-group { margin-bottom: 1.25rem; }

label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text2);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 0.4rem;
}

input[type="text"], input[type="number"], textarea, select {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.95rem;
  padding: 0.6rem 0.85rem;
  outline: none;
  transition: border-color 0.15s;
  resize: vertical;
}

input[type="text"]:focus, input[type="number"]:focus, textarea:focus, select:focus {
  border-color: var(--accent2);
  box-shadow: 0 0 0 2px rgba(201, 168, 76, 0.08);
}

textarea { min-height: 110px; line-height: 1.7; }

/* BADGES */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.55rem;
  border-radius: 100px;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.badge-draft { background: var(--bg3); color: var(--text3); border: 1px solid var(--border); }
.badge-final { background: var(--green-soft); color: var(--green); border: 1px solid rgba(74,158,107,0.3); }
.badge-processing { background: var(--blue-soft); color: var(--blue); border: 1px solid rgba(74,127,181,0.3); }
.badge-done { background: var(--green-soft); color: var(--green); border: 1px solid rgba(74,158,107,0.3); }
.badge-error { background: var(--red-soft); color: var(--red); border: 1px solid rgba(192,71,58,0.3); }
.badge-pending { background: var(--bg3); color: var(--text3); border: 1px solid var(--border); }
.badge-queued { background: var(--blue-soft); color: var(--blue); border: 1px solid rgba(74,127,181,0.2); }
.badge-partial { background: rgba(201,168,76,0.12); color: var(--accent); border: 1px solid rgba(201,168,76,0.3); }

/* DOT indicators */
.dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.dot-draft { background: var(--text3); }
.dot-final { background: var(--green); }
.dot-processing { background: var(--blue); animation: pulse 1s infinite; }
.dot-done { background: var(--green); }
.dot-error { background: var(--red); }
.dot-pending { background: var(--text3); }
.dot-queued { background: var(--blue); opacity: 0.5; }
.dot-partial { background: var(--accent); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* TOAST */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-lg);
  padding: 0.75rem 1.1rem;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(8px);
  transition: all 0.2s;
  pointer-events: auto;
  max-width: 340px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.toast-success { border-left: 3px solid var(--green); }
.toast.toast-error { border-left: 3px solid var(--red); }
.toast.toast-info { border-left: 3px solid var(--accent); }

/* MODAL */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}
.modal-backdrop.open {
  opacity: 1;
  pointer-events: all;
}
.modal {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-lg);
  padding: 2rem;
  width: 440px;
  max-width: 95vw;
  box-shadow: var(--shadow-lg);
  transform: scale(0.96);
  transition: transform 0.15s;
}
.modal-backdrop.open .modal { transform: scale(1); }
.modal-title {
  font-family: var(--font-display);
  font-size: 1.3rem;
  margin-bottom: 1.25rem;
  color: var(--text);
}
.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 1.5rem;
}

/* DIVIDERS */
.divider {
  height: 1px;
  background: var(--border);
  margin: 1.5rem 0;
}

/* EMPTY STATE */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text3);
}
.empty-state-icon {
  font-size: 2.5rem;
  margin-bottom: 1rem;
  opacity: 0.4;
}
.empty-state h3 {
  font-family: var(--font-display);
  font-size: 1.2rem;
  color: var(--text2);
  margin-bottom: 0.5rem;
}
.empty-state p { font-size: 0.9rem; }

/* SCROLLBAR */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }

/* UTILS */
.flex { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.ml-auto { margin-left: auto; }
.text-sm { font-size: 0.85rem; }
.text-muted { color: var(--text2); }
.text-mono { font-family: var(--font-mono); }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.hidden { display: none !important; }
.w-full { width: 100%; }
.spinner {
  width: 14px; height: 14px;
  border: 2px solid var(--border2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }
