/* theme.css — Dark/light theme styles */

/* Theme toggle button */
.theme-toggle-btn {
  position: fixed;
  top: 80px; /* Positioned below navigation bar */
  right: 20px;
  z-index: 999; /* Lower than nav dropdowns (11000) but still visible */
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid rgba(255,179,90,0.4);
  background: rgba(15,15,20,0.9);
  color: #ffb35a;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s;
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 12px rgba(0,0,0,.3);
}

.theme-toggle-btn:hover {
  background: rgba(255,179,90,0.2);
  border-color: #ffb35a;
  transform: scale(1.1);
}

/* ---------------------------------------------------------
   Global background theme (match marketing landing page)
   --------------------------------------------------------- */

/* Light (day) */
[data-theme="light"] {
  /* App palette should feel like marketing “paper” */
  --bg-main: #f7f0e3;      /* paper */
  --bg-surface: #fffaf0;   /* paper-2 */
  --bg-muted: rgba(31,27,22,0.06);
  --bg-hover: rgba(255,255,255,0.55);

  --border: rgba(31,27,22,0.10);
  --border-light: rgba(31,27,22,0.08);

  --text-primary: #1f1b16;
  --text-secondary: rgba(31,27,22,0.78);
  --text-muted: rgba(31,27,22,0.58);

  /* Nav */
  --nav-bg: rgba(255, 250, 240, 0.92);

  /* Text on saturated surfaces */
  --text-on-accent: #1f1b16;

  /* Clause modal tokens */
  --ub-clause-modal-bg: #ffffff;
  --ub-clause-modal-text: #111111;
  --ub-clause-field-bg: #ffffff;
  --ub-clause-field-text: #111111;
  --ub-clause-border: rgba(31,27,22,0.18);

  color-scheme: light;
}

/* Dark (night) */
[data-theme="dark"] {
  --bg-main: #0f0e0d;      /* dark paper */
  --bg-surface: #171513;   /* dark paper-2 */
  --bg-muted: rgba(255,255,255,0.06);
  --bg-hover: rgba(255,255,255,0.08);

  --border: rgba(255,255,255,0.14);
  --border-light: rgba(255,255,255,0.10);

  --text-primary: rgba(255,255,255,0.92);
  /* Slightly brighter for readability */
  --text-secondary: rgba(255,255,255,0.80);
  --text-muted: rgba(255,255,255,0.62);

  /* Nav */
  --nav-bg: rgba(23, 21, 19, 0.92);

  /* Text on saturated surfaces */
  --text-on-accent: #1f1b16;

  /* Clause modal tokens */
  --ub-clause-modal-bg: #0b0b0b;
  --ub-clause-modal-text: #ffffff;
  --ub-clause-field-bg: rgba(255,255,255,0.06);
  --ub-clause-field-text: #ffffff;
  --ub-clause-border: rgba(255,255,255,0.18);

  color-scheme: dark;
}

/* Apply landing-page background globally */
body {
  background-color: var(--bg-main);
  background:
    radial-gradient(1000px 520px at 10% 0%, rgba(255, 217, 61, 0.22), transparent 60%),
    radial-gradient(950px 520px at 85% 8%, rgba(123, 74, 226, 0.16), transparent 62%),
    radial-gradient(900px 560px at 15% 110%, rgba(107, 124, 87, 0.16), transparent 65%),
    radial-gradient(1200px 640px at 90% 120%, rgba(255, 140, 66, 0.12), transparent 62%),
    var(--bg-main);
  color: var(--text-primary);
}

/* Subtle “paper grain” overlay (global) */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.14;
  background:
    repeating-linear-gradient(
      0deg,
      rgba(0,0,0,0.015),
      rgba(0,0,0,0.015) 1px,
      rgba(0,0,0,0.0) 3px,
      rgba(0,0,0,0.0) 6px
    ),
    radial-gradient(700px 380px at 50% 20%, rgba(255, 140, 66, 0.06), transparent 60%),
    radial-gradient(600px 340px at 20% 70%, rgba(123, 74, 226, 0.05), transparent 60%);
}

