/* ============================================
   AiConcorsi — Design System
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ---------- CSS Variables (Light Theme) ---------- */
:root {
  /* Primary palette */
  --primary: #4F46E5;
  --primary-hover: #4338CA;
  --primary-light: #EEF2FF;
  --primary-subtle: rgba(79, 70, 229, 0.08);

  /* Accent */
  --accent: #06B6D4;
  --accent-hover: #0891B2;

  /* Success / Warning / Error */
  --success: #10B981;
  --success-bg: #ECFDF5;
  --warning: #F59E0B;
  --warning-bg: #FFFBEB;
  --error: #EF4444;
  --error-bg: #FEF2F2;

  /* Surfaces */
  --bg-body: #F8FAFC;
  --bg-surface: #FFFFFF;
  --bg-surface-hover: #F1F5F9;
  --bg-sidebar: rgba(255, 255, 255, 0.85);
  --bg-input: #F1F5F9;
  --bg-overlay: rgba(15, 23, 42, 0.45);

  /* Borders */
  --border: #E2E8F0;
  --border-light: #F1F5F9;

  /* Text */
  --text-primary: #0F172A;
  --text-secondary: #475569;
  --text-tertiary: #94A3B8;
  --text-inverse: #FFFFFF;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.12);
  --shadow-xl: 0 20px 60px rgba(0, 0, 0, 0.15);

  /* Layout */
  --sidebar-width: 280px;
  --header-height: 60px;
  --chat-input-height: 64px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
  --transition-slow: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---------- Dark Theme ---------- */
[data-theme="dark"] {
  --primary: #818CF8;
  --primary-hover: #6366F1;
  --primary-light: rgba(129, 140, 248, 0.12);
  --primary-subtle: rgba(129, 140, 248, 0.06);

  --accent: #22D3EE;
  --accent-hover: #06B6D4;

  --success: #34D399;
  --success-bg: rgba(52, 211, 153, 0.1);
  --warning: #FBBF24;
  --warning-bg: rgba(251, 191, 36, 0.1);
  --error: #F87171;
  --error-bg: rgba(248, 113, 113, 0.1);

  --bg-body: #0B1120;
  --bg-surface: #151D2E;
  --bg-surface-hover: #1E293B;
  --bg-sidebar: rgba(21, 29, 46, 0.92);
  --bg-input: #1E293B;
  --bg-overlay: rgba(0, 0, 0, 0.6);

  --border: #1E293B;
  --border-light: #1E293B;

  --text-primary: #F1F5F9;
  --text-secondary: #94A3B8;
  --text-tertiary: #475569;
  --text-inverse: #0F172A;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.4);
  --shadow-xl: 0 20px 60px rgba(0, 0, 0, 0.5);
}

/* ---------- Reset & Base ---------- */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-body);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  transition: background var(--transition-normal), color var(--transition-normal);
  overflow-x: hidden;
  width: 100%;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--primary-hover);
}

button {
  cursor: pointer;
  border: none;
  background: none;
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

/* ---------- Layout ---------- */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  margin-left: var(--sidebar-width);
  transition: margin-left var(--transition-slow);
  overflow-x: hidden;
  max-width: 100vw;
  position: relative;
}

/* ---------- Header ---------- */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: background var(--transition-normal), border-color var(--transition-normal);
  overflow: hidden;
  min-width: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.hamburger {
  display: none;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
}

.hamburger:hover {
  background: var(--bg-surface-hover);
}

.hamburger svg {
  width: 22px;
  height: 22px;
  stroke: var(--text-primary);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--text-primary);
}

.logo-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 800;
  font-size: 0.9rem;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  min-width: 0;
}

/* Theme toggle */
.theme-toggle {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  transition: background var(--transition-fast);
  position: relative;
}

.theme-toggle:hover {
  background: var(--bg-surface-hover);
}

.theme-toggle svg {
  width: 20px;
  height: 20px;
  stroke: var(--text-secondary);
  transition: stroke var(--transition-fast), transform var(--transition-normal);
}

.theme-toggle:hover svg {
  stroke: var(--text-primary);
}

.theme-toggle .icon-sun {
  display: block;
}

.theme-toggle .icon-moon {
  display: none;
}

[data-theme="dark"] .theme-toggle .icon-sun {
  display: none;
}

[data-theme="dark"] .theme-toggle .icon-moon {
  display: block;
}

