﻿/* ==========================================================================
   App design system
   One stylesheet for every page. Pages add layout-only <style> blocks that
   reference these tokens; they never redefine base colors, fonts or buttons.
   ========================================================================== */

/* ---- Tokens ------------------------------------------------------------- */
:root {
  color-scheme: light dark;

  --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-muted: #f9fafb;
  --surface-strong: #f0f2f5;
  --border: #e3e6eb;
  --border-strong: #cfd4dc;
  --text: #111827;
  --text-muted: #5b6475;
  --text-subtle: #8a93a5;

  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eef3ff;
  --accent-text: #1d4ed8;
  --on-accent: #ffffff;

  --success: #067647;
  --success-soft: #ecfdf3;
  --success-border: #abefc6;
  --warning: #b54708;
  --warning-soft: #fffaeb;
  --warning-border: #fedf89;
  --danger: #d92d20;
  --danger-hover: #b42318;
  --danger-soft: #fef3f2;
  --danger-border: #fecdca;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;

  --shadow-xs: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-sm: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-md: 0 12px 32px rgba(16, 24, 40, 0.12), 0 2px 6px rgba(16, 24, 40, 0.05);
  --focus-ring: 0 0 0 3px color-mix(in srgb, var(--accent) 28%, transparent);

  --topbar-height: 56px;
  --page-gutter: 24px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f17;
    --surface: #121826;
    --surface-muted: #161d2b;
    --surface-strong: #1d2536;
    --border: #262f42;
    --border-strong: #354059;
    --text: #e7eaf0;
    --text-muted: #a3acbd;
    --text-subtle: #747e92;

    --accent: #2563eb;
    --accent-hover: #3b82f6;
    --accent-soft: rgba(59, 130, 246, 0.14);
    --accent-text: #82acff;

    --success: #47cd89;
    --success-soft: rgba(23, 178, 106, 0.12);
    --success-border: rgba(71, 205, 137, 0.35);
    --warning: #fdb022;
    --warning-soft: rgba(247, 144, 9, 0.12);
    --warning-border: rgba(253, 176, 34, 0.35);
    --danger: #f97066;
    --danger-hover: #f04438;
    --danger-soft: rgba(240, 68, 56, 0.12);
    --danger-border: rgba(249, 112, 102, 0.35);

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 16px 40px rgba(0, 0, 0, 0.5);
  }
}

/* ---- Base --------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  margin: 0 0 8px;
  color: var(--text);
  font-weight: 650;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

h1 { font-size: 24px; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }

p {
  margin: 0 0 12px;
}

a {
  color: var(--accent-text);
  text-underline-offset: 2px;
}

code,
pre {
  font-family: var(--font-mono);
  font-size: 0.92em;
}

strong {
  font-weight: 600;
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

/* ---- App header --------------------------------------------------------- */
.global-topbar {
  position: sticky;
  top: 0;
  z-index: 5000;
  height: var(--topbar-height);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: saturate(160%) blur(10px);
  -webkit-backdrop-filter: saturate(160%) blur(10px);
}

.global-topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 1200px;
  height: 100%;
  margin: 0 auto;
  padding: 0 var(--page-gutter);
}

.global-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 650;
  font-size: 15px;
  text-decoration: none;
  border-radius: var(--radius-sm);
}

.global-brand-mark {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--on-accent);
}

.global-brand-mark svg {
  width: 16px;
  height: 16px;
}

.global-home-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
}

.global-home-link:hover {
  background: var(--surface-strong);
  color: var(--text);
}

/* ---- Page layout -------------------------------------------------------- */
.container {
  max-width: 1100px;
  margin: 28px auto 48px;
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.tool-page-container {
  max-width: 880px;
}

.hub-container {
  max-width: 1100px;
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0 var(--page-gutter);
}

.tool-page-header {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  margin-bottom: 4px;
}

.tool-page-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  border-radius: var(--radius-sm);
}

.tool-page-back::before {
  content: "\2190";
}

