/* ─────────────────────────────────────────────────────────────────────────────
 * PHASE 121 — App Polish & UX Fixes
 *
 * Covers:
 *   1. Writer scroll stability (overflow-anchor, scroll behavior)
 *   2. Note popover z-index + touch target fixes
 *   3. Unified Settings panel styles
 *   4. Mobile overflow menu enhancements
 *   5. Writer hub undo/redo buttons
 *   6. App-wide visual polish
 *   7. Dark mode support
 *   8. Mobile format bar / keyboard improvements
 * ─────────────────────────────────────────────────────────────────────────── */

/* ── 1. WRITER SCROLL STABILITY ─────────────────────────────────────────── */
#pages-container {
  /* Browser default is auto — keeps scroll position when content
     above cursor changes height (e.g. during paginate rewrites).
     Explicitly setting it ensures no stylesheet override can break it. */
  overflow-anchor: auto;
  /* Prevent any CSS that triggers smooth-scroll from causing perceived
     jumps during rapid typing or DOM mutations */
  scroll-behavior: auto;
}

/* Contenteditable — caret color matches brand blue, no outlines */
.page-content {
  caret-color: #2563eb;
  outline: none !important;
}
.page-content:focus {
  outline: none !important;
  box-shadow: none !important;
}

/* ── 2. NOTE ANCHOR & POPOVER ────────────────────────────────────────────── */
.sn-anchor {
  /* Larger tap target than a single character */
  padding: 1px 3px;
  margin: 0 1px;
  border-radius: 3px;
  cursor: pointer;
  position: relative;
  z-index: 1;
  /* Prevent blue selection flash on long-press */
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* Note popover must sit above everything except settings panel */
#sn-popover {
  z-index: 8800 !important;
}
#sn-popover.open {
  display: flex !important;
}
#sn-popover.sn-mobile-sheet {
  z-index: 8800 !important;
}

/* Make delete button's tap target large enough */
.sn-pop-delete-btn {
  min-width: 40px !important;
  min-height: 40px !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  cursor: pointer !important;
  position: relative !important;
  z-index: 1 !important;
  -webkit-tap-highlight-color: rgba(239,68,68,.12);
}

/* ── 3. UNIFIED SETTINGS PANEL ──────────────────────────────────────────── */
.p121-settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.42);
  z-index: 9990;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
  /* Prevent backdrop from closing when user is interacting */
  touch-action: none;
}
.p121-settings-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.p121-settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(440px, 100vw);
  background: #ffffff;
  z-index: 9991;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: -6px 0 48px rgba(0, 0, 0, 0.2);
  border-radius: 20px 0 0 20px;
  overflow: hidden;
}
.p121-settings-panel.open {
  transform: translateX(0);
}

