/* ============================================================
   PolicyIQ Admin — Design System
   Tokens, layout, and component classes.
   ============================================================ */

/* ----- Custom properties (design tokens) ----- */
:root {
  /* Sidebar */
  --sidebar-bg:         #0b1437;
  --sidebar-bg-light:   #111c44;
  --sidebar-width:      260px;
  --sidebar-text:       rgba(255,255,255,0.72);
  --sidebar-text-hover: #ffffff;
  --sidebar-active-bg:  rgba(255,255,255,0.12);

  /* Canvas / content */
  --canvas-bg:    #f4f6fb;
  --card-bg:      #ffffff;
  --card-shadow:  0 1px 6px rgba(0,0,0,0.08), 0 4px 16px rgba(0,0,0,0.04);
  --card-radius:  12px;

  /* Accent / brand */
  --accent:           #2563eb;
  --accent-dark:      #1d4ed8;
  --accent-gradient:  linear-gradient(135deg, #2563eb 0%, #1e40af 100%);

  /* Topbar */
  --topbar-bg:     #ffffff;
  --topbar-border: #e5e7eb;
  --topbar-height: 60px;

  /* Text */
  --text-primary:   #111827;
  --text-secondary: #6b7280;
  --text-muted:     #9ca3af;

  /* Status badge colours */
  --badge-success-bg:   #dcfce7;
  --badge-success-text: #166534;
  --badge-review-bg:    #fef9c3;
  --badge-review-text:  #854d0e;
  --badge-failed-bg:    #fee2e2;
  --badge-failed-text:  #991b1b;
  --badge-na-bg:        #f3f4f6;
  --badge-na-text:      #6b7280;

  /* Border */
  --border: #e5e7eb;

  /* Font */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

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

html, body {
  margin: 0; padding: 0;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--canvas-bg);
  height: 100%;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

ul { list-style: none; margin: 0; padding: 0; }

/* ============================================================
   LAYOUT — sidebar + main area
   ============================================================ */

body {
  display: flex;
  min-height: 100vh;
}

/* ----- Sidebar ----- */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
  z-index: 100;
  transition: width 0.2s ease;
}

.sidebar--collapsed {
  width: 64px;
}

.sidebar--collapsed .nav-item__label,
.sidebar--collapsed .sidebar__logo-text,
.sidebar--collapsed .sidebar__section-label {
  display: none;
}

.sidebar--collapsed .nav-item {
  justify-content: center;
  padding: 12px 0;
}

/* Logo */
.sidebar__logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.sidebar__logo-img {
  width: 36px;
  height: 36px;
  object-fit: contain;
  flex-shrink: 0;
  filter: brightness(0) invert(1);
}

.sidebar__logo-text {
  font-size: 18px;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: -0.02em;
}

/* Section labels */
.sidebar__section-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.35);
  padding: 20px 20px 8px;
}

/* Nav items */
.sidebar__nav {
  padding: 0 10px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--sidebar-text);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  text-decoration: none;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  white-space: nowrap;
}

.nav-item:hover {
  background: rgba(255,255,255,0.08);
  color: var(--sidebar-text-hover);
  text-decoration: none;
}

.nav-item--active {
  background: var(--accent) !important;
  color: #ffffff !important;
}

.nav-item__icon {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  width: 18px;
  height: 18px;
}

.nav-item__label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Logout at bottom */
.sidebar__logout {
  margin-top: auto;
  padding: 16px 10px;
  border-top: 1px solid rgba(255,255,255,0.06);
}

.nav-item--logout {
  color: rgba(255,255,255,0.55);
}

.nav-item--logout:hover {
  color: #fc8181;
  background: rgba(252,129,129,0.1);
}

/* Settings label — not a clickable link, just a visual anchor */
.nav-item--section {
  cursor: default;
  opacity: 0.6;
  pointer-events: none;
}

/* ----- Main area ----- */
.main-area {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
  overflow-x: hidden;
  transition: margin-left 0.2s ease;
}

.main-area--collapsed {
  margin-left: 64px;
}

