/* ---------- Base Theme Variables ---------- */
:root {
  --bg: #050816;
  --bg-elevated: #0b1020;
  --surface: #111827;
  --surface-soft: #111827;
  --border-subtle: #1f2937;
  --accent: #3b82f6;
  --accent-soft: rgba(59, 130, 246, 0.12);
  --accent-green: #22c55e;
  --text: #e5e7eb;
  --text-soft: #9ca3af;
  --danger: #f97373;
  --shadow-soft: 0 18px 45px rgba(0, 0, 0, 0.45);
  --preview-border: #1f2937;
}

body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  background: radial-gradient(circle at top, #111827 0, #020617 55%, #000 100%);
  color: var(--text);
}

/* Light theme */
body:not(.theme-dark) {
  --bg: #f3f4f6;
  --bg-elevated: #ffffff;
  --surface: #ffffff;
  --surface-soft: #f9fafb;
  --border-subtle: #e5e7eb;
  --text: #111827;
  --text-soft: #6b7280;
  background: radial-gradient(circle at top, #e5e7eb 0, #ffffff 55%, #e5e7eb 100%);
}

body.modal-open {
  overflow: hidden;
}

.hidden {
  display: none !important;
}

/* ---------- Layout ---------- */
.center-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
}

.card {
  background: linear-gradient(145deg, rgba(15, 23, 42, 0.96), rgba(17, 24, 39, 0.98));
  border-radius: 24px;
  box-shadow: var(--shadow-soft);
  padding: 24px 24px 18px;
  max-width: 720px;
  width: 100%;
  border: 1px solid rgba(148, 163, 184, 0.25);
  backdrop-filter: blur(16px);
}

body:not(.theme-dark) .card {
  background: var(--surface);
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.card-header-main h2 {
  margin: 0;
}

/* ---------- Typography ---------- */
h2 {
  font-size: 1.7rem;
  margin: 0;
  letter-spacing: -0.03em;
}

.subtitle {
  margin: 4px 0 0;
  font-size: 0.92rem;
  color: var(--text-soft);
}

.field-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-soft);
  margin-bottom: 6px;
  display: block;
}

/* ---------- Local Mode Badge ---------- */
.local-mode-badge {
  align-self: flex-start;
  background: rgba(34, 197, 94, 0.95);
  border-radius: 999px;
  color: #ecfdf3;
  font-size: 0.78rem;
  padding: 6px 14px;
  text-align: center;
  box-shadow: 0 10px 25px rgba(22, 163, 74, 0.45);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.local-mode-helper {
  font-size: 0.7rem;
  margin-top: 1px;
  opacity: 0.9;
  font-weight: 400;
}

/* ---------- Upload Grid & Dropzones ---------- */
.upload-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
  margin-top: 12px;
}

.drop-column {
  display: flex;
  flex-direction: column;
}

.dropzone {
  border-radius: 18px;
  padding: 16px 14px;
  border: 1px dashed rgba(148, 163, 184, 0.6);
  background: rgba(15, 23, 42, 0.85);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease,
    transform 0.1s ease;
}

body:not(.theme-dark) .dropzone {
  background: var(--surface-soft);
}

.dropzone:hover {
  border-color: var(--accent);
  background: rgba(15, 23, 42, 0.95);
  transform: translateY(-1px);
}

.dropzone.dragover {
  border-style: solid;
  border-color: var(--accent);
  background: rgba(37, 99, 235, 0.1);
}

.dropzone-inner {
  display: flex;
  align-items: center;
  gap: 10px;
}

.drop-icon {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

.drop-text span {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
}

.drop-text small {
  display: block;
  font-size: 0.72rem;
  color: var(--text-soft);
}

/* ---------- Previews ---------- */
.preview {
  margin-top: 10px;
  border-radius: 14px;
  border: 1px solid var(--preview-border);
  background: rgba(15, 23, 42, 0.7);
  padding: 8px;
  max-height: 220px;
  overflow: hidden;
}

body:not(.theme-dark) .preview {
  background: var(--surface-soft);
}

.pdf-preview embed {
  width: 100%;
  height: 200px;
  border-radius: 8px;
  border: none;
}

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

.preview th,
.preview td {
  padding: 4px 6px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.18);
}

.preview th {
  text-align: left;
  font-weight: 600;
  color: var(--text-soft);
}

/* ---------- Form Row & Buttons ---------- */
.form-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
  margin-bottom: 8px;
}

.form-row label {
  font-size: 0.85rem;
  color: var(--text-soft);
}

.form-row input[type="number"] {
  max-width: 100px;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
}

.form-row input[type="number"]:focus {
  outline: none;
  border-color: var(--accent);
}

