/* Identidade visual DriveCursos. Tema escuro (padrão): tons slate/navy que
   ecoam o #1E293B da logo. Tema claro via [data-theme="light"], alternado
   pelo botão ☀️/🌙 (public/theme.js, persistido em localStorage). */
:root {
  color-scheme: dark;
  --bg: #0f1420;
  --surface: #1a2130;
  --surface-hover: #222b3d;
  --border: #2c3547;
  --text: #e8ecf5;
  --text-muted: #94a0b8;
  --accent: #3b82f6;
  --success: #3ecf8e;
  --warning: #f9ab00;
  --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  --card-shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.45);
  --thumb-bg: #0b0e15;
  --badge-yellow-bg: rgba(249, 171, 0, 0.14);
  --badge-yellow-text: #fbc84a;
}

:root[data-theme='light'] {
  color-scheme: light;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-hover: #f1f5fb;
  --border: #e3e8f0;
  --text: #1e293b;
  --text-muted: #5f6b85;
  --accent: #2563eb;
  --success: #34a853;
  --card-shadow: 0 1px 3px rgba(30, 42, 74, 0.08);
  --card-shadow-hover: 0 4px 12px rgba(30, 42, 74, 0.12);
  --thumb-bg: #e8ecf3;
  --badge-yellow-bg: #fdf3d7;
  --badge-yellow-text: #7a5d00;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.page-header {
  padding: 10px 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.page-header h1 {
  margin: 8px 0 0;
  font-size: 22px;
}

.logo-link {
  display: inline-flex;
  align-items: center;
}

.logo {
  height: 38px;
  width: auto;
}

.logo-small {
  height: 32px;
}

/* Logo do wordmark por tema: escura por padrão, clara em data-theme=light */
.logo-for-light {
  display: none;
}

:root[data-theme='light'] .logo-for-dark {
  display: none;
}

:root[data-theme='light'] .logo-for-light {
  display: inline;
}

.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 0;
}

.theme-toggle:hover {
  border-color: var(--accent);
}

/* No escuro mostra o sol (ação: clarear); no claro mostra a lua */
.icon-moon {
  display: none;
}

:root[data-theme='light'] .icon-sun {
  display: none;
}

:root[data-theme='light'] .icon-moon {
  display: inline;
}

.inner-header .theme-toggle {
  margin-left: auto;
}

.inner-header {
  display: flex;
  align-items: center;
  gap: 16px;
}

.inner-header > div {
  min-width: 0;
  flex: 1;
}

.inner-header h1 {
  margin: 2px 0 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.back-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
}

.back-link:hover {
  color: var(--accent);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px;
  padding: 24px 32px;
}

.grid-flush {
  padding: 0;
}

.home-section {
  padding: 20px 32px 0;
}

.home-section:last-child {
  padding-bottom: 40px;
}

.home-section h2 {
  font-size: 15px;
  margin: 0 0 12px;
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.activity-total {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-muted);
}

.resume-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  max-width: 900px;
}

.resume-card {
  display: flex;
  gap: 14px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  text-decoration: none;
  color: var(--text);
  box-shadow: var(--card-shadow);
}

a.resume-card:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
}

.resume-thumb-wrap {
  width: 112px;
  height: 63px;
  flex-shrink: 0;
  background: var(--thumb-bg);
  border-radius: 8px;
  overflow: hidden;
}

