/**
 * MasonryBid Application Stylesheet
 * Native CSS with @layer structure
 * Dark mode first (respects prefers-color-scheme)
 * Mobile-first responsive design
 */

@layer reset, base, components, modules, utilities;

/* ============================================================
   RESET LAYER
   Normalize browser defaults
   ============================================================ */

@layer reset {
  * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
  }

  html {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

  body {
    margin: 0;
    padding: 0;
  }

  button {
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    font: inherit;
    cursor: pointer;
  }

  input, textarea, select {
    font: inherit;
  }

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

/* ============================================================
   COLOR SYSTEM
   OKLCH for perceptually uniform colors
   Separate light & dark mode palettes
   ============================================================ */

:root {
  /* Light mode defaults */
  --bg: oklch(98% 0 0);                   /* off-white background */
  --surface: oklch(100% 0 0);             /* white input/surface background */
  --text: oklch(20% 0 0);                 /* near-black text */
  --text-secondary: oklch(50% 0 0);       /* medium gray secondary text */
  --border: oklch(75% 0 0);               /* visible gray border */
  
  /* Accent colors */
  --accent: oklch(60% 0.15 250);          /* blue */
  --accent-hover: oklch(55% 0.15 250);    /* blue hover */
  --accent-dark: oklch(50% 0.15 250);     /* blue active/pressed */
  
  /* Status colors */
  --success: oklch(65% 0.2 145);          /* green */
  --warning: oklch(75% 0.15 85);          /* orange */
  --danger: oklch(55% 0.2 25);            /* red */
  
  /* Semantic */
  --focus: var(--accent);                 /* focus outline */
  
  /* Typography */
  --font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "Courier New", monospace;
  
  /* Spacing (8px base unit) */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;
  --space-3xl: 64px;
  
  /* Border radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  
  /* Transitions */
  --transition: 150ms ease-in-out;
}

/* Dark mode (respects OS preference) */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: oklch(15% 0 0);                 /* near-black background */
    --surface: oklch(22% 0 0);            /* dark gray surface for inputs */
    --text: oklch(90% 0 0);               /* near-white text */
    --text-secondary: oklch(70% 0 0);     /* light gray secondary text */
    --border: oklch(45% 0 0);             /* visible border in dark mode */
    
    --accent: oklch(70% 0.15 250);        /* lighter blue */
    --accent-hover: oklch(75% 0.15 250);  /* lighter blue hover */
    --accent-dark: oklch(65% 0.15 250);   /* lighter blue active */
  }
}

/* ============================================================
   BASE LAYER
   Typography, form defaults, structural elements
   ============================================================ */

@layer base {
  body {
    font-family: var(--font-family);
    font-size: 16px;
    line-height: 1.5;
    color: var(--text);
    background-color: var(--bg);
    transition: background-color var(--transition), color var(--transition);
  }

  /* Headings */
  h1 {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.2;
    margin-bottom: var(--space-lg);
  }

  h2 {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.3;
    margin-bottom: var(--space-md);
  }

  h3 {
    font-size: 1.25rem;
    font-weight: 600;
    line-height: 1.4;
    margin-bottom: var(--space-md);
  }

  h4, h5, h6 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: var(--space-sm);
  }

  /* Paragraphs */
  p {
    margin-bottom: var(--space-md);
  }

  /* Links */
  a {
    color: var(--accent);
    text-decoration: underline;
    transition: color var(--transition);
  }

  a:hover {
    color: var(--accent-hover);
  }

  /* Form elements */
  label {
    display: block;
    margin-bottom: var(--space-xs);
    font-weight: 500;
  }

  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="date"],
  input[type="time"],
  textarea,
  select {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background-color: var(--surface);
    color: var(--text);
    transition: border-color var(--transition), box-shadow var(--transition);
  }

  input:focus,
  textarea:focus,
  select:focus {
    outline: none;
    border-color: var(--focus);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--focus) 20%, transparent);
  }

  textarea {
    resize: vertical;
    min-height: 120px;
    font-family: var(--font-family);
  }

  /* Form groups */
  .form-group {
    margin-bottom: var(--space-lg);
  }

  .form-group:last-child {
    margin-bottom: 0;
  }

  /* Error messages */
  .error-message {
    color: var(--danger);
    font-size: 14px;
    margin-top: var(--space-xs);
  }

  .field_with_errors input,
  .field_with_errors textarea,
  .field_with_errors select {
    border-color: var(--danger);
  }

  /* Lists */
  ul, ol {
    margin-bottom: var(--space-md);
    margin-left: var(--space-lg);
  }

  li {
    margin-bottom: var(--space-xs);
  }

  /* Code */
  code {
    font-family: var(--font-mono);
    background-color: var(--surface);
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
    font-size: 14px;
  }

  /* HR */
  hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: var(--space-lg) 0;
  }
}

/* ============================================================
   COMPONENTS LAYER
   Reusable UI components (buttons, alerts, badges, etc.)
   ============================================================ */