/* Auth buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: var(--radius-full);
  font-weight: 500;
  font-size: 0.875rem;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.btn-ghost {
  color: var(--text-secondary);
}

.btn-ghost:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary) !important;
}

.btn-secondary {
  background: var(--bg-surface-secondary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary) !important;
  border-color: var(--text-tertiary);
}

.btn-primary {
  background: var(--primary);
  color: var(--text-inverse);
}

.btn-primary:hover {
  background: var(--primary-hover);
  color: #ffffff !important;
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-success {
  background: #22c55e;
  color: #ffffff;
}

.btn-success:hover {
  background: #16a34a;
  color: #ffffff !important;
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  display: flex;
  flex-direction: column;
  z-index: 200;
  transition: transform var(--transition-slow), background var(--transition-normal);
  overflow: hidden;
}

.sidebar-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-header .logo {
  font-size: 1.1rem;
}

.sidebar-close {
  display: none;
  width: 32px;
  height: 32px;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
}

.sidebar-close:hover {
  background: var(--bg-surface-hover);
}

.sidebar-close svg {
  width: 18px;
  height: 18px;
  stroke: var(--text-secondary);
}

.sidebar-search {
  position: relative;
  margin: 10px 12px 16px;
  display: flex;
  align-items: center;
}

.sidebar-search .search-icon {
  position: absolute;
  left: 12px;
  width: 16px;
  height: 16px;
  stroke: var(--text-tertiary);
  pointer-events: none;
}

.sidebar-search input {
  width: 100%;
  padding: 10px 12px 10px 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface-hover);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
  transition: all var(--transition-fast);
  outline: none;
}

.sidebar-search input:focus {
  border-color: var(--primary);
  background: var(--bg-surface);
  box-shadow: 0 0 0 2px var(--primary-subtle);
}

.sidebar-search input::placeholder {
  color: var(--text-tertiary);
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
}

.sidebar-section {
  padding: 0 12px;
  margin-bottom: 8px;
}

.sidebar-section-title {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
  padding: 8px 12px 6px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 450;
  transition: all var(--transition-fast);
}

.sidebar-link:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

.sidebar-link.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

.sidebar-link svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  flex-shrink: 0;
}

.sidebar-link .badge {
  margin-left: auto;
  background: var(--primary);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  min-width: 20px;
  text-align: center;
}

/* Sidebar topic index (study page) */
.topic-list {
  list-style: none;
  padding: 0 12px;
}

.topic-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.topic-item:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

.topic-item.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

.topic-item.completed {
  color: var(--success);
}

.topic-status {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border-radius: var(--radius-full);
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
  font-size: 0.65rem;
  transition: all var(--transition-fast);
}

.topic-item.completed .topic-status {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}

.topic-item.active .topic-status {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

/* Sidebar footer */
.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sidebar-footer-text {
  font-size: 0.8rem;
  color: var(--text-tertiary);
  line-height: 1.5;
}

.sidebar-footer-text a {
  color: var(--primary);
  font-weight: 500;
}

/* Theme toggle nella sidebar (solo mobile) */
.sidebar-theme-toggle {
  display: none;
  /* nascosto su desktop */
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.875rem;
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
  width: 100%;
}

.sidebar-theme-toggle:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

.sidebar-theme-toggle svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  flex-shrink: 0;
}

.sidebar-theme-toggle .icon-sun {
  display: block;
}

.sidebar-theme-toggle .icon-moon {
  display: none;
}

[data-theme="dark"] .sidebar-theme-toggle .icon-sun {
  display: none;
}

[data-theme="dark"] .sidebar-theme-toggle .icon-moon {
  display: block;
}

@media (max-width: 768px) {
  .sidebar-theme-toggle {
    display: flex;
  }
}

/* Mobile overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  z-index: 190;
  opacity: 0;
  transition: opacity var(--transition-normal);
}

.sidebar-overlay.active {
  display: block;
  opacity: 1;
}

/* ---------- Main Content ---------- */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 100%;
  overflow-x: hidden;
}

/* ---------- Homepage Chat Area ---------- */
.home-chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 24px 20px;
  text-align: center;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
}

.greeting {
  margin-bottom: 32px;
}

.greeting h1 {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
  line-height: 1.3;
}

.greeting p {
  font-size: 1rem;
  color: var(--text-secondary);
}

/* Chat Input */
.chat-input-wrapper {
  width: 100%;
  max-width: 640px;
  margin-bottom: 20px;
}

.chat-input-box {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg-surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  transition: all var(--transition-fast);
}

.chat-input-box:focus-within {
  border-color: var(--primary);
  box-shadow: var(--shadow-md), 0 0 0 3px var(--primary-subtle);
}

.chat-input-box textarea {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  resize: none;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--text-primary);
  line-height: 1.5;
  max-height: 120px;
  min-height: 24px;
}

.chat-input-box textarea::placeholder {
  color: var(--text-tertiary);
}

.chat-send-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.chat-send-btn:hover {
  background: var(--primary-hover);
  transform: scale(1.05);
}

.chat-send-btn svg {
  width: 18px;
  height: 18px;
  stroke: #fff;
  fill: none;
}

/* Suggestion chips */
.chips-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 20px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.chip:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}

.chip svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
}

