/* LearnFlow AI - Enhanced Component Layer */
@reference "tailwindcss";

/* =================
   Button Components
   ================= */

.btn-base {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-xs);
  font-weight: 500;
  transition: all var(--duration-fast) var(--easing);
  outline: none;
}

.btn-base:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.btn-base:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-sm {
  height: 1.75rem;
  padding: 0 0.75rem;
  font-size: 0.875rem;
}

.btn-md {
  height: 2.25rem;
  padding: 0 1rem;
  font-size: 0.875rem;
}

.btn-lg {
  height: 2.75rem;
  padding: 0 1.25rem;
  font-size: 1rem;
}

.btn-primary {
  background: var(--color-primary);
  color: var(--color-primary-ink);
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.1);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow: none;
}

.btn-secondary {
  background: var(--color-elev);
  color: var(--color-ink);
  border: 1px solid var(--color-border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-overlay-light);
}

.btn-secondary:active:not(:disabled) {
  transform: translateY(1px);
}

.btn-ghost {
  background: transparent;
  color: var(--color-ink);
}

.btn-ghost:hover:not(:disabled) {
  background: color-mix(in srgb, var(--color-elev) 60%, transparent);
}

.btn-ghost:active:not(:disabled) {
  background: color-mix(in srgb, var(--color-elev) 80%, transparent);
}

.btn-danger {
  background: var(--color-danger);
  color: white;
  box-shadow: var(--shadow-sm);
}

.btn-danger:hover:not(:disabled) {
  filter: brightness(1.1);
}

.btn-danger:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow: none;
}

/* =================
   Sidebar Components
   ================= */

.sidebar-section {
  margin-bottom: 1.5rem;
}

.sidebar-section-header {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.75rem 1rem;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  color: var(--color-ink);
  border-radius: 0.25rem;
  margin: 0 0.5rem;
  transition: all var(--duration-normal) ease;
  cursor: pointer;
}

.sidebar-item:hover {
  background: var(--bg-overlay-light);
}

.sidebar-item.active,
.sidebar-item-active {
  background: color-mix(in srgb, var(--color-primary) 12%, transparent);
  color: var(--color-primary);
  border-left: 2px solid var(--color-primary);
  margin-left: 0.5rem;
  padding-left: 0.5rem;
}

.sidebar-item-icon {
  width: 1rem;
  height: 1rem;
  opacity: 0.75;
}

.sidebar-item-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-item-meta {
  font-size: 0.75rem;
  color: var(--color-muted);
}

/* =================
   Chip System
   ================= */

.chip-base {
  display: inline-flex;
  align-items: center;
  height: 1.5rem;
  padding: 0 0.5rem;
  border-radius: 0.25rem;
  font-size: 0.75rem;
  font-weight: 500;
  transition: colors 0.15s ease;
}

.chip-default {
  background: var(--color-elev);
  color: var(--color-ink);
  border: 1px solid var(--color-border);
}

.chip-info {
  background: color-mix(in srgb, var(--color-info) 12%, transparent);
  color: var(--color-info);
}

.chip-success {
  background: color-mix(in srgb, var(--color-success) 12%, transparent);
  color: var(--color-success);
}

.chip-warn {
  background: color-mix(in srgb, var(--color-warn) 12%, transparent);
  color: var(--color-warn);
}

.chip-danger {
  background: color-mix(in srgb, var(--color-danger) 12%, transparent);
  color: var(--color-danger);
}

.chip-primary {
  background: color-mix(in srgb, var(--color-primary) 12%, transparent);
  color: var(--color-primary);
}

/* =================
   Layout Utilities
   ================= */

.content-container {
  max-width: var(--content-width-default);
  margin-left: auto;
  margin-right: auto;
  padding-left: 1rem;
  padding-right: 1rem;
}

@media (min-width: 768px) {
  .content-container {
    padding-left: 2.5rem;
    padding-right: 2.5rem;
  }
}

.content-narrow {
  max-width: var(--content-width-narrow);
  margin-left: auto;
  margin-right: auto;
  padding-left: 1rem;
  padding-right: 1rem;
}

@media (min-width: 768px) {
  .content-narrow {
    padding-left: 2rem;
    padding-right: 2rem;
  }
}

.sidebar-container {
  width: var(--sidebar-width);
  flex-shrink: 0;
  position: relative;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  border-right: 1px solid color-mix(in srgb, var(--color-border) 60%, transparent);
  background: color-mix(in srgb, var(--color-elev) 50%, transparent);
  transition: background-color var(--duration-normal) var(--easing),
              border-color var(--duration-normal) var(--easing);
}

