/* Phase 2.3 — Active item: instrument-tab gradient + icon glow */
.sidebar-item.active {
  background: linear-gradient(
    to right,
    rgba(56, 189, 248, 0.22),
    rgba(56, 189, 248, 0.04)
  );
  color: #e0f7ff;
  border-left: 3px solid #38bdf8;
}
.sidebar-item.active i,
.sidebar-item.active svg {
  color: #38bdf8 !important;
  filter: drop-shadow(0 0 4px rgba(56, 189, 248, 0.7));
  transform: scale(1.08);
}
.dark .sidebar-item.active {
  background: linear-gradient(
    to right,
    rgba(56, 189, 248, 0.25),
    rgba(56, 189, 248, 0.05)
  );
  color: #e0f7ff;
  border-left: 3px solid #38bdf8;
}

/* Iframe initial bg — matches Phase 1 card dark token */
.dark iframe {
  background-color: #1a2235;
}

/* Phase 10 — smooth cross-fade when switching tools (fix #37) */
iframe {
  transition: opacity 0.2s ease-in-out;
  /* Paint the iframe chrome with the page bg so the blank-document
     moment between src swap and first paint is invisible */
  background-color: var(--bg, #f1f5f9);
}
iframe.loading {
  opacity: 0;
}
/* Give the wrapper a matching bg so no white flash bleeds through */
#iframe-wrapper {
  background-color: var(--bg, #f1f5f9);
}
html.dark iframe,
html.dark #iframe-wrapper {
  background-color: var(--bg); /* resolves to #0a0f1a in dark */
}

/* Sidebar scrollbar styling (visible but subtle) */
#sidebar {
  scrollbar-width: thin; /* Firefox */
  scrollbar-color: #334155 transparent; /* thumb, track */
}
#sidebar::-webkit-scrollbar {
  width: 10px;
}
#sidebar::-webkit-scrollbar-track {
  background: transparent;
}
#sidebar::-webkit-scrollbar-thumb {
  background-color: #334155; /* slate-700 */
  border-radius: 8px;
  border: 2px solid transparent;
  background-clip: content-box;
}
.dark #sidebar::-webkit-scrollbar-thumb {
  background-color: #475569; /* slate-600 */
}

/* Keyboard focus and hover polish for sidebar items */
.sidebar-item {
  outline: none;
}
.sidebar-item:focus-visible {
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.6) inset; /* primary-400 */
  border-radius: 0.5rem;
}
.sidebar-item:hover {
  background-color: rgba(56, 189, 248, 0.08); /* primary-400 at ~8% */
}
.sidebar-item i,
.sidebar-item svg {
  transition:
    color 0.15s ease-in-out,
    transform 0.12s ease-in-out;
}
.sidebar-item:hover i,
.sidebar-item:hover svg {
  color: #7dd3fc; /* primary-300 */
}
.sidebar-item:active i,
.sidebar-item:active svg {
  transform: translateY(0.5px);
}

/* Limit long item labels to 2 lines for tidy rhythm */
.sidebar-item span[data-i18n] {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-clamp: 2; /* standard property for future support */
  overflow: hidden;
  white-space: normal;
  line-height: 1.2;
}

/* Phase 2.4 — Section headers: dot accent + bottom border */
.section-header {
  position: sticky;
  top: 0;
  z-index: 5;
  backdrop-filter: saturate(120%) blur(6px);
  -webkit-backdrop-filter: saturate(120%) blur(6px);
  border-bottom: 1px solid rgba(30, 58, 95, 0.6);
}
.section-header .label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding-top: 0.25rem;
  padding-bottom: 0.25rem;
}
.section-header .label::before {
  content: "";
  display: inline-block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #38bdf8;
  box-shadow: 0 0 5px rgba(56, 189, 248, 0.8);
  flex-shrink: 0;
}

/* Scroll shadows for sidebar to hint overflow */
#sidebar {
  position: relative;
}
#sidebar::before,
#sidebar::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 12px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease-in-out;
}
#sidebar::before {
  top: 0;
  background: linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.22),
    rgba(0, 0, 0, 0)
  );
}
#sidebar::after {
  bottom: 0;
  background: linear-gradient(
    to top,
    rgba(0, 0, 0, 0.22),
    rgba(0, 0, 0, 0)
  );
}
#sidebar.shadow-top::before {
  opacity: 1;
}
#sidebar.shadow-bottom::after {
  opacity: 1;
}