@layer components {
  /* Buttons */
  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 36px;
    padding: 0 var(--space-md);
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-size: 14px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    white-space: nowrap;
  }

  .btn:hover {
    transform: translateY(-1px);
  }

  .btn:active {
    transform: translateY(0);
  }

  .btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }

  .btn-primary {
    background-color: var(--accent);
    color: white;
  }

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

  .btn-primary:active {
    background-color: var(--accent-dark);
  }

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

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

  .btn-danger {
    background-color: var(--danger);
    color: white;
  }

  .btn-danger:hover {
    background-color: oklch(50% 0.2 25) !important;
  }

  .btn-success {
    background-color: var(--success);
    color: white;
  }

  .btn-success:hover {
    background-color: oklch(60% 0.2 145);
  }

  /* Renders a button_to as a plain text link — useful when the action needs
     a POST/DELETE (and therefore a form) but should look like an inline link. */
  .btn-as-link {
    background: transparent;
    border: none;
    padding: 0;
    margin: 0;
    color: var(--danger);
    font: inherit;
    cursor: pointer;
    text-decoration: underline;
  }

  .btn-as-link:hover {
    color: oklch(50% 0.2 25);
  }

  /* ── Project show: blueprint primary CTA ── */
  .btn-xl {
    padding: var(--space-sm) var(--space-xl);
    font-size: 1.05rem;
    font-weight: 600;
    border-radius: 8px;
  }

  /* ── Project show: review-gate row ── */
  .review-gates {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    font-size: 0.85rem;
  }

  .review-gate {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text);
    text-decoration: none;
    transition: background var(--transition), border-color var(--transition);
  }

  .review-gate:hover {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 6%, transparent);
  }

  .review-gate-done {
    border-color: color-mix(in srgb, var(--success) 50%, var(--border));
    color: var(--success);
  }

  .review-gate-in-progress {
    border-color: var(--accent);
    color: var(--accent);
  }

  .review-gate-locked {
    opacity: 0.55;
    pointer-events: none;
    cursor: default;
  }

  .review-gate-icon {
    font-weight: 700;
    font-size: 0.95rem;
  }

  .review-gate-count {
    color: var(--text-secondary);
    font-size: 0.8rem;
  }

  /* ── Project show: hero upload state (no blueprints yet) ── */
  .upload-hero {
    text-align: center;
    padding: var(--space-xl) var(--space-md);
  }

  .upload-hero-icon {
    font-size: 2.5rem;
    margin-bottom: var(--space-sm);
  }

  .upload-hero-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: var(--space-xs);
  }

  .upload-hero-hint {
    color: var(--text-secondary);
    margin-bottom: var(--space-md);
  }

  /* ── Project show: blueprint card row ── */
  .blueprint-summary-filename {
    display: inline-block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
  }

  .blueprint-summary-meta {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-top: var(--space-xs);
  }

  .btn-sm {
    padding: var(--space-xs) var(--space-sm);
    font-size: 13px;
  }

  .btn-lg {
    padding: var(--space-md) var(--space-lg);
    font-size: 16px;
  }

  .btn-block {
    display: flex;
    width: 100%;
  }

  /* Alerts */
  .alert {
    padding: var(--space-md);
    margin-bottom: var(--space-md);
    border-radius: var(--radius-sm);
    display: flex;
    justify-content: space-between;
    align-items: center;
    animation: slideDown 200ms ease-out;
  }

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

  .alert-success {
    background-color: color-mix(in srgb, var(--success) 15%, var(--surface));
    color: var(--text);
    border-left: 4px solid var(--success);
  }

  .alert-danger {
    background-color: color-mix(in srgb, var(--danger) 15%, var(--surface));
    color: var(--text);
    border-left: 4px solid var(--danger);
  }

  .alert-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .alert-close::before {
    content: "×";
    font-size: 24px;
  }

  /* Badges */
  .badge {
    display: inline-block;
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
  }

  .badge-primary {
    background-color: color-mix(in srgb, var(--accent) 20%, var(--surface));
    color: var(--accent);
  }

  .badge-success {
    background-color: color-mix(in srgb, var(--success) 20%, var(--surface));
    color: var(--success);
  }

  .badge-warning {
    background-color: color-mix(in srgb, var(--warning) 20%, var(--surface));
    color: var(--warning);
  }

  .badge-danger {
    background-color: color-mix(in srgb, var(--danger) 20%, var(--surface));
    color: var(--danger);
  }

  /* Cards */
  .card {
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-lg);
  }

  .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-lg);
    padding-bottom: var(--space-md);
    border-bottom: 1px solid var(--border);
  }

  .card-title {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
  }

  .card-body {
    margin-bottom: var(--space-lg);
  }

  .card-footer {
    display: flex;
    gap: var(--space-md);
    padding-top: var(--space-md);
    border-top: 1px solid var(--border);
  }

  /* Forms */
  .form {
    max-width: 500px;
  }

  .form-actions {
    display: flex;
    gap: var(--space-md);
    margin-top: var(--space-xl);
  }

  /* File Upload */
  .file-upload {
    border: 2px dashed var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-lg);
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    position: relative;
  }

  .file-upload input[type="file"] {
    display: none;
  }

  .file-upload:hover {
    border-color: var(--accent);
    background-color: color-mix(in srgb, var(--accent) 5%, var(--surface));
  }

  .file-upload.drag-active {
    border-color: var(--accent);
    background-color: color-mix(in srgb, var(--accent) 10%, var(--surface));
  }

  .file-upload-area {
    pointer-events: none;
  }

  .file-upload-label {
    margin-bottom: var(--space-sm);
  }

  .file-upload-preview {
    color: var(--text-secondary);
  }

  /* Estimate Summary */
  .estimate-summary {
    font-size: 14px;
  }

  .summary-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-sm) 0;
  }

  .summary-row strong {
    font-weight: 600;
  }

  /* Tables */
  table {
    width: 100%;
    border-collapse: collapse;
  }

  th {
    background-color: var(--surface);
    color: var(--text);
    padding: var(--space-md);
    text-align: left;
    font-weight: 600;
    border-bottom: 1px solid var(--border);
  }

  td {
    padding: var(--space-md);
    border-bottom: 1px solid var(--border);
  }

  tr:last-child td {
    border-bottom: none;
  }

  /* Spinner/Loading */
  .spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
  }

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

/* ============================================================
   MODULES LAYER
   Page-specific layouts and sections
   ============================================================ */

