/* ============================================================================
   Sidebar Template Styles
   Ported from the Janani Travels React sidebar (src/components/sidebar)
   Self-contained: light/dark theme, collapsible, mobile drawer, search,
   dropdowns, secondary slide-in panel, flyout, badges, hotkeys.
   ========================================================================== */

/* ---------------------------------------------------------------------------
   Design tokens
--------------------------------------------------------------------------- */
:root {
  --sidebar: 248 250 252;
  --sidebar-foreground: 15 23 42;
  --sidebar-primary: 99 102 241;
  --sidebar-primary-foreground: 255 255 255;
  --sidebar-accent: 226 232 240;
  --sidebar-accent-foreground: 15 23 42;
  --sidebar-ring: 129 140 248;
  --sidebar-border: 226 232 240;

  --background: 248 250 252;
  --foreground: 15 23 42;
  --card: 255 255 255;
  --card-foreground: 15 23 42;
  --muted-foreground: 100 116 139;
  --border: 226 232 240;
  --ring: 129 140 248;
  --primary: 99 102 241;
  --primary-foreground: 255 255 255;

  --sidebar-width: 256px;
  --sidebar-collapsed-width: 68px;

  --radius-sm: 0.25rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;

  color-scheme: light;
}

[data-theme="dark"] {
  --sidebar: 15 23 42;
  --sidebar-foreground: 226 232 240;
  --sidebar-primary: 99 102 241;
  --sidebar-primary-foreground: 255 255 255;
  --sidebar-accent: 30 41 59;
  --sidebar-accent-foreground: 226 232 240;
  --sidebar-ring: 129 140 248;
  --sidebar-border: 30 41 59;

  --background: 2 6 23;
  --foreground: 226 232 240;
  --card: 15 23 42;
  --card-foreground: 226 232 240;
  --muted-foreground: 148 163 184;
  --border: 30 41 59;
  --ring: 129 140 248;
  --primary: 99 102 241;
  --primary-foreground: 255 255 255;

  color-scheme: dark;
}

/* ---------------------------------------------------------------------------
   Reset & base
--------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: rgb(var(--foreground));
  background: rgb(var(--background));
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
}

a {
  color: inherit;
}

/* ---------------------------------------------------------------------------
   App shell
--------------------------------------------------------------------------- */
.sidebar-shell {
  position: fixed;
  inset: 0;
  display: flex;
  overflow: hidden;
  background: rgb(var(--background));
}

.sidebar-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: rgb(var(--background));
}

.sidebar-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 24px;
  background: rgb(var(--card));
  border-bottom: 1px solid rgb(var(--border));
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  z-index: 10;
}

.sidebar-topbar-left,
.sidebar-topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: rgb(var(--background));
  scrollbar-width: thin;
}

.sidebar-content::-webkit-scrollbar {
  width: 6px;
}

.sidebar-content::-webkit-scrollbar-thumb {
  background: rgb(var(--muted-foreground) / 0.35);
  border-radius: 3px;
}

/* ---------------------------------------------------------------------------
   Icon buttons (topbar / generic)
--------------------------------------------------------------------------- */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 36px;
  padding: 0 10px;
  border: 1px solid rgb(var(--border));
  border-radius: var(--radius-md);
  background: rgb(var(--card));
  color: rgb(var(--foreground));
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
}

.icon-btn:hover {
  background: rgb(var(--primary));
  color: rgb(var(--primary-foreground));
  border-color: rgb(var(--primary));
}

.icon-btn:active {
  transform: scale(0.96);
}

.icon-btn:focus-visible,
.menu-item:focus-visible {
  outline: 2px solid rgb(var(--ring));
  outline-offset: 2px;
}

.icon-btn.plain {
  background: transparent;
  border-color: transparent;
  color: rgb(var(--muted-foreground));
  height: auto;
  padding: 4px;
}

.icon-btn.plain:hover {
  background: rgb(var(--sidebar-accent));
  color: rgb(var(--foreground));
  border-color: transparent;
}

.show-on-mobile {
  display: inline-flex;
}

.hide-on-mobile {
  display: none;
}

/* ---------------------------------------------------------------------------
   Sidebar
--------------------------------------------------------------------------- */
.sidebar {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  width: var(--sidebar-width);
  background: rgb(var(--sidebar));
  border-right: 1px solid rgb(var(--sidebar-border));
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  transform: translateX(-100%);
  transition: width 0.3s ease, transform 0.3s ease;
}