/* ----- Topbar ----- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--topbar-height);
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--topbar-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  gap: 16px;
}

.topbar__left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.topbar__toggle {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 4px;
  display: flex;
  align-items: center;
  border-radius: 4px;
}

.topbar__toggle:hover {
  color: var(--text-primary);
  background: var(--canvas-bg);
}

.topbar__title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.topbar__right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar__user {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
  cursor: pointer;
}

.topbar__avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent-gradient);
  color: #ffffff;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
}

.topbar__username {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.topbar__user-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--card-shadow);
  min-width: 180px;
  z-index: 200;
  padding: 6px 0;
}

.topbar__user-menu hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 4px 0;
}

.topbar__user-menu-item {
  display: block;
  padding: 8px 16px;
  font-size: 13px;
  color: var(--text-primary);
  text-decoration: none;
  background: transparent;
  border: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
}

.topbar__user-menu-item:hover {
  background: var(--canvas-bg);
  text-decoration: none;
}

.topbar__user-menu-item--logout {
  color: #dc2626;
}

/* ----- Page canvas ----- */
.page-canvas {
  flex: 1;
  padding: 28px;
  overflow-y: auto;
}

/* ============================================================
   COMPONENTS
   ============================================================ */

/* ----- Page header ----- */
.page-header {
  margin-bottom: 24px;
}

.page-header__title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 4px;
}

.page-header__subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0;
}

/* ----- Card ----- */
.card {
  background: var(--card-bg);
  border-radius: var(--card-radius);
  box-shadow: var(--card-shadow);
  border: 1px solid rgba(0,0,0,0.04);
}

/* ----- Stat cards ----- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  position: relative;
  background: var(--card-bg);
  border-radius: var(--card-radius);
  box-shadow: var(--card-shadow);
  border: 1px solid rgba(0,0,0,0.04);
  padding: 20px;
}

.stat-card__icon {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-card__label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
  padding-right: 48px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stat-card__value {
  font-size: 28px;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1;
  margin-bottom: 6px;
}

.stat-card__delta {
  font-size: 12px;
  font-weight: 600;
}

.stat-card__delta--up   { color: #16a34a; }
.stat-card__delta--down { color: #dc2626; }

/* ----- Data table ----- */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--card-radius);
}

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

.data-table thead {
  position: sticky;
  top: 0;
  background: var(--canvas-bg);
  z-index: 1;
}

.data-table th {
  text-align: left;
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  vertical-align: middle;
}

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

.data-table tbody tr:hover { background: #f9fafb; }

.data-table .actions-col { text-align: right; }

/* ----- Status badges ----- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}

.badge--success  { background: var(--badge-success-bg);  color: var(--badge-success-text); }
.badge--review   { background: var(--badge-review-bg);   color: var(--badge-review-text); }
.badge--failed   { background: var(--badge-failed-bg);   color: var(--badge-failed-text); }
.badge--na       { background: var(--badge-na-bg);       color: var(--badge-na-text); }
.badge--active   { background: var(--badge-success-bg);  color: var(--badge-success-text); }
.badge--inactive { background: var(--badge-na-bg);       color: var(--badge-na-text); }

/* ----- Filter tab strip ----- */
.tab-btn {
  padding: 12px 16px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: color 0.15s, border-color 0.15s;
}

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

/* ----- Buttons ----- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: opacity 0.15s, box-shadow 0.15s;
  text-decoration: none;
}

.btn:hover { opacity: 0.88; text-decoration: none; }

.btn-primary {
  background: var(--accent-gradient);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(37,99,235,0.3);
}

.btn-primary:hover {
  box-shadow: 0 4px 14px rgba(37,99,235,0.4);
  opacity: 1;
}

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

.btn-secondary {
  background: var(--canvas-bg);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-danger {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fca5a5;
}

.btn-sm {
  padding: 5px 12px;
  font-size: 12px;
  border-radius: 6px;
}

/* ----- Modal ----- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Overlay wrapper used with Alpine x-show — keeps display:flex in CSS
   so Alpine's x-show doesn't accidentally clear it from inline styles. */
.modal-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal {
  background: var(--card-bg);
  border-radius: var(--card-radius);
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  width: 100%;
  max-width: 520px;
  padding: 28px;
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal__title {
  font-size: 17px;
  font-weight: 700;
  margin: 0;
}

.modal__close {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 20px;
  line-height: 1;
  padding: 2px;
}

.modal__close:hover { color: var(--text-primary); }

.modal__footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
}

/* ----- Tabs ----- */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
}