/* Settings header */
.p121-sp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px 14px;
  border-bottom: 1px solid #e5e7eb;
  flex-shrink: 0;
  background: #f9fafb;
}
.p121-sp-title {
  font-size: .95rem;
  font-weight: 800;
  color: #111827;
  letter-spacing: -.01em;
}
.p121-sp-close {
  background: none;
  border: 1px solid #e5e7eb;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  cursor: pointer;
  color: #6b7280;
  font-size: .82rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
.p121-sp-close:hover {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #b91c1c;
}

/* Settings tabs */
.p121-sp-tabs {
  display: flex;
  gap: 0;
  padding: 8px 12px 0;
  border-bottom: 1px solid #e5e7eb;
  flex-shrink: 0;
  overflow-x: auto;
  background: #f9fafb;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.p121-sp-tabs::-webkit-scrollbar { display: none; }

.p121-sp-tab {
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 7px 13px;
  font-size: .77rem;
  font-weight: 600;
  color: #6b7280;
  cursor: pointer;
  white-space: nowrap;
  border-radius: 8px 8px 0 0;
  transition: color 0.14s, background 0.14s;
  flex-shrink: 0;
}
.p121-sp-tab:hover {
  color: #2563eb;
  background: rgba(37, 99, 235, 0.05);
}
.p121-sp-tab.active {
  color: #2563eb;
  border-bottom-color: #2563eb;
  background: rgba(37, 99, 235, 0.07);
  font-weight: 700;
}

/* Settings body */
.p121-sp-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}
.p121-sp-pane {
  display: none;
  padding: 4px 0 80px;
}
.p121-sp-pane.active {
  display: block;
}

.p121-sp-section {
  padding: 14px 22px;
  border-bottom: 1px solid #f3f4f6;
}
.p121-sp-section:last-child {
  border-bottom: none;
}
.p121-sp-label {
  font-size: .67rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #9ca3af;
  margin-bottom: 10px;
}
.p121-sp-hint {
  font-size: .8rem;
  color: #6b7280;
  margin-bottom: 10px;
  line-height: 1.5;
}
.p121-sp-select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #e5e7eb;
  border-radius: 9px;
  font-size: .87rem;
  color: #111827;
  background: #fff;
  cursor: pointer;
  appearance: auto;
}
.p121-sp-select:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}
.p121-sp-zoom-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.p121-sp-zoom-btn {
  padding: 8px 14px;
  border: 1px solid #e5e7eb;
  border-radius: 9px;
  background: #fff;
  font-size: .87rem;
  font-weight: 700;
  cursor: pointer;
  color: #374151;
  transition: background 0.14s;
}
.p121-sp-zoom-btn:hover {
  background: #f3f4f6;
}
.p121-sp-zoom-btn.p121-zoom-ctr {
  flex: 1;
  text-align: center;
  min-width: 64px;
}
.p121-sp-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.p121-sp-stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.p121-sp-btn {
  padding: 10px 14px;
  border: 1px solid #e5e7eb;
  border-radius: 9px;
  background: #fff;
  font-size: .83rem;
  font-weight: 600;
  cursor: pointer;
  color: #374151;
  text-align: left;
  transition: background 0.14s, border-color 0.14s;
  white-space: nowrap;
  line-height: 1.3;
}
.p121-sp-btn:hover {
  background: #f3f4f6;
  border-color: #d1d5db;
}
.p121-sp-btn.full {
  width: 100%;
}
.p121-sp-btn.primary {
  background: #2563eb;
  color: #fff;
  border-color: #2563eb;
  font-weight: 700;
}
.p121-sp-btn.primary:hover {
  background: #1d4ed8;
  border-color: #1d4ed8;
}
.p121-sp-btn.highlight {
  background: linear-gradient(160deg, #1d4ed8, #6d28d9);
  color: #fff;
  border: none;
  font-weight: 800;
  box-shadow: 0 2px 12px rgba(109, 40, 217, 0.25);
}
.p121-sp-btn.highlight:hover {
  filter: brightness(1.08);
}
.p121-sp-btn.danger {
  color: #b91c1c;
  border-color: #fca5a5;
}
.p121-sp-btn.danger:hover {
  background: #fee2e2;
  border-color: #ef4444;
}

/* ── 4. MOBILE OVERFLOW MENU ─────────────────────────────────────────────── */
.p121-om-toprow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 16px 10px;
}
.p121-om-title {
  font-size: .7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #9ca3af;
}
.p121-om-closebtn {
  background: none;
  border: none;
  color: #9ca3af;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 0.14s;
}
.p121-om-closebtn:hover {
  background: #f3f4f6;
  color: #374151;
}
.p121-om-group-label {
  font-size: .62rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #9ca3af;
  padding: 8px 16px 4px;
}
.p121-om-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 0 8px 6px;
}
.p121-om-item {
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;  /* override .overflow-sheet .btn flex-start */
  gap: 2px !important;
  font-size: .73rem !important;
  padding: 9px 4px !important;
  text-align: center !important;
  border-radius: 10px !important;
  min-height: 0 !important;
  line-height: 1.2 !important;
  width: 100% !important;              /* fill grid cell */
}
.p121-om-icon {
  font-size: 1.2rem;
  display: block;
  line-height: 1;
}
.p121-om-name {
  display: block;
  font-size: .68rem;
  font-weight: 600;
}
.p121-om-item.p121-om-active {
  background: rgba(37, 99, 235, 0.1) !important;
  border-color: #93c5fd !important;
  color: #1d4ed8 !important;
  font-weight: 700 !important;
}
.p121-om-tool {
  font-size: .82rem !important;
  padding: 9px 16px !important;
  text-align: left !important;
  width: 100% !important;
  border-radius: 8px !important;
  margin: 1px 8px !important;
  width: calc(100% - 16px) !important;
}
.p121-om-divider {
  height: 1px;
  background: #e5e7eb;
  margin: 6px 16px 2px;
}

