/* =============================================================================
   DATA GRID & TABLES STYLES
   Data table, search filter toolbar, pagination, card-view mode, and the home page (stat tiles, department cards, table preview).
   ============================================================================= */

/* ---------- Mobile Record Card View ---------- */
    .view-mode-btn {
      padding: var(--space-1) var(--space-3);
      font-size: 0.78rem;
      font-weight: 600;
      border: none;
      background: transparent;
      border-radius: var(--radius-sm);
      cursor: pointer;
      color: var(--muted);
      transition: all 0.15s ease;
    }
    .view-mode-btn.active {
      background: var(--card);
      color: var(--accent);
      box-shadow: 0 1px 4px rgb(var(--shadow-rgb) / 0.08);
    }

    /* Record Cards Grid - Responsive Desktop Multi-Column Grid & Mobile Single-Column */
    .record-cards-grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
      gap: var(--space-4);
    }
    @media (max-width: 640px) {
      .record-cards-grid {
        grid-template-columns: 1fr;
      }
    }
    .record-card {
      background: var(--card);
      border: 1px solid var(--line);
      border-radius: var(--radius-lg);
      padding: var(--space-4);
      box-shadow: 0 2px 8px rgb(var(--shadow-rgb) / 0.04);
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      gap: var(--space-3);
      height: 100%;
      box-sizing: border-box;
      transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
    }
    .record-card:hover {
      box-shadow: 0 6px 18px rgb(var(--shadow-rgb) / 0.08);
      border-color: var(--accent-line);
      transform: translateY(-2px);
    }
    .record-card-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      border-bottom: 1px solid var(--line-soft);
      padding-bottom: var(--space-3);
      font-size: 0.78rem;
      color: var(--muted);
    }
    .record-card-body {
      display: grid;
      grid-template-columns: repeat(2, 1fr);
      gap: var(--space-3) var(--space-4);
    }
    .record-field {
      display: flex;
      flex-direction: column;
      gap: var(--space-half);
    }
    .record-field-label {
      font-size: 0.7rem;
      text-transform: uppercase;
      letter-spacing: 0.04em;
      color: var(--muted);
      font-weight: 600;
    }
    .record-field-value {
      font-size: 0.88rem;
      font-weight: 500;
      color: var(--ink);
      word-break: break-word;
    }
    .record-card-actions {
      display: flex;
      gap: var(--space-2);
      margin-top: var(--space-1);
      border-top: 1px solid var(--line-soft);
      padding-top: var(--space-3);
    }
    .record-card-actions .btn-sm {
      flex: 1;
      justify-content: center;
      min-height: 40px;
      font-size: 0.82rem;
    }


/* ---------- Table Filter Toolbar ---------- */
    .table-filter-bar {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      justify-content: space-between;
      gap: var(--space-3);
      background: var(--card);
      border: 1px solid var(--line);
      border-radius: var(--radius-lg);
      padding: var(--space-3) var(--space-4);
      margin-bottom: var(--space-4);
      box-shadow: 0 2px 6px rgb(var(--shadow-rgb) / 0.03);
    }

    .table-filter-group {
      display: flex;
      align-items: center;
      gap: var(--space-2);
      flex-wrap: wrap;
      flex: 1;
    }

    .table-search-box {
      position: relative;
      display: flex;
      align-items: center;
      min-width: 220px;
      flex: 1;
    }

    .table-search-box input {
      width: 100%;
      height: 38px;
      padding: 0 var(--space-3) 0 36px;   /* 36px clears the search icon; not spacing */
      border: 1px solid var(--line-strong);
      border-radius: var(--radius-md);
      font-size: 0.85rem;
      background: var(--card);
      color: var(--ink);
      outline: none;
      transition: border-color 0.15s ease, box-shadow 0.15s ease;
    }

    .table-search-box input:focus {
      border-color: var(--accent);
      box-shadow: 0 0 0 3px rgb(var(--accent-rgb) / 0.1);
    }

    .table-search-icon {
      position: absolute;
      left: 12px;
      color: var(--subtle);
      font-size: 0.9rem;
      pointer-events: none;
    }

    .table-filter-select {
      height: 38px;
      padding: 0 var(--space-3);
      border: 1px solid var(--line-strong);
      border-radius: var(--radius-md);
      font-size: 0.83rem;
      background: var(--card);
      color: var(--ink);
      outline: none;
      cursor: pointer;
    }

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

    .table-filter-count {
      font-size: 0.8rem;
      color: var(--muted);
      font-weight: 500;
      white-space: nowrap;
    }

    .panel {
      background: var(--card);
      border: 1px solid var(--line);
      border-radius: var(--radius-lg);
      overflow: hidden;
      width: 100%;
      max-width: 100%;
      box-sizing: border-box;
    }


