/*
 * BreadDoodle — PDF import UI
 *
 * Deliberately self-contained rather than reusing Excalidraw's own CSS custom
 * properties: those are defined on .excalidraw, and this overlay is a sibling
 * of #root so it can survive the editor re-rendering. Dark mode is detected the
 * same way .bt-home-link does it, by looking for theme--dark from body.
 *
 * Palette matches breadtoasting-theme.css: tangerine #eb7006 on paper #fdf6e3.
 */

/* The hidden attribute is UA-styled as display:none, which any class selector
   here outranks. Rows would otherwise stay visible when hidden. */
.btpdf-overlay [hidden] {
  display: none !important;
}

/* ── Launch button ───────────────────────────────────────────────────────── */

.btpdf-launch {
  position: fixed;
  top: 16px;
  left: 60px;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border: 1px solid rgba(235, 112, 6, 0.35);
  border-radius: 10px;
  background: #ffffff;
  color: #c2410c;
  font-family: system-ui, sans-serif;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(77, 36, 30, 0.12);
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.btpdf-launch:hover {
  background: #fff0e6;
  border-color: #eb7006;
  color: #4d241e;
}

.btpdf-launch:focus-visible {
  outline: 2px solid #eb7006;
  outline-offset: 2px;
}

body:has(.excalidraw.theme--dark) .btpdf-launch {
  background: #2a1810;
  border-color: rgba(245, 159, 64, 0.35);
  color: #f7b76b;
}

body:has(.excalidraw.theme--dark) .btpdf-launch:hover {
  background: #3d1f10;
  border-color: #f59f40;
  color: #ffffff;
}

/* The picker is driven by the button; keep it out of the layout and the tab
   order but not display:none, which breaks .click() in some browsers. */
.btpdf-picker {
  position: fixed;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* ── Dialog ──────────────────────────────────────────────────────────────── */

.btpdf-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(77, 36, 30, 0.35);
  font-family: system-ui, sans-serif;
}

.btpdf-overlay--open {
  display: flex;
}

.btpdf-dialog {
  width: 100%;
  max-width: 420px;
  padding: 20px;
  border-radius: 14px;
  background: #fdf6e3;
  color: #4d241e;
  box-shadow: 0 12px 40px rgba(77, 36, 30, 0.3);
}

.btpdf-title {
  margin: 0 0 4px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.btpdf-file {
  margin: 0 0 14px;
  font-size: 12px;
  color: rgba(77, 36, 30, 0.7);
  overflow-wrap: anywhere;
}

.btpdf-error {
  margin: 0 0 14px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #fff0f3;
  color: #b00a35;
  font-size: 12px;
  line-height: 1.45;
}

.btpdf-row {
  display: grid;
  grid-template-columns: 76px 1fr;
  align-items: center;
  gap: 8px 10px;
  margin-bottom: 10px;
  font-size: 13px;
}

.btpdf-label {
  font-weight: 600;
  font-size: 12px;
}

.btpdf-hint {
  grid-column: 2;
  font-size: 11px;
  color: rgba(77, 36, 30, 0.55);
}

.btpdf-input {
  width: 100%;
  height: 32px;
  padding: 0 8px;
  border: 1px solid rgba(77, 36, 30, 0.25);
  border-radius: 8px;
  background: #ffffff;
  color: inherit;
  font: inherit;
  font-size: 13px;
  box-sizing: border-box;
}

.btpdf-input:focus {
  outline: none;
  border-color: #eb7006;
  box-shadow: 0 0 0 3px rgba(235, 112, 6, 0.2);
}

.btpdf-input:disabled {
  opacity: 0.55;
}

.btpdf-row--check {
  grid-template-columns: auto 1fr;
  align-items: start;
  margin-top: 14px;
  font-size: 12px;
  line-height: 1.4;
  cursor: pointer;
}

.btpdf-row--check input {
  margin: 1px 0 0;
  accent-color: #eb7006;
}

/* ── Progress ────────────────────────────────────────────────────────────── */

.btpdf-progress {
  margin-top: 16px;
}

.btpdf-progress-bar {
  height: 6px;
  border-radius: 3px;
  background: rgba(77, 36, 30, 0.12);
  overflow: hidden;
}

.btpdf-progress-fill {
  width: 0;
  height: 100%;
  background: #eb7006;
  transition: width 0.2s ease;
}

.btpdf-progress-text {
  margin: 6px 0 0;
  font-size: 11px;
  color: rgba(77, 36, 30, 0.7);
}

/* ── Actions ─────────────────────────────────────────────────────────────── */

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

.btpdf-button {
  height: 34px;
  padding: 0 16px;
  border: 1px solid rgba(77, 36, 30, 0.25);
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.btpdf-button:hover {
  background: rgba(77, 36, 30, 0.06);
}

.btpdf-button--primary {
  border-color: #eb7006;
  background: #eb7006;
  color: #ffffff;
}

.btpdf-button--primary:hover {
  background: #c2410c;
  border-color: #c2410c;
}

.btpdf-button:disabled {
  opacity: 0.5;
  cursor: default;
}

.btpdf-button:focus-visible {
  outline: 2px solid #4d241e;
  outline-offset: 2px;
}

/* ── Dark mode ───────────────────────────────────────────────────────────── */

body:has(.excalidraw.theme--dark) .btpdf-overlay {
  background: rgba(0, 0, 0, 0.55);
}

body:has(.excalidraw.theme--dark) .btpdf-dialog {
  color-scheme: dark;
  background: #2a1810;
  color: #f7e4d2;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
}

body:has(.excalidraw.theme--dark) .btpdf-file,
body:has(.excalidraw.theme--dark) .btpdf-hint,
body:has(.excalidraw.theme--dark) .btpdf-progress-text {
  color: rgba(247, 228, 210, 0.6);
}

body:has(.excalidraw.theme--dark) .btpdf-input {
  background: #1a0f0a;
  border-color: rgba(247, 228, 210, 0.2);
}

body:has(.excalidraw.theme--dark) .btpdf-input:focus {
  border-color: #f59f40;
  box-shadow: 0 0 0 3px rgba(245, 159, 64, 0.25);
}

body:has(.excalidraw.theme--dark) .btpdf-error {
  background: #3d0015;
  color: #ffd6df;
}

body:has(.excalidraw.theme--dark) .btpdf-progress-bar {
  background: rgba(247, 228, 210, 0.15);
}

body:has(.excalidraw.theme--dark) .btpdf-progress-fill,
body:has(.excalidraw.theme--dark) .btpdf-row--check input {
  background: #f59f40;
  accent-color: #f59f40;
}

body:has(.excalidraw.theme--dark) .btpdf-button {
  border-color: rgba(247, 228, 210, 0.25);
}

body:has(.excalidraw.theme--dark) .btpdf-button:hover {
  background: rgba(247, 228, 210, 0.08);
}

body:has(.excalidraw.theme--dark) .btpdf-button--primary {
  background: #eb7006;
  border-color: #eb7006;
  color: #ffffff;
}

body:has(.excalidraw.theme--dark) .btpdf-button--primary:hover {
  background: #f59f40;
  border-color: #f59f40;
  color: #2a1810;
}

/* ── Small screens ───────────────────────────────────────────────────────── */

@media (max-width: 600px) {
  .btpdf-launch {
    top: 12px;
    left: 52px;
    height: 32px;
    padding: 0 10px;
  }

  .btpdf-row {
    grid-template-columns: 1fr;
  }

  .btpdf-hint {
    grid-column: 1;
  }
}