/* Accordion Sidebar Styles */
.accordion-sidebar {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.accordion-sidebar .sidebar-section-header {
  background: var(--color-elev);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.main-content {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  height: 100%;
}

/* =================
   Visual Dividers
   ================= */

.divider-horizontal {
  border-top: 1px solid color-mix(in srgb, var(--color-border) 60%, transparent);
}

.divider-vertical {
  border-left: 1px solid color-mix(in srgb, var(--color-border) 60%, transparent);
}

.section-divider {
  margin-top: 2rem;
  padding-top: 2rem;
  border-top: 1px solid color-mix(in srgb, var(--color-border) 60%, transparent);
}

/* =================
   Card Components
   ================= */

.card-base {
  background: var(--color-elev);
  border: 1px solid var(--color-border);
  border-radius: 0.5rem;
  box-shadow: var(--shadow-sm);
}

.card-header {
  padding: 1rem;
  border-bottom: 1px solid color-mix(in srgb, var(--color-border) 60%, transparent);
}

.card-body {
  padding: 1rem;
}

.card-footer {
  padding: 1rem;
  border-top: 1px solid color-mix(in srgb, var(--color-border) 60%, transparent);
  background: color-mix(in srgb, var(--color-elev) 50%, transparent);
}

/* =================
   Typography Hierarchy
   ================= */

.display-text {
  font-family: 'Manrope', 'Inter', system-ui, sans-serif;
  font-weight: 700;
  color: var(--color-ink);
  line-height: 1.2;
  letter-spacing: -0.025em;
}

.display-h1 {
  font-size: 1.5rem;
  line-height: 1.2;
}

@media (min-width: 768px) {
  .display-h1 {
    font-size: 1.875rem;
  }
}

@media (min-width: 1024px) {
  .display-h1 {
    font-size: 2.25rem;
  }
}

.display-h2 {
  font-size: 1.25rem;
  line-height: 1.3;
}

@media (min-width: 768px) {
  .display-h2 {
    font-size: 1.5rem;
  }
}

@media (min-width: 1024px) {
  .display-h2 {
    font-size: 1.875rem;
  }
}

.display-h3 {
  font-size: 1.125rem;
  line-height: 1.4;
}

@media (min-width: 768px) {
  .display-h3 {
    font-size: 1.25rem;
  }
}

@media (min-width: 1024px) {
  .display-h3 {
    font-size: 1.5rem;
  }
}

.body-text {
  color: var(--color-ink);
  line-height: 1.6;
}

.body-large {
  font-size: 1rem;
  font-weight: 500;
}

.body-default {
  font-size: 0.875rem;
}

.caption-text {
  color: var(--color-muted);
  font-size: 0.75rem;
  font-weight: 500;
}

/* =================
   Status Indicators
   ================= */

.status-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
}

.status-dot-success {
  background: var(--color-success);
}

.status-dot-warn {
  background: var(--color-warn);
}

.status-dot-danger {
  background: var(--color-danger);
}

.status-dot-info {
  background: var(--color-info);
}

/* =================
   Interactive States
   ================= */

.interactive-hover {
  transition: colors 0.15s ease;
}

.interactive-hover:hover {
  background: var(--bg-overlay-light);
}

.interactive-active {
  transition: all 0.15s ease;
}

.interactive-active:hover {
  background: var(--bg-overlay-light);
}

.interactive-active:active {
  background: var(--bg-overlay-medium);
  transform: translateY(1px);
}

.focus-ring:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* =================
   Responsive Utilities
   ================= */

.mobile-only {
  display: block;
}

@media (min-width: 768px) {
  .mobile-only {
    display: none;
  }
}

.desktop-only {
  display: none;
}

@media (min-width: 768px) {
  .desktop-only {
    display: block;
  }
}

.sidebar-mobile {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 50;
  width: var(--sidebar-width);
  background: var(--color-elev);
  transform: translateX(-100%);
  transition: transform 0.2s ease-in-out;
}

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

@media (min-width: 768px) {
  .sidebar-mobile {
    position: relative;
    z-index: auto;
    transform: translateX(0);
  }
}

.sidebar-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.5);
  transition: opacity 0.2s ease;
}

@media (min-width: 768px) {
  .sidebar-overlay {
    display: none;
  }
}

/* =================
   Header Profile Section
   ================= */

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

.user-profile-section {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  height: 100%;
}