.sidebar.is-mobile-open {
  transform: translateX(0);
}

.sidebar.collapsed:not(.is-mobile-open) {
  width: var(--sidebar-collapsed-width);
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 8px 16px;
  position: relative;
  scrollbar-width: none;
}

.sidebar-nav::-webkit-scrollbar {
  display: none;
}

/* ---------------------------------------------------------------------------
   Sidebar brand / header
--------------------------------------------------------------------------- */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  height: 61px;
  border-bottom: 1px solid rgb(var(--sidebar-border));
  text-decoration: none;
  transition: background 0.15s;
  flex-shrink: 0;
}

.sidebar-brand:hover {
  background: rgb(var(--sidebar-accent));
}

.sidebar-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: var(--radius-md);
  background: rgb(var(--sidebar-primary));
  color: rgb(var(--sidebar-primary-foreground));
  font-weight: 700;
  font-size: 14px;
}

.sidebar-brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sidebar-brand-title {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
  color: rgb(var(--sidebar-foreground));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-brand-subtitle {
  font-size: 10px;
  color: rgb(var(--sidebar-foreground) / 0.6);
}

/* ---------------------------------------------------------------------------
   Sidebar search
--------------------------------------------------------------------------- */
.sidebar-search {
  padding: 12px 12px 0;
  flex-shrink: 0;
}

.search-wrap {
  position: relative;
}

.search-wrap svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: rgb(var(--muted-foreground));
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 8px 34px 8px 36px;
  font-size: 13px;
  color: rgb(var(--sidebar-foreground));
  background: rgb(var(--sidebar-accent));
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

.search-input::placeholder {
  color: rgb(var(--muted-foreground));
}

.search-input:focus {
  border-color: rgb(var(--sidebar-border));
  box-shadow: 0 0 0 2px rgb(var(--sidebar-ring) / 0.5);
}

.search-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: rgb(var(--muted-foreground));
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.search-clear:hover {
  color: rgb(var(--sidebar-foreground));
  background: rgb(var(--sidebar-accent));
}

/* ---------------------------------------------------------------------------
   Menu sections & items
--------------------------------------------------------------------------- */
.menu-section {
  margin-bottom: 12px;
}

.section-title {
  padding: 6px 12px 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: rgb(var(--sidebar-foreground) / 0.5);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.menu-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 12px;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: rgb(var(--sidebar-foreground));
  font-size: 13px;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  overflow: hidden;
}

a.menu-item {
  text-decoration: none;
}

.menu-item:hover {
  background: rgb(var(--sidebar-accent));
  color: rgb(var(--sidebar-accent-foreground));
}

.menu-item.is-active,
.menu-item.is-active:hover {
  background: rgb(var(--sidebar-primary));
  color: rgb(var(--sidebar-primary-foreground));
  font-weight: 500;
}

.menu-item.is-disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.menu-item.is-disabled:hover {
  background: transparent;
}

.menu-item svg {
  flex-shrink: 0;
}

.menu-label {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.menu-chevron {
  flex-shrink: 0;
  transition: transform 0.2s;
}

.menu-group.is-open > .menu-item .menu-chevron {
  transform: rotate(180deg);
}

.badge {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgb(var(--sidebar-accent));
  color: rgb(var(--sidebar-accent-foreground));
}

.menu-item.is-active .badge {
  background: rgb(var(--sidebar-primary-foreground) / 0.2);
  color: rgb(var(--sidebar-primary-foreground));
}

.hotkey {
  flex-shrink: 0;
  font-size: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  background: rgb(var(--sidebar-accent));
  border: 1px solid rgb(var(--sidebar-border));
  color: rgb(var(--sidebar-foreground));
}

.menu-item.is-active .hotkey {
  background: rgb(var(--sidebar-primary-foreground) / 0.2);
  border-color: transparent;
}

/* Submenu (dropdown children) */
.menu-group {
  position: relative;
}

.submenu {
  margin: 0;
  padding: 0;
  list-style: none;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.25s ease;
}

.menu-group.is-open > .submenu {
  max-height: 400px;
}

.submenu-item {
  gap: 8px;
  margin-left: 24px;
  padding: 6px 12px;
  border-left: 1px solid rgb(var(--sidebar-border));
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  font-size: 13px;
}

/* ---------------------------------------------------------------------------
   Secondary slide-in panel
--------------------------------------------------------------------------- */
.secondary-panel {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  background: rgb(var(--sidebar));
  border-right: 1px solid rgb(var(--sidebar-border));
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  visibility: hidden;
}

.secondary-panel.is-open {
  transform: translateX(0);
  visibility: visible;
}

.secondary-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid rgb(var(--sidebar-border));
}

.secondary-back {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px;
  border: none;
  background: transparent;
  color: rgb(var(--sidebar-foreground));
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
}

.secondary-back:hover {
  color: rgb(var(--sidebar-accent-foreground));
  background: rgb(var(--sidebar-accent));
}

.secondary-back[hidden] {
  visibility: hidden;
}

.secondary-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scrollbar-width: thin;
}

