/* Smart Web Apps - global styles
 * - Dark grey default, with Bootstrap color modes.
 * - Keep CSS small and predictable to stay fast.
 */

:root {
  --swa-radius: 14px;
  --swa-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  --swa-sidebar-width: 310px;
}

/* Subtle dark theme tinting (Bootstrap handles most colors). */
html[data-bs-theme="dark"] body {
  background: radial-gradient(1200px 700px at 15% -10%, rgba(255, 255, 255, 0.06), transparent 55%),
    radial-gradient(900px 500px at 85% 0%, rgba(255, 255, 255, 0.04), transparent 60%),
    #0f1115;
}

html[data-bs-theme="light"] body {
  background: #f6f7f9;
}

/* Prevent accidental horizontal scrolling (common with long tool names and offcanvas transitions). */
html,
body {
  overflow-x: hidden;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--swa-sidebar-width) 1fr;
}

@media (max-width: 991.98px) {
  .app-shell {
    /* On mobile, keep layout simple. Sidebar becomes an overlay (offcanvas), and main content flows naturally. */
    display: block;
    grid-template-columns: 1fr;
  }
}

.app-sidebar {
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.03);
  backdrop-filter: blur(10px);
  width: var(--swa-sidebar-width);
  max-width: 100vw;
  min-width: 0;
}

.app-sidebar .offcanvas-body {
  overflow-x: hidden;
}

/* Desktop: keep the sidebar visible and sticky. On smaller screens, Bootstrap's offcanvas behavior should control layout. */
@media (min-width: 992px) {
  .app-sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    overflow: auto;
    overflow-x: hidden;
  }
}

.sidebar-inner {
  padding: 16px;
  min-width: 0;
  overflow-x: hidden;
}

.sidebar-brand .brand-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(135deg, #9ca3af, #e5e7eb);
  margin-right: 10px;
}

.sidebar-brand .brand-logo {
  width: 24px;
  height: 24px;
  margin-right: 10px;
  border-radius: 8px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
  flex: 0 0 auto;
}

.sidebar-brand .brand-name {
  font-weight: 700;
  letter-spacing: 0.2px;
}

.sidebar-divider {
  opacity: 0.15;
}

.sidebar-tool.active {
  border-left: 3px solid rgba(255, 255, 255, 0.65);
}

/* Offcanvas width on small screens (prevent it from overflowing narrow viewports). */
.app-sidebar.offcanvas-start {
  --bs-offcanvas-width: min(92vw, var(--swa-sidebar-width));
}

/* Fallback offcanvas behavior for small screens.
 * - If Bootstrap CSS/JS fails to load (CDN blocked, file:// testing, etc.), the sidebar must not render inline above the header.
 * - When Bootstrap is present, these rules match Bootstrap’s defaults and are effectively no-ops.
 */
@media (max-width: 991.98px) {
  .app-sidebar.offcanvas-lg {
    position: fixed;
    top: 0;
    bottom: 0;
    z-index: var(--bs-offcanvas-zindex, 1045);
    display: flex;
    flex-direction: column;
    max-width: 100%;
    color: var(--bs-offcanvas-color, var(--bs-body-color, #dee2e6));
    visibility: hidden;
    background-color: var(--bs-offcanvas-bg, var(--bs-body-bg, #0f1115));
    background-clip: padding-box;
    outline: 0;
    transition: transform 0.3s ease-in-out;
  }

  .app-sidebar.offcanvas-lg.offcanvas-start {
    left: 0;
    transform: translateX(-100%);
  }

  .app-sidebar.offcanvas-lg.show,
  .app-sidebar.offcanvas-lg.showing,
  .app-sidebar.offcanvas-lg.hiding {
    visibility: visible;
  }

  .app-sidebar.offcanvas-lg.show {
    transform: none;
  }
}

/* Backdrop fallback for the offcanvas sidebar (used by SWA JS fallback if Bootstrap JS isn’t available). */
.offcanvas-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1040;
  width: 100vw;
  height: 100vh;
  background-color: #000;
}

.offcanvas-backdrop.fade {
  opacity: 0;
}

.offcanvas-backdrop.show {
  opacity: 0.5;
}

/* Ensure long tool names don’t cause horizontal scrolling. */
.sidebar-inner .accordion-button,
.sidebar-inner .list-group-item {
  overflow-wrap: anywhere;
  white-space: normal;
  max-width: 100%;
}

.sidebar-inner .accordion,
.sidebar-inner .list-group,
.sidebar-inner .input-group {
  min-width: 0;
  max-width: 100%;
}

.app-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.app-header {
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.02);
  backdrop-filter: blur(10px);
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 32px;
  padding: 0;
}

.header-logo {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
  flex: 0 0 auto;
}

@media (max-width: 575.98px) {
  .app-header .container-fluid {
    padding-top: 6px !important;
    padding-bottom: 6px !important;
  }

  .app-header .container-fluid > .d-flex.align-items-center.justify-content-between {
    flex-wrap: nowrap;
  }

  /* Prevent the brand link from wrapping and making the header taller. */
  .app-header a[href="/"] {
    max-width: 55vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: inline-block;
  }
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 32px;
  padding: 0;
}

.theme-toggle .theme-icon {
  display: none;
}

/* Show the icon that represents the opposite mode. */
html[data-bs-theme="dark"] .theme-toggle .theme-icon-sun {
  display: inline-block;
}

html[data-bs-theme="light"] .theme-toggle .theme-icon-moon {
  display: inline-block;
}

.content-wrap {
  flex: 1;
}

.category-card,
.tool-card {
  border-radius: var(--swa-radius);
  box-shadow: none;
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: rgba(255, 255, 255, 0.03);
  transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease;
}

html[data-bs-theme="light"] .category-card,
html[data-bs-theme="light"] .tool-card {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.08);
}

.category-card:hover,
.tool-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--swa-shadow);
  border-color: rgba(255, 255, 255, 0.22);
}

.category-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.10);
  font-size: 18px;
}

.tool-card-icon {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.10);
  font-size: 14px;
}

.hero {
  border-radius: calc(var(--swa-radius) + 6px);
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02));
}

html[data-bs-theme="light"] .hero {
  background: linear-gradient(135deg, rgba(0, 0, 0, 0.03), rgba(0, 0, 0, 0.01));
}

.ad-slot.is-hidden {
  /* Keep slots present so AdSense can render, but remove any visible "empty space" until content exists. */
  padding: 0 !important;
  margin: 0 !important;
  border: 0 !important;
}

.ad-slot.is-hidden > * {
  padding: 0 !important;
  margin: 0 !important;
  border: 0 !important;
}

.has-anchor-ad {
  padding-bottom: 90px;
}

.output-block {
  border-radius: var(--swa-radius);
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: rgba(255, 255, 255, 0.03);
}

.output-heading {
  font-weight: 700;
  letter-spacing: 0.2px;
}

.output-heading--primary {
  color: #93c5fd;
}

.output-heading--success {
  color: #86efac;
}

.output-heading--warning {
  color: #fcd34d;
}

.output-heading--danger {
  color: #fca5a5;
}

.visually-hidden-focusable:active,
.visually-hidden-focusable:focus {
  position: static !important;
  width: auto;
  height: auto;
  margin: 0;
  overflow: visible;
  clip: auto;
  white-space: normal;
}
