/* ==========================================================================
   KATOMART MODERN PRO - DESIGN SYSTEM
   Theme: Deep Zinc / Slate Dark Mode with Indigo & Violet Accent
   ========================================================================== */

:root, html[data-theme="dark"] {
  color-scheme: dark;

  /* Radii */
  --radius-xs: 4px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-pill: 9999px;

  /* Deep Dark Theme Colors (OKLCH) */
  --background: oklch(0.12 0.012 260);
  --foreground: oklch(0.98 0 0);
  --card: oklch(0.16 0.012 260);
  --card-foreground: oklch(0.98 0 0);
  --card-hover: oklch(0.19 0.015 260);
  
  --sidebar: oklch(0.14 0.012 260);
  --sidebar-border: oklch(1 0 0 / 8%);

  /* Primary Accent: Vibrant Indigo-Violet */
  --primary: hsl(252 88% 64%);
  --primary-hover: hsl(252 88% 70%);
  --primary-foreground: #ffffff;
  --primary-soft: oklch(0.58 0.22 280 / 16%);
  --primary-edge: oklch(0.58 0.22 280 / 38%);
  --primary-glow: 0 0 24px -4px hsla(252, 88%, 64%, 0.4);

  /* Secondary & Neutral Tones */
  --secondary: oklch(0.22 0.01 260);
  --secondary-foreground: oklch(0.92 0 0);
  --muted: oklch(0.20 0.01 260);
  --muted-foreground: oklch(0.68 0.02 260);
  --accent: oklch(0.24 0.015 260);
  --accent-foreground: oklch(0.98 0 0);

  /* Semantic Feedback Colors */
  --destructive: oklch(0.65 0.22 25);
  --destructive-soft: oklch(0.65 0.22 25 / 15%);
  --destructive-edge: oklch(0.65 0.22 25 / 40%);
  --destructive-foreground: #ffffff;

  --success: oklch(0.72 0.19 155);
  --success-soft: oklch(0.72 0.19 155 / 15%);
  --success-edge: oklch(0.72 0.19 155 / 40%);

  --warning: oklch(0.78 0.18 75);
  --warning-soft: oklch(0.78 0.18 75 / 15%);
  --warning-edge: oklch(0.78 0.18 75 / 40%);

  /* Borders & Inputs */
  --border: oklch(1 0 0 / 9%);
  --border-subtle: oklch(1 0 0 / 5%);
  --input: oklch(1 0 0 / 10%);
  --input-focus: oklch(0.58 0.22 280 / 60%);
  --ring: hsl(252 88% 64%);
  --ring-soft: hsla(252, 88%, 64%, 0.25);

  /* Shadow Elevation */
  --shadow-sm: 0 2px 8px -1px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 8px 24px -4px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 16px 40px -8px rgba(0, 0, 0, 0.6);

  /* Typography */
  --font-sans: "Plus Jakarta Sans", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

/* Light Theme Variables */
html[data-theme="light"] {
  color-scheme: light;
  --background: oklch(0.985 0.004 260);
  --foreground: oklch(0.14 0.015 260);
  --card: #ffffff;
  --card-foreground: oklch(0.14 0.015 260);
  --card-hover: oklch(0.965 0.005 260);
  
  --sidebar: oklch(0.965 0.005 260);
  --sidebar-border: oklch(0 0 0 / 8%);

  --primary: hsl(252 88% 58%);
  --primary-hover: hsl(252 88% 50%);
  --primary-foreground: #ffffff;
  --primary-soft: oklch(0.58 0.22 280 / 12%);
  --primary-edge: oklch(0.58 0.22 280 / 30%);
  --primary-glow: 0 0 20px -3px hsla(252, 88%, 58%, 0.3);

  --secondary: oklch(0.94 0.005 260);
  --secondary-foreground: oklch(0.20 0.01 260);
  --muted: oklch(0.93 0.005 260);
  --muted-foreground: oklch(0.48 0.02 260);
  --accent: oklch(0.91 0.01 260);
  --accent-foreground: oklch(0.14 0.015 260);

  --destructive: oklch(0.60 0.22 25);
  --destructive-soft: oklch(0.60 0.22 25 / 12%);
  --destructive-edge: oklch(0.60 0.22 25 / 35%);
  --destructive-foreground: #ffffff;

  --success: oklch(0.62 0.18 155);
  --success-soft: oklch(0.62 0.18 155 / 12%);
  --success-edge: oklch(0.62 0.18 155 / 35%);

  --warning: oklch(0.68 0.18 75);
  --warning-soft: oklch(0.68 0.18 75 / 12%);
  --warning-edge: oklch(0.68 0.18 75 / 35%);

  --border: oklch(0 0 0 / 10%);
  --border-subtle: oklch(0 0 0 / 6%);
  --input: oklch(0 0 0 / 8%);
  --input-focus: oklch(0.58 0.22 280 / 50%);
  --ring: hsl(252 88% 58%);
  --ring-soft: hsla(252, 88%, 58%, 0.25);

  --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.08), 0 1px 2px -1px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 16px -2px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 12px 30px -4px rgba(0, 0, 0, 0.12), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --background: oklch(0.985 0.004 260);
    --foreground: oklch(0.14 0.015 260);
    --card: #ffffff;
    --card-foreground: oklch(0.14 0.015 260);
    --card-hover: oklch(0.965 0.005 260);
    --sidebar: oklch(0.965 0.005 260);
    --sidebar-border: oklch(0 0 0 / 8%);
    --secondary: oklch(0.94 0.005 260);
    --secondary-foreground: oklch(0.20 0.01 260);
    --muted: oklch(0.93 0.005 260);
    --muted-foreground: oklch(0.48 0.02 260);
    --accent: oklch(0.91 0.01 260);
    --accent-foreground: oklch(0.14 0.015 260);
    --destructive: oklch(0.60 0.22 25);
    --destructive-soft: oklch(0.60 0.22 25 / 12%);
    --destructive-edge: oklch(0.60 0.22 25 / 35%);
    --destructive-foreground: #ffffff;
    --success: oklch(0.62 0.18 155);
    --success-soft: oklch(0.62 0.18 155 / 12%);
    --success-edge: oklch(0.62 0.18 155 / 35%);
    --warning: oklch(0.68 0.18 75);
    --warning-soft: oklch(0.68 0.18 75 / 12%);
    --warning-edge: oklch(0.68 0.18 75 / 35%);
    --border: oklch(0 0 0 / 10%);
    --border-subtle: oklch(0 0 0 / 6%);
    --input: oklch(0 0 0 / 8%);
    --input-focus: oklch(0.58 0.22 280 / 50%);
    --ring: hsl(252 88% 58%);
    --ring-soft: hsla(252, 88%, 58%, 0.25);
    --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.08), 0 1px 2px -1px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 16px -2px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 12px 30px -4px rgba(0, 0, 0, 0.12), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  }
}

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

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  touch-action: manipulation;
}

