/* ===============================================================
   FlightLogger Program Loader — Design System
   application.css · Single source of truth
   See DESIGN_SYSTEM.md for usage guidelines.
   =============================================================== */

/* ---- Design Tokens ------------------------------------------ */

:root {
  /* Surface */
  --bg:            #ffffff;
  --surface:       #f9fafb;
  --surface-hover: #f3f4f6;

  /* Border */
  --border:        #e4e4e7;
  --border-strong: #d1d5db;

  /* Text */
  --text:          #18181b;
  --text-muted:    #71717a;
  --text-faint:    #a1a1aa;

  /* Primary accent — FlightLogger navy scale */
  --primary-900: #0c1627;
  --primary-700: #192d4d;
  --primary-600: #254373;
  --primary-400: #3d5a8a;
  --primary-100: #d4ddef;
  --primary-50:  #ecf2f9;

  /* Green scale — FlightLogger green */
  --green-900: #005c31;
  --green-700: #00874a;
  --green-600: #00a656;
  --green-400: #33c47e;
  --green-100: #ccf0df;
  --green-50:  #ebfaf2;

  /* Semantic status */
  --ok:             var(--green-700);
  --ok-bg:          var(--green-50);
  --ok-border:      var(--green-100);
  --processing:     var(--primary-700);
  --processing-bg:  var(--primary-50);
  --processing-border: var(--primary-100);
  --fix:            #dc2626;
  --fix-bg:         #fef2f2;
  --fix-border:     #fecaca;
  --verify:         #d97706;
  --verify-bg:      #fffbeb;
  --verify-border:  #fde68a;

  /* Geometry */
  --radius-sm:   6px;
  --radius-md:   8px;
  --radius-lg:   12px;
  --radius-xl:   16px;
  --radius-pill: 9999px;

  /* Shadow */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 1px 3px 0 rgb(0 0 0 / 0.08), 0 1px 2px -1px rgb(0 0 0 / 0.05);
  --shadow-lg: 0 4px 12px 0 rgb(0 0 0 / 0.10), 0 2px 4px -1px rgb(0 0 0 / 0.06);

  /* Progress */
  --progress-bg:   #e4e4e7;
  --progress-fill: var(--green-700);
}

.dark {
  --bg:            #0e1726;
  --surface:       #142035;
  --surface-hover: #1a2a44;
  --border:        #253550;
  --border-strong: #324766;
  --text:          #ecf2f9;
  --text-muted:    #9197a3;
  --text-faint:    #5f6b7a;

  --primary-900: #254373;
  --primary-700: #3d5a8a;
  --primary-600: #4b6c9e;
  --primary-400: #6b8fbe;
  --primary-100: #1a2a44;
  --primary-50:  #111d30;

  --green-700: #00a656;
  --green-600: #33c47e;
  --green-400: #66d9a0;
  --green-100: #0a3d23;
  --green-50:  #071f14;

  --ok-bg:          var(--green-50);
  --ok-border:      var(--green-100);
  --processing:       #5b9cf5;
  --processing-bg:    #0d1a30;
  --processing-border: #1a3560;
  --fix-bg:         #2c1515;
  --fix-border:     #7f1d1d;
  --verify-bg:      #2c2010;
  --verify-border:  #78350f;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.35);
  --shadow-md: 0 1px 3px 0 rgb(0 0 0 / 0.45), 0 1px 2px -1px rgb(0 0 0 / 0.35);
  --shadow-lg: 0 4px 12px 0 rgb(0 0 0 / 0.55), 0 2px 4px -1px rgb(0 0 0 / 0.35);

  --progress-bg: #253550;
}

/* ---- Base ---------------------------------------------------- */

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

html {
  overflow-x: hidden;
}

body {
  font-family: "Poppins", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  background-image: radial-gradient(circle, rgba(0, 0, 0, 0.10) 1px, transparent 1px);
  background-size: 24px 24px;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  overflow-x: hidden;
  max-width: 100vw;
}

.dark body {
  background-image: radial-gradient(circle, rgba(200, 215, 240, 0.10) 1px, transparent 1px);
}

a {
  color: inherit;
  text-decoration: none;
}

/* ---- Layout -------------------------------------------------- */