/* ── 5. MOBILE WRITER HUB — UNDO/REDO ───────────────────────────────────── */
.p121-wmh-extra {
  min-width: 40px !important;
  border-radius: 9px !important;
  flex-shrink: 0 !important;
}
.p121-wmh-extra span {
  font-size: 1.15rem;
  line-height: 1;
}

/* ── 6. APP-WIDE VISUAL POLISH ──────────────────────────────────────────── */

/* Header: subtle glass */
header {
  backdrop-filter: blur(10px) !important;
  -webkit-backdrop-filter: blur(10px) !important;
}

/* Project cards: hover lift */
.project-card {
  transition: transform 0.18s ease, box-shadow 0.18s ease !important;
  will-change: transform;
}
.project-card:hover {
  transform: translateY(-2px) !important;
  box-shadow: 0 10px 36px rgba(0, 0, 0, 0.11) !important;
}

/* Bottom tab active state */
.bottom-tab.active {
  font-weight: 800 !important;
  border-radius: 10px !important;
}

/* Phase103 "More" button polish */
.phase103-more-btn {
  border-radius: 10px !important;
  font-weight: 800 !important;
}

/* Toast notifications — appear above mobile dock */
#cbs-toast,
.cbs-toast,
[class*="toast-container"],
[id*="toast-container"] {
  bottom: max(80px, calc(72px + env(safe-area-inset-bottom))) !important;
  z-index: 9000 !important;
}

/* Scrollbars — thinner, softer */
::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.28);
}

/* Buttons throughout — consistent focus ring */
button:focus-visible,
.btn:focus-visible {
  outline: 2px solid #3b82f6 !important;
  outline-offset: 2px !important;
}

/* Modal overlays — standardize backdrop blur */
.modal-backdrop,
[id*="modal-backdrop"],
[class*="modal-overlay"] {
  backdrop-filter: blur(4px) !important;
  -webkit-backdrop-filter: blur(4px) !important;
}

/* ── 7. MOBILE FORMAT BAR — KEYBOARD AWARENESS ──────────────────────────── */
/* When the keyboard is open, keep the writer mobile hub visible above it */
@media (max-width: 760px) {
  #writer-mobile-hub {
    /* Use CSS variable set by phase103 keyboard tracker */
    bottom: calc(var(--keyboard-offset, 0px) + env(safe-area-inset-bottom, 0px) + 8px) !important;
    transition: bottom 0.15s ease !important;
    z-index: 8700 !important;
  }

  /* When keyboard is open, hide the bottom nav dock to free screen space */
  body[data-keyboard-open="true"] #bottom-nav,
  body[data-writer-keyboard="open"] #bottom-nav {
    opacity: 0;
    pointer-events: none;
    transform: translateY(100%);
    transition: opacity 0.15s, transform 0.15s;
  }
  body:not([data-keyboard-open="true"]):not([data-writer-keyboard="open"]) #bottom-nav {
    opacity: 1;
    pointer-events: all;
    transform: translateY(0);
    transition: opacity 0.2s, transform 0.2s;
  }

  /* Settings panel full-height on phone */
  .p121-settings-panel {
    border-radius: 0 !important;
    width: 100vw !important;
  }
}