.user-profile-divider {
  width: 1px;
  height: 24px;
  background: color-mix(in srgb, var(--color-border) 40%, transparent);
  margin-right: var(--spacing-xs);
}

.user-profile-info {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, 
    color-mix(in srgb, var(--color-primary) 80%, transparent),
    color-mix(in srgb, var(--color-info) 80%, transparent));
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: var(--text-caption);
  font-weight: 600;
  transition: transform var(--duration-fast) var(--easing);
}

.user-avatar:hover {
  transform: scale(1.05);
}

.user-name {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-ink);
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-action-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-xs);
  background: color-mix(in srgb, var(--color-elev) 50%, transparent);
  border: 1px solid color-mix(in srgb, var(--color-border) 40%, transparent);
  color: var(--color-muted);
  cursor: pointer;
  transition: all var(--duration-fast) var(--easing);
  position: relative;
  overflow: hidden;
}

.user-action-btn:hover {
  background: color-mix(in srgb, var(--color-elev) 80%, transparent);
  border-color: color-mix(in srgb, var(--color-border) 60%, transparent);
  color: var(--color-ink);
  transform: translateY(-1px);
}

.user-action-btn:active {
  transform: translateY(0);
}

.logout-btn {
  width: auto;
  padding: 0 var(--spacing-sm);
  gap: var(--spacing-xs);
  color: var(--color-danger);
}

.logout-btn:hover {
  background: color-mix(in srgb, var(--color-danger) 10%, transparent);
  border-color: color-mix(in srgb, var(--color-danger) 30%, transparent);
  color: var(--color-danger);
}

.logout-btn-text {
  font-size: var(--text-sm);
  font-weight: 500;
  display: none;
}

@media (min-width: 768px) {
  .logout-btn-text {
    display: inline;
  }
}

.theme-toggle-btn:hover {
  background: color-mix(in srgb, var(--color-primary) 10%, transparent);
  border-color: color-mix(in srgb, var(--color-primary) 30%, transparent);
  color: var(--color-primary);
}

.dark .user-action-btn {
  background: color-mix(in srgb, var(--color-elev) 70%, transparent);
  border-color: color-mix(in srgb, var(--color-border) 50%, transparent);
}

.dark .user-action-btn:hover {
  background: var(--color-elev);
  border-color: color-mix(in srgb, var(--color-border) 70%, transparent);
}

/* =================
   Document Header
   ================= */

.document-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--color-elev);
  padding: var(--spacing-lg) var(--spacing-xl);
  margin-bottom: var(--spacing-xl);
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  min-height: 72px;
}

.document-header-title {
  font-size: var(--text-h3);
  font-weight: var(--text-h3-weight);
  line-height: var(--text-h3-line);
  color: var(--color-ink);
  font-family: 'Manrope', 'Inter', system-ui, sans-serif;
  letter-spacing: -0.01em;
  margin: 0;
}

.document-header-export-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-sm);
  padding: var(--spacing-sm) var(--spacing-md);
  background: var(--color-primary);
  color: var(--color-primary-ink);
  border: none;
  border-radius: var(--radius-xs);
  font-size: var(--text-sm);
  font-weight: 500;
  font-family: 'Inter', system-ui, sans-serif;
  cursor: pointer;
  transition: all var(--duration-fast) var(--easing);
  box-shadow: var(--shadow-sm);
}

.document-header-export-btn:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.document-header-export-btn:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

.document-header-export-btn:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* =================
   Export Dialog
   ================= */

.export-dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 9998;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fadeIn var(--duration-fast) var(--easing);
}

.export-dialog-container {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  padding: var(--spacing-lg);
}

.export-dialog-content {
  pointer-events: auto;
  background: var(--color-elev);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 480px;
  padding: var(--spacing-xl);
  animation: scaleIn var(--duration-normal) var(--easing);
  border: 1px solid var(--color-border);
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.98);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.export-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--spacing-lg);
  padding-bottom: var(--spacing-md);
  border-bottom: 1px solid var(--color-border);
}

.export-dialog-title {
  font-size: var(--text-h3);
  font-weight: var(--text-h3-weight);
  line-height: var(--text-h3-line);
  color: var(--color-ink);
  font-family: 'Manrope', 'Inter', system-ui, sans-serif;
  margin: 0;
}

.export-dialog-close-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-xs);
  background: transparent;
  border: none;
  color: var(--color-muted);
  cursor: pointer;
  transition: all var(--duration-fast) var(--easing);
}