@layer modules {
  /* Navigation */
  .navbar {
    background-color: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: var(--space-md) 0;
    position: sticky;
    top: 0;
    z-index: 100;
  }

  .navbar-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--space-md);
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .navbar-brand {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent);
  }

  .navbar-menu {
    display: flex;
    gap: var(--space-md);
    align-items: center;
  }

  .navbar-user {
    font-size: 14px;
    color: var(--text-secondary);
  }

  .navbar-role {
    display: inline-block;
    margin-left: var(--space-sm);
    padding: var(--space-xs) var(--space-sm);
    background-color: var(--accent);
    color: white;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
  }

  /* Page layout */
  .page-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--space-lg) var(--space-md);
    min-height: calc(100vh - 200px);
  }

  /* Blueprint show page: fluid edge-to-edge layout */
  .page-content--fluid {
    max-width: none;
  }

  /* Pages with pipeline header: remove top padding so title sits against navbar */
  .page-content--pipeline {
    padding-top: var(--space-xs) !important;
  }

  /* Pipeline header — project name + step navigation */
  .pipeline-header {
    max-width: 1200px;
    margin: 0 auto var(--space-md);
  }

  .pipeline-header-project {
    text-align: center;
    padding: 0 0 var(--space-xs);
  }

  .pipeline-header-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0;
    line-height: 1.3;
  }

  .pipeline-header-address {
    font-size: 0.8rem;
    color: var(--color-text-secondary);
  }

  /* Step navigation */
  .pipeline-steps {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    padding: var(--space-xs) var(--space-md);
    background: var(--color-bg-subtle, #f9fafb);
    border: 1px solid var(--color-border);
    border-radius: 8px;
  }

  .pipeline-step {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 6px;
    text-decoration: none;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--color-text-secondary);
    transition: background 0.15s, color 0.15s;
    cursor: default;
    white-space: nowrap;
  }

  a.pipeline-step {
    cursor: pointer;
  }

  a.pipeline-step:hover {
    background: var(--color-bg-subtle, #f3f4f6);
    color: var(--color-text);
  }

  .pipeline-step--active {
    color: var(--accent);
    font-weight: 600;
    border-bottom: 3px solid var(--accent);
    border-radius: 0;
    padding-bottom: 3px;
  }

  .pipeline-step--done {
    color: var(--success, #16a34a);
  }

  a.pipeline-step--done:hover {
    background: #f0fdf4;
    color: var(--success, #16a34a);
  }

  .pipeline-step--upcoming {
    color: var(--color-text-tertiary, #d1d5db);
  }

  .pipeline-step-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    font-size: 0.7rem;
    font-weight: 700;
    flex-shrink: 0;
    border: 2px solid currentColor;
    line-height: 1;
  }

  .pipeline-step--active .pipeline-step-indicator {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
  }

  .pipeline-step--done .pipeline-step-indicator {
    background: var(--success, #16a34a);
    color: white;
    border-color: var(--success, #16a34a);
  }

  .pipeline-step--upcoming .pipeline-step-indicator {
    border-color: var(--color-text-tertiary, #d1d5db);
  }

  .pipeline-step-label {
    /* Hidden on small screens if needed */
  }

  .pipeline-step-badge {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 6px;
    font-size: 0.6875rem;
    font-weight: 500;
    line-height: 1.3;
    color: var(--color-text-tertiary, #6b7280);
    background: var(--color-bg-secondary, #f3f4f6);
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 4px;
    text-transform: none;
    letter-spacing: 0;
    vertical-align: middle;
  }

  .pipeline-step-connector {
    width: 24px;
    height: 2px;
    background: var(--color-border);
    flex-shrink: 0;
  }

  .pipeline-step-connector--done {
    background: var(--success, #16a34a);
  }

  /* ── Review-card header (3-column) ────────────────────────────────────
     Replaces the old full-width pipeline-header above each review card.
     Left = project name, center = step nav (segmented-control pill),
     right = metric. */
  .review-card-header {
    display: grid;
    grid-template-columns: 20% 1fr auto;
    align-items: center;
    gap: var(--space-md);
    padding: 2px var(--space-md) 14px;
    margin-bottom: 8px; /* breathing room between header and body content */
    background: var(--color-bg, #fff);
    border-radius: 8px 8px 0 0;
    /* Shadow instead of a border-bottom so the separator doesnt get
       covered by opaque body content (the green Masonry Pages card
       was sitting on top of the 1px line). */
    box-shadow: 0 4px 8px -2px rgba(0, 0, 0, 0.08), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
    position: relative;
    z-index: 2;
  }

  .review-card-header-project {
    min-width: 0;
    overflow: hidden;
  }

  .review-card-header-project-name {
    display: inline-block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 700;
    font-size: 1.1rem;
    line-height: 1.3;
    color: var(--color-text);
    vertical-align: middle;
  }

  .review-card-header-metric {
    text-align: right;
    color: var(--color-text);
    font-size: 0.9rem;
    font-weight: 500;
    white-space: nowrap;
    line-height: 1.3;
  }

  /* Segmented-control look: pill container around the whole nav */
  .review-card-steps {
    display: inline-flex;
    align-items: center;
    justify-self: center;
    gap: 2px;
    padding: 3px;
    background: var(--color-bg-subtle, #f3f4f6);
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 999px;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
  }

  .review-card-step {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border-radius: 999px;
    text-decoration: none;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--color-text-secondary);
    transition: background 0.15s, color 0.15s;
    cursor: default;
    white-space: nowrap;
    line-height: 1.3;
  }

  a.review-card-step { cursor: pointer; }
  a.review-card-step:hover {
    background: var(--color-bg, #fff);
    color: var(--color-text);
  }

  .review-card-step--active {
    background: #dbeafe;       /* light blue — matches active tab / active feature */
    color: #1e40af;            /* dark blue for readable contrast */
    font-weight: 600;
    box-shadow: 0 1px 2px rgba(30, 64, 175, 0.08);
  }

  .review-card-step--done {
    color: var(--success, #16a34a);
  }
  a.review-card-step--done:hover {
    background: #f0fdf4;
    color: var(--success, #16a34a);
  }

  .review-card-step--upcoming {
    color: var(--color-text-tertiary, #9ca3af);
  }

  .review-card-step-indicator {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    font-size: 0.7rem;
    font-weight: 700;
    flex-shrink: 0;
    border: 1.5px solid currentColor;
    line-height: 1;
  }

  .review-card-step--active .review-card-step-indicator {
    background: #2563eb;
    color: white;
    border-color: #2563eb;
  }
  .review-card-step--done .review-card-step-indicator {
    background: var(--success, #16a34a);
    color: white;
    border-color: var(--success, #16a34a);
  }
  .review-card-step--upcoming .review-card-step-indicator {
    border-color: var(--color-text-tertiary, #d1d5db);
  }

  .review-card-step-badge {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 6px;
    font-size: 0.65rem;
    font-weight: 500;
    line-height: 1.3;
    color: var(--color-text-tertiary, #6b7280);
    background: var(--color-bg, #fff);
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 4px;
  }

  /* Blueprint toolbar — slim horizontal bar replacing the two-card header */
  .blueprint-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-md);
    padding: var(--space-sm) var(--space-md);
    margin-bottom: var(--space-md);
    max-width: 1200px;
    margin-left: auto;
    margin-right: auto;
    background: var(--color-bg-subtle, #f9fafb);
    border: 1px solid var(--color-border);
    border-radius: 8px;
  }

  .blueprint-toolbar-left {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    min-width: 0;
  }

  .blueprint-toolbar-info {
    display: flex;
    align-items: baseline;
    gap: var(--space-sm);
    min-width: 0;
  }

  .blueprint-toolbar-title {
    font-size: 1rem;
    font-weight: 700;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .blueprint-toolbar-actions {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    flex-shrink: 0;
  }

  .page-header {
    margin-bottom: var(--space-xl);
  }

  .page-header-title {
    margin: 0 0 var(--space-sm) 0;
  }

  .page-header-subtitle {
    margin: 0;
    color: var(--text-secondary);
    font-size: 14px;
  }

  .page-footer {
    background-color: var(--surface);
    border-top: 1px solid var(--border);
    padding: var(--space-lg) var(--space-md);
    text-align: center;
    color: var(--text-secondary);
    font-size: 14px;
    margin-top: var(--space-3xl);
  }

  /* Auth pages */
  .auth-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: var(--space-md);
  }

  .auth-card {
    width: 100%;
    max-width: 400px;
  }

  .auth-heading {
    text-align: center;
    margin-bottom: var(--space-xl);
  }

  .auth-link {
    text-align: center;
    margin-top: var(--space-lg);
    font-size: 14px;
  }

  .auth-link a {
    color: var(--accent);
    text-decoration: underline;
  }

  /* Grid */
  .grid {
    display: grid;
    gap: var(--space-lg);
  }

  .grid-2 {
    grid-template-columns: 1fr;
  }

  @media (min-width: 768px) {
    .grid-2 {
      grid-template-columns: 1fr 1fr;
    }
  }

  .grid-3 {
    grid-template-columns: 1fr;
  }

  @media (min-width: 768px) {
    .grid-3 {
      grid-template-columns: repeat(2, 1fr);
    }
  }

  @media (min-width: 1024px) {
    .grid-3 {
      grid-template-columns: repeat(3, 1fr);
    }
  }

  /* Flex */
  .flex {
    display: flex;
    gap: var(--space-md);
  }

  .flex-center {
    align-items: center;
    justify-content: center;
  }

  .flex-between {
    justify-content: space-between;
  }

  .flex-end {
    justify-content: flex-end;
  }

  .flex-col {
    flex-direction: column;
  }

  /* Responsive adjustments */
  @media (min-width: 768px) {
    .page-content {
      padding: var(--space-xl) var(--space-lg);
    }

    .navbar-container {
      padding: 0 var(--space-lg);
    }
  }

  @media (min-width: 1024px) {
    .page-content {
      padding: var(--space-2xl) var(--space-xl);
    }
  }
}

/* ============================================================
   UTILITIES LAYER
   Single-purpose helper classes
   ============================================================ */

@layer utilities {
  .hidden {
    display: none !important;
  }

  .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
  }

  .mt-xs { margin-top: var(--space-xs); }
  .mt-sm { margin-top: var(--space-sm); }
  .mt-md { margin-top: var(--space-md); }
  .mt-lg { margin-top: var(--space-lg); }
  .mt-xl { margin-top: var(--space-xl); }

  .mb-xs { margin-bottom: var(--space-xs); }
  .mb-sm { margin-bottom: var(--space-sm); }
  .mb-md { margin-bottom: var(--space-md); }
  .mb-lg { margin-bottom: var(--space-lg); }
  .mb-xl { margin-bottom: var(--space-xl); }

  .pt-md { padding-top: var(--space-md); }
  .pb-md { padding-bottom: var(--space-md); }
  .px-md { padding-left: var(--space-md); padding-right: var(--space-md); }
  .py-md { padding-top: var(--space-md); padding-bottom: var(--space-md); }

  .text-center { text-align: center; }
  .text-right { text-align: right; }
  .text-secondary { color: var(--text-secondary); }
  .text-sm { font-size: 14px; }
  .text-xs { font-size: 12px; }

  .w-full { width: 100%; }
  .max-w-sm { max-width: 400px; }
  .max-w-md { max-width: 600px; }
  .max-w-lg { max-width: 800px; }

  .cursor-pointer { cursor: pointer; }
  .opacity-50 { opacity: 0.5; }
}

/* ============================================================
   EXTRACTION REVIEW
   ============================================================ */

@layer components {

  /* Header */
  .review-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 1.5rem;
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
  }

  .review-title h1 { margin: 0; }
  .review-title .subtitle { color: var(--text-muted); margin-top: 0.25rem; }

  .review-stats {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
  }

  .stat {
    text-align: center;
    min-width: 5rem;
  }

  .stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent);
  }

  .stat-label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }

  /* Material summary */
  .material-summary {
    margin-bottom: 2rem;
  }

  .material-summary h2 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
    color: var(--text-muted);
  }

  .summary-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .summary-item {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    padding: 0.375rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    font-size: 0.875rem;
  }

  .summary-item .code {
    font-weight: 700;
    font-family: var(--font-mono, monospace);
  }

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

  .summary-item.deduction {
    border-color: oklch(0.65 0.15 25);
    color: oklch(0.65 0.15 25);
  }

  /* Wall group */
  .wall-group {
    margin-bottom: 2rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    overflow: hidden;
  }

  .wall-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
  }

  .wall-header h2 {
    font-size: 1rem;
    margin: 0;
  }

  .wall-count {
    color: var(--text-muted);
    font-size: 0.875rem;
  }

  /* Takeoff table */
  .takeoff-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
  }

  .takeoff-table th {
    text-align: left;
    padding: 0.5rem 0.75rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
  }

  .takeoff-table td {
    padding: 0.375rem 0.75rem;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
  }

  .takeoff-table tbody tr:hover {
    background: var(--surface);
  }

  /* Row states */
  .deduction-row { color: oklch(0.65 0.15 25); }
  .deduction-row .col-code strong { color: oklch(0.65 0.15 25); }

  .unreviewed { background: oklch(0.97 0.02 85); }

  .modified td:first-child {
    border-left: 3px solid var(--accent);
  }

  /* Status dots */
  .status-dot {
    font-size: 0.75rem;
  }
  .status-dot.reviewed { color: oklch(0.7 0.15 145); }
  .status-dot.unreviewed { color: oklch(0.7 0.1 50); }

  /* Line type badges */
  .line-type {
    display: inline-block;
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    font-weight: 600;
  }

  .line-type.wall_layer { background: oklch(0.85 0.08 220); }
  .line-type.accent_band { background: oklch(0.85 0.1 145); }
  .line-type.material_swap { background: oklch(0.85 0.1 25); }
  .line-type.opening_deduct { background: oklch(0.85 0.1 50); }
  .line-type.head_detail { background: oklch(0.85 0.08 280); }
  .line-type.jamb_detail { background: oklch(0.85 0.08 280); }
  .line-type.sill_detail { background: oklch(0.85 0.08 280); }
  .line-type.lintel { background: oklch(0.85 0.08 0); }
  .line-type.corner { background: oklch(0.85 0.08 180); }
  .line-type.custom { background: oklch(0.85 0.1 310); }

  /* Confidence badges */
  .confidence-badge {
    display: inline-block;
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    font-weight: 600;
  }

  .confidence-high { background: oklch(0.85 0.12 145); }
  .confidence-medium { background: oklch(0.85 0.1 85); }
  .confidence-low { background: oklch(0.85 0.12 25); }

  .negative { color: oklch(0.65 0.15 25); }

  .opening-ref {
    color: var(--text-muted);
    font-style: italic;
  }

  /* Subtotals */
  .wall-subtotal {
    background: var(--surface);
    font-size: 0.875rem;
  }

  /* Notes row */
  .notes-row .item-notes {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-style: italic;
    padding-top: 0;
    padding-bottom: 0.5rem;
  }

  /* Column widths */
  .col-status { width: 2rem; text-align: center; }
  .col-type { width: 5rem; }
  .col-code { width: 8rem; }
  .col-qty { width: 4rem; text-align: right; }
  .col-length { width: 5rem; text-align: right; }
  .col-height { width: 5rem; text-align: right; }
  .col-sf { width: 6rem; text-align: right; }
  .col-conf { width: 4rem; text-align: center; }
  .col-actions { width: 10rem; text-align: right; }

  /* Action buttons */
  .btn-sm {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    border-radius: 0.25rem;
    text-decoration: none;
    color: var(--text);
    border: 1px solid var(--border);
    background: var(--surface);
    cursor: pointer;
  }

  .btn-sm:hover { background: var(--border); }
  .btn-sm.btn-success { background: oklch(0.92 0.08 145); color: oklch(0.35 0.15 145); border-color: oklch(0.65 0.15 145); }
  .btn-sm.btn-success:hover { background: oklch(0.55 0.15 145); color: white; }
  .btn-sm.btn-danger { background: oklch(0.92 0.08 25); color: oklch(0.35 0.15 25); border-color: oklch(0.65 0.15 25); }
  .btn-sm.btn-danger:hover { background: oklch(0.55 0.15 25); color: white; }

  /* Review actions */
  .review-actions {
    margin: 2rem 0;
    padding: 1.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    text-align: center;
  }

  .action-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-bottom: 0.75rem;
  }

  .btn-confirm {
    background: oklch(0.55 0.15 145);
    color: white;
    border: none;
    padding: 0.625rem 1.5rem;
    border-radius: 0.375rem;
    font-weight: 600;
    cursor: pointer;
  }

  .btn-confirm:hover { background: oklch(0.5 0.15 145); }

  .btn-reject {
    background: transparent;
    color: oklch(0.65 0.15 25);
    border: 1px solid oklch(0.65 0.15 25);
    padding: 0.625rem 1.5rem;
    border-radius: 0.375rem;
    font-weight: 600;
    cursor: pointer;
  }

  .btn-reject:hover { background: oklch(0.65 0.15 25); color: white; }

  .action-hint {
    color: var(--text-muted);
    font-size: 0.875rem;
  }

  .confirmed-badge {
    color: oklch(0.55 0.15 145);
    font-weight: 600;
    font-size: 1.125rem;
  }

  /* Form */
  .line-item-form .form-grid {
    display: grid;
    gap: 1rem;
  }

  .form-row-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
  }

  .line-item-form .form-actions {
    margin-top: 1rem;
    display: flex;
    gap: 0.75rem;
  }

  .source-badge {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    font-weight: 600;
  }

  .source-badge.ai { background: oklch(0.85 0.1 220); }
  .source-badge.manual { background: oklch(0.85 0.1 145); }

  .ai-note {
    color: var(--text-muted);
    font-size: 0.875rem;
  }

  .ai-note code {
    background: var(--surface);
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    font-size: 0.8rem;
  }

  /* Summary page */
  .summary-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1.5rem;
  }

  .summary-table th,
  .summary-table td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
  }

  .summary-table thead th {
    background: var(--surface);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
  }

  .summary-table tfoot td {
    background: var(--surface);
    font-weight: 700;
  }

  .general-notes ul {
    padding-left: 1.25rem;
  }

  .general-notes li {
    margin-bottom: 0.375rem;
    color: var(--text-muted);
  }

  .review-nav {
    display: flex;
    gap: 0.75rem;
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
  }

  /* Add item section */
  .add-item {
    margin-top: 2rem;
    padding: 1.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
  }

  .add-item h2 {
    margin-top: 0;
    font-size: 1rem;
  }

  /* Responsive */
  @media (max-width: 768px) {
    .review-header { flex-direction: column; }
    .review-stats { width: 100%; justify-content: space-between; }
    .form-row-3 { grid-template-columns: 1fr; }
    .action-buttons { flex-direction: column; }

    .takeoff-table {
      font-size: 0.75rem;
    }

    .col-conf, .col-actions { display: none; }
  }
}

/* ============================================================
   BLUEPRINT PAGES GRID
   ============================================================ */

@layer components {
  .blueprint-pages-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 1rem;
  }

  .blueprint-page-card {
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    overflow: hidden;
    background: var(--surface);
    transition: box-shadow 0.15s;
  }

  .blueprint-page-card:hover {
    box-shadow: 0 4px 12px oklch(0 0 0 / 0.15);
  }

  .blueprint-page-card.has-masonry {
    border-color: oklch(0.7 0.15 145);
    box-shadow: 0 0 0 2px oklch(0.7 0.15 145 / 0.25);
  }

  .blueprint-page-thumb {
    width: 100%;
    aspect-ratio: 8.5 / 11;
    overflow: hidden;
    background: oklch(0.95 0 0);
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .blueprint-page-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: top;
    display: block;
  }

  .page-thumb-placeholder {
    font-size: 2.5rem;
    opacity: 0.4;
  }

  .blueprint-page-info {
    padding: 0.5rem 0.625rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.8rem;
  }

  .page-badge {
    display: inline-block;
    padding: 0.1rem 0.375rem;
    border-radius: 0.25rem;
    font-size: 0.7rem;
    font-weight: 600;
    background: var(--border);
    color: var(--text);
  }

  .page-badge.masonry {
    background: oklch(0.85 0.12 145);
    color: oklch(0.3 0.1 145);
  }

  /* ── AI Review Cards ───────────────────────────────────── */

  .review-card {
    margin-bottom: var(--space-md);
  }

  .review-card--approved {
    border-left: 3px solid oklch(0.7 0.15 145);
  }

  .review-card--pending {
    border-left: 3px solid oklch(0.7 0.15 50);
  }

  .review-consensus {
    padding: var(--space-sm) var(--space-md);
    background: var(--color-bg-subtle, #f9fafb);
    border-radius: 6px;
    border: 1px solid var(--color-border);
  }

  .review-consensus-value {
    font-size: 1.1rem;
    word-break: break-word;
  }

  .review-approved-banner {
    padding: var(--space-sm) var(--space-md);
    background: oklch(0.95 0.05 145);
    border-radius: 6px;
    border: 1px solid oklch(0.85 0.1 145);
  }

  .review-run-row {
    transition: background 0.1s;
  }

  .review-run-row:hover {
    background: var(--color-bg, #f3f4f6) !important;
  }

  .badge-success {
    background: oklch(0.85 0.12 145);
    color: oklch(0.3 0.1 145);
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
  }

  .badge-pending {
    background: oklch(0.92 0.05 70);
    color: oklch(0.45 0.1 70);
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
  }

  .badge-failed {
    background: oklch(0.92 0.08 25);
    color: oklch(0.5 0.15 25);
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
  }

  /* ── Consensus source label ────────────────────────────── */

  .consensus-source {
    font-weight: 600;
    color: var(--text);
  }

  /* ── Sheet Index Display (consensus value, 2-col) ─────── */

  .sheet-index-display {
    column-count: 2;
    column-gap: 2rem;
    margin-top: 0.5rem;
  }

  .sheet-category {
    break-inside: avoid;
    margin-bottom: 1rem;
  }

  .category-heading {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary, #6b7280);
    margin: 0 0 0.25rem 0;
    padding-bottom: 0.2rem;
    border-bottom: 1px solid var(--border);
  }

  .sheet-item {
    font-size: 0.8rem;
    padding: 0.1rem 0;
    color: var(--text);
  }

  /* ── Sheet Index Comparison — per-run feedback rows ────── */

  .sic-run-feedback-list {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
  }

  .sic-run-feedback-row {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .sic-run-label {
    flex-shrink: 0;
    margin-top: 0.35rem;
    min-width: 6rem;
    text-align: center;
  }

  /* ── Sheet Index Comparison Matrix (individual runs) ───── */

  .sic-legend {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.375rem;
    margin-bottom: 0.75rem;
    padding: 0.5rem 0.75rem;
    background: var(--color-bg-subtle, #f9fafb);
    border: 1px solid var(--border);
    border-radius: 6px;
  }

  .sic-legend-sep {
    color: var(--text-secondary, #9ca3af);
    margin: 0 0.125rem;
  }

  .sic-agreement {
    margin-left: auto;
  }

  .sic-grid {
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }

  .sic-category {
    /* single column — matrix rows need full width for badges */
  }

  .sic-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.15rem 0.375rem;
    border-radius: 3px;
    font-size: 0.8rem;
  }

  .sic-row--warn {
    background: oklch(0.97 0.04 85);
  }

  .sic-row--suspicious {
    background: oklch(0.95 0.06 25);
  }

  .sic-sheet-label {
    flex: 1;
    min-width: 0;
  }

  .sic-runs {
    display: flex;
    gap: 0.25rem;
    flex-shrink: 0;
  }

  .sic-all-agree {
    display: flex;
    gap: 0.1rem;
  }

  .sic-dot {
    font-size: 0.55rem;
    color: oklch(0.75 0 0);
    line-height: 1.6;
  }

  .sic-badge {
    display: inline-block;
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    font-size: 0.7rem;
    font-weight: 600;
    white-space: nowrap;
  }

  .sic-badge--found {
    background: oklch(0.88 0.1 145);
    color: oklch(0.32 0.1 145);
  }

  .sic-badge--missed {
    background: oklch(0.92 0.06 25);
    color: oklch(0.5 0.12 25);
  }
}

/* ═══════════════════════════════════════════════════════════════════
   Classification Review Card (Phase 9)
   ═══════════════════════════════════════════════════════════════════ */

@layer components {
  .classification-review-card {
    position: relative;
  }

  /* Section headers */
  .classification-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    border-radius: 6px;
    margin-bottom: var(--space-xs);
  }

  .classification-section-header--masonry {
    background: oklch(0.95 0.05 145);
    border: 1px solid oklch(0.85 0.1 145);
  }

  .classification-section-header--review {
    background: oklch(0.95 0.08 85);
    border: 1px solid oklch(0.85 0.12 85);
  }

  .classification-section-header--non-masonry {
    background: var(--color-bg-subtle, #f9fafb);
    border: 1px solid var(--color-border);
  }

  .classification-section-body {
    padding: var(--space-sm) 0;
  }

  /* Category groups within sections */
  .category-group {
    margin-bottom: var(--space-md);
  }

  .category-group-header {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    padding: var(--space-xs) var(--space-sm);
    margin: 0 0 var(--space-xs) 0;
    border-bottom: 1px solid var(--color-border);
  }

  .category-group-collapsible {
    margin-bottom: var(--space-xs);
  }

  .category-group-collapsible > summary {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    padding: var(--space-xs) var(--space-sm);
    border-bottom: 1px solid var(--color-border);
  }

  /* Thumbnail grid */
  .page-thumb-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 150px));
    gap: var(--space-xs);
    padding: var(--space-xs) var(--space-sm);
  }

  .page-thumb-grid--small {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: var(--space-xs);
  }

  .page-thumb-card {
    position: relative;
    border: 2px solid var(--color-border);
    border-radius: 6px;
    overflow: hidden;
    transition: border-color 0.2s;
    background: var(--color-bg-subtle, #fff);
    scroll-margin-top: 80px;
  }

  .page-thumb-card.approved {
    border-color: oklch(0.65 0.15 145);
  }

  .page-thumb-card.rescued {
    border-color: oklch(0.65 0.15 85);
  }

  .page-thumb-card.superseded {
    border-color: oklch(0.75 0.15 80);
  }

  .page-thumb-card.superseded .page-thumb-img,
  .page-thumb-card.superseded .page-thumb-placeholder {
    opacity: 0.45;
    filter: grayscale(0.6);
  }

  .page-thumb-superseded,
  .page-thumb-replaces {
    padding: 6px 8px;
    border-top: 1px solid var(--color-border);
    background: oklch(0.97 0.04 80);
    font-size: 0.75rem;
    line-height: 1.3;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
  }

  .page-thumb-replaces {
    background: oklch(0.97 0.04 240);
  }

  .page-thumb-superseded a,
  .page-thumb-replaces a {
    color: var(--accent);
    text-decoration: underline;
  }

  .page-review-row.superseded .page-review-thumb-img {
    opacity: 0.45;
    filter: grayscale(0.6);
  }

  .page-thumb-card:hover {
    border-color: var(--accent);
  }

  .page-thumb-wrapper {
    cursor: pointer;
    position: relative;
    aspect-ratio: 11 / 8.5;
    overflow: hidden;
    background: var(--color-bg-subtle, #f3f4f6);
  }

  .page-thumb-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .page-thumb-check {
    position: absolute;
    top: 4px;
    right: 4px;
    background: oklch(0.55 0.15 145);
    color: white;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
  }

  .page-thumb-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    color: var(--color-text-secondary);
  }

  .page-thumb-info {
    padding: var(--space-xs);
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  .page-thumb-label {
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .page-thumb-confidence {
    font-size: 0.7rem;
    color: var(--color-text-secondary);
  }

  /* Rescue button on non-masonry pages */
  .page-rescue-btn {
    font-size: 0.65rem !important;
    padding: 2px 6px !important;
    margin-top: 2px;
  }

  /* Section 2: Review list view */
  .review-page-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    padding: var(--space-xs) 0;
  }

  .page-review-row {
    border: 1px solid var(--color-border);
    border-radius: 6px;
    overflow: hidden;
  }

  .page-review-main {
    display: flex;
    gap: var(--space-md);
    padding: var(--space-sm) var(--space-md);
  }

  .page-review-thumb {
    flex-shrink: 0;
    width: 120px;
    cursor: pointer;
  }

  .page-review-thumb-img {
    width: 100%;
    border-radius: 4px;
  }

  .page-review-info {
    flex: 1;
    min-width: 0;
  }

  .page-review-header {
    font-size: 0.9rem;
    margin-bottom: var(--space-xs);
  }

  .page-review-actions {
    margin-top: var(--space-sm);
  }

  .page-review-buttons {
    display: flex;
    gap: var(--space-sm);
  }

  .page-review-decided {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-xs);
  }

  .page-review-feedback {
    margin-top: var(--space-sm);
    padding: var(--space-sm);
    background: var(--color-bg-subtle, #f9fafb);
    border-radius: 6px;
    border: 1px solid var(--color-border);
  }

  /* Reason chips */
  .reason-chips {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
    margin-bottom: var(--space-xs);
  }

  .reason-chip {
    font-size: 0.75rem;
    padding: 4px 10px;
    border-radius: 20px;
    border: 1px solid var(--color-border);
    background: var(--color-bg-subtle, #fff);
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all 0.15s;
  }

  .reason-chip:hover {
    border-color: var(--accent);
    color: var(--accent);
  }

  .reason-chip.selected {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
  }

  /* ── Google Images-style layout ── */
  .classification-layout {
    display: flex;
    gap: var(--space-md);
    align-items: flex-start;
  }

  .classification-sections {
    flex: 1;
    min-width: 260px;
    max-width: 1200px;
  }

  .classification-layout.panel-open .classification-sections {
    flex: 0 0 30%;
    max-width: none;
    max-height: calc(100vh - 72px);
    overflow-y: auto;
    position: sticky;
    top: 72px;
  }

  /* Side panel */
  .classification-side-panel {
    flex: 0 1 68%;
    position: sticky;
    top: 72px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background: var(--color-bg, #fff);
    overflow: hidden;
    max-height: calc(100vh - 72px);
    overflow-y: auto;
    box-shadow: -4px 0 16px rgba(0, 0, 0, 0.08), 0 2px 8px rgba(0, 0, 0, 0.06);
  }

  .side-panel-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-xs) var(--space-sm) var(--space-xs) var(--space-md);
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg-subtle, #f9fafb);
    position: sticky;
    top: 0;
    z-index: 1;
  }

  .side-panel-nav {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
  }

  .side-panel-nav-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 1.3rem;
    cursor: pointer;
    transition: background 0.15s;
  }

  .side-panel-nav-btn:hover:not(:disabled) {
    background: var(--color-border);
  }

  .side-panel-nav-btn:disabled {
    opacity: 0.3;
    cursor: default;
  }

  .side-panel-title {
    flex: 1;
    min-width: 0;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .side-panel-close {
    background: none;
    border: none;
    font-size: 1.3rem;
    line-height: 1;
    color: var(--color-text-secondary);
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    flex-shrink: 0;
  }

  .side-panel-close:hover {
    background: var(--color-border);
    color: var(--color-text);
  }

  .side-panel-img-container {
    position: relative;
  }

  .side-panel-edge-nav {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 32px;
    z-index: 2;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0);
    font-size: 1.8rem;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .side-panel-edge-nav:hover {
    background: rgba(0, 0, 0, 0.3);
    color: rgba(255, 255, 255, 0.9);
  }

  .side-panel-edge-prev { left: 0; }
  .side-panel-edge-next { right: 0; }

  .side-panel-img-viewport {
    overflow: hidden;
    background: #fff;
    max-height: calc(100vh - 200px);
    position: relative;
  }

  .side-panel-img {
    width: 100%;
    display: block;
    max-height: calc(100vh - 200px);
    object-fit: contain;
    cursor: default;
    transform-origin: 0 0;
    transition: none;
    user-select: none;
    -webkit-user-select: none;
  }

  .zoom-controls {
    position: absolute;
    bottom: 8px;
    left: 8px;
    right: auto;
    display: flex;
    gap: 2px;
    z-index: 3;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 6px;
    padding: 2px;
  }

  .zoom-btn {
    width: 32px;
    height: 28px;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.85);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    text-decoration: none;
    transition: background 0.15s;
  }

  .zoom-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
  }

  #zoom_level_btn {
    width: auto;
    padding: 0 6px;
    font-size: 0.75rem;
  }

  .sheet-badge {
    position: absolute;
    bottom: 8px;
    right: 8px;
    z-index: 3;
    background: rgba(0, 0, 0, 0.6);
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.8rem;
    font-weight: 500;
    border-radius: 6px;
    padding: 6px 10px;
    display: flex;
    align-items: center;
    gap: 4px;
    pointer-events: none;
    user-select: none;
  }

  .sheet-badge-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 35vw;
  }

  .sheet-badge-meta {
    flex-shrink: 0;
    white-space: nowrap;
  }

  /* Feature-review clickable callout links — drawn as invisible hit-zones
     over the diagram image, revealed on hover with a blue tint. */
  .fr-callout-link {
    position: absolute;
    cursor: pointer;
    border: 1px solid transparent;
    background: transparent;
    border-radius: 2px;
    pointer-events: auto;
    transition: background 0.1s, border-color 0.1s;
  }

  .fr-callout-link:hover {
    background: rgba(59, 130, 246, 0.18);
    border-color: rgba(59, 130, 246, 0.8);
  }

  .fr-callout-link.fr-callout-unresolved {
    cursor: not-allowed;
  }

  .fr-callout-link.fr-callout-unresolved:hover {
    background: rgba(148, 163, 184, 0.18);
    border-color: rgba(148, 163, 184, 0.8);
  }

  /* Tab bar in the feature-review right panel header.
     Horizontal scroll when overflowing, per-tab close button.
     Grey bottom line on the header, broken under the active tab. */
  .fr-tab-header {
    gap: 0;
    padding: 0 var(--space-xs);
    border-bottom: none; /* replaced by the ::after line below — needed because
                             the tab bars overflow clips any margin-bottom trick,
                             so the active tab has to overlap an *internal* line. */
    position: relative;
  }

  .fr-tab-header::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 1px;
    background: #d1d5db;
    z-index: 0;
    pointer-events: none;
  }

  .fr-tab-bar {
    display: flex;
    align-self: stretch;
    align-items: flex-end;
    flex: 1 1 auto;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
    gap: 2px;
    min-width: 0;
    position: relative;
    z-index: 1;
  }

  .fr-tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
    padding: 4px 8px 4px 10px;
    font-size: 0.8rem;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px 6px 0 0;
    cursor: pointer;
    color: var(--color-text-secondary);
    white-space: nowrap;
    max-width: 240px;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
  }

  .fr-tab:hover {
    background: rgba(59, 130, 246, 0.08);
    color: var(--color-text);
  }

  .fr-tab.active {
    background: #dbeafe; /* light blue — matches selected page card */
    color: var(--color-text);
    border-color: #2563eb; /* dark blue */
    border-bottom-color: #dbeafe; /* match bg so the tabs bottom edge breaks the headers grey line */
    font-weight: 600;
  }

  .fr-tab-label {
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .fr-tab-close {
    border: none;
    background: transparent;
    color: rgba(100, 116, 139, 0.8);
    font-size: 0.95rem;
    line-height: 1;
    padding: 0 4px;
    cursor: pointer;
    border-radius: 3px;
  }

  .fr-tab-close:hover {
    background: rgba(239, 68, 68, 0.15);
    color: #dc2626;
  }

  /* While a new diagram image is loading, hide the floating zoom widget,
     sheet badge, scale badge, and feature-review overlay toggle so they
     dont flash against the empty white viewport. */
  .side-panel-img-container[data-img-loaded="false"] .zoom-controls,
  .side-panel-img-container[data-img-loaded="false"] .sheet-badge,
  .side-panel-img-container[data-img-loaded="false"] .scale-badge,
  .side-panel-img-container[data-img-loaded="false"] .fr-overlay-toggle {
    visibility: hidden;
  }

  /* ── Scale badge (bottom-left) ─────────────────────────────────────────
     Non-interactive pill showing the architectural scale of the diagram
     being viewed (e.g. 1/4" = 1'-0"). Matches .sheet-badge visuals. */
  .scale-badge {
    position: absolute;
    bottom: 8px;
    left: 8px;
    z-index: 3;
    background: rgba(0, 0, 0, 0.6);
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.8rem;
    font-weight: 500;
    border-radius: 6px;
    padding: 6px 10px;
    pointer-events: none;
    user-select: none;
    white-space: nowrap;
  }

  /* When a zoom-controls widget is also at bottom-left (e.g. diagram
     review panel), stack the scale badge above it. */
  .scale-badge--above-zoom {
    bottom: 46px;
  }

  /* Feature-review overlay toggle — standalone button in the top-right of
     the viewport, replacing the toggle that used to live inside the now-
     removed zoom-controls strip. */
  .fr-overlay-toggle {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 3;
    width: 32px;
    height: 28px;
    background: rgba(0, 0, 0, 0.6);
    color: rgba(255, 255, 255, 0.85);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    transition: background 0.15s, color 0.15s;
  }

  .fr-overlay-toggle:hover {
    background: rgba(0, 0, 0, 0.75);
    color: #fff;
  }

  /* ── Blueprint upload: reorderable file list ───────────────────────── */
  .file-stage {
    list-style: none;
    padding: 0;
    margin: 0 0 var(--space-sm) 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
  }

  .file-row {
    display: grid;
    grid-template-columns: 20px 24px 24px 1fr auto 28px;
    align-items: center;
    gap: var(--space-sm);
    padding: 10px var(--space-sm);
    background: var(--color-bg, #fff);
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 8px;
    cursor: grab;
    transition: border-color 0.12s, box-shadow 0.12s, opacity 0.12s;
  }

  .file-row:hover {
    border-color: var(--accent);
  }

  .file-row.is-dragging {
    opacity: 0.4;
    cursor: grabbing;
  }

  .file-row.drop-above {
    box-shadow: 0 -2px 0 var(--accent);
  }

  .file-row.drop-below {
    box-shadow: 0 2px 0 var(--accent);
  }

  .file-row-handle {
    color: var(--color-text-tertiary, #9ca3af);
    font-size: 1rem;
    line-height: 1;
    user-select: none;
    text-align: center;
    letter-spacing: -2px;
  }

  .file-row-number {
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--color-text-secondary);
    text-align: center;
  }

  .file-row-icon {
    font-size: 1.05rem;
    text-align: center;
  }

  .file-row-main {
    min-width: 0;
    overflow: hidden;
  }

  .file-row-name {
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .file-row-sub {
    font-size: 0.75rem;
    color: var(--color-text-secondary);
    margin-top: 2px;
  }

  .file-row-meta {
    font-size: 0.8rem;
    color: var(--color-text-secondary);
    white-space: nowrap;
  }

  .file-row-close {
    background: transparent;
    border: none;
    color: var(--color-text-secondary);
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
    border-radius: 4px;
    padding: 2px 6px;
  }

  .file-row-close:hover {
    background: #fee2e2;
    color: #dc2626;
  }

  .upload-addmore {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
    width: 100%;
    padding: 10px;
    background: transparent;
    border: 1px dashed var(--color-border, #d1d5db);
    border-radius: 6px;
    color: var(--color-text-secondary);
    cursor: pointer;
    font-size: 0.9rem;
    transition: border-color 0.12s, color 0.12s, background 0.12s;
  }

  .upload-addmore:hover,
  .upload-addmore.drag-over {
    border-color: var(--accent);
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 5%, transparent);
  }

  /* Drop highlight for the initial empty zone */
  .file-upload.drag-over {
    border-color: var(--accent) !important;
    background: color-mix(in srgb, var(--accent) 5%, transparent);
  }

  .upload-summary {
    font-size: 0.85rem;
    color: var(--color-text-secondary);
    text-align: center;
    padding: var(--space-xs) 0;
  }

  .page-detail-inline {
    grid-column: 1 / -1;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background: var(--color-bg-subtle, #f9fafb);
    margin: var(--space-xs) 0;
    overflow: hidden;
  }

  .side-panel-sheet-title {
    font-size: 0.9rem;
    font-weight: 600;
    padding: var(--space-xs) var(--space-md) 0;
    margin: 0;
    color: var(--color-text);
  }

  .side-panel-section {
    padding: var(--space-sm) var(--space-md);
  }

  .side-panel-label {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-secondary);
    margin: 0 0 var(--space-xs) 0;
    list-style: none;
  }

  .side-panel-text {
    font-size: 0.85rem;
    color: var(--color-text);
    margin: 0;
    line-height: 1.5;
    font-style: italic;
  }

  /* Run row styles */
  .run-row:hover {
    background: var(--color-bg-hover, #f3f4f6) !important;
  }
  .run-row-selected {
    background: #dbeafe !important;
    border-color: #2563eb !important;
  }
  .run-summary-btn {
    border: 1px solid var(--color-border);
    background: var(--color-bg);
    color: var(--color-text-secondary);
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.15s, color 0.15s;
  }
  .run-summary-btn:hover {
    background: #dbeafe;
    color: #2563eb;
    border-color: #2563eb;
  }
  .run-summary-btn.active {
    background: #2563eb;
    color: #fff;
    border-color: #2563eb;
  }

  /* Selected card highlight (Google Images style — blue outline + blue glow around entire card) */
  .page-thumb-card.panel-selected {
    background: #dbeafe;
    border-color: #2563eb !important;
    outline: 1px solid #2563eb;
    outline-offset: 3px;
    box-shadow: 0 0 0 5px #dbeafe;
  }

  .page-review-row.panel-selected {
    background: #dbeafe;
    outline: 1px solid #2563eb;
    outline-offset: 2px;
    border-radius: 6px;
  }

  /* Diagram bounding boxes on page preview */
  .diagram-bbox {
    transition: box-shadow 0.2s ease;
  }
  .diagram-bbox:hover {
    box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.3);
  }

  /* btn-xs for small rescue buttons */
  .btn-xs {
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 3px;
  }
}

/* ── Classification review: download pulse animation ── */
@keyframes classreview-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.6); }
  70%  { box-shadow: 0 0 0 14px rgba(37, 99, 235, 0); }
  100% { box-shadow: 0 0 0 0 rgba(37, 99, 235, 0); }
}

.download-pulse {
  animation: classreview-pulse 0.7s ease-out 3;
}

@media (prefers-reduced-motion: reduce) {
  .download-pulse {
    animation: none;
  }
}

/* ============================================================
   FEATURE REVIEW UI (Review Gate 3)
   Accordion list + diagram overlay
   ============================================================ */

/* ── Feature accordion row ── */
.feature-row {
  border-bottom: 1px solid var(--border);
}

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

.feature-row-header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  cursor: pointer;
  user-select: none;
  transition: background var(--transition);
}

