/* =====================================================================
 * Lok-N-Blok shared UI layer
 * Loaded by every page. Targets the shared scaffolding (.sidebar, .main,
 * .card, .btn, etc.) without overriding page-specific layout.
 *
 * Goals:
 *   - Real mobile responsiveness with a hamburger drawer on every sidebar page
 *   - 16px form fields (no iOS zoom on focus)
 *   - Touch-friendly tap targets (≥40px)
 *   - Safe-area insets for notched phones
 *   - Smooth scrollbars + scroll-shadow polish
 *   - Accessible focus-visible rings
 *   - prefers-reduced-motion respect
 *   - Print stylesheet that hides nav and prints clean cards
 * ===================================================================== */

/* iOS-safe vh, via JS */
:root {
  --lnb-vh: 1vh;
  --lnb-tap: rgba(212, 168, 67, .15);
  --lnb-focus: #f0c35a;
  --lnb-shadow-sm: 0 2px 8px rgba(0,0,0,.18);
  --lnb-shadow-md: 0 8px 28px rgba(0,0,0,.28);
  --lnb-radius: 12px;
}

/* Anti-FOUC for pages that opt in by setting opacity:0 in head */
html.lnb-fadein body { opacity: 0; transition: opacity .2s ease; }
html.lnb-fadein.lnb-loaded body { opacity: 1; }

/* Color-scheme hint for browser chrome (form controls, scrollbars, etc.) */
html { color-scheme: dark; -webkit-tap-highlight-color: var(--lnb-tap); }

/* Stop overscroll bouncing the sidebar/header on iOS */
html, body { overscroll-behavior-y: none; }

/* Smooth scrolling, but only when the user hasn't asked for reduced motion */
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

/* Focus-visible polish — keyboard users get a visible ring, mouse users don't */
:where(a, button, [role="button"], input, select, textarea, [tabindex]):focus { outline: none; }
:where(a, button, [role="button"], input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--lnb-focus);
  outline-offset: 2px;
  border-radius: 6px;
}

/* Native form controls — kill iOS rounding & enforce 16px to skip zoom */
input, textarea, select, button {
  font: inherit;
}
input[type="text"], input[type="email"], input[type="password"],
input[type="search"], input[type="tel"], input[type="url"],
input[type="number"], textarea, select {
  font-size: 16px !important;        /* iOS Safari zooms anything <16px */
  -webkit-appearance: none;
  appearance: none;
  border-radius: 8px;
}