.export-dialog-close-btn:hover {
  background: color-mix(in srgb, var(--color-elev) 80%, var(--color-bg));
  color: var(--color-ink);
}

.export-dialog-close-btn:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.export-dialog-section {
  margin-bottom: var(--spacing-lg);
}

.export-dialog-label {
  display: block;
  font-size: var(--text-body);
  font-weight: 600;
  color: var(--color-ink);
  margin-bottom: var(--spacing-sm);
  font-family: 'Inter', system-ui, sans-serif;
}

.export-dialog-mode-buttons,
.export-dialog-format-buttons {
  display: flex;
  gap: var(--spacing-sm);
}

.export-dialog-mode-btn,
.export-dialog-format-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--spacing-xs);
  padding: var(--spacing-md);
  background: var(--color-bg);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-muted);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--duration-fast) var(--easing);
}

.export-dialog-format-btn {
  flex-direction: row;
  padding: var(--spacing-sm) var(--spacing-md);
}

.export-dialog-mode-btn:hover,
.export-dialog-format-btn:hover {
  background: color-mix(in srgb, var(--color-primary) 5%, var(--color-bg));
  border-color: color-mix(in srgb, var(--color-primary) 30%, var(--color-border));
  color: var(--color-ink);
}

.export-dialog-mode-btn.active,
.export-dialog-format-btn.active {
  background: color-mix(in srgb, var(--color-primary) 12%, var(--color-bg));
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.export-dialog-mode-btn:disabled,
.export-dialog-format-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.export-dialog-select {
  width: 100%;
  padding: var(--spacing-sm) var(--spacing-md);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xs);
  color: var(--color-ink);
  font-size: var(--text-body);
  font-family: 'Inter', system-ui, sans-serif;
  cursor: pointer;
  transition: all var(--duration-fast) var(--easing);
}

.export-dialog-select:hover:not(:disabled) {
  border-color: color-mix(in srgb, var(--color-primary) 40%, var(--color-border));
}

.export-dialog-select:focus {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-color: var(--color-primary);
}

.export-dialog-select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.export-dialog-actions {
  display: flex;
  gap: var(--spacing-sm);
  margin-top: var(--spacing-xl);
  padding-top: var(--spacing-lg);
  border-top: 1px solid var(--color-border);
}

.export-dialog-action-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-sm);
  padding: var(--spacing-sm) var(--spacing-lg);
  border-radius: var(--radius-xs);
  font-size: var(--text-body);
  font-weight: 500;
  font-family: 'Inter', system-ui, sans-serif;
  cursor: pointer;
  transition: all var(--duration-fast) var(--easing);
  border: none;
  min-height: 40px;
}

.export-dialog-action-btn-secondary {
  background: var(--color-bg);
  color: var(--color-ink);
  border: 1px solid var(--color-border);
}

.export-dialog-action-btn-secondary:hover:not(:disabled) {
  background: color-mix(in srgb, var(--color-elev) 60%, var(--color-bg));
  border-color: color-mix(in srgb, var(--color-border) 120%, var(--color-bg));
}

.export-dialog-action-btn-primary {
  background: var(--color-primary);
  color: var(--color-primary-ink);
  box-shadow: var(--shadow-sm);
}

.export-dialog-action-btn-primary:hover:not(:disabled) {
  filter: brightness(1.1);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.export-dialog-action-btn-primary:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

.export-dialog-action-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.export-dialog-action-btn:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

@media (max-width: 640px) {
  .export-dialog-content {
    max-width: calc(100vw - 2 * var(--spacing-lg));
    padding: var(--spacing-lg);
  }
  
  .export-dialog-mode-buttons {
    flex-direction: column;
  }
  
  .export-dialog-mode-btn {
    flex-direction: row;
    justify-content: center;
  }
}

/* =================
   Accessibility Helpers
   =======================*/

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  white-space: nowrap;
  border: 0;
  clip: rect(0, 0, 0, 0);
}

.touch-target {
  min-height: 44px;
  min-width: 44px;
}

/* =================
   Loading States
   ================= */

.skeleton {
  background: color-mix(in srgb, var(--color-border) 40%, transparent);
  border-radius: 0.25rem;
}

.skeleton-text {
  height: 1rem;
}

.skeleton-heading {
  height: 1.5rem;
}

.skeleton-button {
  height: 2.25rem;
  width: 6rem;
}

.skeleton-avatar {
  height: 2rem;
  width: 2rem;
  border-radius: 50%;
}