.tool-page-back:hover {
  color: var(--accent-text);
}

.tool-page-title {
  margin: 0;
  font-size: 24px;
}

.tool-page-description,
.subtext,
.sub,
.tool-description {
  margin: 6px 0 22px;
  color: var(--text-muted);
  font-size: 14px;
  max-width: 70ch;
}

.section-title {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* Panels: a bordered sub-area inside a page card. */
.section,
.meta,
.panel {
  margin-bottom: 18px;
  padding: 18px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.section h3,
.panel h3 {
  margin: 0 0 14px;
}

.meta {
  padding: 12px 14px;
  font-size: 14px;
  color: var(--text-muted);
}

.meta strong {
  color: var(--text);
}

/* Two-column field grid used by longer forms. */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}

.grid-full {
  grid-column: 1 / -1;
}

.field {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ---- Forms -------------------------------------------------------------- */
.form-group {
  margin-bottom: 18px;
}

label {
  display: block;
  margin-bottom: 6px;
  color: var(--text);
  font-size: 13px;
  font-weight: 550;
}

:where(input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]):not([type="range"]):not([type="color"])),
:where(select),
:where(textarea) {
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 14px;
  box-shadow: var(--shadow-xs);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

:where(textarea) {
  min-height: 96px;
  resize: vertical;
  line-height: 1.5;
}

:where(select) {
  appearance: none;
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238a93a5' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

:where(input, select, textarea)::placeholder {
  color: var(--text-subtle);
}

:where(input, select, textarea):focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

:where(input, select, textarea):disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

input[type="checkbox"],
input[type="radio"] {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
  flex: none;
}

input[type="file"] {
  display: block;
  width: 100%;
  padding: 10px;
  background: var(--surface-muted);
  color: var(--text-muted);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

input[type="file"]:hover {
  border-color: var(--accent);
}

input[type="file"]::file-selector-button {
  margin-right: 12px;
  padding: 7px 12px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
}

input[type="file"]:disabled {
  opacity: 0.6;
}

/* Radio / checkbox rows ("label > input + text"). */
.option-row,
.split-format-option,
.pl-orientation-option,
.labeler-checkbox-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 0 0 8px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-weight: 400;
  font-size: 14px;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.option-row input,
.split-format-option input,
.pl-orientation-option input,
.labeler-checkbox-item input {
  margin-top: 2px;
}

.option-row:hover,
.split-format-option:hover,
.pl-orientation-option:hover,
.labeler-checkbox-item:hover {
  border-color: var(--border-strong);
}

.option-row:has(input:checked),
.split-format-option:has(input:checked),
.pl-orientation-option:has(input:checked),
.labeler-checkbox-item:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.option-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.option-inline > label {
  margin: 0;
}

/* ---- Buttons -------------------------------------------------------------
   A bare <button> is primary. Secondary/danger/ghost come from classes.
   :where() keeps base specificity at zero so component rules always win. */
:where(button),
.btn,
.btn-primary,
.btn-secondary,
.btn-danger,
.btn-open,
.btn-home,
.link-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px 16px;
  background: var(--accent);
  color: var(--on-accent);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: var(--shadow-xs);
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

:where(button):hover,
.btn:hover,
.btn-primary:hover,
.btn-open:hover {
  background: var(--accent-hover);
}

:where(button):active {
  transform: translateY(1px);
}

:where(button):disabled,
.btn:disabled,
.btn-primary:disabled,
.btn-secondary:disabled,
.btn-danger:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* Secondary */
.btn-secondary,
.btn-home,
.link-btn,
.nav-btn,
.dropdown-btn,
.btn-cancel,
.filter-clear-btn,
.selection-button,
.vision-reset-btn,
.vision-copy-btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
}

.btn-secondary:hover,
.btn-home:hover,
.link-btn:hover,
.nav-btn:hover,
.dropdown-btn:hover,
.btn-cancel:hover,
.filter-clear-btn:hover,
.selection-button:hover:not(:disabled),
.vision-reset-btn:hover,
.vision-copy-btn:hover {
  background: var(--surface-strong);
}

/* Danger */
.btn-danger,
.vision-abort-btn {
  background: var(--danger);
  color: #ffffff;
}

.btn-danger:hover,
.vision-abort-btn:hover {
  background: var(--danger-hover);
}

.btn-sm,
.btn-small,
.filter-clear-btn {
  min-height: 32px;
  padding: 5px 12px;
  font-size: 13px;
}

.btn-block {
  width: 100%;
}

.button-group,
.form-actions,
.modal-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 22px;
}

/* ---- Feedback ----------------------------------------------------------- */
.loading,
.loading-pdfs {
  display: none;
  margin-top: 14px;
  color: var(--text-muted);
  font-size: 14px;
}

.loading-pdfs {
  display: block;
  padding: 24px;
  text-align: center;
}

.loading.show {
  display: block;
}

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  margin-right: 8px;
  vertical-align: -3px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(8, 12, 20, 0.5);
  backdrop-filter: blur(3px);
}