/* ---------- News Section ---------- */
.news-section {
  padding: 0 24px 48px;
  max-width: 960px;
  margin: 0 auto;
  width: 100%;
}

.news-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.news-section-header h2 {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-primary);
}

.news-section-header a {
  font-size: 0.875rem;
  font-weight: 500;
}

.news-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

.news-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: all var(--transition-fast);
  position: relative;
  /* For clickable full card */
}

.news-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-xl);
  border-color: var(--primary-light);
}

.news-card a.news-card-link-overlay {
  color: inherit;
  text-decoration: none;
}

.news-card a.news-card-link-overlay::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 10;
}

.news-card-img {
  width: 100%;
  height: 160px;
  object-fit: cover;
  background: linear-gradient(135deg, var(--primary-light), var(--bg-surface-hover));
  display: flex;
  align-items: center;
  justify-content: center;
}

.news-card-img-placeholder {
  width: 100%;
  height: 160px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.5);
  font-size: 2rem;
}

.news-card-body {
  padding: 16px;
}

.news-card-tag {
  display: inline-block;
  padding: 3px 10px;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: var(--radius-full);
  margin-bottom: 8px;
}

.news-card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
  line-height: 1.4;
}

.news-card-excerpt {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 10px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.news-card-meta {
  font-size: 0.78rem;
  color: var(--text-tertiary);
}

/* ---------- Study Page ---------- */
.study-header {
  padding: 16px 24px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
}

.study-breadcrumb {
  font-size: 0.82rem;
  color: var(--text-tertiary);
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.study-breadcrumb a {
  color: var(--primary);
}

.study-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  word-break: break-word;
}

/* Progress bar */
.progress-bar-wrap {
  height: 4px;
  background: var(--border);
  position: relative;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: 0 2px 2px 0;
  transition: width var(--transition-slow);
}

/* Chunk container */
.study-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chunk-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 28px 24px 200px;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
}

.chunk-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 28px;
  margin-bottom: 24px;
  transition: all var(--transition-fast);
}

.chunk-card h2 {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text-primary);
}

.chunk-card h3 {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 20px 0 10px;
  color: var(--text-primary);
}

.chunk-card p {
  font-size: 0.95rem;
  color: var(--text-primary);
  line-height: 1.7;
  margin-bottom: 12px;
}

.chunk-card ul,
.chunk-card ol {
  margin: 8px 0 12px 20px;
  color: var(--text-primary);
  font-size: 0.95rem;
  line-height: 1.7;
}

.chunk-card li {
  margin-bottom: 4px;
}

/* Normative reference link */
.norm-ref {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--primary);
  font-weight: 500;
  cursor: pointer;
  border-bottom: 1px dashed var(--primary);
  transition: all var(--transition-fast);
}

.norm-ref:hover {
  color: var(--primary-hover);
}

.norm-ref svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
}

/* Chunk navigation */
.chunk-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 40px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.chunk-nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 0.9rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}

.chunk-nav-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}

.chunk-nav-btn svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
}

.chunk-nav-info {
  font-size: 0.82rem;
  color: var(--text-tertiary);
  font-weight: 500;
}

.chunk-nav-placeholder {
  width: 120px;
  /* Base width to match buttons approximately */
}

@media (max-width: 480px) {
  .chunk-nav-placeholder {
    width: 40px;
    /* Narrower on mobile */
  }
}

/* ---------- Study Chat (bottom panel — FIXED) ---------- */
.study-chat-panel {
  position: fixed;
  bottom: 0;
  left: var(--sidebar-width);
  right: 0;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  padding: 12px 24px;
  z-index: 100;
  transition: left var(--transition-slow), background var(--transition-normal), border-color var(--transition-normal);
  box-shadow: 0 -6px 30px rgba(0, 0, 0, 0.12), 0 -1px 0 var(--border);
}

.study-chat-suggestions {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.study-chat-suggestions .chip {
  padding: 5px 11px;
  font-size: 0.76rem;
  gap: 4px;
}

.study-chat-suggestions .chip svg {
  width: 12px;
  height: 12px;
}

.study-chat-suggestions::-webkit-scrollbar {
  display: none;
}

.study-chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.study-chat-input-row textarea {
  flex: 1;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--text-primary);
  background: var(--bg-input);
  resize: none;
  outline: none;
  min-height: 42px;
  max-height: 100px;
  line-height: 1.5;
  transition: border-color var(--transition-fast);
}

.study-chat-input-row textarea::placeholder {
  color: var(--text-tertiary);
}

.study-chat-input-row textarea:focus {
  border-color: var(--primary);
}

/* Inline chat messages (nel chunk-scroll) */
.inline-chat-messages {
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin-bottom: 8px;
}

.chat-msg {
  animation: fadeUp 0.35s ease;
  font-size: 0.95rem;
  line-height: 1.7;
}

