/* =========================================================
   INDIAGRAM - Sidebar + Bento + Theme System
   Brand palette from company presentation:
     Cream #FEF6F0  |  Black #231F20  |  Orange #FB5F14
     Yellow #FBD73D  |  Muted #BFBFBF  |  Font: Sora
   ========================================================= */

/* ---------- 0. Sora font import ---------- */
@import url('https://fonts.googleapis.com/css2?family=Sora:wght@300;400;500;600;700;800&display=swap');

/* ---------- 0b. Flash prevention (applied before paint) ---------- */
:root {
  color-scheme: light dark;
}

/* ---------- 1. Design Tokens — Light Theme (cream/warm default) ---------- */
:root,
[data-theme="light"] {
  /* Surfaces — warm cream palette from presentation */
  --ig-bg:        #FEF6F0;      /* cream background */
  --ig-surface:   #FFFFFF;      /* pure white cards */
  --ig-surface2:  #FDF0E6;      /* tinted cream for inset areas */
  --ig-surface3:  #FAE8D8;      /* deeper warm tint */
  --ig-border:    #F0DDD0;      /* warm border */
  --ig-border2:   #E5C9B5;      /* stronger warm border */

  /* Brand colours */
  --ig-brand:     #FB5F14;      /* burnt orange - primary */
  --ig-brand2:    #FBD73D;      /* golden yellow - accent */
  --ig-green:     #046A38;      /* India green (kept functional) */
  --ig-teal:      #FB5F14;      /* maps to orange in this palette */
  --ig-red:       #C0392B;
  --ig-yellow:    #FBD73D;      /* presentation yellow */

  /* Typography */
  --ig-ink:       #231F20;      /* rich black from presentation */
  --ig-ink2:      #3D3838;      /* slightly lighter black */
  --ig-muted:     #7A6F6F;      /* warm mid-grey */
  --ig-muted2:    #BFBFBF;      /* presentation muted grey */

  --ig-shadow:    0 1px 3px rgba(35,31,32,0.07), 0 4px 16px rgba(35,31,32,0.05);
  --ig-shadow-lg: 0 4px 24px rgba(35,31,32,0.11), 0 1px 4px rgba(35,31,32,0.05);
  --ig-glow:      0 0 0 2px rgba(251,95,20,0.18);

  --ig-sidebar-w:       240px;
  --ig-sidebar-w-rail:  64px;
  --ig-topbar-h:        52px;
}

/* ---------- 2. Design Tokens — Dark Theme ---------- */
[data-theme="dark"] {
  /* Dark: keep rich black from presentation, cream becomes a dark tint */
  --ig-bg:        #1A1618;      /* near-black warm dark */
  --ig-surface:   #231F20;      /* presentation rich black */
  --ig-surface2:  #2C2728;      /* slightly lighter */
  --ig-surface3:  #352F30;
  --ig-border:    #3D3535;
  --ig-border2:   #4F4444;

  /* Brand colours stay the same in dark */
  --ig-brand:     #FB5F14;
  --ig-brand2:    #FBD73D;
  --ig-green:     #138808;
  --ig-teal:      #FBD73D;      /* yellow in dark for visibility */
  --ig-red:       #E63946;
  --ig-yellow:    #FBD73D;

  /* Typography on dark */
  --ig-ink:       #FEF6F0;      /* cream becomes text colour on dark */
  --ig-ink2:      #EBE0D8;
  --ig-muted:     #B8A99E;
  --ig-muted2:    #7A6F6F;

  --ig-shadow:    0 1px 3px rgba(0,0,0,0.45), 0 4px 16px rgba(0,0,0,0.35);
  --ig-shadow-lg: 0 4px 24px rgba(0,0,0,0.55), 0 1px 4px rgba(0,0,0,0.35);
  --ig-glow:      0 0 0 2px rgba(251,95,20,0.28);
}

/* ---------- 3. Base reset ---------- */
*, *::before, *::after { box-sizing: border-box; }