.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  border-bottom: 1px solid var(--border);
  background: color-mix(in oklab, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.editorial-shell,
.details-shell {
  max-width: 78rem;
  margin-inline: auto;
}

.brand-title {
  letter-spacing: 0.01em;
}

.app-header-controls {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  flex-shrink: 0;
}

.navbar-divider {
  width: 1px;
  height: 1.25rem;
  background: var(--border);
}


.navbar-icon-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  color: var(--text-muted);
  transition: color 0.15s;
}
.navbar-icon-link:hover {
  color: var(--primary-700);
}
.navbar-icon-link-icon {
  width: 1.15rem;
  height: 1.15rem;
}

.section-title {
  letter-spacing: 0.001em;
  line-height: 1;
}
.section-title .ui-icon {
  flex-shrink: 0;
  transform: translateY(0.035em);
}
.section-title .ui-icon.no-shift {
  transform: none;
}

.logo-mark {
  display: block;
}

.dark .logo-mark {
  filter: brightness(2) saturate(0.85);
}

/* ---- Buttons ------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1;
  padding: 0 0.875rem;
  height: 2.25rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  flex-shrink: 0;
  user-select: none;
  -webkit-user-select: none;
}

.btn:focus-visible {
  outline: 2px solid var(--primary-700);
  outline-offset: 2px;
}

.btn:disabled,
.btn[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary {
  background: var(--primary-700);
  color: #fff;
  border-color: var(--primary-700);
}

.btn-primary:hover {
  background: var(--primary-900);
  border-color: var(--primary-900);
}

.dark .btn-primary {
  background: var(--primary-900);
  border-color: var(--primary-900);
}

.dark .btn-primary:hover {
  background: var(--primary-700);
  border-color: var(--primary-700);
}

.dark .btn-primary:disabled,
.dark .btn-primary[disabled] {
  opacity: 1;
  background: color-mix(in oklab, var(--primary-700) 38%, var(--surface));
  border-color: color-mix(in oklab, var(--primary-700) 42%, var(--border));
  color: var(--text-muted);
}

.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover {
  background: var(--surface);
  border-color: var(--border-strong);
}

.btn-secondary-danger {
  background: var(--bg);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary-danger:hover {
  background: color-mix(in oklab, var(--fix-bg) 50%, var(--surface));
  border-color: var(--fix-border);
  color: var(--fix);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
}

.btn-ghost:hover {
  background: transparent;
  color: var(--text);
}

.btn-danger {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
}

.btn-danger:hover {
  background: transparent;
  color: var(--fix);
}

.btn-danger-filled {
  background: var(--fix);
  color: #fff;
  border-color: var(--fix);
}

.btn-danger-filled:hover {
  background: color-mix(in oklab, var(--fix) 85%, #000);
}

.btn-sm {
  font-size: 0.8rem;
  height: 2rem;
  padding: 0 0.7rem;
}

.btn-lg {
  font-size: 1rem;
  height: 3rem;
  padding: 0 1rem;
}

.btn-icon {
  padding: 0;
  width: 2.25rem;
  height: 2.25rem;
}

.btn-icon.btn-sm { width: 2rem; height: 2rem; }

/* ---- Form controls ------------------------------------------ */

.form-label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.25rem;
}

.form-label-required::after {
  content: " *";
  color: var(--fix);
  font-weight: 400;
}

.form-label-action {
  width: 1.25rem;
  height: 1.25rem;
  min-height: 1.25rem;
  min-width: 1.25rem;
  padding: 0;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.15s;
}
.form-label-action:hover {
  color: var(--primary);
  background: transparent;
}

.input,
.textarea,
.select {
  display: block;
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: 0.875rem;
  font-family: inherit;
}

.input,
.select {
  height: 2.5rem;
  padding: 0 0.75rem;
}

.textarea {
  padding: 0.625rem 0.75rem;
  resize: vertical;
  min-height: 7rem;
  line-height: 1.5;
}

.select {
  appearance: none;
  padding-right: 2rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='2.5' 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 0.625rem center;
  cursor: pointer;
}

.input:focus,
.textarea:focus,
.select:focus {
  outline: none;
  border-color: var(--primary-700);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--primary-700) 15%, transparent);
}

.input::placeholder,
.textarea::placeholder,
.select::placeholder {
  color: var(--text-faint);
}

.select.is-placeholder {
  color: var(--text-faint);
}

.select-sm {
  height: 2rem;
  font-size: 0.8125rem;
  padding: 0 1.75rem 0 0.625rem;
}

/* ---- Toolbar Filter Dropdowns -------------------------------- */

.runs-toolbar-filters .school-picker-dropdown {
  width: 16rem;
  min-width: 0;
  flex-shrink: 1;
}

.runs-toolbar-filters .filter-select-wrap {
  width: 9.5rem;
  min-width: 0;
  flex-shrink: 1;
}

