/**
 * ============================================
 * DESKTOP SIDEBAR - macOS App Style
 * ============================================
 * Replicates the Flutter app sidebar navigation
 * WCAG 2.2 AAA Compliant
 */

/* ============================================
   SIDEBAR CONTAINER
   ============================================ */
.desktop-sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: 220px;
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg, #f8fafc);
  border-right: 1px solid var(--border-color, #e5e7eb);
  z-index: 100;
  overflow-y: auto;
  overflow-x: hidden;
  /* Hide on mobile by default */
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Show on desktop screens */
@media (min-width: 1024px) {
  .desktop-sidebar {
    transform: translateX(0);
  }

  /* Shift main content when sidebar is visible */
  body.has-sidebar main#main-content {
    margin-left: 220px;
  }

  body.has-sidebar .container,
  body.has-sidebar main > .container {
    max-width: calc(100% - 220px);
    margin-left: 0;
    margin-right: auto;
  }

  /* Content wrapper for markdown files */
  body.has-sidebar .content-wrapper {
    max-width: 900px;
    margin: 0 auto;
    padding: 1rem 2rem;
  }

  body.has-sidebar .mobile-bottom-nav {
    display: none !important;
  }

  /* Footer also needs offset */
  body.has-sidebar footer {
    margin-left: 220px;
  }
}

/* ============================================
   BRANDING
   ============================================ */
.sidebar-branding {
  padding: 16px 12px;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
}

.sidebar-logo {
  display: block;
  text-decoration: none;
}

.sidebar-logo:hover {
  text-decoration: none;
}

.sidebar-logo-img {
  width: 100%;
  max-width: 180px;
  height: auto;
  display: block;
  margin: 0 auto;
  transition: opacity 0.2s ease;
}

.sidebar-logo:hover .sidebar-logo-img {
  opacity: 0.85;
}

/* Dark mode: Adjust logo visibility if needed */
@media (prefers-color-scheme: dark) {
  .sidebar-logo-img {
    filter: brightness(1.1);
  }
}

body[data-theme="dark"] .sidebar-logo-img {
  filter: brightness(1.1);
}

/* ============================================
   NAVIGATION
   ============================================ */
.sidebar-nav {
  flex: 1;
  padding: 12px;
  overflow-y: auto;
}

.sidebar-nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.sidebar-nav-list li {
  margin-bottom: 4px;
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-primary, #111827);
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: left;
  font-family: inherit;
  font-size: inherit;
}

.sidebar-nav-item:hover {
  background: rgba(0, 0, 0, 0.05);
}