/* Improved mobile sidebar styles */
@media (max-width: 768px) {
  .sidebar-closed {
    transform: translateX(-100%);
  }

  .sidebar-overlay {
    background-color: rgba(0, 0, 0, 0.5);
    transition: opacity 0.3s ease-in-out;
  }

  .sidebar-overlay.hidden {
    opacity: 0;
    pointer-events: none;
  }
}

/* Enhanced touch styles for tablet devices */
@media (hover: none) and (pointer: coarse) {
  /* Larger touch targets for buttons */
  button,
  .sidebar-item {
    min-height: 48px;
    padding: 12px !important;
  }

  /* Increase spacing between sidebar items */
  .sidebar-item {
    margin-bottom: 8px;
  }

  /* Larger toggle for dark mode */
  #darkModeIndicator {
    width: 24px !important;
    height: 24px !important;
  }

  /* Larger container for dark mode toggle */
  #darkModeToggle .relative {
    width: 48px !important;
    height: 24px !important;
  }

  /* Prevent accidental text selection on touch */
  * {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
  }

  /* Add visible active state for touch feedback */
  button:active,
  .sidebar-item:active {
    transform: scale(0.98);
    transition: transform 0.1s;
  }
}

/* Swipe gesture support */
.swipe-area {
  position: fixed;
  top: 0;
  left: 0;
  width: 20px;
  height: 100%;
  z-index: 15;
}

/* Phase 4.3 — typography */
body {
  font-family: "Barlow", sans-serif;
}
button,
input,
select,
label {
  font-family: "Barlow", sans-serif;
}
/* App name + section headers → Rajdhani technical condensed */
#sidebar .text-lg.font-semibold {
  font-family: "Rajdhani", sans-serif;
  font-weight: 700;
  letter-spacing: 0.03em;
  font-size: 1.1rem;
}
.section-header .label {
  font-family: "Rajdhani", sans-serif;
  font-weight: 600;
  letter-spacing: 0.08em;
}

/* Phase 2.2 — Sidebar: deep navy aviation console background */
.sidebar-nav {
  background-color: #0d1424;
  border-right-color: #1e3a5f !important;
}
.section-header {
  background-color: rgba(13, 20, 36, 0.9) !important;
}
/* Override Tailwind gray-700 hover inside sidebar to match navy palette */
.sidebar-nav .hover\:bg-gray-700:hover {
  background-color: rgba(56, 189, 248, 0.08) !important;
}

/* Phase 2.5 — Desktop topbar */
#topbar {
  background-color: #0d1424;
  border-bottom: 1px solid #1e3a5f;
  flex-shrink: 0;
}

/* =====================================================
   Phase 10 — Collapsible Sidebar Rail
   ===================================================== */

/* 10.1 — Smooth width transition */
#sidebar {
  transition: width 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: width;
}

/* When in rail mode: 56px icon-only rail */
#sidebar.rail {
  width: 56px !important;
  min-width: 56px;
  overflow: visible; /* allow tooltip to escape clip */
}

/* Rail: hide label text, keep icon visible */
#sidebar.rail .sidebar-label {
  opacity: 0;
  max-width: 0;
  overflow: hidden;
  pointer-events: none;
  transition:
    opacity 0.18s ease,
    max-width 0.18s ease;
}
#sidebar.rail .section-header .label-text {
  display: none;
}
#sidebar.rail .section-header .section-chevron {
  display: none;
}
#sidebar.rail .section-header .label::before {
  display: none;
}
#sidebar.rail .section-header {
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
}

/* Phase 7 — Sub-section labels inside Calculators group */
.sub-section-label {
  padding: 6px 12px 2px 20px;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #4b6480;
  display: flex;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  user-select: none;
}
.sub-section-label::before {
  content: "";
  flex: 1;
  height: 1px;
  background: rgba(56, 189, 248, 0.12);
}
/* Hide label text in rail mode; keep the divider line */
#sidebar.rail .sub-section-label span {
  display: none;
}
#sidebar.rail .sub-section-label {
  padding: 6px 0 2px;
  justify-content: center;
}

/* Rail: centre items, kill text-related margins */
#sidebar.rail .sidebar-item {
  justify-content: center !important;
  padding: 0.75rem 0 !important;
}
#sidebar.rail .sidebar-item i,
#sidebar.rail .sidebar-item svg.sidebar-icon {
  margin-right: 0 !important;
}

/* Rail: hide brand text, centre compass */
#sidebar.rail .brand-text {
  display: none;
}
#sidebar.rail #sidebarBrand {
  justify-content: center !important;
}