/* ── 8. DARK MODE SUPPORT ───────────────────────────────────────────────── */
body.dark .p121-settings-panel {
  background: #1f2937;
}
body.dark .p121-sp-header {
  background: #111827;
  border-color: #374151;
}
body.dark .p121-sp-title {
  color: #f9fafb;
}
body.dark .p121-sp-close {
  border-color: #374151;
  color: #9ca3af;
}
body.dark .p121-sp-close:hover {
  background: #7f1d1d;
  border-color: #ef4444;
  color: #fef2f2;
}
body.dark .p121-sp-tabs {
  background: #111827;
  border-color: #374151;
}
body.dark .p121-sp-tab {
  color: #9ca3af;
}
body.dark .p121-sp-tab:hover {
  color: #93c5fd;
  background: rgba(147, 197, 253, 0.06);
}
body.dark .p121-sp-tab.active {
  color: #60a5fa;
  border-bottom-color: #60a5fa;
  background: rgba(96, 165, 250, 0.08);
}
body.dark .p121-sp-section {
  border-color: #374151;
}
body.dark .p121-sp-label {
  color: #6b7280;
}
body.dark .p121-sp-hint {
  color: #9ca3af;
}
body.dark .p121-sp-select {
  background: #374151;
  border-color: #4b5563;
  color: #f3f4f6;
}
body.dark .p121-sp-zoom-btn {
  background: #374151;
  border-color: #4b5563;
  color: #e5e7eb;
}
body.dark .p121-sp-zoom-btn:hover {
  background: #4b5563;
}
body.dark .p121-sp-btn {
  background: #374151;
  border-color: #4b5563;
  color: #e5e7eb;
}
body.dark .p121-sp-btn:hover {
  background: #4b5563;
}
body.dark .p121-sp-btn.primary {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
}
body.dark .p121-sp-btn.primary:hover {
  background: #1d4ed8;
}
body.dark .p121-sp-btn.danger {
  color: #f87171;
  border-color: #7f1d1d;
}
body.dark .p121-sp-btn.danger:hover {
  background: #7f1d1d;
}
body.dark .p121-settings-overlay {
  background: rgba(0, 0, 0, 0.6);
}

/* ── 9. SETTINGS-POP QUICK ACCESS ENHANCEMENT ───────────────────────────── */
/* The tiny settings-pop is now supplemented by the full panel.
   Polish it so if it ever shows, it looks good. */
#settings-pop {
  border-radius: 16px !important;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.18), 0 2px 8px rgba(0, 0, 0, 0.08) !important;
  border: 1px solid #e5e7eb !important;
  padding: 16px !important;
}
body.dark #settings-pop {
  background: #1f2937 !important;
  border-color: #374151 !important;
}

/* ═══════════════════════════════════════════════════════════════════════════
   10. PROJECT HUB — VISUAL POLISH
   ═══════════════════════════════════════════════════════════════════════════ */

/* Folder/project cards — richer depth and hover state */
.folder {
  border-radius: 16px !important;
  transition: transform 0.18s ease, box-shadow 0.18s ease !important;
  will-change: transform;
  overflow: visible !important;
}
.folder:hover {
  transform: translateY(-3px) scale(1.01) !important;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.13), 0 2px 8px rgba(0, 0, 0, 0.07) !important;
}
.folder:active {
  transform: translateY(-1px) scale(1.005) !important;
}

/* Folder body: always white, sharp corners at bottom */
.folder-body {
  border-radius: 0 0 14px 14px !important;
  padding: 12px 14px 14px !important;
}

/* Folder color tab: softer top corners, original height preserved */
.folder-tab {
  border-radius: 8px 8px 0 0 !important;
}

/* Project name: bolder, tighter tracking */
.folder-label {
  font-weight: 800 !important;
  letter-spacing: -.01em !important;
  line-height: 1.25 !important;
}

/* Meta text: softer */
.folder-meta {
  font-size: .72rem !important;
  color: #9ca3af !important;
}

/* Recent badge: pill chip */
.folder-recent-badge {
  z-index: 2 !important;
}

/* Team badge: warm violet */
.phase115-team-badge {
  border-radius: 20px !important;
  font-size: .62rem !important;
  font-weight: 800 !important;
  background: linear-gradient(135deg, #6d28d9, #4f46e5) !important;
  color: #fff !important;
  padding: 2px 8px !important;
}

/* Hub top bar: cleaner layout */
#hub-top-bar {
  padding: 16px 20px 10px !important;
}

