/* ═══════════════════════════════════════════
   GridView — universal list/table styles
   ═══════════════════════════════════════════ */

.gv-root {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* ── Filter bar (canonical-ordered chip row) ── */
.gv-filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  padding: 0.75rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.gv-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.625rem;
  background: var(--bg-alt, var(--bg));
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.8125rem;
  color: var(--text-primary);
  position: relative;
  transition: border-color 0.15s, background 0.15s;
}
.gv-chip:hover { border-color: var(--accent); }

.gv-chip-label {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.75rem;
}

.gv-chip select,
.gv-chip input {
  background: transparent;
  border: 0;
  outline: 0;
  color: var(--text-primary);
  font-size: 0.8125rem;
  padding: 0;
  font-family: inherit;
}

.gv-chip select {
  cursor: pointer;
  padding-right: 0.25rem;
}

.gv-chip-search {
  flex: 1;
  min-width: 200px;
  max-width: 320px;
}
.gv-chip-search .gv-search-input {
  flex: 1;
  min-width: 0;
}

.gv-chip-range input[type="number"] {
  width: 72px;
}

.gv-chip-value {
  font-weight: 500;
}

.gv-chip-clear {
  background: none;
  border: 0;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1;
  padding: 0 0.125rem;
}
.gv-chip-clear:hover { color: var(--danger); }

/* Multi-select dropdown */
.gv-chip-multi { cursor: pointer; }
.gv-chip-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 180px;
  max-height: 280px;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  padding: 0.375rem;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}
.gv-chip-dropdown.hidden { display: none; }
.gv-chip-dropdown label {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.5rem;
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
}
.gv-chip-dropdown label:hover { background: var(--bg-alt); }

/* ── Toolbar (saved views + meta) ── */
.gv-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.gv-views {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  align-items: center;
}

.gv-views-label {
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 500;
  margin-right: 0.25rem;
}

.gv-view-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.625rem;
  background: var(--bg-alt, var(--bg));
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.75rem;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.15s;
}
.gv-view-chip:hover {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.06);
}
.gv-view-chip.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.gv-view-save {
  border-style: dashed;
  color: var(--accent);
}

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

/* ── Grid table ── */
.gv-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.gv-table thead th {
  text-align: left;
  font-weight: 600;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.625rem 0.75rem;
  background: var(--bg-alt, var(--bg));
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1;
}

.gv-table thead th.sortable {
  cursor: pointer;
  user-select: none;
}
.gv-table thead th.sortable:hover { color: var(--accent); }

.gv-sort-arrow {
  display: inline-block;
  margin-left: 0.25rem;
  color: var(--accent);
  font-size: 0.6875rem;
}

.gv-table tbody td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.gv-table tbody tr:hover { background: rgba(99, 102, 241, 0.04); }

.gv-table .align-right { text-align: right; }
.gv-table .align-center { text-align: center; }

/* ── Triage strip ── */
.gv-triage {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.625rem;
  margin-bottom: 0.25rem;
  align-items: stretch;
}
.gv-triage-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  text-align: left;
  cursor: pointer;
  position: relative;
  transition: transform 0.1s, border-color 0.15s, box-shadow 0.15s;
}
.gv-triage-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}
.gv-triage-card.active {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.06);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.25);
}
.gv-triage-label {
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 0.25rem;
}
.gv-triage-value {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.1;
}
.gv-triage-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.125rem;
}
.gv-triage-hint {
  font-size: 0.6875rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}
.gv-triage-danger .gv-triage-value { color: var(--danger); }
.gv-triage-warning .gv-triage-value { color: var(--warning); }
.gv-triage-success .gv-triage-value { color: var(--success); }
.gv-triage-info .gv-triage-value { color: var(--accent); }
.gv-triage-help {
  align-self: center;
  justify-self: end;
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* ── Toolbar tools ── */
.gv-toolbar-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  position: relative;
}
.gv-tool {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
}
.gv-tool-label {
  color: var(--text-muted);
  font-weight: 500;
}
.gv-tool select {
  background: var(--bg-alt, var(--bg));
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  color: var(--text-primary);
  cursor: pointer;
}