/* ---------------------------------------------------------------------------
   Flyout (collapsed mode)
--------------------------------------------------------------------------- */
.flyout {
  position: fixed;
  z-index: 60;
  min-width: 192px;
  max-width: 260px;
  background: rgb(var(--sidebar));
  border: 1px solid rgb(var(--sidebar-border));
  border-radius: var(--radius-lg);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.14);
  overflow: hidden;
  display: none;
}

.flyout.is-open {
  display: block;
}

.flyout-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid rgb(var(--sidebar-border));
  font-size: 13px;
  font-weight: 600;
  color: rgb(var(--sidebar-foreground));
}

.flyout-back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: rgb(var(--sidebar-foreground));
  cursor: pointer;
  transition: background 0.15s;
}

.flyout-back:hover {
  background: rgb(var(--sidebar-accent));
}

.flyout-title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.flyout-body {
  padding: 4px;
}

.flyout .menu-item {
  border-radius: var(--radius-md);
}

/* ---------------------------------------------------------------------------
   Mobile backdrop
--------------------------------------------------------------------------- */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.6);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  border: none;
  padding: 0;
}

.sidebar-backdrop.is-visible {
  opacity: 1;
  pointer-events: auto;
}

/* ---------------------------------------------------------------------------
   Collapsed mode (scoped so the mobile drawer still shows full labels)
--------------------------------------------------------------------------- */
.sidebar.collapsed:not(.is-mobile-open) .menu-label,
.sidebar.collapsed:not(.is-mobile-open) .badge,
.sidebar.collapsed:not(.is-mobile-open) .hotkey,
.sidebar.collapsed:not(.is-mobile-open) .menu-chevron,
.sidebar.collapsed:not(.is-mobile-open) .section-title,
.sidebar.collapsed:not(.is-mobile-open) .sidebar-search,
.sidebar.collapsed:not(.is-mobile-open) .sidebar-brand-subtitle,
.sidebar.collapsed:not(.is-mobile-open) .sidebar-brand-text {
  display: none;
}

.sidebar.collapsed:not(.is-mobile-open) .menu-item {
  justify-content: center;
  padding: 10px 0;
}

.sidebar.collapsed:not(.is-mobile-open) .submenu {
  display: none;
}

.sidebar.collapsed:not(.is-mobile-open) .sidebar-brand {
  justify-content: center;
  padding: 14px 0;
}

/* ---------------------------------------------------------------------------
   Breakpoints
--------------------------------------------------------------------------- */
@media (min-width: 768px) {
  .sidebar {
    position: relative;
    transform: none;
  }

  .sidebar-backdrop {
    display: none;
  }

  .show-on-mobile {
    display: none;
  }

  .hide-on-mobile {
    display: inline-flex;
  }
}

/* ============================================================================
   Demo page styles (remove these when you build your real pages)
   ========================================================================== */
.demo-card {
  background: rgb(var(--card));
  border: 1px solid rgb(var(--border));
  border-radius: var(--radius-lg);
  padding: 20px;
}

.demo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.demo-stat {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.demo-stat-label {
  font-size: 12px;
  color: rgb(var(--muted-foreground));
}

.demo-stat-value {
  font-size: 24px;
  font-weight: 700;
}

.demo-title {
  font-size: 20px;
  font-weight: 700;
  margin: 0 0 4px;
}

.demo-subtitle {
  color: rgb(var(--muted-foreground));
  margin: 0;
}

.demo-note {
  margin-top: 16px;
  padding: 12px 16px;
  border-left: 3px solid rgb(var(--primary));
  background: rgb(var(--card));
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  color: rgb(var(--muted-foreground));
  font-size: 13px;
}