/* Course Access Control */
.locked-content {
  filter: blur(10px);
  pointer-events: none;
  user-select: none;
  opacity: 0.6;
}

.access-control-container {
  position: relative;
  min-height: 400px;
}

.access-guard-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  z-index: 50;
  padding: 80px 24px 24px;
}

.access-guard-box {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  max-width: 480px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-xl);
  animation: fadeUp 0.4s ease-out;
}

.access-guard-icon {
  width: 64px;
  height: 64px;
  background: var(--primary-light);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 24px;
  color: var(--primary);
}

.access-guard-icon svg {
  width: 32px;
  height: 32px;
  stroke: currentColor;
}

.access-guard-box h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--text-primary);
}

.access-guard-box p {
  color: var(--text-secondary);
  margin-bottom: 32px;
  line-height: 1.6;
}

.access-guard-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.access-guard-btn {
  width: 100%;
  justify-content: center;
  padding: 14px;
  font-size: 1rem;
}

/* Risposta AI: blocco testo con bordo laterale */
.chat-msg-ai {
  border-left: 3px solid var(--primary);
  padding: 14px 18px;
  background: var(--primary-subtle);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  color: var(--text-primary);
}

.chat-msg-ai strong {
  font-weight: 700;
}

.chat-msg-ai em {
  font-style: italic;
}

.chat-msg-ai code {
  background: var(--bg-surface-hover);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.88em;
}

.chat-msg-ai ol {
  margin: 6px 0 6px 18px;
}

.chat-msg-ai ol li {
  margin-bottom: 4px;
}

/* Riga azioni sotto la risposta AI */
.chat-msg-actions {
  display: flex;
  gap: 6px;
  margin-top: -12px;
  /* incollata sotto il blocco risposta */
  margin-bottom: 8px;
  padding-left: 4px;
  animation: fadeUp 0.3s ease;
}

.ai-action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-tertiary);
  transition: all var(--transition-fast);
  cursor: pointer;
}

.ai-action-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--primary);
}

.ai-action-btn.copied,
.ai-action-btn.active {
  color: var(--primary);
}

.ai-action-btn svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
}

/* spinner TTS loading */
@keyframes aiSpin {
  to {
    transform: rotate(360deg);
  }
}

.ai-action-spin {
  animation: aiSpin 0.8s linear infinite;
}

/* Typing indicator */
.typing-indicator {
  display: inline-flex;
  gap: 4px;
  padding: 10px 14px;
  background: var(--primary-subtle);
  border-left: 3px solid var(--primary);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  animation: fadeUp 0.25s ease;
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-tertiary);
  animation: typingBounce 1.2s infinite;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

/* ---------- Quiz Panel ---------- */
.quiz-panel {
  display: none;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 24px;
  margin-bottom: 24px;
  animation: fadeUp 0.3s ease;
}

.quiz-panel.active {
  display: block;
}

.quiz-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.quiz-panel-header h3 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.quiz-panel-header h3 svg {
  width: 20px;
  height: 20px;
  stroke: var(--primary);
}

.quiz-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
}

.quiz-close:hover {
  background: var(--bg-surface-hover);
}

.quiz-close svg {
  width: 18px;
  height: 18px;
  stroke: var(--text-secondary);
}

.quiz-question {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 16px;
  line-height: 1.5;
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}

.quiz-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.quiz-option:hover {
  border-color: var(--primary);
  background: var(--primary-subtle);
  color: var(--text-primary);
}

.quiz-option.selected {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 500;
}

.quiz-option.correct {
  border-color: var(--success);
  background: var(--success-bg);
  color: var(--success);
}

.quiz-option.wrong {
  border-color: var(--error);
  background: var(--error-bg);
  color: var(--error);
}

.quiz-option-letter {
  width: 26px;
  height: 26px;
  border-radius: var(--radius-full);
  border: 1.5px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.8rem;
  flex-shrink: 0;
  transition: all var(--transition-fast);
}

.quiz-option.selected .quiz-option-letter {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.quiz-option.correct .quiz-option-letter {
  border-color: var(--success);
  background: var(--success);
  color: #fff;
}

.quiz-option.wrong .quiz-option-letter {
  border-color: var(--error);
  background: var(--error);
  color: #fff;
}

.quiz-feedback {
  display: none;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 16px;
  animation: fadeUp 0.25s ease;
}

.quiz-feedback.show {
  display: flex;
  align-items: center;
  gap: 8px;
}

.quiz-feedback.correct {
  background: var(--success-bg);
  color: var(--success);
}

.quiz-feedback.wrong {
  background: var(--error-bg);
  color: var(--error);
}

.quiz-feedback svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  flex-shrink: 0;
}

.quiz-btn {
  padding: 10px 24px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.9rem;
  transition: all var(--transition-fast);
}