.runs-toolbar-filters .select-sm {
  min-width: 0;
  width: 100%;
}

.filter-select-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.filter-select-wrap .select-sm {
  padding-right: 2.5rem;
}

.filter-clear-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  height: 1.25rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1;
  border-radius: var(--radius-sm);
  cursor: pointer;
  flex-shrink: 0;
  text-decoration: none;
}

.filter-clear-btn:hover {
  background: transparent;
  color: var(--text);
}

.filter-select-wrap .filter-clear-btn {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
}

.filter-select-wrap:has(.filter-clear-btn) .select-sm {
  background-image: none;
}

/* ---- Badge --------------------------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6875rem;
  font-weight: 500;
  line-height: 1;
  padding: 0.4em 0.7em;
  min-height: 2rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  white-space: nowrap;
}

.badge-sm {
  font-size: 0.625rem;
  padding: 0.25em 0.55em;
  min-height: 0;
}

.badge-ok {
  background: var(--ok-bg);
  border-color: var(--ok-border);
  color: var(--ok);
}

.badge-fix {
  background: var(--fix-bg);
  border-color: var(--fix-border);
  color: var(--fix);
}

.badge-verify {
  background: var(--verify-bg);
  border-color: var(--verify-border);
  color: var(--verify);
}

/* When badge-* color classes are used without .badge base, apply color only */
.badge-ok:not(.badge),
.badge-fix:not(.badge),
.badge-verify:not(.badge) {
  background: transparent;
  border-color: transparent;
}

.badge-primary {
  background: var(--primary-100);
  border-color: var(--primary-400);
  color: var(--primary-900);
}

.dark .badge-primary {
  color: var(--primary-400);
}

/* ---- Status pills ------------------------------------------- */

.status-pill {
  border-radius: var(--radius-pill);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 1.45rem;
  padding: 0.12rem 0.6rem;
  font-size: 0.74rem;
  font-weight: 600;
  line-height: 1;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  white-space: nowrap;
}

.status-pill-ok {
  border-color: var(--ok-border);
  color: var(--ok);
  background: var(--ok-bg);
}

.status-pill-needs-fix {
  border-color: var(--verify-border);
  color: var(--verify);
  background: var(--verify-bg);
}

.status-pill-failed {
  border-color: var(--fix-border);
  color: var(--fix);
  background: var(--fix-bg);
}

.status-pill-processing {
  border-color: var(--processing-border);
  color: var(--processing);
  background: var(--processing-bg);
}

.status-pill-queued {
  border-color: var(--border);
  color: var(--text-muted);
  background: var(--surface);
}

/* ---- Service Status Indicator -------------------------------- */

.docling-status {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  cursor: default;
  user-select: none;
}

.docling-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
}

.docling-dot-ok {
  background: var(--ok);
  animation: statusPulse 2s ease-in-out infinite;
}

.docling-dot-error {
  background: var(--fix);
  animation: statusPulse 2s ease-in-out infinite;
}

@keyframes statusPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.7; transform: scale(1.2); }
}

.docling-label {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-faint);
  line-height: 1;
  transition: color 0.2s;
}

.docling-status-ok .docling-label {
  color: var(--ok);
}

.docling-status-error .docling-label {
  color: var(--fix);
}

/* ---- Alert --------------------------------------------------- */

.alert-error {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--fix-border);
  background: var(--fix-bg);
  color: var(--fix);
  font-size: 0.875rem;
  overflow-wrap: break-word;
  word-break: break-word;
  min-width: 0;
}

/* ---- Progress bar ------------------------------------------- */

.run-progress-track,
.details-progress-track {
  position: relative;
  height: 1rem;
  border-radius: var(--radius-pill);
  background: var(--progress-bg);
  overflow: hidden;
}

.run-progress-fill,
.details-progress-fill {
  position: relative;
  width: calc(var(--progress, 0) * 1%);
  min-width: 0;
  height: 100%;
  border-radius: var(--radius-pill);
  background: var(--progress-fill);
  overflow: hidden;
}

.run-progress-fill-failed,
.details-progress-fill-failed {
  background: var(--fix);
}

.run-progress-fill-processing::after,
.details-progress-fill-processing::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    112deg,
    transparent 25%,
    color-mix(in oklab, white 45%, transparent) 48%,
    transparent 72%
  );
  transform: translateX(-130%);
  animation: progress-sweep 1.8s linear infinite;
  pointer-events: none;
}