/* Selection */
::selection { background: rgba(240, 195, 90, .35); color: #fff; }

/* Cross-browser scrollbar consistency */
* { scrollbar-width: thin; scrollbar-color: #2d3d33 transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2d3d33; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #3d5246; }

/* Long-form code/pre blocks — wrap on mobile, scroll on desktop */
pre { max-width: 100%; }

/* =====================================================================
 * Mobile hamburger top bar — injected by lnb-ui.js on pages with .sidebar
 * Shown only ≤900px. Hidden on desktop.
 * ===================================================================== */
.lnb-mobilebar {
  position: fixed; inset: 0 0 auto 0;
  height: calc(56px + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  display: none;
  align-items: center; gap: 12px;
  padding-left: 14px; padding-right: 14px;
  background: rgba(8, 15, 11, .92);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid #243028;
  z-index: 90;
  font-family: 'Space Grotesk', 'Inter', sans-serif;
}
.lnb-mobilebar__btn {
  appearance: none; -webkit-appearance: none;
  background: transparent; border: 1px solid #243028;
  color: #e8ede9; width: 40px; height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 8px; cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
}
.lnb-mobilebar__btn:hover { background: rgba(110, 232, 154, .06); border-color: #2d3d33; }
.lnb-mobilebar__btn:active { transform: scale(.96); }
.lnb-mobilebar__brand {
  display: flex; align-items: center; gap: 10px; min-width: 0;
}
.lnb-mobilebar__logo {
  width: 30px; height: 30px;
  background: linear-gradient(135deg, #27a556, #3dcc6e);
  border-radius: 8px; color: #080f0b;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 11px; letter-spacing: .5px;
  font-family: 'Space Grotesk', sans-serif;
  flex-shrink: 0;
}
.lnb-mobilebar__title {
  font-size: 13px; font-weight: 700; color: #e8ede9;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.lnb-mobilebar__title small {
  display: block; font-size: 9px; color: #f0c35a; font-weight: 600;
  letter-spacing: 1.5px; text-transform: uppercase; margin-top: 1px;
}

/* Backdrop scrim that closes the drawer when tapped */
.lnb-scrim {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, .55);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  opacity: 0; pointer-events: none;
  transition: opacity .22s ease;
  z-index: 95;
}
.lnb-scrim.is-open { opacity: 1; pointer-events: auto; }

/* =====================================================================
 * Mobile breakpoint — ≤900px
 * Sidebar slides in/out, main expands, top bar visible.
 * ===================================================================== */
@media (max-width: 900px) {
  .lnb-mobilebar { display: flex; }

  /* Sidebar becomes a drawer. Works for any page using the .sidebar pattern. */
  .sidebar {
    transform: translateX(-100%);
    transition: transform .26s cubic-bezier(.4, 0, .2, 1);
    box-shadow: var(--lnb-shadow-md);
    width: min(280px, 84vw) !important;
    z-index: 100;
    padding-top: env(safe-area-inset-top, 0px);
  }
  .sidebar.is-open { transform: translateX(0); }

  /* Push the page content below the mobile bar and remove sidebar margin */
  .main, .main-container, main.main {
    margin-left: 0 !important;
    padding-top: calc(56px + env(safe-area-inset-top, 0px) + 14px) !important;
    max-width: 100% !important;
  }
  .main { padding-left: 18px !important; padding-right: 18px !important; }

  /* Bottom safe-area for cards close to home indicator */
  body { padding-bottom: env(safe-area-inset-bottom, 0px); }

  /* Reduce card padding so dashboards breathe */
  .card { padding: 18px !important; border-radius: 14px; }

  /* Page title scaling */
  .page-title { font-size: 22px !important; line-height: 1.2; }
  .page-subtitle { font-size: 12px !important; }
  h1.page-title { word-break: break-word; }

  /* Make button rows wrap and stretch full-width on tiny screens */
  .btn-row { gap: 8px !important; }
  .btn-row .btn { flex: 1 1 auto; min-width: 140px; justify-content: center; }
  .btn { min-height: 44px; }

  /* Wider tap targets on nav items */
  .nav-item { padding: 12px 14px !important; min-height: 44px; }

  /* Make tables horizontally scrollable with a fade hint */
  .lnb-table-scroll, table.scrollable, .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    background:
      linear-gradient(to right, var(--bg-card, #1a1f1d), transparent 12px) left center / 24px 100% no-repeat,
      linear-gradient(to left, var(--bg-card, #1a1f1d), transparent 12px) right center / 24px 100% no-repeat,
      radial-gradient(farthest-side at left, rgba(0,0,0,.4), transparent) left center / 18px 100% no-repeat,
      radial-gradient(farthest-side at right, rgba(0,0,0,.4), transparent) right center / 18px 100% no-repeat;
    background-attachment: local, local, scroll, scroll;
  }

  /* Code/pre blocks: wrap long words instead of horizontal-scrolling forever */
  pre, code {
    word-break: break-word;
    white-space: pre-wrap !important;
  }
  .code-block pre { font-size: 10.5px !important; line-height: 1.55; }
  .code-copy-btn { top: 8px !important; right: 8px !important; padding: 5px 10px !important; }

  /* Toast lifts above home indicator */
  .toast {
    left: 12px !important; right: 12px !important; bottom: calc(12px + env(safe-area-inset-bottom, 0px)) !important;
    max-width: none !important;
  }

  /* Status banner stacks more compactly */
  .status-banner { padding: 14px 16px !important; gap: 12px !important; }
  .status-icon { width: 38px !important; height: 38px !important; }
  .status-text h3 { font-size: 14px !important; }
  .status-text p { font-size: 11.5px !important; }

  /* Two-column template gallery → stacked */
  [style*="grid-template-columns:240px 1fr"],
  [style*="grid-template-columns: 240px 1fr"] {
    display: block !important;
  }
  [style*="grid-template-columns:240px 1fr"] > div:first-child,
  [style*="grid-template-columns: 240px 1fr"] > div:first-child {
    display: grid !important;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)) !important;
    gap: 6px;
    margin-bottom: 14px;
  }
}

/* Tighter still on tiny phones */
@media (max-width: 480px) {
  .main { padding: 14px !important; padding-top: calc(56px + env(safe-area-inset-top, 0px) + 10px) !important; }
  .card { padding: 14px !important; }
  .page-header { padding-bottom: 14px !important; margin-bottom: 18px !important; }
  .page-title { font-size: 19px !important; }

  /* Diagnostics chip cards squeeze nicely */
  #diagChecks { grid-template-columns: 1fr !important; }
}

/* Hide the mobile bar on print */
@media print {
  .lnb-mobilebar, .lnb-scrim, .sidebar { display: none !important; }
  .main, .main-container { margin-left: 0 !important; padding: 0 !important; }
  .card { border: 1px solid #ccc !important; box-shadow: none !important; break-inside: avoid; }
  .btn, .btn-row { display: none !important; }
  body { background: #fff !important; color: #111 !important; }
  * { color: #111 !important; }
  a { color: #1a4f8a !important; text-decoration: underline; }
}

/* Skeleton loader utility */
.lnb-skeleton {
  background: linear-gradient(90deg, #1a1f1d 0%, #243028 50%, #1a1f1d 100%);
  background-size: 200% 100%;
  border-radius: 6px;
  animation: lnb-shimmer 1.4s ease-in-out infinite;
}
@keyframes lnb-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) {
  .lnb-skeleton { animation: none; }
  * { transition: none !important; animation: none !important; }
}

/* Card hover only on hover-capable devices (avoids sticky touch state) */
@media (hover: hover) and (pointer: fine) {
  .card { transition: border-color .2s, transform .2s; }
}