[data-theme="dark"] body::before {
  opacity: 0.16;
  background:
    repeating-linear-gradient(
      0deg,
      rgba(255,255,255,0.015),
      rgba(255,255,255,0.015) 1px,
      rgba(255,255,255,0.0) 3px,
      rgba(255,255,255,0.0) 6px
    );
}

/* ---------------------------------------------------------
   Night mode readability helpers
   - Some legacy pages use inline dark text colors (#333/#000).
   - Only normalize those inside dark surfaces to avoid
     breaking intentionally light/white blocks.
   --------------------------------------------------------- */
[data-theme="dark"] .glass-panel [style*="color:#000"],
[data-theme="dark"] .glass-panel [style*="color: #000"],
[data-theme="dark"] .glass-panel [style*="color:#111"],
[data-theme="dark"] .glass-panel [style*="color: #111"],
[data-theme="dark"] .glass-panel [style*="color:#222"],
[data-theme="dark"] .glass-panel [style*="color: #222"],
[data-theme="dark"] .glass-panel [style*="color:#333"],
[data-theme="dark"] .glass-panel [style*="color: #333"],
[data-theme="dark"] .glass-panel [style*="color:#444"],
[data-theme="dark"] .glass-panel [style*="color: #444"],
[data-theme="dark"] .glass-panel [style*="color:#555"],
[data-theme="dark"] .glass-panel [style*="color: #555"],
[data-theme="dark"] .glass-panel [style*="color:#666"],
[data-theme="dark"] .glass-panel [style*="color: #666"],
[data-theme="dark"] .panel [style*="color:#000"],
[data-theme="dark"] .panel [style*="color: #000"],
[data-theme="dark"] .panel [style*="color:#111"],
[data-theme="dark"] .panel [style*="color: #111"],
[data-theme="dark"] .panel [style*="color:#222"],
[data-theme="dark"] .panel [style*="color: #222"],
[data-theme="dark"] .panel [style*="color:#333"],
[data-theme="dark"] .panel [style*="color: #333"],
[data-theme="dark"] .panel [style*="color:#444"],
[data-theme="dark"] .panel [style*="color: #444"],
[data-theme="dark"] .panel [style*="color:#555"],
[data-theme="dark"] .panel [style*="color: #555"],
[data-theme="dark"] .panel [style*="color:#666"],
[data-theme="dark"] .panel [style*="color: #666"],
[data-theme="dark"] .card [style*="color:#000"],
[data-theme="dark"] .card [style*="color: #000"],
[data-theme="dark"] .card [style*="color:#111"],
[data-theme="dark"] .card [style*="color: #111"],
[data-theme="dark"] .card [style*="color:#222"],
[data-theme="dark"] .card [style*="color: #222"],
[data-theme="dark"] .card [style*="color:#333"],
[data-theme="dark"] .card [style*="color: #333"],
[data-theme="dark"] .card [style*="color:#444"],
[data-theme="dark"] .card [style*="color: #444"],
[data-theme="dark"] .card [style*="color:#555"],
[data-theme="dark"] .card [style*="color: #555"],
[data-theme="dark"] .card [style*="color:#666"],
[data-theme="dark"] .card [style*="color: #666"] {
  color: var(--text-primary) !important;
}

/* Alerts: improve contrast in dark mode */
[data-theme="dark"] .alert-success {
  background: rgba(34, 197, 94, 0.14);
  border-color: rgba(34, 197, 94, 0.55);
  color: rgba(187, 247, 208, 0.95);
}
[data-theme="dark"] .alert-info {
  background: rgba(59, 130, 246, 0.14);
  border-color: rgba(59, 130, 246, 0.55);
  color: rgba(191, 219, 254, 0.95);
}
[data-theme="dark"] .alert-warning {
  background: rgba(245, 158, 11, 0.14);
  border-color: rgba(245, 158, 11, 0.55);
  color: rgba(254, 243, 199, 0.95);
}