/* ---------- 4. Layout shell ---------- */
body.ig-layout {
  margin: 0;
  padding: 0;
  background: var(--ig-bg);
  color: var(--ig-ink);
  font-family: 'Sora', sans-serif;
  transition: background 0.25s, color 0.25s;
  overflow-x: hidden;
}

/* On desktop the body shifts right to make room for sidebar */
body.ig-layout {
  padding-left: var(--ig-sidebar-w);
  padding-top: 0;
  transition: padding-left 0.3s cubic-bezier(0.4,0,0.2,1), background 0.25s, color 0.25s;
}
body.ig-layout.sidebar-collapsed {
  padding-left: var(--ig-sidebar-w-rail);
}
@media (max-width: 768px) {
  body.ig-layout,
  body.ig-layout.sidebar-collapsed {
    padding-left: 0;
    padding-top: var(--ig-topbar-h);
  }
}

/* ---------- 5. Mobile top bar ---------- */
#ig-topbar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--ig-topbar-h);
  z-index: 900;
  background: var(--ig-surface);
  border-bottom: 1px solid var(--ig-border);
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 12px;
  box-shadow: var(--ig-shadow);
}
@media (max-width: 768px) {
  #ig-topbar { display: flex; }
}
.ig-topbar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--ig-ink);
  font-family: 'Sora', sans-serif;
  font-weight: 700;
  font-size: 16px;
}
.ig-topbar-logo img {
  width: 28px;
  height: 28px;
  border-radius: 8px;
}
.ig-topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
#ig-hamburger {
  background: none;
  border: none;
  color: var(--ig-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  transition: background 0.15s, color 0.15s;
}
#ig-hamburger:hover { background: var(--ig-surface2); color: var(--ig-ink); }

/* ---------- 6. Sidebar ---------- */
#ig-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--ig-sidebar-w);
  height: 100vh;
  z-index: 800;
  background: var(--ig-surface);
  border-right: 1px solid var(--ig-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.3s cubic-bezier(0.4,0,0.2,1),
              transform 0.3s cubic-bezier(0.4,0,0.2,1),
              box-shadow 0.3s;
  box-shadow: var(--ig-shadow);
}
#ig-sidebar.collapsed {
  width: var(--ig-sidebar-w-rail);
}
/* Mobile: sidebar is a drawer, slides in from left */
@media (max-width: 768px) {
  #ig-sidebar {
    top: 0;
    transform: translateX(-100%);
    width: var(--ig-sidebar-w) !important;
    box-shadow: none;
    z-index: 1000;
  }
  #ig-sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: 4px 0 32px rgba(0,0,0,0.25);
  }
}

/* ---------- 7. Sidebar header ---------- */
.ig-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 58px;
  border-bottom: 1px solid var(--ig-border);
  flex-shrink: 0;
  gap: 8px;
}
.ig-sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--ig-ink);
  overflow: hidden;
  flex: 1;
  min-width: 0;
}
.ig-sidebar-logo img.ig-logo-icon {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  flex-shrink: 0;
}
.ig-sidebar-logo .ig-logo-text {
  font-family: 'Sora', sans-serif;
  font-weight: 700;
  font-size: 15px;
  color: var(--ig-ink);
  white-space: nowrap;
  overflow: hidden;
  opacity: 1;
  transition: opacity 0.2s, max-width 0.3s;
  max-width: 160px;
}
#ig-sidebar.collapsed .ig-logo-text {
  opacity: 0;
  max-width: 0;
}
.ig-sidebar-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
#ig-sidebar.collapsed .ig-sidebar-header-actions .ig-theme-toggle-label {
  display: none;
}

/* ---------- 8. Sidebar collapse toggle button ---------- */
#ig-sidebar-toggle {
  background: none;
  border: 1px solid var(--ig-border);
  color: var(--ig-muted);
  cursor: pointer;
  padding: 5px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