/* Hub search input: modern rounded */
#hub-search-input {
  border-radius: 12px !important;
  border: 1.5px solid #e5e7eb !important;
  padding: 9px 14px !important;
  font-size: .87rem !important;
  transition: border-color 0.15s, box-shadow 0.15s !important;
}
#hub-search-input:focus {
  outline: none !important;
  border-color: #3b82f6 !important;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.14) !important;
}

/* ── 11. HEADER POLISH ──────────────────────────────────────────────────── */
.app-brand {
  cursor: pointer;
  transition: opacity 0.14s cubic-bezier(.2,.8,.3,1), transform 0.14s cubic-bezier(.34,1.56,.64,1) !important;
}
.app-brand:hover  { opacity: 0.8 !important; transform: scale(1.03) !important; }
.app-brand:active { opacity: 0.65 !important; transform: scale(.97) !important; }

/* Nav tab groups: cleaner separator */
.tab-group + .tab-group {
  border-left: 1px solid rgba(0, 0, 0, 0.06) !important;
}
body.dark .tab-group + .tab-group {
  border-left-color: rgba(255, 255, 255, 0.06) !important;
}

/* Active desktop tab: blue underline + tinted background */
.tab.active {
  color: #2563eb !important;
  border-bottom: 3px solid #2563eb !important;
  background: rgba(37, 99, 235, 0.06) !important;
  font-weight: 700 !important;
}
body.dark .tab.active {
  color: #60a5fa !important;
  border-bottom-color: #60a5fa !important;
  background: rgba(96, 165, 250, 0.08) !important;
}

/* Tab hover: subtle tint */
.tab:hover:not(.active) {
  background: rgba(0, 0, 0, 0.04) !important;
  color: #374151 !important;
}
body.dark .tab:hover:not(.active) {
  background: rgba(255, 255, 255, 0.05) !important;
  color: #d1d5db !important;
}

/* ── 12. WRITER PAGE POLISH ─────────────────────────────────────────────── */

/* Script page sheet: elegant shadow */
.script-page-sheet {
  box-shadow: 0 2px 20px rgba(0, 0, 0, 0.07), 0 1px 4px rgba(0, 0, 0, 0.04) !important;
}

/* Scene heading: slightly taller click target, better visual weight */
.line.scene {
  border-bottom: 1px solid rgba(0, 0, 0, 0.06) !important;
  padding-bottom: 3px !important;
  margin-bottom: 2px !important;
}

/* Character name: bolder */
.line.character {
  font-weight: 700 !important;
}

/* Dialogue: slightly softer ink for readability at length */
.line.dialogue {
  color: #1e293b !important;
}

/* ── 13. BOTTOM NAV / DOCK POLISH ───────────────────────────────────────── */

/* Bottom nav container */
#bottom-nav {
  transition: opacity 0.2s ease, transform 0.2s ease !important;
}

/* Phase103 "More" sheet handle */
.phase103-more-sheet::before {
  content: '';
  display: block;
  width: 36px;
  height: 4px;
  background: #e5e7eb;
  border-radius: 2px;
  margin: 10px auto 4px;
}

/* More button icon: ⋯ → clean grid icon */
.phase103-more-icon {
  font-size: 1.2rem !important;
  letter-spacing: .1em !important;
}

/* More sheet section headings */
.phase103-more-sheet h4 {
  font-size: .65rem !important;
  font-weight: 800 !important;
  text-transform: uppercase !important;
  letter-spacing: .08em !important;
  color: #9ca3af !important;
  padding: 8px 16px 4px !important;
}

/* ── 14. MODAL SYSTEM POLISH ────────────────────────────────────────────── */

/* Generic modal box */
.modal, [role="dialog"] {
  border-radius: 20px !important;
}

/* Modal header */
[class*="modal-header"],
[class*="modal-title"] {
  font-weight: 800 !important;
  letter-spacing: -.01em !important;
}