.quiz-btn-verify {
  background: var(--primary);
  color: #fff;
}

.quiz-btn-verify:hover {
  background: var(--primary-hover);
  color: #fff;
}

/* ---------- Modal (normative references) ---------- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  z-index: 500;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn 0.2s ease;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 95%;
  max-height: 95vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-xl);
  animation: modalSlideUp 0.3s ease;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
}

.modal-close:hover {
  background: var(--bg-surface-hover);
}

.modal-close svg {
  width: 18px;
  height: 18px;
  stroke: var(--text-secondary);
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
  font-size: 0.92rem;
  color: var(--text-secondary);
  line-height: 1.7;
}

.modal-body h4 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 16px 0 8px;
}

.modal-body h4:first-child {
  margin-top: 0;
}

.modal-body p {
  margin-bottom: 10px;
}

.modal-body blockquote {
  border-left: 3px solid var(--primary);
  padding: 12px 16px;
  background: var(--primary-subtle);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin: 12px 0;
  font-style: italic;
}

/* ---------- Footer ---------- */
.footer {
  padding: 16px 24px;
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-tertiary);
  border-top: 1px solid var(--border);
}

.footer a {
  color: var(--primary);
  font-weight: 500;
}

/* ---------- Animations ---------- */
@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes modalSlideUp {
  from {
    opacity: 0;
    transform: translateY(30px) scale(0.97);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes typingBounce {

  0%,
  60%,
  100% {
    transform: translateY(0);
  }

  30% {
    transform: translateY(-5px);
  }
}

/* ---------- Scrollbar Styling ---------- */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

/* ---------- Single News Layout ---------- */
.single-news-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 40px 24px 60px;
  animation: fadeUp 0.4s ease;
  overflow: hidden;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.single-news-back {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.95rem;
  margin-bottom: 24px;
  transition: color var(--transition-fast);
}

.single-news-back:hover {
  color: var(--primary);
}

.single-news-back svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
}

.single-news-cover {
  width: 100%;
  height: 320px;
  border-radius: var(--radius-xl);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 32px;
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
}

.single-news-cover svg {
  width: 80px;
  height: 80px;
  stroke: rgba(255, 255, 255, 0.4);
}

.single-news-header {
  margin-bottom: 40px;
}

.single-news-header .news-card-tag {
  display: inline-block;
  margin-bottom: 16px;
  font-size: 0.85rem;
  padding: 4px 12px;
  border-radius: var(--radius-full);
}

.single-news-title {
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.2;
  margin-bottom: 16px;
  letter-spacing: -0.02em;
  word-wrap: break-word;
  overflow-wrap: break-word;
  hyphens: auto;
}

.single-news-meta {
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--text-tertiary);
  font-size: 0.95rem;
  font-weight: 500;
}

.single-news-meta span {
  display: flex;
  align-items: center;
  gap: 6px;
}

.single-news-meta svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
}