/* ── Group-by pills (replaces old <select>) ── */
.gv-tool-group {
  flex-wrap: wrap;
  gap: 0.375rem;
}
.gv-group-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  align-items: center;
}
.gv-group-pill {
  background: var(--bg-alt, var(--bg));
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 0.3125rem 0.75rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.12s, background 0.12s, color 0.12s, transform 0.08s;
}
.gv-group-pill:hover {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.06);
}
.gv-group-pill.active {
  background: var(--success, #10b981);
  color: white;
  border-color: var(--success, #10b981);
}
.gv-group-pill.active:hover { transform: translateY(-1px); }

@media (max-width: 768px) {
  .gv-tool-group {
    flex-basis: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 0.25rem;
  }
  .gv-group-pills { flex-wrap: nowrap; }
}
.gv-toggle {
  background: var(--bg-alt, var(--bg));
  border: 1px solid var(--border);
  padding: 0.25rem 0.625rem;
  font-size: 0.75rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-primary);
}
.gv-toggle.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.gv-tool-btn {
  background: var(--bg-alt, var(--bg));
  border: 1px solid var(--border);
  padding: 0.25rem 0.625rem;
  font-size: 0.75rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}
.gv-tool-btn:hover { border-color: var(--accent); }

/* ── Columns popover ── */
.gv-columns-popover {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 220px;
  max-height: 320px;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.15);
  padding: 0.5rem;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}
.gv-columns-popover.hidden { display: none; }
.gv-columns-popover label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 0.5rem;
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
}
.gv-columns-popover label:hover { background: var(--bg-alt); }
.gv-col-pop-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.25rem 0.5rem 0.5rem;
  margin-bottom: 0.25rem;
  border-bottom: 1px solid var(--border);
}
.gv-col-all {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  font-size: 0.8125rem;
}
.gv-col-reset {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.6875rem;
  padding: 0.15rem 0.45rem;
  cursor: pointer;
}
.gv-col-reset:hover { border-color: var(--accent); color: var(--accent); }
.gv-col-list { display: flex; flex-direction: column; gap: 0.125rem; }
.gv-columns-popover label input:disabled { opacity: 0.5; }

/* "Expand rows" flag — show every record's detail block as an extended row. */
.gv-check-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  color: var(--text-primary);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}
.gv-check-toggle input { cursor: pointer; margin: 0; }

/* ── Dual horizontal scrollbars (top mirrors the wrapper's bottom bar) ── */
.gv-scroll-top {
  display: none; /* shown by JS only when the table overflows horizontally */
  overflow-x: auto;
  overflow-y: hidden;
}
.gv-scroll-top-inner { height: 1px; }
/* Force a persistent scrollbar on both bars (macOS overlay bars hide otherwise). */
.gv-scroll-top::-webkit-scrollbar,
.gv-body .table-wrapper::-webkit-scrollbar {
  height: 10px;
  -webkit-appearance: none;
}
.gv-scroll-top::-webkit-scrollbar-thumb,
.gv-body .table-wrapper::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 5px;
}
.gv-scroll-top::-webkit-scrollbar-thumb:hover,
.gv-body .table-wrapper::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}
.gv-scroll-top, .gv-body .table-wrapper { scrollbar-width: thin; }

/* ── Group rows ── */
/* Inline row expansion (config.expandedRowRenderer) */
.gv-expand-cell {
  width: 2rem;
  text-align: center;
  padding: 0 !important;
}
.gv-expand-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0.25rem;
  display: inline-flex;
  align-items: center;
  border-radius: var(--radius-sm, 4px);
  line-height: 1;
}
.gv-expand-btn:hover { color: var(--accent); background: rgba(99, 102, 241, 0.08); }
.gv-expand-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.gv-row-expanded { background: rgba(99, 102, 241, 0.05); }
.gv-detail-row > td {
  background: var(--bg-alt, rgba(99, 102, 241, 0.03));
  padding: 0.85rem 1rem !important;
  border-bottom: 1px solid var(--border);
}

