/* =====================================================================
   library-list.css  —  Shared mobile-first dense list styling for the
   Library content pages: Office Memorandums, Rules, Acts, Reader's Forum.

   Design system: "Accessible & Ethical" (authority navy + trust gold),
   WCAG-AA contrast, 44px touch targets, full light/dark.

   Per-page accent: add ONE class to .oms-container
     .lib-om   (navy, default)   .lib-rules (red)
     .lib-acts (green)           .lib-forum (purple)
   ===================================================================== */

/* ---- Accent tokens (single source of truth) ---- */
.oms-container {
  --om-accent: #1E3A8A;          /* authority navy (default / OM) */
  --om-gold: #B45309;            /* trust gold (NEW tag) */
  --om-gsr: #0E7490;             /* teal (GSR tag) */
}

[data-theme="dark"] .oms-container {
  --om-accent: #3B82F6;
  --om-gold: #FBBF24;
  --om-gsr: #22D3EE;
}

.oms-container.lib-rules { --om-accent: #DC2626; }
[data-theme="dark"] .oms-container.lib-rules { --om-accent: #F87171; }

.oms-container.lib-acts { --om-accent: #16A34A; }
[data-theme="dark"] .oms-container.lib-acts { --om-accent: #4ADE80; }

.oms-container.lib-forum { --om-accent: #7C3AED; }
[data-theme="dark"] .oms-container.lib-forum { --om-accent: #A78BFA; }

.oms-container.lib-caselaw { --om-accent: #D97706; }
[data-theme="dark"] .oms-container.lib-caselaw { --om-accent: #FBBF24; }

/* ---- Page shell ---- */
.oms-container {
  height: calc(100vh - 64px);
  height: calc(100dvh - 64px);
  overflow-y: auto;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
}

/* ====== Compact sticky header ====== */
.page-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background-color: var(--bg-primary);
  border-bottom: 1px solid var(--mud-palette-divider);
  padding: 8px 10px 10px;
}

[data-theme="light"] .page-header { background-color: #ffffff; }

.hdr-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.hdr-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  border-radius: 8px;
  background: var(--om-accent);
  color: #fff;
}

.hdr-icon .mud-icon-root { color: #fff; }

.hdr-titles {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
  min-width: 0;
}

.header-title {
  font-size: 1.0625rem;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

[data-theme="light"] .header-title { color: var(--text-primary); }

.header-sub {
  font-size: 0.6875rem;
  color: var(--text-secondary);
  margin-top: 1px;
}

.count-pill {
  margin-left: auto;
  flex: 0 0 auto;
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--om-accent);
  background: var(--bg-hover);
  padding: 3px 9px;
  border-radius: 20px;
}

/* ====== Search row ====== */
.search-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.search-box {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 42px;
  padding: 0 8px 0 10px;
  border: 1.5px solid var(--mud-palette-divider);
  border-radius: 10px;
  background: var(--bg-primary);
  transition: border-color 150ms ease;
}

.search-box:focus-within { border-color: var(--om-accent); }
.search-box-icon { color: var(--text-secondary); flex: 0 0 auto; }

.search-input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  font-size: 16px; /* 16px avoids iOS auto-zoom */
  color: var(--text-primary);
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
}

/* Kill UA focus ring / search decorations (the global .mud-* :focus
   outline rule and webkit search bubble both render an overlay). The
   .search-box:focus-within border is the intended affordance. */
.search-input:focus,
.search-input:focus-visible {
  outline: none !important;
  box-shadow: none !important;
}

.search-input::placeholder { color: var(--text-secondary); opacity: 0.8; }
.search-input::-webkit-search-decoration,
.search-input::-webkit-search-cancel-button { -webkit-appearance: none; display: none; }

.search-clear {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
}

.search-clear:hover { background: var(--bg-hover); }
.search-clear:focus, .search-clear:focus-visible { outline: none; }

.filter-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border: 1.5px solid var(--mud-palette-divider);
  border-radius: 10px;
  background: var(--bg-primary);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 150ms ease;
}

.filter-btn:hover { background: var(--bg-hover); }

.filter-btn.active {
  border-color: var(--om-accent);
  background: var(--om-accent);
  color: #fff;
}

.filter-btn.active .mud-icon-root { color: #fff; }

.filter-dot {
  position: absolute;
  top: -3px;
  right: -3px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--om-gold);
  border: 2px solid var(--bg-primary);
}

/* ====== Active filter chip ====== */
.active-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 4px 6px 4px 10px;
  border: 1px solid var(--mud-palette-divider);
  border-radius: 20px;
  background: var(--bg-hover);
  color: var(--om-accent);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  max-width: 100%;
}

.active-chip .chip-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.active-chip .chip-x {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.12);
  font-size: 12px;
  line-height: 1;
}

[data-theme="dark"] .active-chip .chip-x { background: rgba(255, 255, 255, 0.18); }

/* ====== Scroll region ====== */
.scrollable-content {
  flex: 1;
  min-height: 0;
  padding-bottom: 24px;
}

.om-list { background: transparent; }

/* ====== List row (edge-to-edge, dense) ====== */
.om-row {
  display: flex;
  align-items: stretch;
  gap: 10px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--mud-palette-divider);
  cursor: pointer;
  transition: background-color 120ms ease;
}

.om-row:hover { background-color: var(--bg-hover); }
.om-row:active { background-color: var(--bg-hover); }
.om-row:focus-visible { outline: 2px solid var(--om-accent); outline-offset: -2px; }

.om-accent {
  width: 3px;
  flex: 0 0 auto;
  border-radius: 3px;
  background: var(--om-accent);
  opacity: 0.85;
}

.om-row.gsr .om-accent { background: var(--om-gsr); }

.om-body { flex: 1; min-width: 0; }

.om-r1 {
  display: flex;
  align-items: center;
  gap: 6px;
}

.om-gi {
  font-family: var(--font-brand);
  font-weight: 700;
  font-size: 0.9375rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

[data-theme="light"] .om-gi { color: var(--text-primary); }

.om-tag {
  flex: 0 0 auto;
  font-size: 0.5938rem;
  font-weight: 700;
  letter-spacing: 0.4px;
  color: #fff;
  padding: 1px 5px;
  border-radius: 4px;
}

.om-tag-gsr { background: var(--om-gsr); }
.om-tag-new { background: var(--om-gold); }
[data-theme="dark"] .om-tag-new { color: #1A1A1A; }

/* NOTE: scoped under .oms-container — OM/Rule documents inject the legacy
   om.css ruleset inline (a bare, page-wide `.om-title`: centered/bold/1.3rem)
   the moment the ContentViewer mounts. Scoping keeps the list rule winning by
   specificity; the viewer lives outside .oms-container so it is untouched. */
.oms-container .om-title {
  font-family: var(--font-brand);
  font-style: italic;
  font-size: 0.8125rem;
  line-height: 1.35;
  color: var(--text-secondary);
  margin: 2px 0 0;
  text-align: left;
  font-weight: 400;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

[data-theme="light"] .oms-container .om-title { color: #495057; }

.om-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 5px;
}

.om-subj {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--om-accent);
}

.om-subj-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.om-subject-img {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  object-fit: cover;
  border-radius: 3px;
}

.om-swatch {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  border-radius: 3px;
  background: var(--om-accent);
  opacity: 0.85;
}

.om-date {
  margin-left: auto;
  flex: 0 0 auto;
  font-size: 0.6875rem;
  color: var(--text-secondary);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

[data-theme="light"] .om-date { color: #6c757d; }

/* ====== States ====== */
.om-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.om-loadmore { padding: 14px 0; }

.om-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 220px;
  text-align: center;
  color: var(--text-secondary);
  padding: 0 24px;
}

.om-empty-icon { color: var(--text-secondary); opacity: 0.5; }
.om-empty-sub { opacity: 0.7; }

/* ====== Compact tabs (Rules / Acts) ====== */
.oms-container .mud-tabs-toolbar { min-height: 40px; }
[data-theme="light"] .oms-container .mud-tabs-toolbar { background-color: #ffffff; }
[data-theme="light"] .oms-container .mud-tab { background-color: transparent; }
.oms-container .mud-tab { min-height: 40px; min-width: 0; padding: 0 12px; text-transform: none; }
.oms-container .mud-tabs-panels,
.oms-container .mud-tab-panel { padding: 0; }

/* ====== Scale up on larger screens ====== */
@media (min-width: 768px) {
  .page-header { padding: 12px 16px 14px; }
  .hdr-top { gap: 12px; }
  .header-title { font-size: 1.25rem; }
  .om-row { padding: 12px 16px; gap: 12px; }
  .om-gi { font-size: 1rem; }
  .oms-container .om-title { font-size: 0.875rem; }
  .om-meta { gap: 12px; }
  .om-subj, .om-date, .om-tag, .header-sub, .count-pill { font-size: 0.75rem; }
  .om-subject-img, .om-swatch { width: 20px; height: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  .om-row, .search-box, .filter-btn { transition: none; }
}

/* =====================================================================
   Split view (master-detail) — AA-44
   List and embedded ContentViewer are in-flow flex SIBLINGS, so they can
   never overlap. The panel takes a flex-basis of --ayra-split-width (the
   AA-17 var the ayraSplit divider JS updates); the list fills the rest.
   ===================================================================== */
.lib-split-host { position: relative; }

.lib-split-panel {
  display: flex;
  min-width: 0;
  height: 100%;
  background: var(--bg-primary);
  border-left: 1px solid var(--mud-palette-divider);
}

.lib-split-divider {
  flex: 0 0 6px;
  width: 6px;
  cursor: col-resize;
  background: var(--bg-secondary, var(--bg-hover));
  border-right: 1px solid var(--mud-palette-divider);
  position: relative;
  user-select: none;
}

.lib-split-divider::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 2px;
  height: 28px;
  border-radius: 2px;
  background: var(--om-accent);
  opacity: 0.5;
}

.lib-split-divider:hover { background: var(--bg-hover); }
.lib-split-divider:hover::after { opacity: 1; }

.lib-split-inner {
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  overflow: hidden;
}

/* Desktop/tablet: list + panel sit side by side (flex siblings) */
@media (min-width: 900px) {
  .lib-split-host.split-open {
    display: flex;
    height: calc(100vh - 64px);
    height: calc(100dvh - 64px);
    overflow: hidden;
  }

  .lib-split-host.split-open .oms-container {
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
    height: 100%;
  }

  /* Learn-MCQ split (AA-93): the question shell flexes left, panel docks right */
  .lib-split-host.split-open .mcq-page {
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
    height: 100%;
  }

  .lib-split-host.split-open .lib-split-panel {
    flex: 0 0 var(--ayra-split-width, 45%);
    max-width: 75%;
    animation: lib-split-slide-in 0.18s ease-out;
  }
}

@keyframes lib-split-slide-in {
  from { transform: translateX(24px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Narrow desktop window (mobile devices navigate instead): full-screen overlay */
@media (max-width: 899px) {
  .lib-split-host.split-open .lib-split-panel {
    position: fixed;
    top: calc(var(--appbar-offset, 64px) + env(safe-area-inset-top, 0px));
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1100;
    box-shadow: -6px 0 24px rgba(0, 0, 0, 0.28);
  }

  .lib-split-divider { display: none; }
}

/* Selected row in master-detail */
.oms-container .om-row.selected { background: var(--bg-hover); }
.oms-container .om-row.selected .om-accent { opacity: 1; width: 4px; }