#ig-sidebar-toggle:hover {
  background: var(--ig-surface2);
  color: var(--ig-brand);
  border-color: var(--ig-brand);
}
#ig-sidebar.collapsed #ig-sidebar-toggle svg.icon-collapse {
  display: none;
}
#ig-sidebar:not(.collapsed) #ig-sidebar-toggle svg.icon-expand {
  display: none;
}

/* ---------- 9. Theme toggle button ---------- */
.ig-theme-toggle {
  background: none;
  border: 1px solid var(--ig-border);
  color: var(--ig-muted);
  cursor: pointer;
  padding: 5px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
.ig-theme-toggle:hover {
  background: var(--ig-surface2);
  color: var(--ig-brand);
  border-color: var(--ig-brand);
}
[data-theme="dark"] .ig-icon-sun { display: block; }
[data-theme="dark"] .ig-icon-moon { display: none; }
[data-theme="light"] .ig-icon-sun { display: none; }
[data-theme="light"] .ig-icon-moon { display: block; }

/* ---------- 10. Sidebar scroll area ---------- */
.ig-sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 0 16px;
  scrollbar-width: thin;
  scrollbar-color: var(--ig-border2) transparent;
}
.ig-sidebar-scroll::-webkit-scrollbar { width: 3px; }
.ig-sidebar-scroll::-webkit-scrollbar-thumb { background: var(--ig-border2); border-radius: 2px; }

/* ---------- 11. Nav groups & items ---------- */
.ig-nav-group {
  margin-bottom: 2px;
}
.ig-nav-group-btn {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 8px 14px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--ig-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-family: 'JetBrains Mono', monospace;
  gap: 8px;
  text-align: left;
  transition: color 0.15s;
  min-height: 32px;
  border-radius: 0;
  white-space: nowrap;
  overflow: hidden;
}
.ig-nav-group-btn:hover { color: var(--ig-ink2); }
.ig-nav-group-btn .ig-nav-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}
.ig-nav-group-label {
  flex: 1;
  opacity: 1;
  transition: opacity 0.2s;
  overflow: hidden;
  white-space: nowrap;
}
.ig-nav-group-chevron {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
  transition: transform 0.2s;
  opacity: 0.5;
}
.ig-nav-group.open .ig-nav-group-chevron {
  transform: rotate(180deg);
}
#ig-sidebar.collapsed .ig-nav-group-label,
#ig-sidebar.collapsed .ig-nav-group-chevron {
  opacity: 0;
  width: 0;
  overflow: hidden;
  transition: opacity 0.15s, width 0.3s;
}

/* Group items list */
.ig-nav-items {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.3s cubic-bezier(0.4,0,0.2,1);
}
.ig-nav-group.open .ig-nav-items {
  max-height: 2000px;
}
#ig-sidebar.collapsed .ig-nav-items {
  max-height: 0;
}