.feature-row-header:hover {
  background: color-mix(in srgb, var(--accent) 5%, transparent);
}

.feature-row.panel-selected > .feature-row-header {
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.feature-row--approved > .feature-row-header {
  background: color-mix(in srgb, var(--success) 5%, transparent);
}

.feature-row-status-icon {
  font-size: 1rem;
  width: 1.2rem;
  text-align: center;
  flex-shrink: 0;
}

.feature-row-name {
  flex: 1;
  font-size: 0.875rem;
  font-weight: 500;
}

.feature-row-count {
  flex-shrink: 0;
  font-size: 0.75rem;
}

.feature-row-badge {
  flex-shrink: 0;
}

.feature-row-arrow {
  font-size: 0.65rem;
  color: var(--text-secondary);
  flex-shrink: 0;
  width: 1rem;
  text-align: center;
}

/* ── Feature body ── */
.feature-row-body {
  border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 60%, var(--surface));
}

.feature-detail-inner {
  padding: var(--space-sm);
}

/* ── Wall section row ── */
.wall-section-row {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-sm);
  background: var(--surface);
  overflow: hidden;
  transition: border-color var(--transition);
}

.wall-section-row:hover {
  border-color: var(--accent);
}

.wall-section-row.wall-highlighted {
  border-color: #f59e0b;
  box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.2);
}