.tab {
  padding: 8px 16px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-secondary);
  border: none;
  background: transparent;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  border-radius: 4px 4px 0 0;
  transition: color 0.15s;
}

.tab:hover { color: var(--accent); }

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

/* ----- Search bar ----- */
.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 12px;
  height: 38px;
}

.search-bar__icon { color: var(--text-muted); flex-shrink: 0; }

.search-bar__input {
  border: none;
  outline: none;
  font-size: 13px;
  color: var(--text-primary);
  background: transparent;
  flex: 1;
}

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

/* ----- Pagination ----- */
.pagination {
  display: flex;
  align-items: center;
  gap: 4px;
  justify-content: flex-end;
  margin-top: 16px;
}

.page-btn {
  min-width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-primary);
  transition: background 0.12s;
  padding: 0 6px;
}

.page-btn:hover { background: var(--canvas-bg); }

.page-btn--active {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}

/* ----- Sortable table headers ----- */
.sort-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: inherit;
  text-decoration: none;
  white-space: nowrap;
}

.sort-link:hover { color: var(--accent); }

.sort-link--active { color: var(--accent); }

/* The caret sits at low contrast until the column is sorted or hovered, so a
   row of headers does not read as a row of arrows. */
.sort-caret { font-size: 9px; opacity: 0.35; }
.sort-link:hover .sort-caret,
.sort-link--active .sort-caret { opacity: 1; }

/* ----- Inline filter select (matches .search-bar height) ----- */
.filter-select {
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--text-primary);
  font-size: 13px;
  padding: 0 10px;
  cursor: pointer;
  max-width: 200px;
}

/* ----- Toast ----- */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  min-width: 240px;
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  animation: piqSlideIn 0.2s ease;
}

.toast--ok     { background: #dcfce7; color: #166534; }
.toast--error  { background: #fee2e2; color: #991b1b; }
.toast--info   { background: #dbeafe; color: #1e40af; }

@keyframes piqSlideIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

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

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

.form-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.form-input-icon {
  position: absolute;
  left: 12px;
  color: var(--text-muted);
  display: flex;
}

.form-input {
  width: 100%;
  padding: 10px 12px 10px 38px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.15s;
  background: var(--card-bg);
}

.form-input:focus { border-color: var(--accent); }

.form-input-eye {
  position: absolute;
  right: 12px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  padding: 0;
}

/* Select */
.form-select {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  color: var(--text-primary);
  outline: none;
  background: var(--card-bg);
  cursor: pointer;
}

.form-select:focus { border-color: var(--accent); }

/* ----- Toolbar row ----- */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.toolbar__left  { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.toolbar__right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ----- Section grid ----- */
.section-grid {
  display: grid;
  gap: 20px;
}

.section-grid--2 { grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); }
.section-grid--3 { grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr)); }

/* ============================================================
   LOGIN PAGE
   ============================================================ */

body.login-body {
  display: flex;
  align-items: stretch;
  min-height: 100vh;
  background: var(--card-bg);
}

.login-container {
  display: flex;
  width: 100%;
  min-height: 100vh;
}

/* Brand panel (left) */
.login-brand {
  flex: 1;
  background: linear-gradient(160deg, #0b1437 0%, #0f2460 50%, #0d3b8c 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px 56px;
  position: relative;
  overflow: hidden;
}

.login-brand::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 30% 70%, rgba(37,99,235,0.18) 0%, transparent 60%),
    radial-gradient(ellipse 50% 40% at 80% 20%, rgba(99,179,237,0.12) 0%, transparent 50%);
  pointer-events: none;
}

/* Decorative artwork on the brand panel */
.login-brand__circuit {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 240px;
  opacity: 0.35;
  pointer-events: none;
}
.login-brand__doc {
  position: absolute;
  right: 28px;
  bottom: 44px;
  width: 150px;
  opacity: 0.14;
  pointer-events: none;
}