.loading-content {
  min-width: min(380px, 100%);
  padding: 28px;
  text-align: center;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  font-weight: 550;
}

.loading-content .spinner {
  display: block;
  width: 32px;
  height: 32px;
  margin: 0 auto 14px;
  border-width: 3px;
}

.progress-container {
  display: none;
  margin-top: 16px;
}

.progress-label {
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 550;
}

.progress-bar {
  width: 100%;
  height: 8px;
  margin-bottom: 6px;
  overflow: hidden;
  background: var(--surface-strong);
  border-radius: 999px;
}

.progress-fill {
  width: 0%;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.3s ease;
}

.progress-text {
  color: var(--text-muted);
  font-size: 12px;
}

/* Callouts */
.warning,
.info-box,
.match,
.success-box,
.success,
.error-box,
.error,
.error-message,
.callout {
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  background: var(--surface-muted);
}

.warning,
.info-box {
  background: var(--warning-soft);
  border-color: var(--warning-border);
  color: var(--warning);
}

.match,
.success-box,
.success {
  background: var(--success-soft);
  border-color: var(--success-border);
  color: var(--success);
}

.error-box,
.error,
.error-message {
  background: var(--danger-soft);
  border-color: var(--danger-border);
  color: var(--danger);
}

.success-box h3,
.error-box h3 {
  margin-bottom: 4px;
  color: inherit;
}

.success-box p,
.error-box p {
  margin: 0;
}

.success-box a,
.error-box a {
  color: inherit;
  font-weight: 600;
}

/* JS-toggled callouts start hidden. */
.error:not(.show),
.success:not(.show) {
  display: none;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.5;
}

/* ---- Home hub ----------------------------------------------------------- */
.hub-hero {
  padding: 36px 0 20px;
}