/* ---------- Main Data Table Grid ---------- */
    table.grid {
      width: 100%;
      border-collapse: collapse;
      font-size: 0.85rem;
    }

    table.grid th,
    table.grid td {
      padding: var(--space-3) var(--space-4);
      text-align: left;
      border-bottom: 1px solid var(--line);
      white-space: nowrap;
    }

    table.grid td.cell-wrap,
    table.grid th.cell-wrap {
      white-space: normal;
      word-break: break-word;
    }

    table.grid thead th {
      background: var(--neutral-soft);
      font-size: 0.7rem;
      text-transform: uppercase;
      letter-spacing: 0.05em;
      color: var(--muted);
      cursor: pointer;
      user-select: none;
    }

    table.grid thead th:hover {
      color: var(--ink);
    }

    table.grid tbody tr {
      transition: background-color var(--duration-fast) var(--ease-out),
                  box-shadow var(--duration-fast) var(--ease-out);
    }

    table.grid tbody tr:hover {
      background: var(--accent-soft);
      box-shadow: inset 3px 0 0 var(--accent);
    }

    table.grid tbody tr:active {
      background: var(--accent-soft-strong);
    }

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


    .grid-wrap {
      overflow-x: auto;
      width: 100%;
      max-width: 100%;
      min-width: 0;
      -webkit-overflow-scrolling: touch;
    }

    /* ---------- Sortable headers (A13) ----------
       The whole label is a button (keyboard-operable); aria-sort is on the <th>. */
    .th-sort {
      display: inline-flex;
      align-items: center;
      gap: var(--space-1);
      padding: 0;
      border: 0;
      background: none;
      font: inherit;
      color: inherit;
      letter-spacing: inherit;
      text-transform: inherit;
      cursor: pointer;
    }

    .th-sort:hover {
      color: var(--ink);
    }

    .th-sort .sort-arrow,
    .th-sort svg.sort-arrow {
      width: 12px;
      height: 12px;
      flex-shrink: 0;
    }

    .th-sort .sort-idle {
      opacity: 0.45;
    }

    /* Numbers line up on the right with fixed-width digits (skill 8) */
    table.grid th.num,
    table.grid td.num {
      text-align: right;
      font-variant-numeric: tabular-nums;
    }

    table.grid td.date-cell {
      color: var(--muted);
      font-size: var(--text-xs);
      font-variant-numeric: tabular-nums;
    }

    /* ---------- Records table: dense rows, header stays visible while scrolling ---------- */
    table.grid.dense td {
      padding-block: var(--space-1);   /* ~41px rows around the 32px row buttons */
    }

    .grid-wrap.records-scroll {
      max-height: min(72vh, 780px);
      overflow: auto;
    }

    .grid-wrap.records-scroll thead th {
      position: sticky;
      top: 0;
      z-index: 2;
    }


/* ---------- Pagination Pager ---------- */
    .pager {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: var(--space-3) var(--space-4);
      font-size: 0.8rem;
      color: var(--muted);
    }

    .pager .btns {
      display: flex;
      gap: var(--space-1);
      align-items: center;
    }

    .pager button {
      border: 1px solid var(--line);
      background: var(--card);
      border-radius: var(--radius-md);
      width: 28px;
      height: 28px;
    }

    .pager button:disabled {
      opacity: 0.4;
    }

    .pager .num {
      padding: var(--space-1) var(--space-3);
      border-radius: var(--radius-md);
      font-size: 0.8rem;
    }

    .pager .num.current {
      background: var(--accent-bg);
      color: var(--accent-ink);
    }


