/* ============ Variáveis e temas ============ */
:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #faf8f4;
  --text: #1f2430;
  --muted: #6b7280;
  --border: #e4e0d6;
  --primary: #6d4cc2;
  --primary-soft: #efe9fb;
  --on-primary: #ffffff;
  --ok: #1f9d55;
  --warn: #d99a00;
  --late: #d93a3a;
  --done: #2563eb;
  --none: #8b919a;
  --shadow: 0 1px 3px rgba(20, 20, 40, .08), 0 4px 14px rgba(20, 20, 40, .04);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

[data-theme="dark"] {
  --bg: #12141a;
  --surface: #1b1e27;
  --surface-2: #21252f;
  --text: #e8eaf0;
  --muted: #9aa3b2;
  --border: #2d3240;
  --primary: #9d82ee;
  --primary-soft: #2a2442;
  --on-primary: #14101f;
  --ok: #3ecf80;
  --warn: #f0b429;
  --late: #ff6b6b;
  --done: #6aa2ff;
  --none: #7d8592;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

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

h1, h2, h3, p { margin: 0; }

/* ============ Topbar ============ */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}

.topbar-inner {
  max-width: 980px; margin: 0 auto; padding: 10px 16px;
  display: flex; flex-wrap: wrap; gap: 10px 16px;
  align-items: center; justify-content: space-between;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 1.25rem; line-height: 1.1; }
.tagline { font-size: .75rem; color: var(--muted); }

.project-controls { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

select, input[type="date"], input[type="number"], textarea {
  font: inherit; color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  min-height: 38px;
}

select { max-width: 220px; }

select:focus, input:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

/* ============ Botões ============ */
.btn {
  font: inherit; font-weight: 600; font-size: .9rem;
  background: var(--primary); color: var(--on-primary);
  border: 1px solid var(--primary);
  border-radius: 10px; padding: 8px 14px; min-height: 38px;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.08); }
.btn.small { padding: 6px 12px; font-size: .85rem; }
.btn.ghost { background: transparent; color: var(--primary); }
.btn.danger { background: transparent; color: var(--late); border-color: var(--late); }
.btn.icon { padding: 6px 10px; }

.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* ============ Layout ============ */
.container {
  max-width: 980px; margin: 0 auto; padding: 16px;
  display: flex; flex-direction: column; gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.section-title { font-size: 1.05rem; margin-bottom: 12px; }
.hint { color: var(--muted); font-size: .8rem; margin-top: 10px; }

/* ============ Resumo ============ */
.overall { margin-bottom: 16px; }
.overall-top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.overall-label { font-weight: 600; }
.overall-pct { font-size: 1.8rem; font-weight: 800; color: var(--primary); }

.stats {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}

.stat {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  display: flex; flex-direction: column; gap: 2px;
}
.stat label, .stat-label { font-size: .78rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.stat strong { font-size: 1.25rem; }
.stat small { color: var(--muted); font-size: .78rem; }
.stat input[type="date"] { margin-top: 4px; width: 100%; }

/* ============ Barras de progresso ============ */
.bar {
  height: 10px; border-radius: 999px;
  background: var(--primary-soft);
  overflow: hidden;
}
.bar.big { height: 16px; }
.fill {
  height: 100%; width: 0;
  background: linear-gradient(90deg, var(--primary), #b08cff);
  border-radius: 999px;
  transition: width .35s ease;
}

/* ============ Fases ============ */
.phases { display: flex; flex-direction: column; gap: 16px; }

.phase-head {
  display: flex; flex-wrap: wrap; gap: 10px;
  align-items: center; justify-content: space-between;
}
.phase-title { display: flex; gap: 12px; align-items: center; }
.phase-num {
  flex: none; width: 36px; height: 36px; border-radius: 50%;
  background: var(--primary-soft); color: var(--primary);
  display: grid; place-items: center; font-weight: 800;
}
.phase-title h2 { font-size: 1.05rem; line-height: 1.25; }
.weight { font-size: .78rem; color: var(--muted); }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: .8rem; font-weight: 700;
  padding: 4px 12px; border-radius: 999px;
  border: 1px solid currentColor;
  white-space: nowrap;
}
.badge::before {
  content: ""; width: 9px; height: 9px; border-radius: 50%; background: currentColor;
}
.badge.ok   { color: var(--ok);   background: color-mix(in srgb, var(--ok) 14%, transparent); }
.badge.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 18%, transparent); }
.badge.late { color: var(--late); background: color-mix(in srgb, var(--late) 14%, transparent); }
.badge.done { color: var(--done); background: color-mix(in srgb, var(--done) 14%, transparent); }
.badge.none { color: var(--none); background: color-mix(in srgb, var(--none) 14%, transparent); }

.phase-progress { display: flex; align-items: center; gap: 12px; margin: 14px 0 4px; }
.phase-progress .bar { flex: 1; }
.pct { font-weight: 800; min-width: 3.2ch; text-align: right; }
.count { font-size: .78rem; color: var(--muted); margin-bottom: 12px; }

.dates {
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  margin: 8px 0 14px;
}
.dates label { display: flex; flex-direction: column; gap: 4px; font-size: .78rem; color: var(--muted); font-weight: 600; }
.dates input { width: 100%; }

.sub-title {
  font-size: .85rem; font-weight: 700; color: var(--primary);
  margin: 10px 0 6px;
}

.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }

.step label {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}
.step label:hover { border-color: var(--primary); }

input[type="checkbox"] {
  flex: none; width: 20px; height: 20px; margin-top: 2px;
  accent-color: var(--primary); cursor: pointer;
}

.step-text { display: flex; flex-direction: column; gap: 2px; }
.step-text strong { font-size: .93rem; }
.step-text small { color: var(--muted); font-size: .8rem; }

.step label:has(input:checked) { border-color: color-mix(in srgb, var(--ok) 55%, var(--border)); }
.step label:has(input:checked) strong { opacity: .65; text-decoration: line-through; }

/* Módulo de palavras */
.words-module {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}
.words-grid {
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-bottom: 12px;
}
.words-grid label { display: flex; flex-direction: column; gap: 4px; font-size: .78rem; color: var(--muted); font-weight: 600; }
.words-grid input { width: 100%; }
.words-line { display: flex; align-items: center; gap: 12px; }
.words-line .bar { flex: 1; }

/* Anotações */
.notes { margin-top: 16px; display: flex; flex-direction: column; gap: 6px; }
.notes label { font-size: .85rem; font-weight: 700; }
.notes textarea { width: 100%; min-height: 84px; resize: vertical; line-height: 1.45; overflow: hidden; }

/* Rodapé e toast */
.footer { max-width: 980px; margin: 8px auto 32px; padding: 0 16px; color: var(--muted); font-size: .8rem; text-align: center; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 999px; font-size: .9rem;
  opacity: 0; pointer-events: none; transition: .25s;
  max-width: 90vw; text-align: center; z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 560px) {
  .card { padding: 14px; }
  .overall-pct { font-size: 1.5rem; }
  select { max-width: 100%; flex: 1 1 100%; }
}

@media print {
  .topbar, .exports, .footer, .toast { display: none; }
  body { background: #fff; }
}