.login-brand__inner {
  position: relative;
  z-index: 1;
  max-width: 440px;
}

.login-brand__logo {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 36px;
}

.login-brand__mark { width: 46px; height: 46px; flex-shrink: 0; }
.login-brand__logo-img { width: 48px; height: 48px; object-fit: contain; }

.login-brand__logo-text {
  font-size: 34px;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.login-brand__tagline-group {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}

.login-brand__feature {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 15px;
  font-weight: 700;
}

.login-brand__sep {
  width: 1px;
  height: 18px;
  background: rgba(255,255,255,0.28);
  flex-shrink: 0;
}

.login-brand__rule {
  height: 1px;
  background: rgba(255,255,255,0.14);
  margin: 0 0 30px;
}

.login-brand__headline {
  font-size: 30px;
  font-weight: 800;
  line-height: 1.25;
  color: #ffffff;
  margin: 0 0 16px;
}

.login-brand__body {
  font-size: 15px;
  line-height: 1.6;
  color: rgba(255,255,255,0.65);
  margin: 0;
}

/* Form panel (right) */
.login-form-panel {
  width: 480px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 40px;
  background: var(--card-bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
}

.login-card__logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}

.login-card__logo-img { width: 36px; height: 36px; object-fit: contain; }
.login-card__logo-mark { width: 36px; height: 36px; flex-shrink: 0; }

.login-card__logo-text {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.login-card__title {
  font-size: 24px;
  font-weight: 800;
  color: var(--text-primary);
  margin: 0 0 6px;
}

.login-card__subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin: 0 0 28px;
}

.login-error {
  background: var(--badge-failed-bg);
  color: var(--badge-failed-text);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13.5px;
  font-weight: 600;
  margin-bottom: 18px;
}

.login-form { display: flex; flex-direction: column; }

.btn-login {
  width: 100%;
  justify-content: center;
  padding: 12px;
  font-size: 15px;
  margin-top: 8px;
}

.login-card__footer {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  margin: 28px 0 0;
}

/* ----- Alpine.js cloak ----- */
[x-cloak] { display: none !important; }

/* ----- Responsive ----- */
@media (max-width: 900px) {
  .login-brand { display: none; }
  .login-form-panel { width: 100%; }
}

/* 6-column stat grid only at wide desktop */
@media (min-width: 1280px) {
  .stat-grid { grid-template-columns: repeat(6, 1fr); }
}

@media (max-width: 1100px) {
  .page-canvas { padding: 20px; }
}

@media (max-width: 768px) {
  /* Sidebar becomes an off-canvas overlay drawer: hidden by default (translated
     off-screen), slides in over the content when opened via the burger button.
     Content never gets pushed/margined on mobile — the sidebar floats above it. */
  .sidebar {
    width: 260px;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 200;
  }
  .sidebar:not(.sidebar--collapsed) {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,0.3);
  }
  /* Undo the desktop icon-rail collapse: on mobile "collapsed" just means
     off-screen (via the transform above), so labels stay full-size whenever
     the drawer is actually visible. */
  .sidebar--collapsed { width: 260px; }
  .sidebar--collapsed .nav-item__label,
  .sidebar--collapsed .sidebar__logo-text,
  .sidebar--collapsed .sidebar__section-label { display: revert; }
  .sidebar--collapsed .nav-item { justify-content: flex-start; padding: 10px 20px; }

  .main-area,
  .main-area--collapsed { margin-left: 0; }
  .page-canvas { padding: 16px; }

  /* Section grids stack */
  .section-grid--2,
  .section-grid--3 { grid-template-columns: 1fr !important; }

  /* Page header row-flex wraps */
  .page-header > div { flex-direction: column !important; align-items: flex-start !important; }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 150;
  }
}

@media (min-width: 769px) {
  /* Backdrop only ever makes sense for the mobile overlay drawer */
  .sidebar-backdrop { display: none !important; }
}