/* Rail: hide footer labels + toggles that don't make sense */
#sidebar.rail .rail-hide {
  display: none !important;
}
#sidebar.rail .sidebar-footer-icon {
  margin-right: 0 !important;
}

/* Rail mode — fix footer clickability: full-width centred icons */
#sidebar.rail .sidebar-footer {
  padding-left: 0 !important;
  padding-right: 0 !important;
}
#sidebar.rail #darkModeToggle,
#sidebar.rail .language-row {
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
}
/* Tooltip for footer items in rail mode */
#sidebar.rail #darkModeToggle,
#sidebar.rail .language-row {
  position: relative;
  overflow: visible;
}
#sidebar.rail #darkModeToggle::after,
#sidebar.rail .language-row::after {
  content: attr(data-label);
  position: absolute;
  left: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%);
  background: #0d1424;
  border: 1px solid #1e3a5f;
  color: #e0f7ff;
  font-family: "Barlow", sans-serif;
  font-size: 0.78rem;
  white-space: nowrap;
  padding: 0.3rem 0.7rem;
  border-radius: 6px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
  z-index: 200;
}
#sidebar.rail #darkModeToggle:hover::after,
#sidebar.rail .language-row:hover::after {
  opacity: 1;
}
/* Allow tooltips to escape sidebar in rail mode */
#sidebar.rail {
  overflow-y: auto;
  overflow-x: visible;
}

/* Non-rail: show labels with transition */
.sidebar-label {
  opacity: 1;
  max-width: 200px;
  overflow: hidden;
  white-space: nowrap;
  transition:
    opacity 0.18s ease 0.05s,
    max-width 0.22s ease;
}

/* 10.2 — Rail hover tooltip */
#sidebar.rail .sidebar-item {
  position: relative;
  overflow: visible;
}
#sidebar.rail .sidebar-item::after {
  content: attr(data-label);
  position: absolute;
  left: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%);
  background: #0d1424;
  border: 1px solid #1e3a5f;
  color: #e0f7ff;
  font-family: "Barlow", sans-serif;
  font-size: 0.78rem;
  white-space: nowrap;
  padding: 0.3rem 0.7rem;
  border-radius: 6px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
  z-index: 200;
}
#sidebar.rail .sidebar-item:hover::after {
  opacity: 1;
}

/* 10.3 — Section group accordion */
.section-header {
  cursor: pointer;
  display: flex !important;
  align-items: center;
  justify-content: space-between;
  user-select: none;
}
.section-chevron {
  width: 12px;
  height: 12px;
  color: #64748b;
  flex-shrink: 0;
  transition: transform 0.22s ease;
}
.section-header.collapsed .section-chevron {
  transform: rotate(-90deg);
}
.section-group {
  overflow: hidden;
  max-height: 1200px;
  transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.section-group.collapsed {
  max-height: 0;
}

/* 10.4 — Upgraded active item glow bar (replaces border-left) */
.sidebar-item {
  position: relative;
  border-left: none !important;
}
.sidebar-item.active {
  background: linear-gradient(
    to right,
    rgba(56, 189, 248, 0.18),
    rgba(56, 189, 248, 0.04)
  ) !important;
  border-left: none !important;
  color: #e0f7ff;
}
.sidebar-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 20%;
  bottom: 20%;
  width: 3px;
  background: #38bdf8;
  border-radius: 0 2px 2px 0;
  box-shadow:
    0 0 8px rgba(56, 189, 248, 0.8),
    0 0 16px rgba(56, 189, 248, 0.35);
}
/* Rail mode active: bottom dot indicator */
#sidebar.rail .sidebar-item.active::before {
  top: auto;
  bottom: 4px;
  left: 50%;
  right: auto;
  transform: translateX(-50%);
  width: 16px;
  height: 3px;
  border-radius: 2px;
}

/* 10.5 — Topbar sidebar collapse button */
#sidebarCollapseBtn {
  display: none; /* shown via md:flex override below */
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  color: #64748b;
  background: transparent;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  margin-right: 12px;
  transition:
    color 0.15s ease,
    background 0.15s ease;
}
#sidebarCollapseBtn:hover {
  color: #38bdf8;
  background: rgba(56, 189, 248, 0.1);
}
@media (min-width: 768px) {
  #sidebarCollapseBtn {
    display: flex;
  }
}
#sidebarCollapseBtn .chevron-icon {
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}
#sidebar.rail ~ .flex-1 #sidebarCollapseBtn .chevron-icon,
.rail-collapsed #sidebarCollapseBtn .chevron-icon {
  transform: rotate(180deg);
}
/* END PHASE 10 */