body {
  background-color: var(--background);
  color: var(--foreground);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

::selection {
  background: var(--primary);
  color: var(--primary-foreground);
}

/* Scrollbar Styling */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--muted);
  border-radius: var(--radius-pill);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--muted-foreground);
}

/* Common SVGs */
svg {
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
}

/* ==========================================================================
   BUTTONS & CONTROLS
   ========================================================================== */
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--foreground);
  background: var(--secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 16px;
  white-space: nowrap;
  transition: all 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  user-select: none;
}

button:hover {
  background: var(--accent);
  border-color: oklch(1 0 0 / 15%);
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
  transform: none;
}

button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 3px var(--ring-soft);
}

/* Primary Button */
.btn-primary {
  background: var(--primary);
  border-color: transparent;
  color: var(--primary-foreground);
  box-shadow: var(--primary-glow);
}
.btn-primary:hover {
  background: var(--primary-hover);
  border-color: transparent;
  box-shadow: 0 0 28px -2px hsla(252, 88%, 64%, 0.6);
}

/* Ghost Button */
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted-foreground);
}
.btn-ghost:hover {
  background: var(--accent);
  color: var(--foreground);
}

/* Outline Button */
.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--foreground);
}
.btn-outline:hover {
  background: var(--muted);
  border-color: var(--input);
}

/* Icon-only Button */
.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: var(--radius-md);
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted-foreground);
}
.btn-icon:hover {
  background: var(--muted);
  color: var(--foreground);
  border-color: var(--border);
}
.btn-icon svg {
  width: 18px;
  height: 18px;
}
.btn-icon.btn-sm {
  width: 30px;
  height: 30px;
}
.btn-icon.btn-sm svg {
  width: 15px;
  height: 15px;
}

.btn-sm {
  padding: 5px 12px;
  font-size: 12.5px;
  border-radius: var(--radius-sm);
}

.btn-block {
  width: 100%;
}

/* Form Inputs */
input, textarea, select {
  font-family: inherit;
  font-size: 16px; /* 16px prevents iOS Safari auto-zoom on focus */
  color: var(--foreground);
  background: color-mix(in oklab, var(--card) 85%, var(--muted));
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 9px 14px;
  width: 100%;
  min-width: 0;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

input::placeholder, textarea::placeholder {
  color: var(--muted-foreground);
  opacity: 0.75;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  background: var(--card);
  border-color: var(--ring);
  box-shadow: 0 0 0 3px var(--ring-soft);
}

select option {
  background: var(--card);
  color: var(--foreground);
}

label {
  display: block;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--foreground);
  margin-bottom: 6px;
}

.hidden {
  display: none !important;
}

/* ==========================================================================
   LOGIN VIEW
   ========================================================================== */
#login-view {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
  max-width: 100%;
  padding: 24px;
  background-color: var(--background);
  overflow: hidden;
}

.login-top-actions {
  position: absolute;
  top: 20px;
  right: 20px;
  z-index: 10;
}