.single-news-content {
  font-size: 1.05rem;
  line-height: 1.8;
  color: var(--text-primary);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.single-news-content p {
  margin-bottom: 24px;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.single-news-content h2 {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 48px 0 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.single-news-content h3 {
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 32px 0 16px;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.single-news-content ul,
.single-news-content ol {
  margin-bottom: 24px;
  padding-left: 24px;
}

.single-news-content li {
  margin-bottom: 10px;
}

.single-news-content li::marker {
  color: var(--primary);
  font-weight: bold;
}

.single-news-content blockquote {
  border-left: 4px solid var(--primary);
  background: var(--primary-subtle);
  padding: 24px 32px;
  border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
  margin: 32px 0;
  font-style: italic;
  font-size: 1.1rem;
  color: var(--text-secondary);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.single-news-content strong {
  color: var(--text-primary);
  font-weight: 600;
}

.news-share-block {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.news-share-label {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.news-share-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: var(--bg-surface-hover);
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}

.news-share-btn:hover {
  transform: translateY(-2px);
  color: #fff;
}

.news-share-btn.fb:hover {
  background: #1877F2;
}

.news-share-btn.x:hover {
  background: #000000;
}

[data-theme="dark"] .news-share-btn.x:hover {
  background: #333;
}

.news-share-btn.wa:hover {
  background: #25D366;
}

.news-share-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.news-call-to-action {
  background: linear-gradient(135deg, var(--bg-surface), var(--primary-light));
  border: 1px solid var(--primary-subtle);
  border-radius: var(--radius-lg);
  padding: 32px;
  text-align: center;
  margin-top: 60px;
}

.news-call-to-action h3 {
  margin: 0 0 12px;
  font-size: 1.4rem;
}

.news-call-to-action p {
  color: var(--text-secondary);
  margin-bottom: 24px;
  font-size: 0.95rem;
}

/* ---------- Pagination (Google-style) ---------- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 40px 0;
  padding: 0;
  list-style: none;
}

.page-item {
  display: inline-flex;
}

.page-link {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  border-radius: var(--radius-full);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all var(--transition-fast);
}

.page-link:hover:not(.disabled) {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

.page-item.active .page-link {
  background: var(--primary);
  color: white;
  pointer-events: none;
}

.page-item.disabled .page-link {
  color: var(--text-tertiary);
  pointer-events: none;
  opacity: 0.6;
}

.page-link svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
}

.pagination-ellipsis {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  color: var(--text-tertiary);
  font-weight: 600;
}

/* ---------- Authentication Pages (Login/Register) ---------- */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg-body);
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 440px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 40px;
  box-shadow: var(--shadow-xl);
  animation: fadeUp 0.3s ease;
  position: relative;
  overflow: hidden;
}

.auth-header {
  text-align: center;
  margin-bottom: 32px;
}

.auth-header .logo {
  justify-content: center;
  margin-bottom: 24px;
}

.auth-header h1 {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.auth-header p {
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.auth-form-group {
  margin-bottom: 20px;
}

.auth-form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.auth-form-group input:not([type="checkbox"]) {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--text-primary);
  background: var(--bg-input);
  outline: none;
  transition: all var(--transition-fast);
}

.auth-form-group input:not([type="checkbox"])::placeholder {
  color: var(--text-tertiary);
}

.auth-form-group input:not([type="checkbox"]):focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-subtle);
}

.auth-options {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  font-size: 0.85rem;
}

.auth-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}

.auth-checkbox input[type="checkbox"] {
  accent-color: var(--primary);
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.auth-options a,
.auth-footer a {
  color: var(--primary);
  font-weight: 500;
  text-decoration: none;
}

.auth-options a:hover,
.auth-footer a:hover {
  color: var(--primary-hover);
  text-decoration: underline;
}

.auth-btn {
  width: 100%;
  padding: 12px;
  font-size: 1rem;
  justify-content: center;
  border-radius: var(--radius-md);
}

.auth-footer {
  text-align: center;
  margin-top: 24px;
  font-size: 0.9rem;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
  padding-top: 24px;
}

.auth-divider {
  display: flex;
  align-items: center;
  text-align: center;
  margin: 24px 0;
  color: var(--text-tertiary);
  font-size: 0.85rem;
  font-weight: 500;
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid var(--border);
}

.auth-divider::before {
  margin-right: 12px;
}

.auth-divider::after {
  margin-left: 12px;
}

/* ---------- Student Dashboard (Le mie sessioni) ---------- */
.dashboard-container {
  padding: 40px 32px 80px;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

.dashboard-header {
  margin-bottom: 32px;
}

.dashboard-header h1 {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.dashboard-header p {
  color: var(--text-secondary);
  font-size: 0.95rem;
}

/* Stats Grid */
.dashboard-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 24px;
  margin-bottom: 40px;
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--primary-light);
}

.stat-icon {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-icon.primary {
  background: rgba(99, 102, 241, 0.1);
  color: var(--primary);
}

.stat-icon.success {
  background: rgba(16, 185, 129, 0.1);
  color: #10B981;
}

.stat-icon.warning {
  background: rgba(245, 158, 11, 0.1);
  color: #F59E0B;
}

.stat-icon svg {
  width: 28px;
  height: 28px;
  stroke-width: 2;
}

.stat-info {
  flex: 1;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.2;
}

.stat-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 500;
  margin-top: 4px;
}

/* Two-column layout */
.dashboard-content-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 32px;
}

@media (max-width: 1024px) {
  .dashboard-content-grid {
    grid-template-columns: 1fr;
  }
}

.dashboard-section-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Course Cards */
.course-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.course-progress-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  transition: all var(--transition-fast);
}

.course-progress-card:hover {
  border-color: var(--primary-light);
  box-shadow: var(--shadow-sm);
}

.course-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.course-title-group h3 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.course-title-group p {
  font-size: 0.85rem;
  color: var(--text-tertiary);
}

.course-action .btn {
  padding: 6px 14px;
  font-size: 0.8rem;
}

.progress-container {
  width: 100%;
}

.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 0.85rem;
  font-weight: 500;
}

.progress-text {
  color: var(--text-secondary);
}

.progress-pct {
  color: var(--primary);
  font-weight: 700;
}

.progress-track {
  width: 100%;
  height: 8px;
  background: var(--bg-surface-hover);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--primary-hover));
  border-radius: var(--radius-full);
  transition: width 1s ease-out;
}

/* Activity Timeline */
.activity-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px 24px 16px;
  /* Reduced bottom padding */
  height: fit-content;
  align-self: start;
}

.activity-list {
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: relative;
}