/* Hide WHEN column when viewport is narrow — rebalance to 3 cols */
@media (max-width: 1100px) {
  .dash-files-table .col-when { display: none; }
  .dash-files-table col:nth-child(1) { width: 50%; }
  .dash-files-table col:nth-child(2) { width: 26%; }
  .dash-files-table col:nth-child(3) { width: 24%; }
}

/* Hide STATUS column at phone widths — rebalance to 2 cols */
@media (max-width: 640px) {
  .dash-files-table .col-status { display: none; }
  .dash-files-table col:nth-child(1) { width: 65%; }
  .dash-files-table col:nth-child(2) { width: 35%; }
}

@media (max-width: 520px) {
  /* Stat grid: 2 per row on mobile */
  .stat-grid { grid-template-columns: repeat(2, 1fr) !important; }

  /* Topbar: hide page title to save space */
  .topbar__title { display: none; }

  /* Tables: tighter cell padding */
  .data-table th,
  .data-table td { padding: 8px 10px; }
}

/* ============================================================
   EXTRACT PAGE
   ============================================================ */

/* Flush modifier: removes page-canvas padding for the extract layout */
.page-canvas--flush {
  padding: 0;
  overflow: hidden;
}

/* Root flex column filling the content area */
.extract-page {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--topbar-height));
}

/* ----- Upload strip ----- */
.extract-strip {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  height: 52px;
}

.extract-strip__file-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px dashed var(--border);
  transition: border-color 0.15s, color 0.15s;
  white-space: nowrap;
}

.extract-strip__file-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.extract-strip__filename {
  flex: 1;
  font-size: 13px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.extract-strip__stage {
  font-size: 12px;
  color: var(--accent);
  font-weight: 600;
  white-space: nowrap;
}

.extract-strip__api-key {
  width: 220px;
  font-size: 13px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--canvas-bg);
  color: var(--text-primary);
  outline: none;
}

.extract-strip__api-key:focus { border-color: var(--accent); }

/* ----- Drop zone ----- */
.extract-dropzone {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: var(--canvas-bg);
}

.extract-dropzone__icon {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: #fff;
  border: 2px dashed var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.extract-dropzone__title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

.extract-dropzone__sub {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0;
}

/* ----- Split panels ----- */
.extract-panels {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

.extract-pdf {
  width: 55%;
  background: #1e293b;
  overflow-y: auto;
  flex-shrink: 0;
}

.extract-fields-panel {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

/* ----- Banner ----- */
.extract-banner {
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 500;
  border-radius: 6px;
  flex-shrink: 0;
}

.extract-banner.partial {
  background: var(--badge-review-bg);
  color: var(--badge-review-text);
}

.extract-banner.failed {
  background: var(--badge-failed-bg);
  color: var(--badge-failed-text);
}

/* ----- Metrics bar ----- */
.extract-metrics-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
}

.extract-metric {
  font-size: 12.5px;
  color: var(--text-secondary);
}

/* ----- Field sections ----- */
.extract-section {
  padding: 0;
  overflow: hidden;
  flex-shrink: 0;
}

.extract-section__title {
  margin: 0;
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  background: var(--canvas-bg);
  border-bottom: 1px solid var(--border);
}

.extract-field {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
  gap: 8px;
}

.extract-field:last-child { border-bottom: none; }

.extract-field:hover { background: #eff6ff; }

.extract-field--null { opacity: 0.45; }

.extract-field__key {
  flex: 0 0 42%;
  font-size: 12.5px;
  color: var(--text-secondary);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.extract-field__val {
  flex: 1;
  font-size: 12.5px;
  color: var(--text-primary);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.extract-field__dot {
  flex: 0 0 20px;
  display: flex;
  justify-content: center;
}

/* ----- PDF.js elements ----- */
.pdf-page-wrapper {
  position: relative;
  margin: 12px auto;
  display: block;
}

.pdf-page-wrapper canvas { display: block; }

.pdf-page-wrapper .overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
}

.highlight-rect {
  fill: rgba(37, 99, 235, 0.18);
  stroke: #2563eb;
  stroke-width: 2;
}

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

.pulse { animation: pulse-border 1.2s ease-in-out infinite; }

#pdf-error {
  padding: 20px;
  color: #dc2626;
  font-size: 13px;
}