.theme-toggle-btn {
  color: var(--muted-foreground);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
.theme-toggle-btn:hover {
  color: var(--primary);
  background: var(--muted);
}
.theme-toggle-btn svg {
  width: 18px;
  height: 18px;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.theme-toggle-btn:hover svg {
  transform: rotate(20deg);
}

.login-backdrop {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, hsla(252, 88%, 64%, 0.18) 0%, hsla(270, 80%, 50%, 0.05) 50%, transparent 70%);
  transform: translate(-50%, -50%);
  filter: blur(60px);
  pointer-events: none;
  z-index: 0;
}

.login-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 420px;
  background: color-mix(in oklab, var(--card) 85%, transparent);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg), 0 0 0 1px oklch(1 0 0 / 5%);
  padding: 40px 32px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: cardAppear 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes cardAppear {
  from { opacity: 0; transform: translateY(16px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.login-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
}

.brand-badge {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, var(--primary), hsl(275 80% 50%));
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--primary-glow);
}
.brand-badge .icon-brand {
  width: 26px;
  height: 26px;
}

.login-head h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.login-head p.sub {
  color: var(--muted-foreground);
  font-size: 13px;
  max-width: 280px;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-wrapper .field-icon {
  position: absolute;
  left: 12px;
  width: 18px;
  height: 18px;
  color: var(--muted-foreground);
  pointer-events: none;
}

.input-wrapper input {
  padding-left: 40px;
  padding-right: 40px;
  font-size: 16px;
}

.btn-input-action {
  position: absolute;
  right: 6px;
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  padding: 0;
  color: var(--muted-foreground);
}
.btn-input-action:hover {
  background: transparent;
  color: var(--foreground);
}
.btn-input-action svg {
  width: 18px;
  height: 18px;
}

.btn-arrow {
  width: 18px;
  height: 18px;
  transition: transform 0.18s ease;
}
.btn-primary:hover .btn-arrow {
  transform: translateX(3px);
}

.error {
  color: var(--destructive);
  background: var(--destructive-soft);
  border: 1px solid var(--destructive-edge);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 13px;
  text-align: center;
  line-height: 1.4;
  animation: shake 0.3s ease;
}
.error:empty {
  display: none;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* ==========================================================================
   APP SHELL
   ========================================================================== */
#app-view {
  display: none;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

/* Topbar Header */
header.topbar {
  flex: none;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 max(18px, env(safe-area-inset-right)) 0 max(18px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--border);
  background: color-mix(in oklab, var(--background) 88%, transparent);
  backdrop-filter: blur(16px);
  z-index: 20;
}

#sidebar-toggle-btn {
  flex-shrink: 0;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.topbar-left .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  user-select: none;
}

.brand-mark.sm {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--primary), hsl(275 80% 50%));
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 10px hsla(252, 88%, 64%, 0.3);
}
.brand-mark.sm svg {
  width: 16px;
  height: 16px;
}

.brand-text {
  display: flex;
  flex-direction: column;
}
.brand-name {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.1;
}
.brand-sub {
  font-size: 11px;
  color: var(--muted-foreground);
}

/* Tabs Navigation */
nav.tabs {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--muted);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  padding: 4px;
}

nav.tabs button {
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  color: var(--muted-foreground);
  padding: 5px 16px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: none;
}

nav.tabs button:hover {
  color: var(--foreground);
  background: oklch(1 0 0 / 5%);
  transform: none;
}

nav.tabs button.active {
  color: var(--foreground);
  background: var(--card);
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}

/* Mobile Tabs Dropdown */
.mobile-tabs-dropdown {
  display: none;
  position: relative;
}

.mobile-tabs-trigger {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 14px;
  background: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 600;
  color: var(--foreground);
  box-shadow: none;
  cursor: pointer;
  transition: all 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  user-select: none;
}

.mobile-tabs-trigger:hover,
.mobile-tabs-trigger.open {
  background: var(--card);
  border-color: var(--primary);
  color: var(--primary);
  transform: none;
}

.mobile-tab-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: inherit;
}
.mobile-tab-icon svg {
  width: 15px;
  height: 15px;
}

.mobile-tab-arrow {
  width: 14px;
  height: 14px;
  color: var(--muted-foreground);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
.mobile-tabs-trigger.open .mobile-tab-arrow {
  transform: rotate(180deg);
  color: var(--primary);
}

/* Mobile Tabs Backdrop & Popover Menu */
.mobile-tabs-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 998;
}

.mobile-tabs-menu {
  display: none;
  position: fixed;
  top: calc(60px + env(safe-area-inset-top, 0px) + 6px);
  left: 50%;
  transform: translateX(-50%);
  width: min(88vw, 280px);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 40px -8px rgba(0, 0, 0, 0.5), 0 0 0 1px var(--border);
  padding: 8px;
  flex-direction: column;
  gap: 6px;
  z-index: 999;
  animation: menuSlideDown 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes menuSlideDown {
  from {
    opacity: 0;
    transform: translate(-50%, -6px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0) scale(1);
  }
}

.mobile-tabs-backdrop.hidden,
.mobile-tabs-menu.hidden {
  display: none !important;
}

.mobile-tab-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  background: var(--muted);
  border: 1px solid transparent;
  color: var(--foreground);
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  box-shadow: none;
  cursor: pointer;
  transition: all 0.15s ease;
}