.hub-title {
  margin: 0 0 6px;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.hub-subtitle {
  margin: 0;
  color: var(--text-muted);
}

.hub-group {
  margin-top: 26px;
}

.hub-group-title {
  margin: 0 0 12px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.hub-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.hub-tool-link {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  min-height: 100%;
  padding: 16px;
  color: inherit;
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.hub-tool-link:hover {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.hub-tool-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent-text);
}

.hub-tool-icon svg {
  width: 20px;
  height: 20px;
}

.hub-tool-title {
  margin: 0 0 2px;
  font-size: 15px;
  font-weight: 600;
}

.hub-tool-desc {
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.45;
}

.hub-legacy {
  margin: 28px 0 0;
  color: var(--text-subtle);
  font-size: 13px;
}

/* ---- Recent PDFs -------------------------------------------------------- */
.recent-pdfs {
  margin-top: 36px;
}

.hub-container .recent-pdfs {
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}

.recent-pdfs h3 {
  margin-bottom: 14px;
  font-size: 17px;
}

.pdf-filter {
  display: none;
  margin-bottom: 16px;
  padding: 14px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
}

.pdf-filter-title {
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 600;
}

#filter_checkboxes {
  display: flex !important;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

#filter_checkboxes label {
  display: inline-flex !important;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 5px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

#filter_checkboxes label:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.pdf-selection-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 14px;
  color: var(--text-muted);
}

.pdf-load-more-wrap {
  display: flex;
  justify-content: center;
  margin-top: 14px;
}

.no-pdfs {
  padding: 28px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

.pdf-source-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 550;
  white-space: nowrap;
}

/* Table: stacked cards on phones, real table from 768px. */
@media (max-width: 767px) {
  /* pdf_history.js sets display: table inline; phones need block cards. */
  .pdf-table,
  .short-links-table {
    display: block !important;
  }
}

.pdf-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.pdf-table thead {
  display: none;
}

.pdf-table tbody {
  display: block;
}

.pdf-table tbody tr:not(.pdf-viewer-row) {
  display: grid;
  grid-template-columns: auto 1fr;
  margin-bottom: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
}

.pdf-table td {
  display: block;
  padding: 4px 14px;
  color: var(--text);
  word-break: break-word;
}

.pdf-table td.pdf-select-cell {
  grid-row: 1 / span 6;
  padding: 14px 0 14px 14px;
}

.pdf-table td:nth-child(2) {
  padding-top: 12px;
  font-weight: 600;
}

.pdf-table td:nth-child(3),
.pdf-table td:nth-child(5),
.pdf-table td:nth-child(6) {
  color: var(--text-muted);
  font-size: 13px;
}

.pdf-table td:nth-child(5)::before { content: "Created "; color: var(--text-subtle); }
.pdf-table td:nth-child(6)::before { content: "Size "; color: var(--text-subtle); }

.pdf-table td:last-child {
  padding-top: 8px;
  padding-bottom: 12px;
}

.pdf-table td[colspan] {
  grid-column: 1 / -1;
}

.pdf-select-col,
.pdf-select-cell {
  width: 40px;
  text-align: center;
}

.pdf-actions {
  position: relative;
}

.dropdown-btn {
  min-height: 34px;
  padding: 5px 12px;
  font-size: 13px;
}

.dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 1000;
  min-width: 200px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}

.dropdown-menu.active {
  display: block;
}

.dropdown-item {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  background: none;
  color: var(--text);
  border: none;
  border-radius: var(--radius-sm);
  box-shadow: none;
  font-size: 14px;
  font-weight: 450;
  text-align: left;
  cursor: pointer;
}

.dropdown-item:hover {
  background: var(--surface-strong);
}

.dropdown-item.delete {
  color: var(--danger);
}

.dropdown-item.delete:hover {
  background: var(--danger-soft);
}

.pdf-viewer-row {
  display: none !important;
}

.pdf-viewer-row.active {
  display: block !important;
  margin: -6px 0 12px;
}

.pdf-viewer-row td {
  padding: 0 !important;
  background: var(--surface-strong);
  border-radius: var(--radius);
  overflow: hidden;
}

.pdf-viewer-row iframe {
  display: block;
  width: 100%;
  height: 70vh;
  border: none;
}

/* ---- Modal -------------------------------------------------------------- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 6000;
  padding: 16px;
  background: rgba(8, 12, 20, 0.5);
  backdrop-filter: blur(3px);
}

.modal-overlay.show {
  display: flex;
  align-items: center;
  justify-content: center;
}

.rename-modal {
  width: 100%;
  max-width: 420px;
  padding: 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.rename-modal h3 {
  margin: 0 0 14px;
}

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

/* ---- Legacy workbench tabs --------------------------------------------- */
.tool-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  -webkit-overflow-scrolling: touch;
}

.tool-tab {
  flex-shrink: 0;
  margin-bottom: -1px;
  padding: 10px 12px;
  background: none;
  color: var(--text-muted);
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  box-shadow: none;
  font-size: 14px;
  font-weight: 500;
}