.sidebar-nav-item:focus-visible {
  outline: 2px solid var(--color-primary, #00ACC1);
  outline-offset: -2px;
}

.sidebar-nav-item.active {
  background: rgba(0, 172, 193, 0.1);
  border: 1px solid rgba(0, 172, 193, 0.3);
}

.sidebar-nav-item.active .sidebar-nav-label {
  color: var(--color-primary, #00ACC1);
  font-weight: 600;
}

/* Icons */
.sidebar-nav-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: var(--text-secondary, #6b7280);
}

.sidebar-nav-item.active .sidebar-nav-icon {
  color: var(--color-primary, #00ACC1);
}

.sidebar-nav-icon .icon-active {
  display: none;
}

.sidebar-nav-item.active .sidebar-nav-icon .icon-default {
  display: none;
}

.sidebar-nav-item.active .sidebar-nav-icon .icon-active {
  display: block;
}

/* Content */
.sidebar-nav-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.sidebar-nav-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary, #111827);
  line-height: 1.3;
}

.sidebar-nav-subtitle {
  font-size: 11px;
  color: var(--text-muted, #9ca3af);
  line-height: 1.3;
}

/* Badge */
.sidebar-nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 600;
  color: white;
  background: var(--color-primary, #00ACC1);
  border-radius: 10px;
}

.sidebar-nav-badge[hidden] {
  display: none;
}

/* Accent Button (Install App) */
.sidebar-nav-item-accent {
  color: var(--color-primary, #00ACC1);
}

.sidebar-nav-item-accent .sidebar-nav-icon {
  color: var(--color-primary, #00ACC1);
}

.sidebar-nav-item-accent:hover {
  background: rgba(0, 172, 193, 0.1);
}

/* Danger Button (Clear Data) */
.sidebar-nav-item-danger {
  color: #dc2626;
}

.sidebar-nav-item-danger .sidebar-nav-icon {
  color: #dc2626;
}

.sidebar-nav-item-danger:hover {
  background: rgba(220, 38, 38, 0.1);
}

/* ============================================
   SECTION DIVIDERS
   ============================================ */
.sidebar-section-divider {
  padding: 24px 12px 8px;
}

.sidebar-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted, #9ca3af);
}

/* ============================================
   KEYBOARD SHORTCUTS
   ============================================ */
.sidebar-shortcuts {
  margin: 12px;
  padding: 12px;
  background: rgba(0, 0, 0, 0.03);
  border-radius: 8px;
}

.sidebar-shortcuts-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary, #6b7280);
  margin-bottom: 8px;
}

.sidebar-shortcut {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.sidebar-shortcut:last-child {
  margin-bottom: 0;
}

.sidebar-shortcut-label {
  font-size: 11px;
  color: var(--text-muted, #9ca3af);
}

.sidebar-shortcut-key {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px 6px;
  font-size: 10px;
  font-weight: 500;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  color: var(--text-secondary, #6b7280);
  background: rgba(0, 0, 0, 0.08);
  border-radius: 4px;
  border: none;
}

/* Keyboard shortcut styling (dynamic based on OS) */
.kbd-symbol {
  font-family: -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  font-size: 11px;
}

.kbd-text {
  font-size: 9px;
  text-transform: uppercase;
}

.kbd-key {
  font-size: 10px;
  font-weight: 600;
}

.kbd-plus {
  opacity: 0.5;
  font-size: 9px;
  margin: 0 1px;
}

.sidebar-shortcut.has-conflict .sidebar-shortcut-key {
  opacity: 0.6;
  text-decoration: line-through;
}

.sidebar-shortcuts-note {
  display: none;
  font-size: 9px;
  color: var(--text-muted, #9ca3af);
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(0, 0, 0, 0.05);
  line-height: 1.4;
}

/* ============================================
   THEME TOGGLE
   ============================================ */
#sidebar-theme-toggle .icon-dark {
  display: none;
}

body[data-theme="dark"] #sidebar-theme-toggle .icon-light {
  display: none;
}

body[data-theme="dark"] #sidebar-theme-toggle .icon-dark {
  display: block;
}

@media (prefers-color-scheme: dark) {
  body:not([data-theme="light"]) #sidebar-theme-toggle .icon-light {
    display: none;
  }

  body:not([data-theme="light"]) #sidebar-theme-toggle .icon-dark {
    display: block;
  }
}

/* ============================================
   DARK MODE
   ============================================ */
@media (prefers-color-scheme: dark) {
  .desktop-sidebar {
    --sidebar-bg: #1a1a2e;
    background: var(--sidebar-bg);
    border-color: var(--dark-border, #30363d);
  }

  .sidebar-branding {
    border-color: var(--dark-border, #30363d);
  }

  .sidebar-logo-title {
    color: var(--dark-text, #e8eef5);
  }

  .sidebar-logo-subtitle {
    color: var(--dark-text-secondary, #8b949e);
  }

  .sidebar-nav-item:hover {
    background: rgba(255, 255, 255, 0.05);
  }

  .sidebar-nav-item.active {
    background: rgba(0, 172, 193, 0.15);
    border-color: rgba(0, 172, 193, 0.3);
  }

  .sidebar-nav-label {
    color: var(--dark-text, #e8eef5);
  }

  .sidebar-nav-icon {
    color: var(--dark-text-secondary, #8b949e);
  }

  .sidebar-nav-subtitle,
  .sidebar-section-title,
  .sidebar-shortcut-label {
    color: var(--dark-text-muted, #6e7681);
  }

  .sidebar-shortcuts {
    background: rgba(255, 255, 255, 0.05);
  }

  .sidebar-shortcut-key {
    background: rgba(255, 255, 255, 0.1);
    color: var(--dark-text-secondary, #8b949e);
  }
}

body[data-theme="dark"] .desktop-sidebar {
  --sidebar-bg: #1a1a2e;
  background: var(--sidebar-bg);
  border-color: var(--dark-border, #30363d);
}

body[data-theme="dark"] .sidebar-branding {
  border-color: var(--dark-border, #30363d);
}

body[data-theme="dark"] .sidebar-logo-title {
  color: var(--dark-text, #e8eef5);
}

body[data-theme="dark"] .sidebar-logo-subtitle {
  color: var(--dark-text-secondary, #8b949e);
}

body[data-theme="dark"] .sidebar-nav-item:hover {
  background: rgba(255, 255, 255, 0.05);
}

body[data-theme="dark"] .sidebar-nav-item.active {
  background: rgba(0, 172, 193, 0.15);
  border-color: rgba(0, 172, 193, 0.3);
}

body[data-theme="dark"] .sidebar-nav-label {
  color: var(--dark-text, #e8eef5);
}

body[data-theme="dark"] .sidebar-nav-icon {
  color: var(--dark-text-secondary, #8b949e);
}

body[data-theme="dark"] .sidebar-nav-subtitle,
body[data-theme="dark"] .sidebar-section-title,
body[data-theme="dark"] .sidebar-shortcut-label {
  color: var(--dark-text-muted, #6e7681);
}

body[data-theme="dark"] .sidebar-shortcuts {
  background: rgba(255, 255, 255, 0.05);
}

body[data-theme="dark"] .sidebar-shortcut-key {
  background: rgba(255, 255, 255, 0.1);
  color: var(--dark-text-secondary, #8b949e);
}

/* ============================================
   REDUCED MOTION
   ============================================ */
@media (prefers-reduced-motion: reduce) {
  .desktop-sidebar,
  .sidebar-nav-item {
    transition: none;
  }
}

/* ============================================
   HIGH CONTRAST MODE
   ============================================ */
@media (forced-colors: active) {
  .sidebar-nav-item.active {
    border: 2px solid currentColor;
  }

  .sidebar-nav-badge {
    border: 1px solid currentColor;
  }
}

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {
  .desktop-sidebar {
    display: none !important;
  }

  body.has-sidebar .container,
  body.has-sidebar main > .container {
    margin-left: 0;
    max-width: 100%;
  }
}