.mobile-tab-item-content {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mobile-tab-item svg.item-icon {
  width: 16px;
  height: 16px;
  color: var(--muted-foreground);
}

.mobile-tab-item:hover,
.mobile-tab-item:active {
  background: var(--accent);
  color: var(--foreground);
}

.mobile-tab-item.active {
  background: color-mix(in oklab, var(--primary) 16%, transparent);
  border-color: color-mix(in oklab, var(--primary) 35%, transparent);
  color: var(--primary);
  font-weight: 600;
}
.mobile-tab-item.active svg.item-icon {
  color: var(--primary);
}

.mobile-tab-check {
  width: 16px;
  height: 16px;
  color: var(--primary);
  margin-left: auto;
}

/* Topbar Right Profile */
.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--muted);
  padding: 4px 12px 4px 4px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-subtle);
}

.user-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, hsl(252 80% 60%), hsl(210 90% 55%));
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.user-profile .who {
  font-size: 13px;
  font-weight: 500;
  color: var(--foreground);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#logout-btn {
  padding: 6px 12px;
  font-size: 13px;
}
#logout-btn .btn-ic {
  width: 16px;
  height: 16px;
}

/* ==========================================================================
   MAIN LAYOUT & SIDEBAR
   ========================================================================== */
main.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 340px 1fr;
  transition: grid-template-columns 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
}

/* Collapsed Sidebar */
main.layout.sidebar-collapsed {
  grid-template-columns: 0px 1fr;
}

aside.catalog {
  background: var(--sidebar);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  transition: opacity 0.2s ease;
}

main.layout.sidebar-collapsed aside.catalog {
  opacity: 0;
  pointer-events: none;
}

/* Sidebar Search Filter */
.catalog-filter-box {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--sidebar);
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-subtle);
}

.catalog-search-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.catalog-search-wrapper svg.search-ic {
  position: absolute;
  left: 10px;
  width: 15px;
  height: 15px;
  color: var(--muted-foreground);
  pointer-events: none;
}

.catalog-search-wrapper input {
  padding: 7px 32px 7px 32px;
  font-size: 13px;
  border-radius: var(--radius-sm);
  background: var(--card);
}

.catalog-search-wrapper .clear-search-btn {
  position: absolute;
  right: 6px;
  background: transparent;
  border: none;
  padding: 0;
  width: 22px;
  height: 22px;
  color: var(--muted-foreground);
  display: none;
}
.catalog-search-wrapper .clear-search-btn:hover {
  color: var(--foreground);
}

/* Course Progress Widget in Sidebar */
.course-progress-card {
  margin: 12px 14px 6px;
  padding: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.progress-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 12px;
}
.progress-label {
  color: var(--muted-foreground);
  font-weight: 500;
}
.progress-percent {
  color: var(--primary);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.progress-bar-track {
  height: 5px;
  background: var(--muted);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), hsl(270 80% 60%));
  border-radius: var(--radius-pill);
  transition: width 0.3s ease;
}

/* Sidebar Tree (Courses, Modules, Lessons) */
.catalog-tree {
  padding: 8px 10px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.course-node {
  border-radius: var(--radius-md);
  transition: background-color 0.15s ease;
}

.course-title-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  padding: 9px 10px;
  color: var(--foreground);
  font-size: 13.5px;
  font-weight: 600;
  white-space: normal;
  justify-content: flex-start;
}
.course-title-btn:hover {
  background: var(--accent);
  color: var(--foreground);
  transform: none;
}
.course-title-btn .chevron-icon {
  width: 16px;
  height: 16px;
  color: var(--muted-foreground);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  flex-shrink: 0;
}
.course-title-btn.open .chevron-icon {
  transform: rotate(90deg);
  color: var(--primary);
}

.module-node {
  margin-left: 14px;
  margin-top: 4px;
  border-left: 1px solid var(--border);
  padding-left: 8px;
}

.module-title-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  padding: 7px 8px;
  color: var(--muted-foreground);
  font-size: 13px;
  font-weight: 500;
  white-space: normal;
  justify-content: flex-start;
}
.module-title-btn:hover {
  background: var(--accent);
  color: var(--foreground);
  transform: none;
}
.module-title-btn.open {
  color: var(--foreground);
}
.module-title-btn .chevron-icon {
  width: 14px;
  height: 14px;
  transition: transform 0.2s ease;
}
.module-title-btn.open .chevron-icon {
  transform: rotate(90deg);
}
.module-title-btn .mod-badge {
  margin-left: auto;
  font-size: 11px;
  color: var(--muted-foreground);
  background: var(--muted);
  border-radius: var(--radius-pill);
  padding: 1px 7px;
  font-weight: 500;
}

