:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --text: #1c1c1a;
  --muted: #6b6b66;
  --border: #e3e2dd;
  --accent: #2f6f4f;
  --accent-soft: #dcece3;
  --danger: #a13d3d;
  --danger-soft: #f4dede;
  --radius: 10px;
  --gap: 1rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a;
    --surface: #202226;
    --text: #eceae4;
    --muted: #9b9a94;
    --border: #34363b;
    --accent: #6fbf94;
    --accent-soft: #223b30;
    --danger: #d98c8c;
    --danger-soft: #3a2626;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.45;
}

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: 2.5rem 1.25rem 4rem;
}

.view { display: block; }
.view[hidden] { display: none; }

/* ---- Tela principal / contador ---- */

.loop-name {
  margin: 0 0 1.75rem;
  font-size: 1.3rem;
  font-weight: 600;
  text-align: center;
  color: var(--muted);
}

.counter {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  text-align: center;
}

.counter-label {
  margin: 0;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.counter-cycle-name {
  margin: 0.25rem 0 1rem;
  font-size: 2rem;
  font-weight: 700;
}

.counter-goal {
  margin: -0.5rem 0 1.25rem;
  color: var(--muted);
  font-style: italic;
}

.counter-position {
  font-size: 1.1rem;
  font-weight: 600;
}

.counter-remaining {
  margin: 0.15rem 0 1.5rem;
  color: var(--muted);
}

.progress-row {
  text-align: left;
  margin-top: 1.1rem;
}

.progress-row-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
  margin-bottom: 0.35rem;
}

.progress-row-label .pct { font-weight: 700; }

.progress-bar {
  height: 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  overflow: hidden;
}

.progress-bar > div {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.2s ease;
}

.progress-bar.is-loop > div { background: var(--text); opacity: 0.75; }

.empty-state, .finished-state, .not-started-state {
  text-align: center;
  padding: 1rem 0;
}

.empty-state p, .finished-state p, .not-started-state p {
  color: var(--muted);
}

/* ---- Linha do tempo ---- */

.timeline {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 1.75rem;
  padding: 0;
  list-style: none;
}

.timeline li {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  font-size: 0.85rem;
  background: var(--surface);
  color: var(--muted);
}

.timeline li.concluido {
  border-color: var(--accent);
  color: var(--accent);
}

.timeline li.atual {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  font-weight: 600;
}

.timeline-caption {
  text-align: center;
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.35rem;
}

/* ---- Barra de ações ---- */

.toolbar {
  margin-top: 1.5rem;
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* ---- Botões ---- */

.btn {
  font: inherit;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: transparent;
}
.btn-ghost:hover { color: var(--accent); background: var(--accent-soft); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  font-weight: 600;
}
.btn-primary:hover { opacity: 0.92; border-color: var(--accent); }

.btn-danger {
  color: var(--danger);
  border-color: var(--danger-soft);
}
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }

.btn-icon {
  padding: 0.35rem 0.55rem;
  line-height: 1;
}

.btn-sm { font-size: 0.85rem; padding: 0.35rem 0.65rem; }

/* ---- Editor ---- */

.editor-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.editor-header h1 {
  font-size: 1.15rem;
  margin: 0;
  flex: 1;
}

.field {
  margin-bottom: 1rem;
}

.field label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.3rem;
}

.field input[type="text"],
.field input[type="date"],
.field input[type="number"],
.field textarea,
.field select {
  width: 100%;
  font: inherit;
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.cycles-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin: 1rem 0;
}

.cycle-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem;
  background: var(--surface);
}

.cycle-card-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.cycle-card-row:last-child { margin-bottom: 0; }

.cycle-card-row .field { flex: 1; margin-bottom: 0; }

.cycle-duration-value { max-width: 5.5rem; flex: 0 0 auto; }
.cycle-duration-unit { flex: 1; }

.cycle-actions {
  display: flex;
  gap: 0.35rem;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.cycle-meta {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.4rem;
}

.editor-section {
  margin-top: 1.75rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.editor-section h2 {
  font-size: 0.95rem;
  margin: 0 0 0.6rem;
}

.editor-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 1.5rem;
}

.editor-actions .spacer { flex: 1; }

.data-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.35rem;
}

/* ---- Toast ---- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 0.6rem 1rem;
  border-radius: 8px;
  font-size: 0.9rem;
  max-width: 90vw;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.toast.is-error { background: var(--danger); color: white; }
.toast[hidden] { display: none; }