/* Individual nav item */
.ig-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 14px 7px 36px;
  text-decoration: none;
  color: var(--ig-ink2);
  font-size: 13px;
  font-weight: 500;
  border-left: 2px solid transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
  overflow: hidden;
  min-height: 36px;
  border-radius: 0 8px 8px 0;
  margin-right: 8px;
}
.ig-nav-item:hover {
  background: var(--ig-surface2);
  color: var(--ig-brand);
}
.ig-nav-item.active {
  background: rgba(255,103,31,0.08);
  color: var(--ig-brand);
  border-left-color: var(--ig-brand);
  font-weight: 600;
}
.ig-nav-item .ig-nav-item-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  opacity: 0.7;
}
.ig-nav-item.active .ig-nav-item-icon { opacity: 1; }
.ig-nav-item .ig-nav-item-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: opacity 0.15s;
}
.ig-nav-item .ig-nav-item-badge {
  font-size: 9px;
  font-family: 'JetBrains Mono', monospace;
  padding: 1px 6px;
  border-radius: 4px;
  font-weight: 600;
  flex-shrink: 0;
}
.ig-badge-live { background: rgba(220,38,38,0.12); color: #EF4444; border: 1px solid rgba(220,38,38,0.2); }
.ig-badge-new  { background: rgba(255,103,31,0.1); color: var(--ig-brand); border: 1px solid rgba(255,103,31,0.2); }
.ig-badge-ai   { background: rgba(8,145,178,0.1); color: var(--ig-teal); border: 1px solid rgba(8,145,178,0.2); }

/* Top-level direct nav item (no group) */
.ig-nav-direct {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  text-decoration: none;
  color: var(--ig-ink2);
  font-size: 13px;
  font-weight: 500;
  border-left: 2px solid transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
  overflow: hidden;
  min-height: 40px;
  border-radius: 0 8px 8px 0;
  margin-right: 8px;
}
.ig-nav-direct:hover {
  background: var(--ig-surface2);
  color: var(--ig-brand);
}
.ig-nav-direct.active {
  background: rgba(255,103,31,0.08);
  color: var(--ig-brand);
  border-left-color: var(--ig-brand);
  font-weight: 600;
}
.ig-nav-direct .ig-nav-icon { width: 16px; height: 16px; flex-shrink: 0; }
.ig-nav-direct .ig-nav-direct-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 1;
  transition: opacity 0.2s;
}
#ig-sidebar.collapsed .ig-nav-direct-label {
  opacity: 0;
  width: 0;
}

/* Divider */
.ig-nav-divider {
  height: 1px;
  background: var(--ig-border);
  margin: 8px 14px;
}

/* Section label when collapsed: show just icons, no labels */
#ig-sidebar.collapsed .ig-nav-group-btn { justify-content: center; padding: 8px; }
#ig-sidebar.collapsed .ig-nav-direct { justify-content: center; padding: 8px; }

/* ---------- 12. Mobile overlay ---------- */
#ig-sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(7,12,24,0.6);
  backdrop-filter: blur(2px);
  z-index: 999;
}
#ig-sidebar-overlay.visible { display: block; }

/* ---------- 13. Bento grid & cards ---------- */
.bento-grid {
  display: grid;
  gap: 16px;
  padding: 20px;
}
.bento-grid-2 { grid-template-columns: repeat(2, 1fr); }
.bento-grid-3 { grid-template-columns: repeat(3, 1fr); }
.bento-grid-4 { grid-template-columns: repeat(4, 1fr); }
.bento-grid-12 { grid-template-columns: repeat(12, 1fr); }

@media (max-width: 1024px) {
  .bento-grid-3 { grid-template-columns: repeat(2, 1fr); }
  .bento-grid-4 { grid-template-columns: repeat(2, 1fr); }
  .bento-grid-12 { grid-template-columns: repeat(6, 1fr); }
}
@media (max-width: 640px) {
  .bento-grid-2, .bento-grid-3, .bento-grid-4, .bento-grid-12 {
    grid-template-columns: 1fr;
  }
}

.bento-card {
  background: var(--ig-surface);
  border: 1px solid var(--ig-border);
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--ig-shadow);
  transition: box-shadow 0.2s, border-color 0.2s, transform 0.2s;
  position: relative;
  overflow: hidden;
}
.bento-card:hover {
  box-shadow: var(--ig-shadow-lg);
  border-color: var(--ig-border2);
  transform: translateY(-1px);
}
.bento-card.bento-link {
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  display: block;
}
.bento-card.bento-link:hover { border-color: rgba(255,103,31,0.35); }
.bento-card.bento-sm { padding: 14px 16px; border-radius: 12px; }
.bento-card.bento-flush { padding: 0; overflow: hidden; }

/* Col/row spans for bento */
.col-span-1 { grid-column: span 1; }
.col-span-2 { grid-column: span 2; }
.col-span-3 { grid-column: span 3; }
.col-span-4 { grid-column: span 4; }
.col-span-6 { grid-column: span 6; }
.col-span-8 { grid-column: span 8; }
.col-span-12{ grid-column: span 12; }
.row-span-2 { grid-row: span 2; }
@media (max-width: 768px) {
  .col-span-2, .col-span-3, .col-span-4,
  .col-span-6, .col-span-8, .col-span-12 { grid-column: span 1; }
}