/* Lesson Item Button */
.lesson-item {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: 10px;
  margin-top: 2px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
  border: 1px solid transparent;
}
.lesson-item:hover {
  background: var(--card-hover);
}
.lesson-item.active {
  background: var(--primary-soft);
  border-color: var(--primary-edge);
  box-shadow: 0 0 12px -2px hsla(252, 88%, 64%, 0.2);
}

/* Checkbox de Conclusão */
.lesson-check-btn {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1.5px solid var(--muted-foreground);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: transparent;
  flex-shrink: 0;
  transition: all 0.15s ease;
}
.lesson-check-btn svg {
  width: 11px;
  height: 11px;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.lesson-item.completed .lesson-check-btn {
  background: var(--success);
  border-color: var(--success);
  color: #ffffff;
}
.lesson-item.completed .lesson-check-btn svg {
  opacity: 1;
}

.lesson-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.lesson-title-text {
  font-size: 13px;
  color: var(--foreground);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lesson-item.completed .lesson-title-text {
  color: var(--muted-foreground);
}
.lesson-item.active .lesson-title-text {
  color: var(--foreground);
  font-weight: 600;
}

.lesson-dur-text {
  font-size: 11px;
  color: var(--muted-foreground);
  font-variant-numeric: tabular-nums;
  margin-top: 1px;
}

/* Side Item (Bancos, Provas, Baralhos) */
.side-item-card {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-bottom: 8px;
  color: var(--foreground);
  white-space: normal;
  transition: all 0.18s ease;
}
.side-item-card:hover {
  background: var(--card-hover);
  border-color: oklch(1 0 0 / 18%);
  transform: translateY(-1px);
}
.side-item-card.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: 0 0 16px -2px hsla(252, 88%, 64%, 0.25);
}
.side-item-card .card-title {
  display: block;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.side-item-card .card-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted-foreground);
  margin-top: 4px;
}

/* ==========================================================================
   CONTENT AREA & PLAYER
   ========================================================================== */
section.player-area {
  padding: 24px 32px;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--background);
}

/* Placeholder Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 80px 20px;
  color: var(--muted-foreground);
}
.empty-icon-wrap {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-xl);
  background: var(--card);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.empty-icon-wrap svg {
  width: 32px;
  height: 32px;
}
.empty-state h3 {
  font-size: 18px;
  font-weight: 600;
  color: var(--foreground);
  margin-bottom: 6px;
}
.empty-state p {
  font-size: 14px;
  max-width: 440px;
}
.empty-state p.placeholder-desc {
  max-width: 440px;
  line-height: 1.6;
  margin-bottom: 6px;
}

.inline-sidebar-ref {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
  width: 26px;
  height: 26px;
  padding: 0;
  margin: 0 4px;
  border-radius: var(--radius-sm);
  background: var(--muted);
  border: 1px solid var(--border);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: all 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

.inline-sidebar-ref:hover {
  background: var(--card);
  border-color: var(--primary);
  transform: translateY(-1px) scale(1.06);
}

.inline-sidebar-ref svg {
  width: 15px;
  height: 15px;
}

.placeholder-btn {
  margin-top: 14px;
  gap: 8px;
  padding: 10px 22px;
  font-size: 14px;
  font-weight: 600;
  border-radius: var(--radius-pill);
}
.placeholder-btn svg {
  width: 18px;
  height: 18px;
}

/* Lesson Top Navigation Bar */
.lesson-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--muted-foreground);
}
.breadcrumbs .crumb {
  color: var(--muted-foreground);
}
.breadcrumbs .sep {
  color: oklch(1 0 0 / 20%);
  font-size: 11px;
}
.breadcrumbs .current {
  color: var(--foreground);
  font-weight: 500;
}

.lesson-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

#lesson-complete-btn.completed {
  background: var(--success-soft);
  border-color: var(--success-edge);
  color: var(--success);
}
#lesson-complete-btn .ic-check {
  width: 14px;
  height: 14px;
}

.lesson-nav-buttons {
  display: flex;
  gap: 4px;
}

/* Lesson Header */
.lesson-head {
  margin-bottom: 16px;
}
#lesson-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
  margin-bottom: 4px;
}
.lesson-meta-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--muted-foreground);
}

/* Video Player */
.video-container {
  position: relative;
  width: 100%;
  background: #000000;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  margin-bottom: 12px;
}

video#player {
  width: 100%;
  max-height: 68vh;
  display: block;
  background: #000;
  aspect-ratio: 16 / 9;
  outline: none;
}

video::cue {
  background-color: rgba(0, 0, 0, 0.82);
  color: #ffffff;
  font-family: var(--font-sans);
  font-size: 22px;
  line-height: 1.4;
  padding: 4px 12px;
  border-radius: 4px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.9);
}

/* Theatre Mode */
#app-view.theatre-mode main.layout {
  grid-template-columns: 0px 1fr;
}
#app-view.theatre-mode video#player {
  max-height: 82vh;
}