.tool-tab:hover {
  background: none;
  color: var(--text);
}

.tool-tab.active {
  color: var(--accent-text);
  border-bottom-color: var(--accent);
}

.tool-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.tool-nav-left {
  display: flex;
  gap: 8px;
}

.tool-index {
  color: var(--text-muted);
  font-size: 13px;
}

.tool-card {
  display: none;
  padding: 8px 0;
}

.tool-card.active {
  display: block;
}

/* ---- Short links -------------------------------------------------------- */
.short-link-slug-row {
  display: flex;
  align-items: stretch;
}

.short-link-prefix {
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  background: var(--surface-strong);
  color: var(--text-muted);
  border: 1px solid var(--border-strong);
  border-right: none;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  font-family: var(--font-mono);
}

.short-link-slug-row input {
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.short-link-hint {
  margin-top: 6px;
  color: var(--text-muted);
  font-size: 12px;
}

.short-link-status {
  min-height: 22px;
  margin-top: 10px;
  font-size: 14px;
}

.short-link-status-success { color: var(--success); }
.short-link-status-error { color: var(--danger); }

.short-links-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.short-links-table thead {
  display: none;
}

.short-links-table tbody {
  display: block;
}

.short-links-table tbody tr {
  display: block;
  margin-bottom: 10px;
  padding: 8px 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.short-links-table td {
  display: block;
  padding: 4px 14px;
  word-break: break-word;
}

.short-links-table td a {
  color: var(--accent-text);
  text-decoration: none;
}

.short-links-table td a:hover {
  text-decoration: underline;
}

.short-links-table td:first-child a {
  font-family: var(--font-mono);
  font-weight: 600;
}

.short-link-state-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 550;
}

.short-link-state-badge.is-active {
  background: var(--success-soft);
  border-color: var(--success-border);
  color: var(--success);
}

.short-link-state-badge.is-inactive {
  background: var(--surface-strong);
  color: var(--text-muted);
}

.short-link-row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* ---- Desktop tables ---------------------------------------------------- */
@media (min-width: 768px) {
  .pdf-table,
  .short-links-table {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    border-collapse: separate;
    border-spacing: 0;
    overflow: visible;
  }

  .pdf-table thead,
  .short-links-table thead {
    display: table-header-group;
  }

  .pdf-table tbody,
  .short-links-table tbody {
    display: table-row-group;
  }

  .pdf-table th,
  .short-links-table th {
    padding: 10px 12px;
    background: var(--surface-muted);
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-align: left;
    text-transform: uppercase;
  }

  .pdf-table th:first-child,
  .short-links-table th:first-child {
    border-top-left-radius: var(--radius);
  }

  .pdf-table th:last-child,
  .short-links-table th:last-child {
    border-top-right-radius: var(--radius);
  }

  .pdf-table tbody tr:not(.pdf-viewer-row),
  .short-links-table tbody tr {
    display: table-row;
    margin: 0;
    padding: 0;
    background: none;
    border: none;
    border-radius: 0;
  }

  .pdf-table tbody tr:not(.pdf-viewer-row):hover,
  .short-links-table tbody tr:hover {
    background: var(--surface-muted);
  }

  .pdf-table td,
  .short-links-table td {
    display: table-cell;
    padding: 10px 12px !important;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    font-weight: 400 !important;
    font-size: 14px !important;
  }

  .pdf-table td:nth-child(2) {
    font-weight: 550 !important;
  }

  .pdf-table td::before {
    content: none !important;
  }

  .pdf-table tbody tr:last-child td,
  .short-links-table tbody tr:last-child td {
    border-bottom: none;
  }

  .pdf-viewer-row.active {
    display: table-row !important;
    margin: 0;
  }

  .pdf-viewer-row td {
    border-radius: 0;
  }

  .dropdown-menu {
    left: auto;
    right: 0;
  }
}

/* ---- Label Vision ------------------------------------------------------- */
.vision-upload-area {
  margin-bottom: 16px;
  padding: 32px 20px;
  text-align: center;
  background: var(--surface-muted);
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.vision-upload-area:hover,
.vision-upload-area.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.vision-upload-text {
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
}

.vision-upload-hint {
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 13px;
}

#vision_file_input {
  display: none;
}

.vision-counter-info {
  margin-bottom: 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

.vision-images-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.vision-image-card {
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: box-shadow 0.15s ease;
}

.vision-image-card:hover {
  box-shadow: var(--shadow-sm);
}

.vision-image-card.vision-card-highlight {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 45%, transparent), var(--shadow-md);
}

.vision-sequence-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 12;
  padding: 3px 8px;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  pointer-events: none;
}