.gv-group-row {
  background: var(--bg-alt, rgba(99, 102, 241, 0.04));
  cursor: pointer;
}
.gv-group-row:hover { background: rgba(99, 102, 241, 0.08); }
.gv-group-row td {
  font-weight: 500;
  padding: 0.625rem 0.75rem !important;
  border-bottom: 1px solid var(--border);
}
.gv-group-meta {
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 400;
  margin-left: 0.75rem;
}
.gv-group-total {
  color: var(--text-primary);
  font-weight: 600;
}
/* Directional group subtotals: money-in (green) / money-out (red). */
.gv-in { color: var(--success, #16a34a); font-weight: 600; }
.gv-out { color: var(--danger, #dc2626); font-weight: 600; }
.gv-group-meta.gv-in, .gv-group-meta.gv-out { font-weight: 600; }
/* Column-aligned split sits under the net, smaller, with a small gap. */
.gv-group-split {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  font-size: 0.6875rem;
  font-weight: 500;
  margin-top: 0.1rem;
}

/* ── Density modes ── */
.gv-density-compact tbody td { padding: 0.375rem 0.625rem; }
.gv-density-compact tbody tr { font-size: 0.8125rem; }
.gv-density-detailed tbody td { padding: 0.75rem 0.75rem; }
.gv-density-detailed tbody tr { font-size: 0.875rem; }

/* ── Print: show only the active grid, in clean monochrome layout ── */
@media print {
  body.gv-printing {
    background: white !important;
  }
  body.gv-printing > *:not(#main-app),
  body.gv-printing #sidebar,
  body.gv-printing #chat-panel,
  body.gv-printing #chat-slide-tab,
  body.gv-printing #chat-toggle,
  body.gv-printing #chat-backdrop,
  body.gv-printing #sidebar-backdrop,
  body.gv-printing #mobile-nav-toggle,
  body.gv-printing #theme-toggle,
  body.gv-printing .gv-toolbar,
  body.gv-printing .gv-bulk-bar,
  body.gv-printing .gv-views,
  body.gv-printing .gv-scroll-top,
  body.gv-printing .help-icon-btn {
    display: none !important;
  }
  body.gv-printing #main-content,
  body.gv-printing .page-content {
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
  }
  body.gv-printing .gv-root:not(.gv-print-target) {
    display: none !important;
  }
  body.gv-printing .gv-print-target .gv-filter-bar {
    background: white !important;
    border: 1px solid #ccc !important;
    page-break-inside: avoid;
  }
  body.gv-printing .gv-print-target .gv-chip {
    background: white !important;
    border-color: #ccc !important;
  }
  body.gv-printing .gv-print-target .gv-chip-clear,
  body.gv-printing .gv-print-target select,
  body.gv-printing .gv-print-target input[type="text"],
  body.gv-printing .gv-print-target input[type="number"] {
    border: none !important;
    color: black !important;
    background: transparent !important;
  }
  body.gv-printing .gv-print-target .gv-table {
    width: 100% !important;
    border-collapse: collapse !important;
    font-size: 11pt !important;
    color: black !important;
  }
  body.gv-printing .gv-print-target .gv-table th,
  body.gv-printing .gv-print-target .gv-table td {
    border: 1px solid #ddd !important;
    padding: 4pt 6pt !important;
    background: white !important;
    color: black !important;
  }
  body.gv-printing .gv-print-target .gv-table thead th {
    background: #f3f3f3 !important;
    font-weight: 700 !important;
  }
  body.gv-printing .gv-print-target .gv-group-row td {
    background: #f8f8f8 !important;
    font-weight: 700 !important;
    page-break-after: avoid;
  }
  body.gv-printing .gv-print-target .gv-triage {
    page-break-inside: avoid;
    margin-bottom: 8pt;
  }
  body.gv-printing .gv-print-target .gv-triage-card {
    border: 1px solid #ccc !important;
    box-shadow: none !important;
    background: white !important;
  }
  body.gv-printing .gv-select-cell { display: none !important; }
  /* Repeat headers on every page */
  body.gv-printing .gv-print-target thead { display: table-header-group; }
  body.gv-printing .gv-print-target tbody { display: table-row-group; }
  body.gv-printing .gv-print-target tr { page-break-inside: avoid; }
  /* Add the page title at top of print */
  body.gv-printing .gv-print-target::before {
    content: "AusBooks · " attr(data-screen) " · Printed " attr(data-printed-at);
    display: block;
    font-size: 9pt;
    color: #555;
    margin-bottom: 8pt;
    border-bottom: 1px solid #ccc;
    padding-bottom: 4pt;
  }
}

/* ── Selection ── */
.gv-select-cell {
  width: 40px;
  text-align: center;
}
.gv-select-cell input[type="checkbox"] {
  cursor: pointer;
}
.gv-table tbody tr.gv-row-selected {
  background: rgba(99, 102, 241, 0.08) !important;
}

/* ── Bulk action bar ── */
.gv-bulk-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0.625rem 0.875rem;
  background: var(--accent);
  border-radius: var(--radius);
  color: white;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.25);
  animation: gv-slide-in 0.18s ease-out;
}
.gv-bulk-bar.hidden { display: none; }
.gv-bulk-count {
  font-size: 0.875rem;
}
.gv-bulk-count strong { font-weight: 700; }
.gv-bulk-clear {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.4);
  color: white;
  font-size: 0.75rem;
  padding: 0.25rem 0.625rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin-left: auto;
}
.gv-bulk-clear:hover { background: rgba(255, 255, 255, 0.12); }
.gv-bulk-bar .btn {
  margin: 0;
}

@keyframes gv-slide-in {
  from { transform: translateY(-6px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}
