:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1f262f;
  --border: #2a313a;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --danger: #b91c1c;
  --success: #16a34a;
  --warning: #d97706;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

button {
  font: inherit;
  background: var(--accent);
  color: #fff;
  border: 0;
  padding: .55rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  transition: background .15s;
}
button:hover:not(:disabled) { background: var(--accent-hover); }
button:disabled { opacity: .5; cursor: not-allowed; }

button.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
button.ghost:hover { background: var(--surface-2); }

button.danger { background: var(--danger); }
button.danger:hover { background: #991b1b; }

button.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: .2rem .5rem;
  font-size: 1rem;
  line-height: 1;
  min-width: unset;
}
button.icon-btn:hover { background: var(--surface-2); }

.setting-row {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  padding: 1rem 0;
}
.setting-row p { margin: .25rem 0 0; }

.switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 24px;
  flex-shrink: 0;
  margin-top: .25rem;
}
.switch input { opacity: 0; width: 0; height: 0; padding: 0; }
.switch .slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 24px;
  transition: background-color .2s;
}
.switch .slider::before {
  content: '';
  position: absolute;
  height: 18px;
  width: 18px;
  left: 2px;
  top: 2px;
  background-color: var(--text);
  border-radius: 50%;
  transition: transform .2s;
}
.switch input:checked + .slider { background-color: var(--accent); border-color: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(22px); background-color: #fff; }

input, textarea {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: .55rem .75rem;
  border-radius: 6px;
  font: inherit;
  width: 100%;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }

textarea { font-family: ui-monospace, "SF Mono", monospace; font-size: 13px; resize: vertical; }

label { display: block; margin-bottom: .8rem; }
label > input { margin-top: .3rem; }

.screen { min-height: 100vh; padding: 2rem; max-width: 1100px; margin: 0 auto; }

#login { display: flex; align-items: center; justify-content: center; }
#login .card { width: 100%; max-width: 360px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

h1 { margin: 0 0 1rem; font-size: 1.5rem; font-weight: 600; }
h2 { margin: 0 0 1rem; font-size: 1.1rem; font-weight: 600; }
h3 { margin: 0 0 .5rem; font-size: 1rem; font-weight: 600; }

#dashboard > header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 2rem;
}
#dashboard > header h1 { margin: 0; }
#dashboard > header > div { display: flex; gap: 1rem; align-items: center; }
#user-email { color: var(--muted); font-size: .85rem; }

.section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.section-head h2 { margin: 0; }

#upload-zone { display: flex; gap: 1rem; align-items: center; }
#picked-file-name { color: var(--muted); }
#upload-progress-wrap { margin-top: 1rem; display: flex; gap: 1rem; align-items: center; }
#upload-progress { flex: 1; height: 8px; }
#upload-progress::-webkit-progress-bar { background: var(--surface-2); border-radius: 4px; }
#upload-progress::-webkit-progress-value { background: var(--accent); border-radius: 4px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .7rem .6rem; text-align: left; border-bottom: 1px solid var(--border); }
th { font-weight: 500; color: var(--muted); font-size: .85rem; }
tbody tr:last-child td { border-bottom: none; }
td .actions { display: flex; gap: .4rem; }
td button { padding: .35rem .7rem; font-size: .85rem; }