.vision-image-thumb {
  position: relative;
  aspect-ratio: 1;
  background: var(--surface-strong);
}

.vision-image-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.vision-card-actions {
  display: flex;
  gap: 6px;
  padding: 8px;
  background: var(--surface-muted);
  border-top: 1px solid var(--border);
}

.vision-card-btn {
  width: 36px;
  min-width: 36px;
  height: 36px;
  min-height: 36px;
  padding: 0;
  font-size: 0;
}

.vision-card-btn svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.vision-card-delete {
  background: var(--danger);
}

.vision-card-delete:hover {
  background: var(--danger-hover);
}

.vision-card-resend {
  width: auto;
  padding: 0 8px;
  background: var(--warning);
  font-size: 11px;
  font-weight: 700;
}

.vision-card-resend:hover {
  background: color-mix(in srgb, var(--warning) 85%, black);
}

.vision-card-result {
  margin: 8px;
  max-height: 180px;
  overflow: auto;
  padding: 6px 8px;
  background: var(--surface-muted);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
}

.vision-card-result.is-error {
  background: var(--danger-soft);
  border-color: var(--danger-border);
  color: var(--danger);
}

.vision-result-edit {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.vision-edit-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.vision-edit-field label {
  margin: 0;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.vision-edit-field input {
  min-height: 30px;
  padding: 4px 8px;
  font-size: 12px;
}

.vision-card-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 10;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.vision-controls {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 16px;
}

.vision-override-wrap {
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
}

.vision-override-wrap label {
  color: var(--text);
}

.vision-override-wrap input {
  max-width: 360px;
}

.vision-override-wrap textarea {
  max-width: 640px;
  min-height: 88px;
}

.vision-expected-summary {
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 12px;
}

.vision-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.vision-status {
  padding: 12px 14px;
  background: var(--surface-muted);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
}

.vision-status:empty {
  display: none;
}

.vision-results-section {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.vision-results-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.vision-results-header h3 {
  flex: 1;
  margin: 0;
}

.vision-copy-btn.copied {
  background: var(--success-soft);
  border-color: var(--success-border);
  color: var(--success);
}

.vision-bulk-fill {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  padding: 12px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.vision-bulk-fill label {
  margin: 0;
}

.vision-bulk-fill input {
  flex: 1;
  min-width: 160px;
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.vision-results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.vision-results-table th {
  padding: 10px 8px;
  background: var(--surface-muted);
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
}

.vision-results-table td {
  padding: 8px;
  border-bottom: 1px solid var(--border);
  word-break: break-word;
}

.vision-results-table .vision-col-box-name {
  min-width: 180px;
}

.vision-results-table tbody tr {
  cursor: pointer;
}

.vision-results-table tbody tr:hover {
  background: var(--surface-muted);
}

.vision-results-table tbody tr.vision-duplicate-row {
  background: var(--danger-soft);
}

.vision-results-table td.vision-duplicate-cell,
.vision-results-table .vision-low-confidence {
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 700;
}

.vision-error {
  margin-top: 4px;
  color: var(--danger);
  font-size: 12px;
}

.vision-image-preview-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 6000;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: rgba(0, 0, 0, 0.8);
}

.vision-image-preview-modal.show {
  display: flex;
}

.vision-image-preview-content {
  position: relative;
  min-width: min(90vw, 640px);
  max-width: 90vw;
  max-height: 90vh;
  overflow: auto;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.vision-preview-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding-right: 44px;
}

.vision-preview-toolbar button {
  min-height: 34px;
  padding: 5px 12px;
  font-size: 13px;
}

.vision-preview-stage {
  position: relative;
  display: inline-block;
  max-width: 100%;
  user-select: none;
}

.vision-preview-stage.crop-mode {
  cursor: crosshair;
}

.vision-preview-selection {
  display: none;
  position: absolute;
  border: 2px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.22);
  pointer-events: none;
}

.vision-preview-hint {
  color: var(--text-muted);
  font-size: 13px;
}

.vision-image-preview-img {
  display: block;
  width: 100%;
  height: auto;
}

.vision-preview-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 36px;
  min-height: 36px;
  height: 36px;
  padding: 0;
  background: var(--surface-strong);
  color: var(--text);
  border: 1px solid var(--border);
  font-size: 20px;
}

.vision-preview-close:hover {
  background: var(--border);
}

@media (min-width: 768px) {
  .vision-images-container {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  }
}

/* ---- Login -------------------------------------------------------------- */
body.login-body {
  display: flex;
  flex-direction: column;
}

.login-card {
  width: min(420px, calc(100% - 32px));
  margin: auto;
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  transform: translateY(-28px);
}

.login-title {
  margin: 0 0 4px;
  font-size: 20px;
}

.login-subtitle {
  margin: 0 0 20px;
  color: var(--text-muted);
  font-size: 14px;
}

.login-field-wrap {
  position: relative;
}

.login-field-wrap input[type="password"],
.login-field-wrap input[type="text"] {
  min-height: 46px;
  padding-right: 48px;
  font-size: 16px;
}

.login-toggle-password {
  position: absolute;
  top: 50%;
  right: 6px;
  width: 36px;
  min-height: 36px;
  height: 36px;
  padding: 0;
  background: transparent;
  color: var(--text-muted);
  border: none;
  box-shadow: none;
  transform: translateY(-50%);
}

.login-toggle-password:hover {
  background: var(--surface-strong);
  color: var(--text);
}

.login-toggle-password:active {
  transform: translateY(-50%);
}

.login-toggle-password svg {
  width: 20px;
  height: 20px;
  pointer-events: none;
}

.login-error {
  margin-top: 12px;
  padding: 10px 12px;
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid var(--danger-border);
  border-radius: var(--radius-sm);
  font-size: 14px;
}

.login-actions {
  margin-top: 16px;
}

.login-submit-btn {
  width: 100%;
  min-height: 44px;
}

/* ---- Column mapping (Build Split step 2) ------------------------------ */
.map-page .field-group,
.map-page .checkbox-group {
  margin-bottom: 14px;
  padding: 16px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.map-page .field-label {
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 600;
}

.map-page .preview {
  margin-top: 8px;
  padding: 10px 12px;
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.map-page .range-preview {
  color: var(--text);
  font-weight: 600;
}

.map-page .range-preview code {
  color: var(--accent-text);
  font-weight: 700;
}

.map-page .checkbox-group label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 14px;
  cursor: pointer;
}

.map-page .button-group button {
  min-width: 160px;
}

.map-page .select2-container {
  width: 100% !important;
}

body .select2-container--default .select2-selection--single {
  height: 40px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
}

body .select2-container--default .select2-selection--single .select2-selection__rendered {
  padding-left: 12px;
  padding-right: 36px;
  color: var(--text);
  line-height: 38px;
}

body .select2-container--default .select2-selection--single .select2-selection__arrow {
  height: 38px;
  right: 8px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238a93a5' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
}

body .select2-container--default .select2-selection--single .select2-selection__arrow b {
  display: none;
}

body .select2-container--default .select2-selection--single .select2-selection__placeholder {
  color: var(--text-subtle);
}

body .select2-container--default.select2-container--focus .select2-selection--single,
body .select2-container--default.select2-container--open .select2-selection--single {
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

body .select2-dropdown {
  overflow: hidden;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}

body .select2-search--dropdown {
  padding: 8px;
  background: var(--surface-muted);
  border-bottom: 1px solid var(--border);
}

body .select2-container--default .select2-search--dropdown .select2-search__field {
  min-height: 36px;
  padding: 6px 10px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
}

body .select2-results__option {
  padding: 8px 12px;
}

body .select2-container--default .select2-results__option--highlighted.select2-results__option--selectable {
  background: var(--accent);
  color: var(--on-accent);
}

body .select2-container--default .select2-results__option--selected {
  background: var(--accent-soft);
}

/* ---- Trucking flow ------------------------------------------------------ */
.trucking-layout {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.blob-reference {
  position: sticky;
  top: calc(var(--topbar-height) + 16px);
  padding: 16px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.blob-reference h3 {
  margin: 0 0 10px;
}

.blob-reference pre {
  max-height: 520px;
  margin: 0;
  overflow: auto;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.info-section {
  margin: 20px 0;
  padding: 18px;
  text-align: left;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.info-row {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.info-row:last-child {
  border-bottom: none;
}

.info-label {
  color: var(--text-muted);
  font-weight: 600;
}

.info-value {
  word-break: break-word;
}

.status-centered {
  text-align: center;
}

.bol-number {
  margin-bottom: 20px;
  color: var(--accent-text);
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 700;
}

.spinner-lg {
  display: block;
  width: 44px;
  height: 44px;
  margin: 24px auto;
  border-width: 3px;
}

/* ---- PDF viewer page ---------------------------------------------------- */
.viewer-page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px var(--page-gutter) 32px;
}

.viewer-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.viewer-toolbar-title {
  margin: 0 auto 0 0;
  font-size: 18px;
}

.viewer-frame-wrap {
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.viewer-frame {
  display: block;
  width: 100%;
  height: calc(100vh - var(--topbar-height) - 130px);
  min-height: 420px;
  border: none;
  background: #fff;
}

/* ---- Phones ------------------------------------------------------------- */
@media (max-width: 640px) {
  :root {
    --page-gutter: 16px;
  }

  /* 16px stops iOS from zooming into focused fields. */
  :where(input, select, textarea):not(.annotationLayer *):not(.freeform-label) {
    font-size: 16px !important;
  }

  body {
    background: var(--surface);
  }

  .container {
    margin: 0;
    padding: 20px var(--page-gutter) 32px;
    border: none;
    border-radius: 0;
    box-shadow: none;
  }

  .hub-container {
    padding: 0 var(--page-gutter);
  }

  .hub-hero {
    padding-top: 24px;
  }

  .hub-container .recent-pdfs {
    margin-left: calc(-1 * var(--page-gutter));
    margin-right: calc(-1 * var(--page-gutter));
    padding: 20px var(--page-gutter);
    border-left: none;
    border-right: none;
    border-radius: 0;
  }

  .tool-page-title {
    font-size: 21px;
  }

  .section,
  .panel {
    padding: 14px;
  }

  .button-group > :where(button, a),
  .form-actions > :where(button, a) {
    flex: 1 1 100%;
  }

  .trucking-layout {
    grid-template-columns: 1fr;
  }

  .blob-reference {
    position: static;
  }

  .info-row {
    grid-template-columns: 1fr;
    gap: 2px;
  }

  .viewer-toolbar > a,
  .viewer-toolbar > button {
    flex: 1 1 calc(50% - 10px);
  }

  .viewer-toolbar-title {
    flex-basis: 100%;
  }

  .viewer-frame {
    height: 70vh;
    min-height: 360px;
  }

  .rename-modal-actions > button {
    flex: 1;
  }
}

@media (max-width: 900px) {
  .trucking-layout {
    grid-template-columns: 1fr;
  }

  .blob-reference {
    position: static;
  }
}

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