/* Alert modal buttons */
#alert-modal-ok,
#alert-modal-cancel {
  border-radius: 10px !important;
  font-weight: 700 !important;
  padding: 10px 20px !important;
  transition: filter 0.14s !important;
}
#alert-modal-ok:hover,
#alert-modal-cancel:hover {
  filter: brightness(1.06) !important;
}

/* ── 15. FORM ELEMENTS — GLOBAL POLISH ──────────────────────────────────── */
input[type="text"],
input[type="email"],
input[type="search"],
input[type="number"],
input[type="url"],
textarea,
select {
  border-radius: 9px !important;
  transition: border-color 0.14s, box-shadow 0.14s !important;
}
input[type="text"]:focus,
input[type="email"]:focus,
input[type="search"]:focus,
input[type="number"]:focus,
textarea:focus,
select:focus {
  outline: none !important;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15) !important;
}

/* ── 16. BUTTONS — GLOBAL POLISH ────────────────────────────────────────── */
.btn {
  border-radius: 10px !important;
  font-weight: 600 !important;
  transition: background 0.14s, box-shadow 0.14s, transform 0.1s !important;
}
.btn:active {
  transform: scale(0.97) !important;
}
.btn:focus-visible {
  outline: 2px solid #3b82f6 !important;
  outline-offset: 2px !important;
}

/* ── 17. DARK MODE HUB ───────────────────────────────────────────────────── */
body.dark .folder-body {
  background: #1f2937 !important;
  border-color: #374151 !important;
}
body.dark .folder-label {
  color: #f3f4f6 !important;
}
body.dark .folder-meta {
  color: #6b7280 !important;
}
body.dark #hub-search-input {
  background: #1f2937 !important;
  border-color: #374151 !important;
  color: #f3f4f6 !important;
}
body.dark #hub-search-input:focus {
  border-color: #60a5fa !important;
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.14) !important;
}
body.dark .folder:hover {
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35) !important;
}

/* ── 18. DARK MODE — REMOVE CORKBOARD TEXTURE ──────────────────────────── */
/*
 * wardrobe-local-png-rebuild.css sets the corkboard PNG on html + body with
 * !important. Override in dark mode so the background is a clean dark slate.
 * Using :has() (supported in all modern browsers) to target <html> based on
 * body.dark class. The body.dark rule covers body itself.
 */
html:has(body.dark) {
  background-image: none !important;
  background-color: #0f172a !important;
}
body.dark {
  background-image: none !important;
  background-color: #111827 !important;
}

/* ── 18b. SETTINGS PANEL — REVISION COLOR GRID ─────────────────────────── */
.p121-sp-rev-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  margin-top: 4px;
}
.p121-sp-rev-swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 5px 2px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  background: #fff;
  font-size: 0.68rem;
  color: #374151;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  white-space: nowrap;
}
.p121-sp-rev-swatch:hover {
  background: #f3f4f6;
  border-color: #9ca3af;
}
.p121-sp-rev-swatch.active {
  background: #eff6ff;
  border-color: #3b82f6;
  color: #1d4ed8;
  font-weight: 600;
}
.p121-rev-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: block;
}
body.dark .p121-sp-rev-swatch {
  background: #1f2937;
  border-color: #374151;
  color: #d1d5db;
}
body.dark .p121-sp-rev-swatch:hover {
  background: #252d42;
  border-color: #6b7280;
}
body.dark .p121-sp-rev-swatch.active {
  background: #1d2d4a;
  border-color: #60a5fa;
  color: #93c5fd;
}

/* ── 19. NAV — HIDE REDUNDANT TOOLS DROPDOWN ───────────────────────────── */
/*
 * The ⚙️ Settings panel (phase121) already covers all Tools and Export options
 * organised in dedicated tabs. The standalone #tools-btn dropdown duplicates
 * those options, clutters the nav, and confuses new users.
 * Hide it — users reach everything through ⚙️ Settings instead.
 */
#tools-btn {
  display: none !important;
}