@keyframes progress-sweep {
  to { transform: translateX(190%); }
}

/* ---- Infinite scroll spinner ------------------------------------ */

.runs-infinite-scroll-trigger {
  padding: 2rem 0;
  display: block;
}

.runs-infinite-scroll-spinner {
  display: flex;
  justify-content: center;
  padding: 1rem 0;
}

.spinner-icon {
  width: 1.25rem;
  height: 1.25rem;
  color: var(--text-muted);
  animation: spinner-rotate 0.8s linear infinite;
}

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

/* ---- Card ---------------------------------------------------- */

.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
}

.card-elevated {
  box-shadow: var(--shadow-md);
}

/* ---- Data table --------------------------------------------- */

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.data-table thead tr {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.data-table thead th {
  padding: 0.6rem 0.875rem;
  text-align: left;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-muted);
  white-space: nowrap;
}

.table-sort-link {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  transition: color 0.15s;
}

.table-sort-link:hover {
  color: var(--primary-700);
}

.table-sort-link.is-sorted {
  color: var(--text);
}

.sort-arrow {
  font-size: 0.55rem;
  line-height: 1;
}

.data-table tbody tr {
  position: relative;
  z-index: 1;
  border-bottom: 1px solid var(--border);
}

.data-table tbody tr:last-child {
  border-bottom: none;
}

.data-table tbody tr:hover {
  z-index: 10;
  background: color-mix(in oklab, var(--primary-700) 4%, var(--bg));
}

.data-table tbody tr:focus-within {
  z-index: 10;
}

.data-table tbody td {
  padding: 0.75rem 0.875rem;
  vertical-align: middle;
  color: var(--text);
}

.data-table tbody td:last-child,
.data-table thead th:last-child {
  padding-right: 1.5rem;
}

/* ---- Flash toasts ------------------------------------------- */