/* Buttons: richer in dark mode */
[data-theme="dark"] .btn {
  box-shadow: 0 10px 26px rgba(0,0,0,0.35);
}

/* Dark mode: keep all filled buttons the same color */
[data-theme="dark"] .btn-primary,
[data-theme="dark"] .btn-secondary,
[data-theme="dark"] .btn-success,
[data-theme="dark"] .btn-danger,
[data-theme="dark"] .btn-warning {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%) !important;
  border: 1px solid rgba(255, 179, 128, 0.22) !important;
  color: var(--text-light) !important;
  box-shadow: 0 12px 28px rgba(0,0,0,0.40), 0 0 0 1px rgba(255,140,66,0.08);
}
[data-theme="dark"] .btn-primary:hover,
[data-theme="dark"] .btn-secondary:hover,
[data-theme="dark"] .btn-success:hover,
[data-theme="dark"] .btn-danger:hover,
[data-theme="dark"] .btn-warning:hover {
  background: linear-gradient(135deg, rgba(255, 179, 128, 0.95) 0%, var(--primary) 55%, var(--primary-dark) 100%) !important;
  color: var(--text-light) !important;
  box-shadow: 0 14px 34px rgba(0,0,0,0.48), 0 0 26px rgba(255,140,66,0.16);
}
[data-theme="dark"] .btn-ghost {
  background: rgba(255,255,255,0.03);
  border-color: rgba(255,255,255,0.16);
}
[data-theme="dark"] .btn-ghost:hover {
  background: rgba(255,255,255,0.07);
  border-color: rgba(255,255,255,0.22);
}

/* Dark-mode modal polish */
[data-theme="dark"] .modal {
  background: rgba(0,0,0,0.70);
}
[data-theme="dark"] .modal-content {
  border-color: rgba(255,255,255,0.12);
  box-shadow: 0 18px 60px rgba(0,0,0,0.55);
}

/* Modals: override legacy inline text colors in dark mode (but keep buttons/links) */
[data-theme="dark"] .modal-content :where(
  p, span, small, div, section, article, header, footer,
  label, h1, h2, h3, h4, h5, h6,
  ul, ol, li, table, thead, tbody, tr, td, th, code
):not(a):not(button):not(.btn)[style*="color:"] ,
[data-theme="dark"] .modal-content :where(
  p, span, small, div, section, article, header, footer,
  label, h1, h2, h3, h4, h5, h6,
  ul, ol, li, table, thead, tbody, tr, td, th, code
):not(a):not(button):not(.btn)[style*="color:#"] {
  color: var(--text-primary) !important;
}

/* Clause builder modal is especially style-heavy; force readable text in dark mode */
[data-theme="dark"] #addClauseModal .modal-content,
[data-theme="dark"] #addClauseModal .modal-content :where(p, span, small, div, section, article, header, footer, label, h1, h2, h3, h4, h5, h6, code, ul, ol, li) {
  color: var(--text-primary) !important;
}
[data-theme="dark"] #addClauseModal .modal-content :where(.placeholder-desc, small, .help, .hint) {
  color: var(--text-secondary) !important;
}

/* Clause modal: dark-mode specific requirements
   - modal background matches page
   - form fields are white
   - headings/placeholders/buttons are brighter */
[data-theme="dark"] #addClauseModal .modal-content {
  background: var(--bg-main) !important;
  border-color: rgba(255,255,255,0.14) !important;
}

[data-theme="dark"] #addClauseModal .modal-header {
  border-bottom-color: rgba(255,255,255,0.14) !important;
}

[data-theme="dark"] #addClauseModal :where(h3, h4, h5, label) {
  color: rgba(255,255,255,0.95) !important;
}