/* ── 20. SHOT LIST — FIT TABLE TO CONTAINER, FIX OVERLAP ───────────────── */
/*
 * The shot list table carries an inline min-width:820px which causes a ~20px
 * horizontal overflow on desktop widths. The resulting scrollbar renders
 * INSIDE the wrapper and visually overlaps the bottom table row (users see
 * "something underneath" the AUDIO / DUR / STATUS cells). Fix by:
 *   a) Overriding the inline min-width so the table fills its container.
 *   b) Setting table-layout:fixed with explicit column widths that sum to 100%.
 *   c) Ensuring the wrapper only shows a scrollbar on genuinely narrow screens.
 */

/* Force table to fill container without overflowing */
.shot-table-wrap,
.shotlist-wide-wrap {
  overflow-x: hidden !important;
}
.shot-table-wrap table,
.shotlist-wide-table {
  min-width: 0 !important;
  width: 100% !important;
  table-layout: fixed !important;
}

/*
 * Column proportions (11 cols):
 * drag | sketch | setup | shot-type | description | lens | move | audio | dur | status | delete
 * Widths chosen so they sum comfortably within any desktop viewport ≥ 800px.
 */
.shot-table-wrap table colgroup,
.shotlist-wide-table colgroup { display: none; }

.shot-table-wrap table th:nth-child(1),
.shot-table-wrap table td:nth-child(1) { width: 26px  !important; padding: 0 !important; }   /* drag */
.shot-table-wrap table th:nth-child(2),
.shot-table-wrap table td:nth-child(2) { width: 54px  !important; }                          /* sketch */
.shot-table-wrap table th:nth-child(3),
.shot-table-wrap table td:nth-child(3) { width: 44px  !important; }                          /* setup */
.shot-table-wrap table th:nth-child(4),
.shot-table-wrap table td:nth-child(4) { width: 82px  !important; }                          /* shot type */
.shot-table-wrap table th:nth-child(5),
.shot-table-wrap table td:nth-child(5) { width: 120px !important; min-width: 0 !important; } /* description — fixed, clips with ellipsis */
.shot-table-wrap table th:nth-child(6),
.shot-table-wrap table td:nth-child(6) { width: 60px  !important; }                          /* lens */
.shot-table-wrap table th:nth-child(7),
.shot-table-wrap table td:nth-child(7) { width: 74px  !important; }                          /* move */
.shot-table-wrap table th:nth-child(8),
.shot-table-wrap table td:nth-child(8) { width: 74px  !important; }                          /* audio */
.shot-table-wrap table th:nth-child(9),
.shot-table-wrap table td:nth-child(9) { width: 48px  !important; }                          /* dur */
.shot-table-wrap table th:nth-child(10),
.shot-table-wrap table td:nth-child(10){ width: 82px  !important; }                          /* status */
.shot-table-wrap table th:nth-child(11),
.shot-table-wrap table td:nth-child(11){ width: 68px  !important; padding: 0 4px !important; } /* delete — wide enough for full button */

/* Allow inputs/selects inside cells to fill the cell */
.shot-table-wrap table td input,
.shot-table-wrap table td select {
  width: 100% !important;
  min-width: 0 !important;
  box-sizing: border-box !important;
}

/* Clip text that can't fit; better than overflow */
.shot-table-wrap table td {
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  white-space: nowrap !important;
}
/* Description: nowrap + ellipsis — stays in its fixed 120px column */
.shot-table-wrap table td:nth-child(5) {
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
}

/* On mobile / narrow viewports: restore horizontal scroll */
@media (max-width: 880px) {
  .shot-table-wrap,
  .shotlist-wide-wrap {
    overflow-x: auto !important;
  }
  .shot-table-wrap table,
  .shotlist-wide-table {
    min-width: 700px !important;
    table-layout: auto !important;
  }
}

/* Sketch panel — ensure it stacks above the table when open */
#shot-sketch-wrap,
.shot-sketch-panel,
[id*="shot-sketch"],
[class*="shot-sketch-panel"] {
  z-index: 500 !important;
  position: relative !important;
}