.flash-stack {
  position: fixed;
  inset: auto 1rem 1rem auto;
  z-index: 80;
  display: flex;
  width: min(24rem, calc(100vw - 1.5rem));
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.flash-toast {
  --flash-accent: var(--primary-700);
  --flash-timeout: 5000ms;
  pointer-events: auto;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  padding: 0.65rem 0.75rem;
  font-size: 0.82rem;
  line-height: 1.35;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.flash-toast::after {
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 2px;
  transform-origin: left center;
  transform: scaleX(1);
  background: color-mix(in oklab, var(--flash-accent) 70%, transparent);
  animation: flash-timeout-countdown var(--flash-timeout) linear forwards;
}

.flash-toast-message {
  flex: 1;
}

.flash-toast-close {
  margin-top: -0.1rem;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}

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

.flash-toast-leave {
  opacity: 0;
  transform: translateY(0.4rem);
}

.flash-toast-success {
  --flash-accent: var(--ok);
  border-color: var(--ok-border);
  background: var(--ok-bg);
  color: var(--ok);
}

.flash-toast-error {
  --flash-accent: var(--fix);
  border-color: var(--fix-border);
  background: var(--fix-bg);
  color: var(--fix);
}

.flash-toast-info {
  --flash-accent: var(--text-muted);
  border-color: var(--border);
  background: var(--bg);
  color: var(--text);
}

.flash-toast[data-flash-persistent="true"]::after {
  display: none;
}

@keyframes flash-timeout-countdown {
  to { transform: scaleX(0); }
}

@media (max-width: 640px) {
  .flash-stack {
    left: 0.75rem;
    right: 0.75rem;
    width: auto;
  }
}

/* ---- Theme toggle ------------------------------------------- */

.theme-toggle {
  display: inline-flex;
  padding: 0;
  border: none;
  border-radius: var(--radius-pill);
  background: transparent;
  cursor: pointer;
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--primary-400);
  outline-offset: 2px;
  border-radius: var(--radius-pill);
}

.theme-toggle-track {
  position: relative;
  display: block;
  width: 3.25rem;
  height: 2rem;
  border-radius: var(--radius-pill);
  background: linear-gradient(
    90deg,
    color-mix(in oklab, #f4b942 30%, var(--surface)) 0%,
    color-mix(in oklab, #5e84cb 20%, var(--surface)) 100%
  );
  border: 1px solid var(--border);
  transition: background 0.2s ease;
}

.theme-toggle:hover .theme-toggle-track {
  border-color: var(--primary-400);
}

.theme-toggle[data-mode="dark"] .theme-toggle-track {
  background: linear-gradient(
    90deg,
    color-mix(in oklab, #f4b942 12%, #2e3440) 0%,
    color-mix(in oklab, #5e84cb 18%, #2e3440) 100%
  );
  border-color: #434c5e;
}

.theme-toggle-thumb {
  position: absolute;
  top: 50%;
  left: 3px;
  width: 1.5rem;
  height: 1.5rem;
  transform: translateY(-50%);
  border-radius: 50%;
  background: var(--bg);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease;
}

.theme-toggle[data-mode="dark"] .theme-toggle-thumb {
  transform: translateY(-50%) translateX(1.25rem);
  background: #d8dee9;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.theme-toggle-thumb-icon {
  position: absolute;
  width: 0.75rem;
  height: 0.75rem;
  inset: 0;
  margin: auto;
}

.theme-toggle-thumb-sun  { color: #b45309; }
.theme-toggle-thumb-moon { display: none; color: #4c566a; }

.theme-toggle[data-mode="dark"] .theme-toggle-thumb-sun  { display: none; }
.theme-toggle[data-mode="dark"] .theme-toggle-thumb-moon { display: block; }

/* ---- Dropzone ----------------------------------------------- */

.upload-dropzone-frame,
.upload-controls-panel {
  min-height: 14rem;
}

.upload-controls-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
}

.dropzone-icon-circle {
  background: var(--bg);
  box-shadow: var(--shadow-sm);
}

@media (min-width: 1024px) {
  .upload-split-grid { align-items: stretch; }
  .upload-split-grid > * { min-height: 14rem; }
  .upload-controls-panel { height: 100%; }
}

.dropzone-frame {
  border: 2px dashed var(--border);
  border-radius: var(--radius-xl);
  background: var(--surface);
  cursor: pointer;
}

.dropzone-frame:hover,
.dropzone-frame.dropzone--dragover {
  border-color: var(--primary-400);
  background: var(--primary-50);
}

.dropzone-frame.dropzone--has-files {
  border-color: var(--primary-700);
  background: var(--primary-50);
}

.dropzone-file-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  max-width: 14rem;
}

.dropzone-file-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
  border-radius: 9999px;
  font-size: 0.75rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0.6;
  background: none;
  border: none;
  color: inherit;
  padding: 0;
}

.dropzone-file-remove:hover {
  opacity: 1;
}

/* ---- Run instructions --------------------------------------- */

.run-instructions-group {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 0.25rem;
  min-height: 0;
}

.run-instructions-textarea {
  flex: 1 1 auto;
  height: 100%;
  min-height: 0;
}

@media (min-width: 1024px) {
  .run-instructions-textarea { min-height: 9.2rem; }
}

/* ---- Preset picker ------------------------------------------ */

.preset-actions {
  position: relative;
  z-index: 1;
}

.preset-picker {
  position: relative;
  z-index: 20;
}

.preset-picker .input[readonly],
.school-picker-dropdown .input[readonly] {
  cursor: pointer;
}

.preset-picker-menu {
  position: absolute;
  top: calc(100% + 0.25rem);
  left: 0;
  right: 0;
  z-index: 40;
  max-height: 14rem;
  overflow-y: auto;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--bg);
  box-shadow: var(--shadow-lg), 0 0 0 1px rgb(0 0 0 / 0.04);
  padding: 0;
}

/* ---- Combobox input wrap + clear button ------------------------- */

.combobox-input-wrap {
  position: relative;
}

.combobox-input-wrap > .input {
  padding-right: 2rem;
}

/* ---- Combobox search input ------------------------------------- */

.combobox-search-input {
  display: block;
  width: calc(100% - 0.5rem);
  margin: 0.25rem auto;
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius-md) - 2px);
  background: var(--surface);
  color: var(--text);
  font-size: 0.8rem;
  font-family: inherit;
  outline: none;
}
.combobox-search-input:focus {
  border-color: var(--primary-700);
}

.preset-picker-menu .combobox-search-input,
.school-picker-menu .combobox-search-input {
  position: sticky;
  top: 0;
  z-index: 1;
  margin: 0;
  width: 100%;
  padding: 0.5rem;
  border-radius: 0;
  border: none;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

/* ---- Dropdown option rows (shared by school picker + preset picker) ----- */

.dropdown-option-row {
  display: flex;
  align-items: center;
  gap: 0;
  border-radius: 0;
  min-height: 2rem;
  padding-right: 0.35rem;
  padding-left: 0.25rem;
  cursor: pointer;
}

.dropdown-option-row:last-child {
  margin-bottom: 0.25rem;
}

.dropdown-option-row:hover {
  background: var(--surface-hover);
}

.dropdown-option-row.is-active {
  background: var(--primary-50);
  color: var(--primary-700);
}

.dropdown-option-row.is-focused {
  background: var(--surface-hover);
}

.dropdown-option-row.is-active.is-focused {
  background: var(--primary-100);
}

.dropdown-option-select {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  min-width: 0;
  flex: 1;
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 0.84rem;
  line-height: 1.2;
  padding: 0.45rem 0.55rem;
  border-radius: calc(var(--radius-md) - 2px);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
}

.dropdown-option-actions {
  display: flex;
  align-items: center;
  gap: 0.1rem;
  flex-shrink: 0;
  visibility: hidden;
}

.dropdown-option-row:hover .dropdown-option-actions {
  visibility: visible;
}

.dropdown-option-action {
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: calc(var(--radius-md) - 2px);
  height: 1.5rem;
  width: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.5;
  font-family: inherit;
  padding: 0;
}

.dropdown-option-action:hover {
  opacity: 1;
  color: var(--text);
}

/* ---- School picker dropdown (form) -------------------------- */

.school-picker-dropdown {
  position: relative;
  z-index: 30;
}

.school-picker-display {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  height: 2.5rem;
  padding: 0 0.5rem 0 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  cursor: pointer;
  overflow: hidden;
  white-space: nowrap;
}

.runs-toolbar-filters .school-picker-display {
  position: relative;
  height: 2rem;
  padding: 0 2rem 0 0.65rem;
  font-size: 0.8125rem;
  gap: 0;
}

.runs-toolbar-filters .school-picker-display .filter-clear-btn {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
}

.school-picker-display-label {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.school-picker-menu {
  position: absolute;
  top: calc(100% + 0.25rem);
  left: 0;
  min-width: 100%;
  width: max-content;
  max-width: 22rem;
  z-index: 40;
  max-height: 14rem;
  overflow-y: auto;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--bg);
  box-shadow: var(--shadow-lg), 0 0 0 1px rgb(0 0 0 / 0.04);
  padding: 0;
}

/* ---- System preset badge ------------------------------------ */

.preset-system-badge {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  padding: 0.05rem 0.4rem;
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--primary-700);
  background: var(--primary-50);
  border: 1px solid var(--primary-100);
  border-radius: var(--radius-sm);
  line-height: 1.4;
}

.preset-description {
  width: 100%;
  font-size: 0.7rem;
  line-height: 1.3;
  color: var(--text-muted, var(--text));
  opacity: 0.55;
  margin-top: -0.25rem;
}

/* ---- Preset dialog ------------------------------------------ */

.preset-dialog {
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  max-width: min(42rem, calc(100vw - 2rem));
  width: 100%;
  margin: auto;
  color: var(--text);
}

.preset-dialog[open] {
  display: flex;
  flex-direction: column;
}

.preset-dialog::backdrop {
  background: rgb(0 0 0 / 0.35);
  backdrop-filter: blur(2px);
}

.preset-dialog-body {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Dialog form input contrast — stronger borders + inset shadow so dark inputs pop on grey panel */
.preset-dialog .input,
.preset-dialog .textarea,
.preset-dialog .select {
  border-color: var(--border-strong);
}
.dark .preset-dialog .input,
.dark .preset-dialog .textarea {
  box-shadow: inset 0 1px 3px rgb(0 0 0 / 0.35);
}
.preset-dialog .instructions-pre {
  background: var(--bg);
  border-color: var(--border-strong);
}

/* ---- Delete dialog ------------------------------------------ */

.run-delete-dialog {
  max-width: 26rem;
  width: min(26rem, calc(100vw - 1.5rem));
  border-radius: var(--radius-xl);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  margin: auto;
  padding: 0;
  color: var(--text);
}

.run-delete-dialog[open] {
  position: fixed;
  inset: 0;
  margin: auto;
}

.run-delete-dialog::backdrop {
  background: rgb(0 0 0 / 0.35);
  backdrop-filter: blur(2px);
}

/* ---- Runs section header & toolbar -------------------------- */

.runs-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.runs-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.runs-toolbar-filters {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  flex-wrap: wrap;
  min-width: 0;
}

.runs-toolbar-divider {
  width: 1px;
  height: 1.25rem;
  background: var(--border);
  flex-shrink: 0;
}

.runs-toolbar-views {
  display: flex;
  gap: 0.25rem;
}

/* ---- Runs table & empty state ------------------------------- */

.runs-table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-xl);
  border: 1px solid var(--border);
  background: var(--bg);
}