.resume-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.resume-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.resume-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.resume-name {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.resume-course {
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.activity-chart {
  display: flex;
  gap: 6px;
  align-items: flex-end;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  max-width: 640px;
  box-shadow: var(--card-shadow);
}

.day-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.day-bar-track {
  height: 96px;
  width: 100%;
  max-width: 26px;
  display: flex;
  align-items: flex-end;
}

.day-bar {
  width: 100%;
  background: var(--accent);
  border-radius: 4px 4px 0 0;
  min-height: 0;
}

.day-label {
  font-size: 10px;
  color: var(--text-muted);
}

.video-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.video-meta {
  font-size: 11px;
  color: var(--text-muted);
}

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 48px;
  box-shadow: var(--card-shadow);
  max-width: 380px;
  text-align: center;
}

.login-logo {
  height: 48px;
}

.login-tagline {
  margin: 0;
  color: var(--text-muted);
  font-size: 14px;
}

.login-error {
  margin: 0;
  color: #ff6b6b;
  font-size: 13px;
}

.google-btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  font-size: 15px;
  font-weight: 600;
  padding: 12px 28px;
  border-radius: 999px;
}

.google-btn:hover {
  filter: brightness(1.1);
}

.logout-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
}

.logout-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

/* Item alvo de âncora (ex: vindo do "Último concluído" da home) */
.video-item:target,
.material-item:target {
  scroll-margin-top: 90px;
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  box-shadow: inset 3px 0 0 var(--accent);
}

.course-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  text-decoration: none;
  color: var(--text);
  box-shadow: var(--card-shadow);
  transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.course-card:hover {
  background: var(--surface-hover);
  transform: translateY(-2px);
  box-shadow: var(--card-shadow-hover);
}

.course-thumb-wrap {
  aspect-ratio: 16 / 9;
  background: var(--thumb-bg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.course-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.course-body {
  padding: 14px 16px;
}

.course-body h2 {
  font-size: 16px;
  margin: 0 0 10px;
  line-height: 1.3;
}

.progress-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.progress-bar {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.progress-pct {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  min-width: 34px;
  text-align: right;
}

.progress-fill {
  height: 100%;
  background: var(--success);
  border-radius: 999px;
}

.progress-label {
  font-size: 12px;
  color: var(--text-muted);
}

.course-counters {
  display: flex;
  gap: 10px;
}

.header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-row h1 {
  margin: 0;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.add-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  text-decoration: none;
}

.add-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.sync-btn {
  background: var(--accent);
  border: none;
  color: #fff;
  font-size: 13px;
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
}

.sync-btn:disabled {
  opacity: 0.6;
  cursor: wait;
}

.collection-card {
  position: relative;
}

.card-link {
  display: block;
  text-decoration: none;
  color: var(--text);
}

.kind-badge {
  display: inline-block;
  font-size: 11px;
  color: var(--badge-yellow-text);
  background: var(--badge-yellow-bg);
  padding: 2px 8px;
  border-radius: 999px;
  margin-bottom: 8px;
}

.delete-btn,
.edit-btn {
  position: absolute;
  top: 8px;
  background: rgba(13, 18, 30, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.35);
  color: #fff;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
}

.delete-btn {
  right: 8px;
}

.delete-btn:hover {
  background: #e5484d;
  border-color: #e5484d;
}

.edit-btn {
  right: 44px;
}

.edit-btn:hover {
  background: var(--accent);
  border-color: var(--accent);
}

.collection-card.editing {
  display: flex;
  align-items: center;
  min-height: 180px;
}

.rename-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  width: 100%;
}

.rename-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--text-muted);
}

.rename-form input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 10px;
  font-size: 14px;
}

.rename-actions {
  display: flex;
  gap: 8px;
}

.rename-actions button {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  font-size: 13px;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
}

.rename-actions button[type='submit'] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.add-section {
  margin: 24px 32px 48px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-width: 640px;
  box-shadow: var(--card-shadow);
}

.add-section h2 {
  font-size: 16px;
  margin: 0 0 14px;
}

.add-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.add-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--text-muted);
}

.add-form input,
.add-form select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 10px;
  font-size: 14px;
}

.add-form button {
  align-self: flex-start;
  background: var(--accent);
  border: none;
  color: #fff;
  font-size: 14px;
  padding: 8px 20px;
  border-radius: 999px;
  cursor: pointer;
}

.hint {
  font-size: 12px;
  color: var(--text-muted);
  margin: 12px 0 0;
}