/* Timeline vertical line */
.activity-list::before {
  content: '';
  position: absolute;
  left: 19px;
  top: 8px;
  bottom: 30px;
  /* stops before the last item's text ends */
  width: 2px;
  background: var(--border);
  z-index: 1;
}

.activity-item {
  display: flex;
  gap: 16px;
  position: relative;
  z-index: 2;
}

.activity-dot {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-surface);
  border: 2px solid var(--primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--primary);
}

.activity-dot svg {
  width: 18px;
  height: 18px;
}

.activity-content {
  padding-top: 4px;
}

.activity-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.activity-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.activity-time {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-tertiary);
  display: flex;
  align-items: center;
  gap: 4px;
}

.activity-time svg {
  width: 12px;
  height: 12px;
}


/* ---------- Responsive Images ---------- */
img {
  max-width: 100%;
  height: auto;
  display: block;
}

.single-news-content img {
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  margin: 20px 0;
}

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
  .news-grid {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  }

  .dashboard-container {
    padding: 32px 24px 64px;
  }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-wrapper {
    margin-left: 0;
  }

  .hamburger {
    display: flex;
  }

  .sidebar-close {
    display: flex;
  }

  .sidebar-header .logo {
    display: flex;
    /* visibile su mobile: l'header è coperto dalla sidebar */
  }

  .header {
    padding: 0 12px;
    gap: 8px;
  }

  .logo span:not(.logo-icon) {
    font-size: 1rem;
  }

  .study-header {
    padding: 12px 16px;
  }

  .home-chat-area {
    padding: 32px 16px;
  }

  .greeting h1 {
    font-size: 1.4rem;
  }

  .news-section {
    padding: 0 16px 32px;
  }

  .news-grid {
    grid-template-columns: 1fr;
  }

  .chunk-scroll {
    padding: 20px 16px 220px; /* Aumentato ulteriormente per evitare sovrapposizione con barra chat quando i chip vanno a capo */
  }

  .chunk-card {
    padding: 20px;
  }

  .chunk-card h2 {
    font-size: 1.15rem;
  }

  .study-chat-panel {
    left: 0;
    padding: 10px 16px;
  }

  .study-chat-suggestions {
    flex-wrap: wrap;
    overflow-x: visible;
  }

  /* Theme toggle si sposta nella sidebar — nascosto nell'header */
  .header .theme-toggle {
    display: none;
  }

  /* Pulsanti auth: compatti ma visibili */
  .header-right {
    gap: 4px;
    /* distanzia un po' i bottoni */
  }

  .btn-ghost,
  .btn-primary {
    padding: 6px 12px;
    font-size: 0.8rem;
  }


  .modal {
    max-width: 100%;
    max-height: 90vh;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    margin-top: auto;
  }

  .chat-msg {
    max-width: 90%;
  }

  /* Single News Responsive */
  .single-news-container {
    max-width: 100%;
    padding: 24px 16px 40px;
    overflow: hidden;
    word-wrap: break-word;
    overflow-wrap: break-word;
  }

  .single-news-cover {
    height: 200px;
    margin-bottom: 24px;
  }

  .single-news-title {
    font-size: 1.8rem;
    line-height: 1.3;
    margin-bottom: 12px;
  }

  .single-news-meta {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    font-size: 0.85rem;
  }

  .single-news-content {
    font-size: 1rem;
    line-height: 1.7;
  }

  .single-news-content h2 {
    font-size: 1.4rem;
    margin: 32px 0 16px;
  }

  .single-news-content h3 {
    font-size: 1.2rem;
    margin: 24px 0 12px;
  }

  .single-news-content blockquote {
    padding: 16px 20px;
    margin: 24px 0;
    font-size: 1rem;
  }

  .news-share-block {
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 32px;
  }

  .news-call-to-action {
    padding: 24px 20px;
    margin-top: 40px;
  }

  .news-call-to-action h3 {
    font-size: 1.2rem;
  }
}

@media (max-width: 480px) {
  .greeting h1 {
    font-size: 1.2rem;
  }

  .chunk-nav {
    flex-direction: column;
  }

  .chunk-nav-btn {
    width: 100%;
    justify-content: center;
  }

  /* Single News Small Mobile */
  .single-news-container {
    max-width: 100%;
    padding: 20px 12px 32px;
    overflow: hidden;
    word-wrap: break-word;
    overflow-wrap: break-word;
  }

  .single-news-cover {
    height: 160px;
    margin-bottom: 20px;
  }

  .single-news-title {
    font-size: 1.5rem;
    line-height: 1.3;
    margin-bottom: 10px;
  }

  .single-news-meta {
    font-size: 0.8rem;
  }

  .single-news-content {
    font-size: 0.95rem;
    line-height: 1.6;
  }

  .single-news-content h2 {
    font-size: 1.3rem;
    margin: 28px 0 14px;
  }

  .single-news-content h3 {
    font-size: 1.1rem;
    margin: 20px 0 10px;
  }

  .single-news-content blockquote {
    padding: 14px 16px;
    margin: 20px 0;
    font-size: 0.95rem;
  }

  .news-share-block {
    margin-top: 24px;
  }

  .news-share-btn {
    width: 36px;
    height: 36px;
  }

  .news-call-to-action {
    padding: 20px 16px;
    margin-top: 32px;
  }

  .news-call-to-action h3 {
    font-size: 1.1rem;
  }

  .news-call-to-action p {
    font-size: 0.9rem;
  }
}