.runs-table-wrap .data-table {
  table-layout: fixed;
  width: 100%;
  min-width: 52rem;
}

.run-table-files-cell {
  max-width: 1px;
  width: 100%;
  overflow: visible;
  position: relative;
  z-index: 1;
}

.run-table-progress-cell {
  min-width: 0;
}

.data-table thead th.run-table-actions-head,
.data-table tbody td.run-table-actions-cell {
  padding-right: 0.5rem;
  padding-left: 0.5rem;
}

.data-table tbody td.run-table-files-cell {
  padding-right: 1.5rem;
}

.data-table tbody td.run-table-actions-cell .runs-actions {
  justify-content: flex-end;
}

.run-progress-track-table {
  flex: 1;
  min-width: 0;
}

.run-table-files-cell > .file-hover > span {
  display: flex;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
}

.run-table-files-cell > .file-hover > span > .truncate {
  min-width: 0;
}

/* Tooltips inside scroll containers are positioned by JS (fixed_tooltip_controller),
   so disable the CSS hover rules to avoid double-showing */
.runs-table-wrap .file-hover:hover .file-tooltip,
.runs-table-wrap .file-hover:focus-within .file-tooltip {
  display: none;
}

.runs-empty-state {
  border-radius: var(--radius-xl);
  border: 2px dashed var(--border);
  padding: 2.5rem 1.5rem;
  text-align: center;
  font-size: 0.875rem;
  opacity: 0.75;
  background: var(--bg);
}