.counter {
  font-size: 12px;
  color: var(--text-muted);
}

.course-page {
  padding: 16px 32px 48px;
  max-width: 900px;
  margin: 0 auto;
}

.module {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 12px;
  overflow: hidden;
  box-shadow: var(--card-shadow);
}

.module summary {
  cursor: pointer;
  padding: 14px 18px;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  list-style: none;
}

.module summary::-webkit-details-marker {
  display: none;
}

.module-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.module-progress {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 400;
  color: var(--text-muted);
}

.module-bar {
  width: 90px;
  height: 5px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.module-bar-fill {
  display: block;
  height: 100%;
  background: var(--success);
  border-radius: 999px;
  transition: width 0.3s ease;
}

.module-pct {
  min-width: 34px;
  text-align: right;
  color: var(--text);
  font-weight: 600;
}

.module-count {
  background: var(--bg);
  padding: 2px 8px;
  border-radius: 999px;
}

.video-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--border);
}

.video-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
}

.video-item:last-child {
  border-bottom: none;
}

.video-item.watched {
  opacity: 0.6;
}

.thumb-wrap {
  position: relative;
  width: 96px;
  height: 54px;
  flex-shrink: 0;
  background: #000;
  border-radius: 6px;
  overflow: hidden;
}

.thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.badge {
  position: absolute;
  top: 2px;
  right: 2px;
  background: var(--success);
  color: #fff;
  font-size: 11px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-name {
  flex: 1;
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.video-name:hover {
  color: var(--accent);
}

.toggle-btn {
  flex-shrink: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
}

.video-item.watched .toggle-btn {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}

.toggle-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.material-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.material-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 18px;
  border-bottom: 1px solid var(--border);
}

.material-item:last-child {
  border-bottom: none;
}

.material-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.material-name {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  color: var(--text-muted);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.material-name:hover {
  color: var(--accent);
}

.material-item {
  flex-wrap: nowrap;
}

.material-item.read {
  opacity: 0.6;
}

.toggle-btn-small {
  padding: 4px 10px;
}

.material-item.read .toggle-btn-small {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}

/* ===================== Mobile (<= 640px) =====================
   Sem isso o layout é fixo para desktop: o cabeçalho espreme logo +
   4 botões numa linha só, e a linha do vídeo espreme thumb + nome +
   metadados (duração/tamanho/data) + botão, tudo lado a lado. */
@media (max-width: 640px) {
  .logo {
    height: 30px;
  }

  .page-header {
    padding: 10px 16px;
  }

  .grid,
  .home-section,
  .course-page {
    padding-left: 16px;
    padding-right: 16px;
  }

  .add-section {
    margin-left: 16px;
    margin-right: 16px;
  }

  /* Cabeçalho principal: quebra em duas linhas em vez de espremer os
     botões (tema, cadastrar, sincronizar, sair) contra a logo. */
  .header-row {
    flex-wrap: wrap;
    row-gap: 10px;
  }

  .header-actions {
    flex: 1 1 auto;
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  /* Sincronizar vira botão só com ícone (mantém o texto no title/tooltip) */
  .sync-btn .btn-text {
    display: none;
  }

  .sync-btn {
    padding: 8px 12px;
  }

  /* Vídeo/material: o botão de ação desce para uma segunda linha,
     liberando toda a largura para nome + duração/tamanho/data. */
  .video-item,
  .material-item {
    display: grid;
    grid-template-columns: auto 1fr;
    column-gap: 12px;
    row-gap: 8px;
    padding: 10px 16px;
  }

  .thumb-wrap,
  .material-icon {
    grid-column: 1;
    grid-row: 1 / 3;
  }

  .material-icon {
    align-self: start;
    margin-top: 2px;
  }

  .video-info,
  .material-name {
    grid-column: 2;
    grid-row: 1;
  }

  .toggle-btn,
  .toggle-btn-small {
    grid-column: 2;
    grid-row: 2;
    justify-self: start;
  }
}
