/* === CSS CUSTOM PROPERTIES === */
:root {
  /* Minimalist SaaS Palette (Slate/Zinc) */
  --primary: #18181B; /* Zinc 900 */
  --primary-hover: #27272A; /* Zinc 800 */
  
  --secondary: #3B82F6; /* Blue 500 for accents */
  --secondary-hover: #2563EB; /* Blue 600 */
  --secondary-subtle: #EFF6FF; /* Blue 50 */
  
  /* Text */
  --text-main: #0F172A; /* Slate 900 */
  --text-muted: #475569; /* Slate 600 */
  --text-light: #94A3B8; /* Slate 400 */
  --text-inverse: #FFFFFF;
  
  /* Backgrounds & Surfaces */
  --bg-main: #F8FAFC; /* Slate 50 */
  --bg-card: #FFFFFF;
  --bg-elevated: #F1F5F9; /* Slate 100 */
  
  /* Borders */
  --border-light: #E2E8F0; /* Slate 200 */
  --border-dark: #CBD5E1; /* Slate 300 */
  
  /* Status colors */
  --success: #10B981;
  --success-subtle: #ECFDF5;
  --warning: #F59E0B;
  --warning-subtle: #FFFBEB;
  --danger: #EF4444;
  --danger-subtle: #FEF2F2;
  --info: #3B82F6;
  --info-subtle: #EFF6FF;
  
  /* Subject colors - refined */
  --color-lingua-galega: #3B82F6;
  --color-lengua-castellana: #E11D48;
  --color-historia-espana: #D97706;
  --color-filosofia: #7C3AED;
  --color-ingles: #059669;
  --color-historia-arte: #CA8A04;
  --color-joyeria: #475569; /* Sleek slate for specific test */
  
  /* Spacing */
  --sidebar-width: 260px;
  --header-height: 64px;
  --gap-xs: 4px;
  --gap-sm: 8px;
  --gap-md: 16px;
  --gap-lg: 24px;
  --gap-xl: 32px;
  --gap-2xl: 48px;
  
  /* Radius */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;
  
  /* Shadows - Crisp and subtle */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.025);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.05), 0 4px 6px -4px rgba(0, 0, 0, 0.025);
  
  /* Typography */
  --font-display: 'Inter', system-ui, -apple-system, sans-serif;
  --font-body: 'Inter', system-ui, -apple-system, sans-serif;
  
  /* Transitions */
  --transition-fast: 0.15s ease-in-out;
  --transition-base: 0.2s ease-in-out;
}

/* === RESET & BASE === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-main);
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  text-decoration: none;
  color: inherit;
}

button {
  border: none;
  background: none;
  font-family: inherit;
  color: inherit;
  cursor: pointer;
}

img, svg {
  max-width: 100%;
  display: block;
}

/* === CUSTOM SCROLLBAR === */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-dark);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-light);
}

/* === TYPOGRAPHY === */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.25;
  margin-bottom: var(--gap-sm);
  color: var(--text-main);
  letter-spacing: -0.02em;
}
h1 { font-size: 2.25rem; font-weight: 700; }
h2 { font-size: 1.875rem; }
h3 { font-size: 1.5rem; }
h4 { font-size: 1.25rem; }
p { margin-bottom: var(--gap-md); }

.text-xs { font-size: 0.75rem; }
.text-sm { font-size: 0.875rem; }
.text-lg { font-size: 1.125rem; }
.text-xl { font-size: 1.25rem; }

.text-primary { color: var(--primary); }
.text-gray { color: var(--text-muted); }
.text-gray-light { color: var(--text-light); }
.text-center { text-align: center; }
.font-display { font-family: var(--font-display); }
.font-bold { font-weight: 600; }
.font-medium { font-weight: 500; }

/* === LAYOUT === */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background-color: var(--bg-card);
  border-right: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform var(--transition-base);
}

.sidebar-header {
  height: var(--header-height);
  padding: 0 var(--gap-lg);
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
  border-bottom: 1px solid var(--border-light);
}

.logo-icon {
  color: var(--primary);
}

.logo-text {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--text-main);
  letter-spacing: -0.02em;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: var(--gap-lg) 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--gap-md);
  padding: 8px var(--gap-lg);
  color: var(--text-muted);
  transition: all var(--transition-fast);
  width: 100%;
  font-weight: 500;
  margin: 0 var(--gap-sm);
  width: calc(100% - var(--gap-lg));
  border-radius: var(--radius-md);
}
.nav-item:hover {
  background-color: var(--bg-main);
  color: var(--text-main);
}
.nav-item.active {
  background-color: var(--secondary-subtle);
  color: var(--secondary);
}

.nav-group {
  display: flex;
  flex-direction: column;
}
.nav-expand {
  justify-content: space-between;
}
.nav-expand .chevron {
  transition: transform var(--transition-fast);
  margin-left: auto;
}
.nav-expand .chevron.rotated {
  transform: rotate(180deg);
}

.nav-subitems {
  display: none;
  flex-direction: column;
  padding: var(--gap-xs) 0;
}
.nav-subitems.expanded {
  display: flex;
}

.nav-subitem {
  padding: 6px var(--gap-lg) 6px 48px;
  color: var(--text-muted);
  font-size: 0.875rem;
  transition: all var(--transition-fast);
  border-radius: var(--radius-md);
  margin: 0 var(--gap-sm);
  width: calc(100% - var(--gap-lg));
}
.nav-subitem:hover {
  color: var(--text-main);
  background-color: var(--bg-main);
}
.nav-subitem.active {
  color: var(--secondary);
  font-weight: 600;
}