.primary-btn,
.secondary-btn {
  border-radius: 999px;
  border: none;
  font-size: 0.9rem;
  padding: 8px 18px;
  cursor: pointer;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.primary-btn {
  margin-top: 6px;
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: white;
  box-shadow: 0 10px 30px rgba(37, 99, 235, 0.35);
}

.primary-btn:hover {
  filter: brightness(1.05);
}

.secondary-btn {
  background: transparent;
  color: var(--text-soft);
  border: 1px solid var(--border-subtle);
}

.secondary-btn:hover {
  background: rgba(148, 163, 184, 0.12);
}

/* ---------- Progress Bar ---------- */
.progress-bar-container {
  position: relative;
  margin-top: 10px;
  height: 6px;
  border-radius: 999px;
  background: rgba(31, 41, 55, 0.9);
  overflow: hidden;
  display: none;
}

.progress-bar-container.show {
  display: block;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #22c55e, #3b82f6);
  transition: width 0.15s ease-out;
}

.progress-bar-container.fade-out {
  opacity: 0;
  transition: opacity 0.4s ease-out;
}

/* ---------- FAB Buttons ---------- */
.settings-fab,
.feedback-fab {
  position: fixed;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 10px 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  z-index: 900;
}

.settings-fab {
  bottom: 22px;
  right: 22px;
  width: 46px;
  height: 46px;
  border-radius: 999px;
  padding: 0;
  font-size: 1.1rem;
  background: radial-gradient(circle at 30% 0, #60a5fa, #2563eb);
  color: #e5e7eb;
}

.feedback-fab {
  bottom: 22px;
  left: 22px;
  background: rgba(15, 23, 42, 0.95);
  color: var(--text-soft);
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.4);
}

/* ---------- Modal (Settings + Feedback) ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 950;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.7);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  z-index: 1;
  background: var(--surface);
  border-radius: 16px;
  padding: 18px 18px 14px;
  width: 100%;
  max-width: 420px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  box-shadow: var(--shadow-soft);
}

.settings-modal-content {
  max-width: 460px;
}

.modal-content h3 {
  margin-top: 2px;
  margin-bottom: 6px;
}

.modal-content p {
  margin: 0 0 8px;
  font-size: 0.85rem;
  color: var(--text-soft);
}

.modal-content textarea {
  width: 100%;
  max-width: 100%;
  min-height: 100px;
  max-height: 200px;

  /* Centering + perfect fit */
  display: block;
  margin: 8px auto;

  /* Clean look */
  padding: 10px 12px;
  border-radius: 12px;

  border: 1px solid var(--border-subtle);
  background: var(--surface-soft);
  color: var(--text);

  font-size: 0.9rem;
  line-height: 1.35;
  resize: vertical;
  box-sizing: border-box;
}

.modal-content textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.modal-actions {
  margin-top: 10px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ---------- Settings groups & switch ---------- */
.settings-group {
  margin-bottom: 14px;
}

/* IMPORTANT: only apply this to normal labels, not toggle labels */
.settings-group > label:not(.switch) {
  font-size: 0.85rem;
  color: var(--text-soft);
  display: block;
  margin-bottom: 4px;
}

.settings-group input[type="number"],
.settings-group select {
  width: 100%;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  background: var(--surface-soft);
  color: var(--text);
  font-size: 0.85rem;
}

.settings-group input[type="number"]:focus,
.settings-group select:focus {
  outline: none;
  border-color: var(--accent);
}

.settings-hint {
  margin: 4px 0 0;
  font-size: 0.75rem;
  color: var(--text-soft);
}

.settings-footer {
  margin-top: 10px;
  font-size: 0.8rem;
  color: var(--text-soft);
}

/* Toggle switch */
.switch {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

/* prevent old label styles from breaking layout */
.switch input {
  display: none;
}

.slider {
  position: relative;
  width: 34px;
  height: 18px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.7); /* gray when OFF */
  transition: background 0.15s ease, box-shadow 0.15s ease;
  flex-shrink: 0;
}

.slider::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 999px;
  background: white;
  transition: transform 0.15s ease;
}

/* GREEN when ON */
.switch input:checked + .slider {
  background: var(--accent-green);
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.35);
}

.switch input:checked + .slider::before {
  transform: translateX(16px);
}

.switch-label {
  font-size: 0.85rem;
  color: var(--text-soft);
  line-height: 1.3;
}

/* ---------- Spinner ---------- */
.spinner.small {
  font-size: 0.75rem;
  color: var(--text-soft);
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  bottom: 22px;
  background: rgba(15, 23, 42, 0.96);
  border-radius: 999px;
  padding: 7px 16px;
  font-size: 0.8rem;
  color: var(--text-soft);
  border: 1px solid rgba(148, 163, 184, 0.6);
  opacity: 0;
  pointer-events: none;
  z-index: 920;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- Errors ---------- */
.error {
  color: var(--danger);
  font-size: 0.8rem;
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .card {
    max-width: 540px;
    padding: 20px 16px 16px;
  }

  .upload-grid {
    grid-template-columns: minmax(0, 1fr);
  }

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

@media (max-width: 600px) {
  .settings-fab {
    bottom: 18px;
    right: 18px;
  }

  .feedback-fab {
    bottom: 18px;
    left: 18px;
  }
}