/* White fields (inputs + textarea + select + preview editor) */
[data-theme="dark"] #addClauseModal input[type="text"],
[data-theme="dark"] #addClauseModal input[type="email"],
[data-theme="dark"] #addClauseModal input[type="tel"],
[data-theme="dark"] #addClauseModal input[type="url"],
[data-theme="dark"] #addClauseModal input[type="number"],
[data-theme="dark"] #addClauseModal input[type="password"],
[data-theme="dark"] #addClauseModal textarea,
[data-theme="dark"] #addClauseModal select,
[data-theme="dark"] #addClauseModal #clauseContentPreview {
  background: #ffffff !important;
  background-color: #ffffff !important;
  color: #111111 !important;
  border-color: rgba(0,0,0,0.20) !important;
}
[data-theme="dark"] #addClauseModal input::placeholder,
[data-theme="dark"] #addClauseModal textarea::placeholder {
  color: rgba(17,17,17,0.55) !important;
}

/* Formatting toolbar + buttons brighter */
[data-theme="dark"] #addClauseModal .formatting-toolbar {
  background: rgba(255,255,255,0.06) !important;
  border-color: rgba(255,255,255,0.14) !important;
}
[data-theme="dark"] #addClauseModal .format-btn {
  background: rgba(255,255,255,0.08) !important;
  border-color: rgba(255,255,255,0.18) !important;
  color: rgba(255,255,255,0.92) !important;
}
[data-theme="dark"] #addClauseModal .format-btn:hover {
  background: rgba(255,255,255,0.14) !important;
  border-color: rgba(255,255,255,0.26) !important;
}
[data-theme="dark"] #addClauseModal .toolbar-separator {
  background: rgba(255,255,255,0.18) !important;
}

/* Placeholder section: brighter headings and items */
[data-theme="dark"] #addClauseModal .modal-placeholders-section {
  border-top-color: rgba(255,255,255,0.14) !important;
}
[data-theme="dark"] #addClauseModal .modal-placeholder-item {
  background: rgba(255,255,255,0.06) !important;
  border-color: rgba(255,255,255,0.16) !important;
}
[data-theme="dark"] #addClauseModal .modal-placeholder-item:hover {
  background: rgba(255,255,255,0.10) !important;
  border-color: rgba(255, 140, 66, 0.55) !important;
}
[data-theme="dark"] #addClauseModal .modal-placeholder-item code {
  color: rgba(255,255,255,0.95) !important;
}
[data-theme="dark"] #addClauseModal .modal-placeholder-item .placeholder-desc {
  color: rgba(255,255,255,0.78) !important;
}

/* ---------------------------------------------------------
   Dark-mode safety net for legacy inline styles (sitewide)
   - Many older templates use inline styles like color:#333 or background:#fff.
   - Normalize those to theme colors so text remains readable.
   - Preserve “paper” areas (contracts) as black-on-white.
   --------------------------------------------------------- */