.wall-section-header {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-sm);
  background: color-mix(in srgb, var(--bg) 80%, var(--surface));
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}

.wall-status-icon {
  font-size: 0.85rem;
  flex-shrink: 0;
}

.wall-location-input {
  flex: 1;
  font-size: 0.8rem !important;
  padding: 2px 4px !important;
  height: auto !important;
  min-height: 0 !important;
  border-radius: 3px !important;
}

.wall-sf-badge {
  flex-shrink: 0;
  font-size: 0.75rem;
  color: var(--text-secondary);
  min-width: 60px;
  text-align: right;
}

/* ── Wall measurement grid ── */
.wall-fields-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  padding: var(--space-xs) var(--space-sm);
}

.wall-field-label {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0;
  margin: 0;
  display: block;
}

.wall-field-input {
  width: 100% !important;
  padding: 3px 4px !important;
  font-size: 0.78rem !important;
  height: auto !important;
  min-height: 0 !important;
  border-radius: 3px !important;
}

.wall-field-select {
  width: 100% !important;
  padding: 3px 4px !important;
  font-size: 0.78rem !important;
  height: auto !important;
  min-height: 0 !important;
  border-radius: 3px !important;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

/* ── Wall openings ── */
.wall-openings-section {
  padding: var(--space-xs) var(--space-sm);
  border-top: 1px dashed var(--border);
}

.opening-row {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 3px;
  font-size: 0.78rem;
}

/* ── Diagram chip buttons ── */
.diagram-chip {
  padding: 2px 8px;
  font-size: 0.72rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: all var(--transition);
}

.diagram-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.diagram-chip.active {
  background: #dbeafe; /* light blue — matches the active tab */
  color: var(--text);
  border-color: #2563eb; /* dark blue */
}

/* ── Feature action buttons ── */
.feature-actions {
  display: flex;
  gap: var(--space-sm);
  padding: var(--space-sm) 0 var(--space-xs);
  align-items: center;
}

/* ── Badge danger (missing from base styles) ── */
.badge-danger {
  background: color-mix(in srgb, var(--danger) 15%, transparent);
  color: var(--danger);
}