/* ---- Run cards ---------------------------------------------- */

.run-card {
  position: relative;
  z-index: 1;
  background: var(--bg);
  border-color: var(--border);
  min-width: 0;
  overflow: hidden;
}

.run-progress-track-card {
  flex: 1;
  min-width: 0;
}

.run-card:hover,
.run-card:focus-within {
  z-index: 20;
}

.run-card-meta-grid {
  gap: 0.45rem;
  margin-bottom: 0;
}

.run-card-actions {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
}

.run-meta-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  border-radius: var(--radius-md);
  min-height: 2rem;
  padding: 0.35rem 0.55rem;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface);
}

/* ---- Run action buttons ------------------------------------- */

.runs-actions .btn {
  height: 2.05rem;
  min-height: 2.05rem;
  padding-inline: 0.66rem;
  font-size: 0.76rem;
}

.runs-actions .btn-download {
  justify-content: center;
}


/* ---- Narrow-screen fixes ------------------------------------ */

@media (max-width: 479px) {
  /* --- Header nav --- */
  .navbar-icon-link { display: none; }
  .navbar-divider { display: none; }
  .docling-label { display: none; }
  .app-header-controls { gap: 0.35rem; }

  /* --- Toolbar: push filters to own row --- */
  .runs-toolbar-filters {
    width: 100%;
    order: 99;
  }
  .runs-toolbar-divider { display: none; }

  /* --- Upload form --- */
  .upload-dropzone-frame,
  .upload-controls-panel { min-height: 10rem; }
  .upload-controls-panel .grid.grid-cols-2 { grid-template-columns: 1fr; }

  /* --- Run cards: constrain grid & compact spacing --- */
  #runs_cards_list { grid-template-columns: minmax(0, 1fr); }
  .run-card.p-4 { padding: 0.75rem; }
  .run-card .mb-3 { margin-bottom: 0.5rem; }

  /* --- Meta chips: stay 2-col, shrink vertically --- */
  .run-card-meta-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.3rem;
    margin-bottom: 0.75rem;
  }
  .run-meta-chip {
    min-height: 1.6rem;
    padding: 0.2rem 0.4rem;
  }

  /* --- Action bar: tighter --- */
  .run-card-actions {
    margin-top: 0.2rem;
    padding-top: 0.5rem;
  }

  /* --- Buttons: icon-only uniformly --- */
  .run-card-actions .btn span:not(.sr-only) { display: none; }
  .runs-actions .btn-download { min-width: auto; }
}

/* ---- View toggles ------------------------------------------- */

.view-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  text-decoration: none;
}

.view-toggle:hover {
  color: var(--primary-700);
  border-color: var(--primary-400);
}

.view-toggle.is-active {
  color: var(--primary-700);
  border-color: var(--primary-400);
  background: var(--primary-50);
}

/* ---- Details page ------------------------------------------- */

.details-hero {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
}

/* Two-column details grid */
.details-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}
@media (min-width: 768px) {
  .details-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}