[data-theme="dark"] :where(p, span, small, li, td, th, div, section, article, header, footer, label, h1, h2, h3, h4, h5, h6)[style*="color:#000"],
[data-theme="dark"] :where(p, span, small, li, td, th, div, section, article, header, footer, label, h1, h2, h3, h4, h5, h6)[style*="color: #000"],
[data-theme="dark"] :where(p, span, small, li, td, th, div, section, article, header, footer, label, h1, h2, h3, h4, h5, h6)[style*="color:#111"],
[data-theme="dark"] :where(p, span, small, li, td, th, div, section, article, header, footer, label, h1, h2, h3, h4, h5, h6)[style*="color: #111"],
[data-theme="dark"] :where(p, span, small, li, td, th, div, section, article, header, footer, label, h1, h2, h3, h4, h5, h6)[style*="color:#222"],
[data-theme="dark"] :where(p, span, small, li, td, th, div, section, article, header, footer, label, h1, h2, h3, h4, h5, h6)[style*="color: #222"],
[data-theme="dark"] :where(p, span, small, li, td, th, div, section, article, header, footer, label, h1, h2, h3, h4, h5, h6)[style*="color:#333"],
[data-theme="dark"] :where(p, span, small, li, td, th, div, section, article, header, footer, label, h1, h2, h3, h4, h5, h6)[style*="color: #333"],
[data-theme="dark"] :where(p, span, small, li, td, th, div, section, article, header, footer, label, h1, h2, h3, h4, h5, h6)[style*="color:#444"],
[data-theme="dark"] :where(p, span, small, li, td, th, div, section, article, header, footer, label, h1, h2, h3, h4, h5, h6)[style*="color: #444"],
[data-theme="dark"] :where(p, span, small, li, td, th, div, section, article, header, footer, label, h1, h2, h3, h4, h5, h6)[style*="color:#555"],
[data-theme="dark"] :where(p, span, small, li, td, th, div, section, article, header, footer, label, h1, h2, h3, h4, h5, h6)[style*="color: #555"],
[data-theme="dark"] :where(p, span, small, li, td, th, div, section, article, header, footer, label, h1, h2, h3, h4, h5, h6)[style*="color:#666"],
[data-theme="dark"] :where(p, span, small, li, td, th, div, section, article, header, footer, label, h1, h2, h3, h4, h5, h6)[style*="color: #666"] {
  color: var(--text-primary) !important;
}

[data-theme="dark"] :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background:#fff"],
[data-theme="dark"] :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background: #fff"],
[data-theme="dark"] :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background:#ffffff"],
[data-theme="dark"] :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background: #ffffff"],
[data-theme="dark"] :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background-color:#fff"],
[data-theme="dark"] :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background-color: #fff"],
[data-theme="dark"] :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background-color:#ffffff"],
[data-theme="dark"] :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background-color: #ffffff"] {
  background: var(--bg-surface) !important;
  border-color: var(--border-light) !important;
}

/* Preserve contract “paper” (black on white) */
[data-theme="dark"] .contract-paper,
[data-theme="dark"] .contract-paper * {
  color: #111 !important;
}
[data-theme="dark"] .contract-paper {
  background: #fff !important;
}

/* Within contract “paper”, keep inline white backgrounds white (signature boxes, etc.) */
[data-theme="dark"] .contract-paper :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background:#fff"],
[data-theme="dark"] .contract-paper :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background: #fff"],
[data-theme="dark"] .contract-paper :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background:#ffffff"],
[data-theme="dark"] .contract-paper :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background: #ffffff"],
[data-theme="dark"] .contract-paper :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background-color:#fff"],
[data-theme="dark"] .contract-paper :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background-color: #fff"],
[data-theme="dark"] .contract-paper :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background-color:#ffffff"],
[data-theme="dark"] .contract-paper :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background-color: #ffffff"] {
  background: #fff !important;
  background-color: #fff !important;
}

/* Promoter signature pad must always be white */
#signaturePad {
  background: #ffffff !important;
  background-color: #ffffff !important;
}
/* Inline white backgrounds inside panels → theme surfaces in dark mode
   (prevents “white-on-white” when legacy inline text colors are normalized) */