/* ---------- 14. Content wrapper ---------- */
#ig-content {
  min-height: 100vh;
}

/* ---------- 15. Page header strip (inside content) ---------- */
.ig-page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 0;
  gap: 12px;
  flex-wrap: wrap;
}
.ig-page-title {
  font-family: 'Sora', sans-serif;
  font-size: 20px;
  font-weight: 700;
  color: var(--ig-ink);
  margin: 0;
}
.ig-page-subtitle {
  font-size: 13px;
  color: var(--ig-muted);
  margin: 2px 0 0;
}

/* ---------- 16. Live ticker (inside content) ---------- */
.ig-ticker-bar {
  background: var(--ig-surface2);
  border-bottom: 1px solid var(--ig-border);
  overflow: hidden;
  height: 32px;
  display: flex;
  align-items: center;
}
.ig-ticker-label {
  flex-shrink: 0;
  background: var(--ig-brand);
  color: #fff;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.1em;
  padding: 0 10px;
  height: 100%;
  display: flex;
  align-items: center;
  z-index: 1;
}
.ig-ticker-track {
  display: flex;
  white-space: nowrap;
  animation: ig-ticker 36s linear infinite;
  font-size: 11px;
  color: var(--ig-muted);
  gap: 32px;
  padding: 0 16px;
}
.ig-ticker-track:hover { animation-play-state: paused; }
@keyframes ig-ticker {
  0%   { transform: translateX(0); }
  100% { transform: translateX(-50%); }
}

/* ---------- 17. Stat/KPI chip ---------- */
.ig-stat-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--ig-muted);
  padding: 4px 10px;
  background: var(--ig-surface2);
  border: 1px solid var(--ig-border);
  border-radius: 20px;
}
.ig-stat-chip strong { color: var(--ig-ink2); }

/* ---------- 18. Focus ring for accessibility ---------- */
:focus-visible {
  outline: 2px solid var(--ig-brand);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- 19. Smooth color transitions ---------- */
.bento-card, #ig-sidebar, #ig-topbar, body.ig-layout {
  transition-property: background, color, border-color, box-shadow;
  transition-duration: 0.25s;
}

/* ---------- 20. Scrollbar theming ---------- */
[data-theme="dark"] {
  scrollbar-color: #4F4444 #1A1618;
}
/* ---------- 21. Hide old top navbars (superseded by sidebar) ---------- */
/* About page and other pages have a fixed <nav> element or #indiagram-nav
   injected by indiagram-components.js. The sidebar replaces these. */
body.ig-layout #indiagram-nav { display: none !important; }
/* Hide all legacy top navs once sidebar is active */
body.ig-layout > nav { display: none !important; }
body.ig-layout header:not(#ig-topbar) { display: none !important; }
/* Give hero/content sections breathing room now that top nav is gone */
body.ig-layout .hero { padding-top: 40px !important; }
/* Fix body padding-top that was set for old sticky header */
body.ig-layout { padding-top: 0 !important; }
@media (max-width: 768px) {
  body.ig-layout { padding-top: var(--ig-topbar-h) !important; }
}
/* Adjust old page wrapper padding */
body.ig-layout main.content,
body.ig-layout .page-content,
body.ig-layout section:first-child {
  padding-top: 0;
}

/* ---------- 22. Bento card theme color fix for dark mode ---------- */
[data-theme="dark"] .bento-card {
  background: var(--ig-surface);
  border-color: var(--ig-border);
}

/* ---------- 23. Focus ring accessibility ---------- */
.ig-nav-item:focus-visible,
.ig-nav-direct:focus-visible,
.ig-nav-group-btn:focus-visible {
  outline: 2px solid var(--ig-brand);
  outline-offset: -2px;
}

[data-theme="light"] {
  scrollbar-color: #E5C9B5 #FEF6F0;
}