.details-info-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0.75rem 1rem;
  min-width: 0;
}

.details-panel-title {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.67rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.55;
  margin-bottom: 0.5rem;
  padding-bottom: 0.45rem;
  border-bottom: 1px solid var(--border);
}

.details-info-rows {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.details-info-row {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  font-size: 0.82rem;
}
.details-info-row dt {
  flex-shrink: 0;
  width: 5.5rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  opacity: 0.55;
}
.details-info-row dd {
  font-weight: 500;
  min-width: 0;
  word-break: break-word;
}

.ui-placeholder-dash {
  font-size: 0.75rem;
  opacity: 0.4;
}

/* Row distribution chips */
.details-row-mix {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.details-row-chip {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  padding: 0.15rem 0.4rem;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.2;
}

.details-row-chip-ok { color: var(--ok); border-color: var(--ok-border); background: var(--ok-bg); }
.details-row-chip-verify { color: var(--verify); border-color: var(--verify-border); background: var(--verify-bg); }
.details-row-chip-fix { color: var(--fix); border-color: var(--fix-border); background: var(--fix-bg); }

/* Edit pencil button */
.btn-icon-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.2rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  opacity: 0.55;
  transition: opacity 0.15s ease;
  cursor: pointer;
}
.btn-icon-ghost:hover { opacity: 1; }

/* Country select wrapper — keeps custom styling but adds native caret via overlay */
.select-wrap {
  position: relative;
}
.select-wrap .select {
  appearance: none;
  padding-right: 2rem;
}
.select-wrap::after {
  content: "";
  pointer-events: none;
  position: absolute;
  right: 0.6rem;
  top: 50%;
  transform: translateY(-50%);
  width: 12px;
  height: 12px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-size: contain;
}

/* Subtle red "Clear" text button for preset picker (inside input) */
.preset-clear-btn {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--fix);
  background: none;
  border: none;
  padding: 0.1rem 0.2rem;
  cursor: pointer;
  opacity: 0.55;
  transition: opacity 0.15s ease;
}
.preset-clear-btn:hover {
  opacity: 1;
}
.preset-clear-btn.hidden {
  display: none;
}

/* Allow school picker dropdown to overflow dialog boundaries */
.preset-dialog:has(.school-picker-dropdown) {
  overflow: visible;
}
.preset-dialog:has(.school-picker-dropdown) .preset-dialog-body {
  overflow: visible;
}

/* Link-styled button */
.link-btn {
  background: none;
  border: none;
  color: var(--primary-700);
  font-size: inherit;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.link-btn:hover { text-decoration: none; }

/* Instructions pre block inside dialog */
.instructions-pre {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.8125rem;
  line-height: 1.6;
  max-height: 20rem;
  overflow-y: auto;
  margin-top: 0.75rem;
  padding: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.details-progress-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.details-progress-wrap .details-progress-track {
  flex: 1;
  min-width: 0;
}


/* ---- File tooltip ------------------------------------------- */

.file-hover {
  position: relative;
  cursor: pointer;
  z-index: 2;
}

.file-hover > * {
  cursor: pointer;
}

.file-hover:hover,
.file-hover:focus-within {
  z-index: 120;
}

.file-tooltip {
  display: none;
  position: absolute;
  left: 0;
  top: calc(100% + 0.35rem);
  z-index: 50;
  min-width: 14rem;
  max-width: min(34rem, 80vw);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  padding: 0.45rem 0.55rem;
}

.file-hover:hover .file-tooltip,
.file-hover:focus-within .file-tooltip {
  display: block;
}

/* Flip tooltip above on the last two table rows so it doesn't get clipped */
.data-table tbody tr:last-child .file-tooltip,
.data-table tbody tr:nth-last-child(2) .file-tooltip {
  top: auto;
  bottom: calc(100% + 0.35rem);
}

.file-tooltip-line {
  font-size: 0.73rem;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-tooltip-line-wrap {
  font-size: 0.73rem;
  line-height: 1.35;
  white-space: normal;
  word-break: break-word;
  max-width: 30rem;
}

/* ---- Icons --------------------------------------------------- */

.ui-icon {
  display: inline-block;
  vertical-align: middle;
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
}

.ui-icon-xs {
  width: 0.78rem;
  height: 0.78rem;
}

.ui-icon-md {
  width: 1.15rem;
  height: 1.15rem;
}

/* ---- Utility classes ---------------------------------------- */

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

.brand-green {
  color: var(--primary-700);
}