/* ---------- Sidebar — utente loggato ---------- */
.sidebar-user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-surface-hover);
  border-radius: var(--radius-md);
  margin-bottom: 6px;
}

.sidebar-user-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: .5px;
  flex-shrink: 0;
}

.sidebar-user-info {
  min-width: 0;
  flex: 1;
}

.sidebar-user-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-email {
  font-size: 0.72rem;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-logout-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  color: #ef4444;
  text-decoration: none;
  transition: background var(--transition-fast);
}

.sidebar-logout-btn:hover {
  background: rgba(239, 68, 68, .08);
  color: #ef4444;
}

.sidebar-logout-btn svg {
  width: 15px;
  height: 15px;
  stroke: currentColor;
  flex-shrink: 0;
}

/* ===== Chapter Completion Button ===== */
.chunk-completion-wrap {
  display: flex;
  justify-content: center;
  padding: 24px 0 8px;
}

.mark-complete-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 20px;
  border-radius: var(--radius-full);
  border: 1.5px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.mark-complete-btn svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
}

.mark-complete-btn:hover {
  border-color: #22c55e;
  color: #22c55e;
  background: rgba(34, 197, 94, 0.06);
}

.mark-complete-btn.completed {
  border-color: #22c55e;
  color: #22c55e;
  background: rgba(34, 197, 94, 0.1);
}

/* ===== Disabled chat panel: compact single-row ===== */
.study-chat-panel.disabled {
  padding: 8px 24px;
}

.study-chat-panel.disabled .study-chat-input-row textarea {
  min-height: 38px;
  max-height: 38px;
  resize: none;
}

/* ---------- Popover Bubble (Fumetto) ---------- */
.popover-bubble {
  display: none;
  position: absolute;
  bottom: 80px;
  left: 24px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  width: 320px;
  z-index: 200;
  padding: 16px;
  animation: fadeUp 0.3s ease;
}

.popover-bubble.active {
  display: block;
}

.popover-bubble::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 24px;
  border-width: 8px;
  border-style: solid;
  border-color: var(--bg-surface) transparent transparent transparent;
}

.popover-bubble::before {
  content: '';
  position: absolute;
  top: 100%;
  left: 23px;
  border-width: 9px;
  border-style: solid;
  border-color: var(--border) transparent transparent transparent;
}

.popover-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-primary);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.popover-header svg {
  width: 18px;
  height: 18px;
  stroke: var(--primary);
}

.popover-body {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ref-badge {
  display: inline-block;
  background: var(--primary-light);
  color: var(--primary);
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  border: 1px solid var(--primary-subtle);
}

/* ---------- Cookie Banner ---------- */
.cookie-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
  z-index: 1000;
  transform: translateY(100%);
  transition: transform 0.3s ease-in-out;
}

.cookie-banner.show {
  transform: translateY(0);
}

.cookie-banner-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}

.cookie-banner-text {
  flex: 1;
  min-width: 250px;
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.4;
  text-align: center;
}

.cookie-banner-text strong {
  color: var(--text-primary);
}

.cookie-banner-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

.cookie-btn {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.cookie-btn-accept {
  background: var(--primary);
  color: var(--text-inverse);
}

.cookie-btn-accept:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.cookie-btn-reject {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.cookie-btn-reject:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

.cookie-btn-settings {
  background: transparent;
  color: var(--primary);
  border: none;
  font-size: 0.8rem;
  text-decoration: underline;
  padding: 4px 8px;
}

.cookie-btn-settings:hover {
  color: var(--primary-hover);
}

/* Mobile responsive */
@media (max-width: 768px) {
  .cookie-banner-content {
    flex-direction: column;
    align-items: stretch;
    text-align: center;
  }
  
  .cookie-banner-text {
    min-width: auto;
  }
  
  .cookie-banner-actions {
    justify-content: center;
    flex-wrap: wrap;
  }
  
  .cookie-btn {
    flex: 1;
    min-width: 120px;
    justify-content: center;
  }
}

[data-theme="dark"] .popover-bubble::after {
  border-color: var(--bg-surface) transparent transparent transparent;
}

[data-theme="dark"] .ref-badge {
  background: rgba(129, 140, 248, 0.15);
  color: #a5b4fc;
}