.status {
  display: inline-block; padding: .15rem .55rem; border-radius: 999px;
  font-size: .75rem; font-weight: 500; text-transform: uppercase; letter-spacing: .03em;
}
.status-uploading  { background: #1e293b; color: #93c5fd; }
.status-queued     { background: #1f1f3f; color: #c4b5fd; }
.status-processing { background: #422006; color: #fbbf24; }
.status-ready      { background: #052e16; color: #4ade80; }
.status-failed     { background: #450a0a; color: #fca5a5; }

.empty { color: var(--muted); text-align: center; padding: 1rem; }
.error { color: #fca5a5; margin: .5rem 0 0; font-size: .85rem; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }

dialog {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.5rem;
  max-width: 600px;
  width: 92%;
}
dialog::backdrop { background: rgba(0,0,0,.6); }
.dialog-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1rem; }

@media (max-width: 600px) {
  .screen { padding: 1rem; }
  th:nth-child(4), td:nth-child(4),
  th:nth-child(5), td:nth-child(5),
  th:nth-child(6), td:nth-child(6) { display: none; }
}

/* ============================================================================
   TABS — Acervo / Migração
   ============================================================================ */
.tabs {
  display: flex;
  gap: .25rem;
  border-bottom: 1px solid var(--border);
  margin: 0;
}
.tab {
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: .7rem 1.25rem;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  margin-bottom: -1px;
  font-size: 1rem;
  font-weight: 500;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
  background: transparent;
}

/* ============================================================================
   MIGRAÇÃO — chips de status
   ============================================================================ */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
  cursor: default;
  user-select: none;
}
.chip.pending { background: #1f262f; color: #6b7280; }
.chip.running {
  background: #422006;
  color: #fbbf24;
  animation: chip-pulse 1.4s ease-in-out infinite;
}
.chip.done    { background: #052e16; color: #4ade80; }
.chip.error   {
  background: #450a0a;
  color: #fca5a5;
  cursor: pointer;
}
.chip.error:hover { background: #5b1010; }
.chip.na { background: #1a1a1a; color: #4a4a4a; }

/* Botão ↻ embutido em chip de erro */
.chip-retry {
  all: unset;
  cursor: pointer;
  padding: 0 4px;
  margin-left: 2px;
  border-radius: 3px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  color: inherit;
  transition: background .12s;
}
.chip-retry:hover { background: rgba(255, 255, 255, .15); }

@keyframes chip-pulse {
  50% { opacity: .55; }
}

/* ============================================================================
   MIGRAÇÃO — KPIs por fase (header)
   ============================================================================ */
.phases-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: .75rem;
}
.phase-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .75rem .9rem;
}
.phase-label {
  font-size: .8rem;
  color: var(--muted);
  margin-bottom: .5rem;
  font-weight: 500;
}
.phase-counts {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
}
.phase-counts .chip { cursor: pointer; }
.phase-counts .chip:hover { transform: scale(1.05); }

.btn-phase-control {
  display: block;
  width: 100%;
  margin-top: .5rem;
  font-size: .75rem;
  padding: .35rem .5rem;
  text-align: center;
}
.btn-phase-control.phase-paused {
  background: var(--warning);
  color: #fff;
  border-color: var(--warning);
}
.btn-phase-control.phase-paused:hover { background: #b45309; }

/* ============================================================================
   MIGRAÇÃO — filtros e paginação
   ============================================================================ */
.filters {
  display: flex;
  gap: .5rem;
  align-items: center;
  flex-wrap: wrap;
}
.filter {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: .4rem .6rem;
  border-radius: 6px;
  font: inherit;
  font-size: .85rem;
  width: auto;
}
.filter:focus { outline: 2px solid var(--accent); border-color: transparent; }
select.filter { min-width: 160px; }
input.filter { min-width: 220px; }

#mig-lessons-table th,
#mig-lessons-table td {
  font-size: .82rem;
  padding: .55rem .5rem;
  vertical-align: middle;
}
#mig-lessons-table th:nth-child(1),
#mig-lessons-table td:nth-child(1) { max-width: 200px; }
#mig-lessons-table th:nth-child(2),
#mig-lessons-table td:nth-child(2) {
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-top: 1rem;
}

/* Coluna de checkbox compacta */
.col-check { width: 32px; text-align: center; padding: 0; }
.col-check input { cursor: pointer; transform: scale(1.1); }

/* Barra flutuante de batch retry (aparece quando há linhas selecionadas) */
.batch-bar {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .65rem 1rem;
  display: flex;
  gap: .5rem;
  align-items: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
  z-index: 100;
  flex-wrap: wrap;
  max-width: calc(100vw - 32px);
}
.batch-bar > span { color: var(--muted); font-size: .9rem; padding: 0 .25rem; }
.batch-bar > span strong { color: var(--text); font-weight: 600; }
.batch-bar button { font-size: .85rem; padding: .4rem .8rem; }

/* ============================================================================
   MIGRAÇÃO — modal de detalhes
   ============================================================================ */
#mig-details-dialog { max-width: 720px; }
.mig-details-body { max-height: 60vh; overflow-y: auto; }
.mig-details-body h4 {
  margin: 1rem 0 .4rem;
  font-size: .95rem;
  color: var(--text);
  border-top: 1px solid var(--border);
  padding-top: .8rem;
}
.mig-details-body h4:first-child { border-top: 0; padding-top: 0; }
.kv {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: .35rem .8rem;
  margin: 0;
  font-size: .85rem;
}
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.kv dd code { background: var(--surface-2); padding: 1px 5px; border-radius: 3px; font-size: .8rem; }
.error-msg { color: #fca5a5; }
.log-list { list-style: none; padding: 0; margin: 0; font-size: .8rem; }
.log-list li {
  padding: .35rem .5rem;
  border-left: 3px solid var(--border);
  margin-bottom: .25rem;
  background: var(--surface-2);
  border-radius: 0 4px 4px 0;
}
.log-list li.log-error { border-left-color: #ef4444; }
.log-list li.log-warn  { border-left-color: #eab308; }
.log-list li.log-info  { border-left-color: var(--accent); }

@media (max-width: 600px) {
  /* No mobile, esconder colunas Curso/Módulo + Replace (3 chips de status menos críticos) */
  #mig-lessons-table th:nth-child(1), #mig-lessons-table td:nth-child(1),
  #mig-lessons-table th:nth-child(7), #mig-lessons-table td:nth-child(7) { display: none; }
  .filter { width: 100%; }
}