[data-theme="dark"] .glass-panel :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background:#fff"],
[data-theme="dark"] .glass-panel :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background: #fff"],
[data-theme="dark"] .glass-panel :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background:#ffffff"],
[data-theme="dark"] .glass-panel :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background: #ffffff"],
[data-theme="dark"] .glass-panel :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background-color:#fff"],
[data-theme="dark"] .glass-panel :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background-color: #fff"],
[data-theme="dark"] .glass-panel :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background-color:#ffffff"],
[data-theme="dark"] .glass-panel :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background-color: #ffffff"],
[data-theme="dark"] .glass-panel :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background: rgb(255, 255, 255)"],
[data-theme="dark"] .glass-panel :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background:rgb(255,255,255)"],
[data-theme="dark"] .glass-panel :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background-color: rgb(255, 255, 255)"],
[data-theme="dark"] .glass-panel :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background-color:rgb(255,255,255)"],
[data-theme="dark"] .panel :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background:#fff"],
[data-theme="dark"] .panel :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background: #fff"],
[data-theme="dark"] .panel :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background:#ffffff"],
[data-theme="dark"] .panel :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background: #ffffff"],
[data-theme="dark"] .panel :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background-color:#fff"],
[data-theme="dark"] .panel :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background-color: #fff"],
[data-theme="dark"] .panel :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background-color:#ffffff"],
[data-theme="dark"] .panel :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background-color: #ffffff"],
[data-theme="dark"] .card :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background:#fff"],
[data-theme="dark"] .card :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background: #fff"],
[data-theme="dark"] .card :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background:#ffffff"],
[data-theme="dark"] .card :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background: #ffffff"],
[data-theme="dark"] .card :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background-color:#fff"],
[data-theme="dark"] .card :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background-color: #fff"],
[data-theme="dark"] .card :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background-color:#ffffff"],
[data-theme="dark"] .card :where(div, section, article, header, footer, p, span, small, ul, ol, li, table, thead, tbody, tr, td, th)[style*="background-color: #ffffff"] {
  background: var(--bg-surface) !important;
  border-color: var(--border-light) !important;
}

/* Make sure page content sits above the grain overlay */
body > * {
  position: relative;
  z-index: 1;
}

[data-theme="light"] .theme-toggle-btn {
  background: rgba(255,255,255,0.90);
  border-color: rgba(31,27,22,0.22);
}

/* Mobile optimizations */
@media (max-width: 768px) {
  .theme-toggle-btn {
    top: 70px; /* Positioned below navigation bar on mobile */
    right: 10px;
    left: auto !important; /* Prevent it from stretching */
    width: 32px;
    height: 32px;
    max-width: 32px !important;
    min-width: 32px !important;
    font-size: 14px;
    border-width: 1.5px;
    box-shadow: 0 2px 8px rgba(0,0,0,.2);
    border-radius: 50% !important; /* Keep it circular */
  }
  
  /* Improve touch targets */
  .btn {
    min-height: 44px;
    padding: 12px 16px;
  }
  
  /* Better spacing on mobile */
  .wrap {
    padding: 20px 12px 60px;
  }
  
  .glass-panel {
    padding: 20px 16px;
    border-radius: 16px;
  }
  
  /* Stack form elements */
  .form-grid {
    grid-template-columns: 1fr !important;
  }
  
  /* Larger text on mobile */
  body {
    font-size: 16px;
  }
  
  /* Better table scrolling */
  .table-container {
    -webkit-overflow-scrolling: touch;
    overflow-x: auto;
  }
  
  /* Improve button spacing */
  .btn-row {
    flex-direction: column;
    gap: 8px;
  }
  
  .btn-row .btn {
    width: 100%;
  }
}

/* Tablet optimizations */
@media (min-width: 769px) and (max-width: 1024px) {
  .wrap {
    padding: 30px 20px 60px;
  }
  
  .document-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Landscape Orientation Optimizations */
@media (max-width: 768px) and (orientation: landscape) {
  .theme-toggle-btn {
    top: 60px; /* Positioned below navigation bar in landscape */
    right: 8px;
    left: auto !important; /* Prevent it from stretching */
    width: 28px;
    height: 28px;
    max-width: 28px !important;
    min-width: 28px !important;
    font-size: 12px;
    border-width: 1.5px;
    box-shadow: 0 2px 6px rgba(0,0,0,.2);
    border-radius: 50% !important; /* Keep it circular */
  }
  
  .wrap {
    padding: 16px 16px 40px;
  }
  
  .glass-panel {
    padding: 16px 20px;
  }
  
  /* Better use of horizontal space */
  .document-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-md);
  }
}

@media (max-width: 640px) and (orientation: landscape) {
  .wrap {
    padding: 12px 14px 30px;
  }
  
  .glass-panel {
    padding: 14px 16px;
  }
  
  .document-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-sm);
  }
}