/* ---------- Empty State Message ---------- */
    .empty-state {
      padding: var(--space-7) var(--space-5);
      text-align: center;
      color: var(--muted);
      font-size: 0.9rem;
    }

    /* ---------- Empty / error states (skill 5: what, why, what to do) ---------- */
    .state-block {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: var(--space-1);
      padding: var(--space-7) var(--space-5);
      text-align: center;
    }

    .state-icon {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      width: 44px;
      height: 44px;
      margin-bottom: var(--space-1);
      border-radius: var(--radius-lg);
      background: var(--neutral-soft);
      color: var(--muted);
    }

    .state-icon svg {
      width: 22px;
      height: 22px;
    }

    .state-block.is-error .state-icon {
      background: var(--err-soft);
      color: var(--err);
    }

    .state-title {
      margin: 0;
      font-weight: 600;
      color: var(--ink);
    }

    .state-reason {
      margin: 0;
      max-width: 52ch;
      font-size: var(--text-sm);
      color: var(--muted);
    }

    .state-actions {
      display: flex;
      flex-wrap: wrap;
      justify-content: center;
      gap: var(--space-2);
      margin-top: var(--space-2);
    }

    /* ---------- Recently opened strip ----------
       Quick way back to the tables someone uses most, above the directory */
    .recent-strip {
      margin-bottom: var(--space-5);
    }

    .recent-heading {
      margin: 0 0 var(--space-2);
      font-size: var(--text-xs);
      font-weight: 600;
      text-transform: uppercase;
      letter-spacing: 0.08em;
      color: var(--muted);
    }

    .recent-list {
      display: flex;
      flex-wrap: wrap;
      gap: var(--space-2);
    }

    .recent-chip {
      display: inline-flex;
      align-items: center;
      gap: var(--space-2);
      min-height: 36px;
      max-width: 100%;
      padding: var(--space-1) var(--space-3);
      background: var(--card);
      border: 1px solid var(--line);
      border-radius: var(--radius-md);
      color: var(--ink);
      font-size: var(--text-sm);
      font-weight: 600;
      text-decoration: none;
      transition: border-color var(--duration-fast) var(--ease-out),
                  background-color var(--duration-fast) var(--ease-out),
                  scale var(--duration-fast) var(--ease-out);
    }

    .recent-chip:hover {
      border-color: var(--accent-line);
      background: var(--accent-soft);
    }

    .recent-chip:active {
      scale: 0.97;
    }

    .recent-chip i {
      color: var(--muted);
      flex-shrink: 0;
    }

    .recent-chip-name {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .recent-chip-dept {
      flex-shrink: 0;
      font-size: var(--text-xs);
      font-weight: 600;
      color: var(--muted);
      text-transform: uppercase;
      letter-spacing: 0.05em;
    }

    /* ---------- Home: greeting header ----------
       A plain heading instead of the big banner, so departments show on the first screen */
    .home-head {
      display: flex;
      align-items: flex-end;
      justify-content: space-between;
      flex-wrap: wrap;
      gap: var(--space-3);
      margin-bottom: var(--space-5);
    }

    .home-greeting {
      margin: 0;
      font-size: var(--text-2xl);
      font-weight: 700;
      letter-spacing: -0.01em;
      color: var(--ink);
    }

    .home-sub {
      margin: var(--space-1) 0 0;
      font-size: var(--text-base);
      color: var(--muted);
    }

    /* ---------- Home: stat tiles ---------- */
    .stat-tiles {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
      gap: var(--space-4);
      margin-bottom: var(--space-5);
    }

    .stat-tile {
      display: flex;
      align-items: center;
      gap: var(--space-3);
      padding: var(--space-4);
      background: var(--card);
      border: 1px solid var(--line);
      border-radius: var(--radius-lg);
      box-shadow: var(--shadow-sm);
      min-width: 0;
      /* "backwards" (not "both") so the finished animation doesn't pin transform and block the hover lift */
      animation: statTileIn var(--duration-normal) var(--ease-out) backwards;
      transition: transform var(--duration-fast) var(--ease-out),
                  border-color var(--duration-fast) var(--ease-out),
                  box-shadow var(--duration-fast) var(--ease-out);
    }

    /* Tiles arrive one after another, left to right */
    .stat-tile:nth-child(2) { animation-delay: 50ms; }
    .stat-tile:nth-child(3) { animation-delay: 100ms; }
    .stat-tile:nth-child(4) { animation-delay: 150ms; }

    @keyframes statTileIn {
      from {
        opacity: 0;
        transform: translateY(8px);
      }
      to {
        opacity: 1;
        transform: none;
      }
    }

    .stat-tile:hover {
      transform: translateY(-2px);
      border-color: var(--accent-line);
      box-shadow: var(--shadow-hover);
    }

    .stat-tile:hover .stat-icon svg {
      scale: 1.08;
    }

    /* Reduced motion: keep the colour/shadow hover cue, drop the movement */
    @media (prefers-reduced-motion: reduce) {
      .stat-tile:hover {
        transform: none;
      }
      .stat-tile:hover .stat-icon svg {
        scale: none;
      }
    }

    .stat-icon {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      width: 44px;
      height: 44px;
      flex-shrink: 0;
      border-radius: var(--radius-lg);
      background: var(--accent-soft);
      color: var(--accent);
    }

    .stat-icon svg {
      width: 24px;
      height: 24px;
      transition: scale var(--duration-fast) var(--ease-out);
    }

    .stat-body {
      min-width: 0;
    }

    .stat-label {
      font-size: var(--text-sm);
      color: var(--muted);
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .stat-value {
      margin-top: var(--space-half);
      font-size: var(--text-xl);
      font-weight: 700;
      line-height: 1.2;
      color: var(--ink);
      font-variant-numeric: tabular-nums;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .stat-value.is-muted {
      color: var(--muted);
    }

    /* A date/time value is longer than a count, so it steps down a size rather than truncate */
    .stat-value.is-when {
      font-size: var(--text-lg);
      line-height: 1.5;
    }

    .stat-sub {
      font-size: var(--text-xs);
      color: var(--muted);
    }

    /* ---------- Home: department cards (the "master" half) ---------- */
    .dept-panel {
      margin-bottom: var(--space-5);
      padding: var(--space-4) var(--space-5) var(--space-5);
      overflow: visible;
    }

    .dept-panel-head,
    .preview-head {
      display: flex;
      align-items: center;
      flex-wrap: wrap;
      gap: var(--space-3);
      margin-bottom: var(--space-4);
    }

    .dept-panel-icon {
      display: inline-flex;
      color: var(--accent);
    }

    .dept-panel-icon svg {
      width: 28px;
      height: 28px;
    }

    .dept-panel-title,
    .preview-title {
      flex: 1 1 220px;
      min-width: 0;
    }

    .dept-panel-title h2,
    .preview-title h2 {
      margin: 0;
      font-size: var(--text-lg);
      font-weight: 700;
      color: var(--ink);
    }

    .dept-panel-title p,
    .preview-title p {
      margin: var(--space-half) 0 0;
      font-size: var(--text-sm);
      color: var(--muted);
    }

    .dept-search {
      flex: 0 1 340px;
      min-width: 200px;
    }

    .dept-cards {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
      gap: var(--space-3);
    }

    .dept-card {
      display: flex;
      align-items: flex-start;
      gap: var(--space-3);
      width: 100%;
      padding: var(--space-4);
      background: var(--surface-raised);
      border: 1px solid var(--line);
      border-radius: var(--radius-lg);
      color: var(--ink);
      font: inherit;
      text-align: left;
      cursor: pointer;
      transition: border-color var(--duration-fast) var(--ease-out),
                  box-shadow var(--duration-fast) var(--ease-out),
                  transform var(--duration-fast) var(--ease-out),
                  scale var(--duration-fast) var(--ease-out);
    }

    .dept-card:hover {
      border-color: var(--accent-line);
      transform: translateY(-2px);
      box-shadow: var(--shadow-hover);
    }

    .dept-card:focus-visible {
      outline: 2px solid var(--focus-ring);
      outline-offset: 2px;
    }

    /* Selected card: accent border + tint, and the pressed state for screen readers */
    .dept-card[aria-pressed="true"] {
      border-color: var(--accent);
      background: var(--accent-soft);
      box-shadow: 0 0 0 1px var(--accent);
    }

    .dept-card-icon {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      width: 44px;
      height: 44px;
      flex-shrink: 0;
      border-radius: var(--radius-lg);
      background: var(--accent-soft);
      color: var(--accent);
    }

    .dept-card[aria-pressed="true"] .dept-card-icon {
      background: var(--accent-bg);
      color: var(--accent-ink);
    }

    .dept-card-icon svg {
      width: 22px;
      height: 22px;
    }

    .dept-card-body {
      display: flex;
      flex-direction: column;
      gap: var(--space-half);
      flex: 1;
      min-width: 0;
    }

    .dept-card-name {
      font-size: var(--text-base);
      font-weight: 700;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .dept-card-desc {
      font-size: var(--text-xs);
      color: var(--muted);
      line-height: 1.45;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
      overflow: hidden;
    }

    .dept-card-meta {
      display: flex;
      flex-wrap: wrap;
      gap: var(--space-1) var(--space-4);
      margin-top: var(--space-2);
      font-size: var(--text-xs);
      font-weight: 600;
      color: var(--ink-soft);
      font-variant-numeric: tabular-nums;
    }

    .dept-card-meta > span {
      display: inline-flex;
      align-items: center;
      gap: var(--space-1);
    }

    .dept-card-meta svg {
      color: var(--muted);
    }

    .dept-card-go {
      align-self: center;
      flex-shrink: 0;
      color: var(--muted);
      transition: transform var(--duration-fast) var(--ease-out), color var(--duration-fast) var(--ease-out);
    }

    .dept-card:hover .dept-card-go,
    .dept-card[aria-pressed="true"] .dept-card-go {
      color: var(--accent);
    }

    .dept-card:hover .dept-card-go {
      transform: translateX(2px);
    }

    .dept-cards-more {
      display: flex;
      justify-content: center;
      margin-top: var(--space-4);
    }

    /* ---------- Home: selected department's tables (the "detail" half) ---------- */
    .preview-panel .preview-head {
      padding: var(--space-4) var(--space-5) 0;
    }

    .preview-title p {
      display: flex;
      flex-wrap: wrap;
      gap: var(--space-1) var(--space-2);
      font-variant-numeric: tabular-nums;
    }

    /* Dot separators between the preview facts */
    .preview-title p > span + span::before {
      content: "·";
      margin-right: var(--space-2);
    }

    /* Only the table scrolls sideways on narrow screens, never the page */
    .preview-scroll {
      overflow-x: auto;
    }

    .preview-table {
      width: 100%;
      border-collapse: collapse;
      font-size: var(--text-sm);
    }

    .preview-table th {
      padding: var(--space-2) var(--space-4);
      font-size: var(--text-xs);
      font-weight: 600;
      text-align: left;
      text-transform: uppercase;
      letter-spacing: 0.06em;
      color: var(--muted);
      background: var(--neutral-soft);
      border-top: 1px solid var(--line);
      border-bottom: 1px solid var(--line);
      white-space: nowrap;
    }

    .preview-table td {
      padding: var(--space-2) var(--space-4);
      height: 48px;
      color: var(--ink-soft);
      border-bottom: 1px solid var(--line-soft);
      vertical-align: middle;
    }

    .preview-table tbody tr:last-child td {
      border-bottom: 0;
    }

    .preview-table tbody tr {
      cursor: pointer;
      transition: background-color var(--duration-fast) var(--ease-out);
    }

    .preview-table tbody tr:hover {
      background: var(--neutral-soft);
    }

    .preview-table .num {
      text-align: right;
      font-variant-numeric: tabular-nums;
      white-space: nowrap;
    }

    .col-name-inner {
      display: inline-flex;
      align-items: center;
      gap: var(--space-2);
      white-space: nowrap;
    }

    .col-name-inner svg {
      color: var(--muted);
      flex-shrink: 0;
    }

    .col-name a {
      color: var(--ink);
      font-weight: 600;
      text-decoration: none;
    }

    .preview-table tbody tr:hover .col-name a {
      color: var(--accent);
    }

    .col-name a:focus-visible {
      outline: 2px solid var(--focus-ring);
      outline-offset: 2px;
      border-radius: var(--radius-xs);
    }

    .col-desc {
      max-width: 0;
      width: 45%;
    }

    .cell-trunc {
      display: block;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      color: var(--muted);
    }

    .col-updated {
      white-space: nowrap;
      color: var(--muted);
      font-variant-numeric: tabular-nums;
    }

    .col-actions {
      width: 1%;
    }

    .preview-actions {
      display: flex;
      align-items: center;
      justify-content: flex-end;
      gap: var(--space-1);
    }

    .preview-go {
      color: var(--muted);
      margin-left: var(--space-1);
      transition: transform var(--duration-fast) var(--ease-out), color var(--duration-fast) var(--ease-out);
    }

    .preview-table tbody tr:hover .preview-go {
      color: var(--accent);
      transform: translateX(2px);
    }

    /* Narrow screens: recent tables become one sideways-scrolling strip, and the
       preview drops description and last-updated so name + count fit */
    @media (max-width: 768px) {
      .recent-list {
        flex-wrap: nowrap;
        overflow-x: auto;
        scrollbar-width: none;
        margin: 0 calc(-1 * var(--space-4));
        padding: 0 var(--space-4) var(--space-1);
      }
      .recent-chip {
        flex-shrink: 0;
      }
      .home-greeting {
        font-size: var(--text-xl);
      }
      .stat-tiles {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: var(--space-3);
      }
      .stat-tile {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-2);
        padding: var(--space-3) var(--space-4);
      }
      .stat-body {
        width: 100%;
      }
      .stat-label {
        white-space: normal;
      }
      .stat-icon {
        width: 36px;
        height: 36px;
      }
      .stat-icon svg {
        width: 18px;
        height: 18px;
      }
      .stat-value {
        font-size: var(--text-lg);
      }
      .dept-panel {
        padding: var(--space-4);
      }
      .dept-search {
        flex: 1 1 100%;
      }
      .dept-cards {
        grid-template-columns: minmax(0, 1fr);
      }
      .preview-panel .preview-head {
        padding: var(--space-4) var(--space-4) 0;
      }
      .preview-table .col-desc,
      .preview-table .col-updated {
        display: none;
      }
      .preview-table th,
      .preview-table td {
        padding-left: var(--space-3);
        padding-right: var(--space-3);
      }
      .col-name-inner {
        white-space: normal;
      }
      .col-name-inner svg {
        display: none;
      }
    }

/* ---------- Grid Responsive Media Queries ---------- */
    @media (max-width: 768px) {
      .table-filter-bar {
        flex-direction: column;
        align-items: stretch;
        gap: var(--space-3);
      }
      .table-filter-group {
        flex-direction: column;
        width: 100%;
      }
      .table-filter-select, .table-search-box {
        width: 100%;
      }
      .summary-bar {
        grid-template-columns: repeat(2, 1fr);
        display: grid;
        gap: var(--space-2);
      }
      .drawer {
        top: auto;
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        height: 88vh;
        max-height: 88vh;
        z-index: 1050;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        transform: translateY(100%);
        transition: transform var(--duration-normal) var(--ease-out);
        box-shadow: 0 -10px 40px rgb(var(--shadow-rgb) / 0.25);
      }
      .drawer.shown {
        transform: translateY(0);
      }
      .modal-card {
        width: 95%;
        max-width: 95%;
        padding: var(--space-5) var(--space-4);
        margin: var(--space-3);
      }
      input, select, textarea {
        font-size: 16px !important;
        height: 44px;
      }
      .btn {
        min-height: 44px;
      }
    }

    @media (max-width: 640px) {
      .mobile-bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 62px;
        background: var(--card);
        border-top: 1px solid var(--line);
        z-index: 980;
        justify-content: space-around;
        align-items: center;
        box-shadow: 0 -4px 16px rgb(var(--shadow-rgb) / 0.06);
        padding-bottom: env(safe-area-inset-bottom);
      }
      .mobile-nav-link {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: var(--space-half);
        font-size: 0.68rem;
        font-weight: 600;
        color: var(--muted);
        text-decoration: none;
        cursor: pointer;
        background: transparent;
        border: none;
        padding: var(--space-2) var(--space-3);
      }
      .mobile-nav-link.active {
        color: var(--accent);
      }
      .mobile-nav-link .icon {
        font-size: 1.15rem;
      }
      .record-card-body {
        grid-template-columns: 1fr;
      }
    }

    .breadcrumb {
      font-size: 0.78rem;
      color: var(--muted);
      display: flex;
      align-items: center;
      gap: var(--space-1);
      margin-bottom: var(--space-1);
    }

    .page-head {
      display: flex;
      align-items: flex-start;
      justify-content: space-between;
      gap: var(--space-4);
      margin-bottom: var(--space-4);
      flex-wrap: wrap;
    }

    .page-head h1 {
      font-size: 1.4rem;
      margin: 0 0 var(--space-1);
    }

    .page-head .desc {
      color: var(--muted);
      font-size: 0.88rem;
      max-width: 60ch;
    }

    /* ---------- Page actions + "More" menu (table page header) ----------
       Frequent actions stay visible; secondary and destructive ones sit in a menu so the
       header fits on one line on phones and Delete isn't next to Add Record (A9). */
    .page-actions {
      display: flex;
      gap: var(--space-2);
      align-items: center;
      flex-wrap: wrap;
    }

    .btn > svg,
    .menu-item > svg {
      width: 16px;
      height: 16px;
      flex-shrink: 0;
    }

    .menu {
      position: relative;
    }

    .menu-list {
      position: absolute;
      right: 0;
      top: calc(100% + 6px);
      z-index: 50;
      display: grid;
      gap: var(--space-half);
      min-width: 240px;
      padding: var(--space-2);
      background: var(--surface-raised);
      border: 1px solid var(--line);
      border-radius: var(--radius-lg);
      box-shadow: var(--shadow-lg);
    }

    .menu-list[hidden] {
      display: none;
    }

    .menu-item {
      display: flex;
      align-items: center;
      gap: var(--space-2);
      width: 100%;
      min-height: 40px;
      padding: var(--space-2) var(--space-3);
      border: 0;
      border-radius: var(--radius-md);
      background: transparent;
      color: var(--ink);
      font: 500 var(--text-sm) var(--font-sans);
      text-align: left;
      text-decoration: none;
      cursor: pointer;
    }

    .menu-item:hover,
    .menu-item:focus-visible {
      background: var(--neutral-soft);
    }

    .menu-item:disabled {
      color: var(--muted);
      cursor: not-allowed;
    }

    .menu-item.danger {
      color: var(--err);
    }

    .menu-item.danger:hover,
    .menu-item.danger:focus-visible {
      background: var(--err-soft);
    }

    /* Refresh keeps its spinning icon and cooldown text inside the menu */
    .menu-item.spinning .icon {
      animation: spinIcon 1.2s linear infinite;
    }

    .menu-sep {
      height: 1px;
      margin: var(--space-1) var(--space-half);
      background: var(--line);
    }

    /* Filter extras sit inline on larger screens */
    .filter-extras {
      display: contents;
    }

    .show-sm {
      display: none !important;
    }

    /* ---------- Phones: records first ---------- */
    @media (max-width: 640px) {
      .hide-sm {
        display: none !important;
      }

      .show-sm {
        display: flex !important;
      }

      .page-head > div.page-actions {
        flex-wrap: nowrap;
        width: 100%;
      }

      .page-head > div.page-actions .btn {
        flex: 0 0 auto;
        min-width: 0;
      }

      .page-head > div.page-actions #addRecordBtn {
        flex: 1 1 auto;
      }

      .filter-extras {
        display: flex;
        flex-wrap: wrap;
        gap: var(--space-2);
        width: 100%;
      }

      .filter-extras.collapsed-sm {
        display: none;
      }

      /* Search and the Filters button share one line */
      .table-filter-group {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
      }

      .table-filter-group .table-search-box {
        flex: 1 1 180px;
      }

      .summary-bar {
        gap: var(--space-1) var(--space-4);
        padding: var(--space-3) var(--space-4);
        margin-bottom: var(--space-3);
      }

    }

    /* A state block inside the record-cards grid spans every column */
    .state-span {
      grid-column: 1 / -1;
    }