.sidebar-footer {
  padding: var(--gap-lg);
  border-top: 1px solid var(--border-light);
  background-color: var(--bg-main);
}

.main-wrapper {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  position: sticky;
  top: 0;
  height: var(--header-height);
  background-color: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--gap-xl);
  z-index: 50;
}

.hamburger-btn {
  display: none;
  color: var(--text-main);
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
  font-size: 0.875rem;
  color: var(--text-light);
  font-weight: 500;
}
.breadcrumb .current {
  color: var(--text-main);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--gap-md);
}

.session-timer {
  font-family: var(--font-body);
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  background: var(--bg-main);
  padding: 4px 12px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-light);
  font-weight: 500;
  font-size: 0.875rem;
}

.user-profile .avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--secondary-subtle);
  color: var(--secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.875rem;
}

/* === BUTTONS === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--gap-sm);
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-weight: 500;
  font-size: 0.875rem;
  transition: all var(--transition-fast);
  cursor: pointer;
  border: 1px solid transparent;
}
.btn-primary {
  background-color: var(--primary);
  color: var(--text-inverse);
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover {
  background-color: var(--primary-hover);
}
.btn-secondary {
  background-color: var(--bg-card);
  border: 1px solid var(--border-dark);
  color: var(--text-main);
  box-shadow: var(--shadow-sm);
}
.btn-secondary:hover {
  background-color: var(--bg-main);
}
.btn-ghost {
  color: var(--text-muted);
}
.btn-ghost:hover {
  background-color: var(--bg-main);
  color: var(--text-main);
}
.btn-danger {
  background-color: var(--danger);
  color: white;
}
.btn-danger:hover {
  background-color: #DC2626; /* Red 600 */
}

/* === FORMS === */
input, textarea, select {
  width: 100%;
  background-color: var(--bg-card);
  border: 1px solid var(--border-dark);
  color: var(--text-main);
  padding: 10px var(--gap-md);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.875rem;
  transition: all var(--transition-fast);
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--secondary);
  box-shadow: 0 0 0 3px var(--secondary-subtle);
}

/* === UTILITIES === */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--gap-lg); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--gap-lg); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--gap-lg); }
.auto-responsive { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: var(--gap-lg); }

.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-align-center { display: flex; align-items: center; }

.gap-xs { gap: var(--gap-xs); }
.gap-sm { gap: var(--gap-sm); }
.gap-md { gap: var(--gap-md); }
.gap-lg { gap: var(--gap-lg); }

.p-sm { padding: var(--gap-sm); }
.p-md { padding: var(--gap-md); }
.p-lg { padding: var(--gap-lg); }
.p-xl { padding: var(--gap-xl); }

.m-0 { margin: 0; }
.mb-xs { margin-bottom: var(--gap-xs); }
.mb-sm { margin-bottom: var(--gap-sm); }
.mb-md { margin-bottom: var(--gap-md); }
.mb-lg { margin-bottom: var(--gap-lg); }
.mb-xl { margin-bottom: var(--gap-xl); }
.mt-sm { margin-top: var(--gap-sm); }
.mt-md { margin-top: var(--gap-md); }

.w-full { width: 100%; }
.h-full { height: 100%; }

.hidden { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* Mobile topic sidebar toggle — hidden on desktop */
.mobile-topic-toggle-btn,
.close-mobile-sidebar-btn {
  display: none;
}

/* Sidebar Overlay for Mobile */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  z-index: 99;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-base);
}
.sidebar-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

/* === RESPONSIVE === */
@media (min-width: 769px) {
  .md\:hidden { display: none !important; }
}

@media (max-width: 1024px) {
  /* On tablets landscape, tone down the 4 and 3 column grids to 2 */
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    z-index: 100;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }
  .main-wrapper {
    margin-left: 0;
  }
  .hamburger-btn {
    display: flex;
  }
  .header {
    padding: 0 var(--gap-md);
  }
  
  /* Mobile Subject & Topic View Responsiveness */
  .mobile-topic-toggle-btn,
  .close-mobile-sidebar-btn {
    display: inline-flex !important;
  }
  .topic-sidebar {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 85% !important;
    max-width: 320px;
    z-index: 90;
    transform: translateX(-100%);
    transition: transform var(--transition-base);
    box-shadow: var(--shadow-lg);
  }
  .topic-sidebar.mobile-active {
    transform: translateX(0);
  }
  .topic-content {
    padding: var(--gap-md) !important;
  }
  .flex-grow-mobile {
    flex: 1 1 100%;
    justify-content: center;
  }
}

@media (max-width: 600px) {
  /* For mobile phones, force 1 column */
  .grid-2, .grid-3, .grid-4 {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  h1 { font-size: 1.6rem; }
  h2 { font-size: 1.35rem; }
  h3 { font-size: 1.15rem; }
  .p-lg, .p-xl { padding: var(--gap-md) !important; }
}

/* Markdown Content Styling */
.markdown-body {
  word-break: break-word;
  overflow-wrap: break-word;
}
.markdown-body table {
  display: block;
  width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  margin: var(--gap-md) 0;
}
.markdown-body table th, .markdown-body table td {
  padding: 8px 12px;
  border: 1px solid var(--border-light);
}
.markdown-body table th {
  background: var(--bg-elevated);
  font-weight: 600;
}
.markdown-body pre {
  max-width: 100%;
  overflow-x: auto;
  background: var(--bg-elevated);
  padding: var(--gap-md);
  border-radius: var(--radius-md);
}
.markdown-body img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-md);
}
.markdown-body blockquote {
  border-left: 4px solid var(--primary);
  margin: var(--gap-md) 0;
  padding: var(--gap-sm) var(--gap-md);
  background: var(--bg-elevated);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