/* Player Toolbar */
.player-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 16px;
  margin-bottom: 18px;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.toolbar-group .ctl {
  display: flex;
  align-items: center;
  gap: 8px;
}
.toolbar-group label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  font-size: 12.5px;
  color: var(--muted-foreground);
}
.ctl-ic {
  width: 15px;
  height: 15px;
}
.toolbar-group select {
  width: auto;
  min-width: 110px;
  padding: 5px 10px;
  font-size: 13px;
  border-radius: var(--radius-sm);
  background: var(--background);
}

.btn-toolbar {
  background: transparent;
  border: 1px solid var(--border);
  padding: 5px 12px;
  font-size: 12.5px;
  border-radius: var(--radius-sm);
  color: var(--muted-foreground);
}
.btn-toolbar:hover {
  background: var(--muted);
  color: var(--foreground);
}
.btn-toolbar svg {
  width: 14px;
  height: 14px;
}

/* Video Tabs (Multiple videos in lesson) */
.video-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.video-tabs button {
  padding: 6px 14px;
  font-size: 13px;
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--muted-foreground);
}
.video-tabs button.active {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--foreground);
  font-weight: 600;
}

/* Resources & Downloads */
.resources-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin-top: 20px;
}

.resource-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
}

.resource-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.res-ic {
  width: 18px;
  height: 18px;
  color: var(--primary);
}
.block-title {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--foreground);
}

ul.files {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
ul.files li a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--background);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--foreground);
  text-decoration: none;
  font-size: 13px;
  transition: all 0.15s ease;
}
ul.files li a:hover {
  border-color: var(--primary-edge);
  background: var(--primary-soft);
  color: var(--primary);
}

/* ==========================================================================
   DYNAMIC PANELS: QUESTIONS, EXAMS & FLASHCARDS
   ========================================================================== */
.q-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.q-head h2 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.q-headside {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.q-meta {
  color: var(--muted-foreground);
  font-size: 13px;
}

/* Exam Question Map Quick Navigation */
.exam-map-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: 10px 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 18px;
}
.exam-map-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted-foreground);
  margin-right: 6px;
}
.exam-map-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: var(--radius-xs);
  font-size: 12px;
  font-weight: 600;
  background: var(--background);
  border: 1px solid var(--border);
  color: var(--muted-foreground);
}
.exam-map-btn.current {
  border-color: var(--primary);
  color: var(--primary);
  box-shadow: 0 0 8px hsla(252, 88%, 64%, 0.3);
}
.exam-map-btn.answered {
  background: var(--primary-soft);
  border-color: var(--primary-edge);
  color: var(--foreground);
}

/* Progress bar */
.progress-track {
  height: 6px;
  background: var(--muted);
  border-radius: var(--radius-pill);
  overflow: hidden;
  margin: 0 0 20px;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), hsl(270 80% 60%));
  border-radius: var(--radius-pill);
  transition: width 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Question Card */
.q-card {
  background: var(--card);
  color: var(--card-foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
  padding: 24px;
  margin-bottom: 20px;
}
.q-statement {
  white-space: pre-wrap;
  font-size: 15.5px;
  line-height: 1.65;
  margin-top: 10px;
}
.q-media img {
  max-width: 100%;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  margin-top: 14px;
}

/* Question Options */
.q-options {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.q-opt {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  text-align: left;
  justify-content: flex-start;
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  white-space: normal;
  font-weight: 400;
  line-height: 1.5;
  transition: all 0.16s ease;
}
.q-opt:hover {
  background: var(--accent);
  border-color: oklch(1 0 0 / 18%);
  transform: none;
}
.q-opt-key {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--border);
  color: var(--muted-foreground);
  font-size: 12px;
  font-weight: 700;
  background: var(--card);
  transition: all 0.15s ease;
}
.q-opt-body {
  flex: 1;
  min-width: 0;
  white-space: pre-wrap;
}

/* Option States */
.q-opt.sel {
  border-color: var(--primary);
  background: var(--primary-soft);
}
.q-opt.sel .q-opt-key {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-foreground);
}

.q-opt.ok {
  border-color: var(--success);
  background: var(--success-soft);
}
.q-opt.ok .q-opt-key {
  background: var(--success);
  border-color: var(--success);
  color: #000;
}

.q-opt.bad {
  border-color: var(--destructive);
  background: var(--destructive-soft);
}
.q-opt.bad .q-opt-key {
  background: var(--destructive);
  border-color: var(--destructive);
  color: #fff;
}

.q-opt:disabled:not(.sel):not(.ok):not(.bad) {
  opacity: 0.6;
}

/* Row types (Ordering, Matching, Fill blank) */
.q-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.q-row .lbl {
  font-size: 13.5px;
  color: var(--muted-foreground);
  min-width: 100px;
}
.q-row input, .q-row select {
  width: auto;
  flex: 1;
  min-width: 160px;
}
.q-row button {
  padding: 6px 12px;
  font-size: 13px;
}
.q-row .ord-content {
  flex: 1;
  min-width: 0;
}

/* Feedback & Explanation */
.q-feedback {
  margin-top: 20px;
  border-radius: var(--radius-md);
  padding: 14px 18px;
  font-size: 14.5px;
  font-weight: 600;
}
.q-feedback.ok {
  background: var(--success-soft);
  border: 1px solid var(--success-edge);
  color: var(--success);
}
.q-feedback.bad {
  background: var(--destructive-soft);
  border: 1px solid var(--destructive-edge);
  color: var(--destructive);
}
.q-feedback.part {
  background: var(--warning-soft);
  border: 1px solid var(--warning-edge);
  color: var(--warning);
}

.q-explanation {
  margin-top: 14px;
  background: var(--background);
  border-left: 3px solid var(--primary);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  padding: 12px 18px;
  color: var(--foreground);
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
}

/* Question Navigation */
.q-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 14px;
}
.q-nav .grp {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* Timer Badge */
.timer {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 13.5px;
  color: var(--primary);
  background: var(--primary-soft);
  border: 1px solid var(--primary-edge);
  border-radius: var(--radius-pill);
  padding: 4px 14px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.timer.low {
  color: var(--destructive);
  background: var(--destructive-soft);
  border-color: var(--destructive-edge);
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* Exam Result Card */
.score-big {
  font-size: 34px;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 12px 0 6px;
}
.score-big .pct {
  color: var(--muted-foreground);
  font-size: 18px;
  font-weight: 500;
  margin-left: 6px;
}

.result-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0;
}
.result-grid button {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  font-weight: 600;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--muted-foreground);
}
.result-grid button.ok {
  background: var(--success-soft);
  color: var(--success);
  border-color: var(--success-edge);
}
.result-grid button.bad {
  background: var(--destructive-soft);
  color: var(--destructive);
  border-color: var(--destructive-edge);
}
.result-grid button.part {
  background: var(--warning-soft);
  color: var(--warning);
  border-color: var(--warning-edge);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 12px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--border);
  color: var(--muted-foreground);
}
.badge.ok {
  color: var(--success);
  border-color: var(--success-edge);
  background: var(--success-soft);
}
.badge.bad {
  color: var(--destructive);
  border-color: var(--destructive-edge);
  background: var(--destructive-soft);
}
.badge.part {
  color: var(--warning);
  border-color: var(--warning-edge);
  background: var(--warning-soft);
}

/* ==========================================================================
   FLASHCARDS - REAL 3D FLIP EFFECT
   ========================================================================== */
.fc-perspective-container {
  perspective: 1200px;
  width: 100%;
  max-width: 680px;
  margin: 0 auto 20px;
}

.fc-card-3d {
  position: relative;
  width: 100%;
  min-height: 280px;
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
  cursor: pointer;
}

.fc-card-3d.flipped {
  transform: rotateY(180deg);
}

.fc-card-face {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  padding: 36px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.fc-card-3d:hover .fc-card-face {
  border-color: var(--primary-edge);
  box-shadow: var(--shadow-lg), 0 0 24px -4px hsla(252, 88%, 64%, 0.15);
}

.fc-card-face.face-back {
  transform: rotateY(180deg);
  background: color-mix(in oklab, var(--card) 92%, var(--primary-soft));
  border-color: var(--primary-edge);
}

.fc-face-tag {
  position: absolute;
  top: 14px;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 3px 10px;
  border-radius: var(--radius-pill);
}

.fc-card-content {
  font-size: 18px;
  line-height: 1.6;
  white-space: pre-wrap;
  color: var(--foreground);
  max-width: 90%;
}

.fc-hint-tap {
  position: absolute;
  bottom: 12px;
  font-size: 11.5px;
  color: var(--muted-foreground);
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Rich text rendered inside questions/flashcards */
.rich {
  white-space: normal;
}
.rich p { margin: 0 0 8px; }
.rich p:last-child { margin-bottom: 0; }
.rich ul, .rich ol { margin: 0 0 8px; padding-left: 22px; }
.rich li { margin: 3px 0; }
.rich h1, .rich h2, .rich h3 { margin: 14px 0 8px; font-weight: 700; line-height: 1.3; }
.rich h1 { font-size: 1.3em; }
.rich h2 { font-size: 1.2em; }
.rich h3 { font-size: 1.1em; }
.rich blockquote {
  border-left: 3px solid var(--primary);
  padding: 4px 14px;
  color: var(--muted-foreground);
  margin: 10px 0;
  background: var(--primary-soft);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.rich code {
  background: var(--muted);
  border-radius: var(--radius-xs);
  padding: 2px 6px;
  font-family: var(--font-mono);
  font-size: 0.9em;
}
.rich pre {
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  overflow-x: auto;
  margin: 10px 0;
}
.rich pre code { background: none; padding: 0; }
.rich img { max-width: 100%; border-radius: var(--radius-md); }
.rich a { color: var(--primary); text-decoration: underline; }
.rich table { border-collapse: collapse; margin: 10px 0; width: 100%; }
.rich th, .rich td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; font-size: 13px; }
.rich th { background: var(--muted); }

/* ==========================================================================
   MODALS
   ========================================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}

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

.modal-card {
  width: 100%;
  max-width: 460px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 24px;
  animation: modalScale 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalScale {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.modal-header h3 {
  font-size: 18px;
  font-weight: 700;
}

.shortcut-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.shortcut-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--background);
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.shortcut-item .key {
  background: var(--muted);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: var(--radius-xs);
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 11.5px;
  color: var(--primary);
}

/* Subtitles Settings Modal */
.sub-preview-box {
  width: 100%;
  height: 120px;
  background: #000000;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  margin-bottom: 20px;
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 0 24px rgba(0, 0, 0, 0.8);
}
.sub-preview-bg {
  text-align: center;
  max-width: 90%;
}
.sub-preview-cue {
  display: inline-block;
  font-family: var(--font-sans);
  padding: 4px 12px;
  border-radius: 4px;
  transition: font-size 0.15s ease, color 0.15s ease, background-color 0.15s ease;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.9);
}
.sub-settings-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

/* ==========================================================================
   TOAST NOTIFICATIONS
   ========================================================================== */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background: var(--card);
  color: var(--foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 10px 16px;
  font-size: 13.5px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toastSlideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

@keyframes toastSlideUp {
  from { opacity: 0; transform: translateY(12px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.toast.toast-success {
  border-color: var(--success-edge);
  background: color-mix(in oklab, var(--card) 90%, var(--success-soft));
}
.toast.toast-error {
  border-color: var(--destructive-edge);
  background: color-mix(in oklab, var(--card) 90%, var(--destructive-soft));
}

/* ==========================================================================
   MOBILE SIDEBAR DRAWER & BACKDROP (DESKTOP HIDDEN)
   ========================================================================== */
.sidebar-backdrop {
  display: none;
}

.mobile-sidebar-header {
  display: none;
}

/* ==========================================================================
   RESPONSIVE DESIGN (TABLETS & MOBILE)
   ========================================================================== */
@media (max-width: 880px) {
  main.layout {
    display: block;
    position: relative;
    grid-template-columns: 1fr;
    height: calc(100vh - 60px);
    height: calc(100dvh - 60px);
    overflow: hidden;
  }

  main.layout.sidebar-collapsed {
    grid-template-columns: 1fr;
  }

  /* Off-canvas Drawer on Mobile */
  aside.catalog {
    position: fixed;
    top: 60px;
    left: 0;
    bottom: 0;
    width: min(85vw, 340px);
    height: calc(100vh - 60px);
    height: calc(100dvh - 60px);
    max-height: none;
    background: var(--sidebar);
    border-right: 1px solid var(--sidebar-border);
    border-bottom: none;
    box-shadow: var(--shadow-lg);
    z-index: 60;
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.28s ease;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    opacity: 1 !important;
    pointer-events: auto !important;
  }

  #app-view.mobile-sidebar-open aside.catalog {
    transform: translateX(0);
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.5);
  }

  /* Mobile Backdrop */
  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    top: 60px;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
    z-index: 50;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
  }

  #app-view.mobile-sidebar-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  /* Mobile Drawer Header */
  .mobile-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    background: var(--sidebar);
    border-bottom: 1px solid var(--border-subtle);
    position: sticky;
    top: 0;
    z-index: 20;
  }
  .mobile-sidebar-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--foreground);
    letter-spacing: -0.01em;
  }

  /* Player Area on Mobile takes full width & height */
  section.player-area {
    padding: 14px;
    height: 100%;
    width: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Mobile inputs safeguard against iOS zoom */
  input, textarea, select {
    font-size: 16px !important;
  }

  /* Header adjustments for smaller screens */
  header.topbar {
    padding: 0 max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left));
    gap: 8px;
  }
  #sidebar-toggle-btn {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    padding: 0;
  }
  .topbar-left {
    gap: 10px;
    flex-shrink: 0;
  }
  .brand-sub {
    display: none;
  }
  .brand-name {
    font-size: 13.5px;
  }

  /* Hide horizontal tabs and show modern dropdown menu on mobile */
  nav.tabs {
    display: none !important;
  }
  .mobile-tabs-dropdown {
    display: inline-flex;
    flex-shrink: 0;
  }
  .mobile-tabs-backdrop:not(.hidden) {
    display: block;
  }
  .mobile-tabs-menu:not(.hidden) {
    display: flex;
  }

  .user-profile .who {
    display: none;
  }
  .user-profile {
    padding: 3px;
  }

  #logout-btn .btn-label {
    display: none;
  }
  #logout-btn {
    padding: 6px 8px;
  }

  /* Lesson top bar mobile wrapping */
  .lesson-top-bar {
    gap: 10px;
  }
  .breadcrumbs {
    font-size: 11.5px;
    width: 100%;
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: none;
  }
  .breadcrumbs::-webkit-scrollbar {
    display: none;
  }

  /* Player toolbar on mobile */
  .player-toolbar {
    padding: 8px 12px;
    gap: 10px;
  }
  .toolbar-group {
    gap: 10px;
  }
  .btn-toolbar span {
    display: none;
  }
  .btn-toolbar {
    padding: 6px 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
