:root {
  --bg: #0b1020;
  --surface: #131a2e;
  --surface-2: #1a2340;
  --border: #243049;
  --text: #e6ebf5;
  --muted: #93a0bb;
  --accent: #5eead4;
  --accent-ink: #062a25;
  --danger: #f87171;
  --radius: 14px;
  --cell: 34px;
  --first-col: 220px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(900px 500px at 85% -10%, rgba(94, 234, 212, 0.08), transparent 60%),
    radial-gradient(700px 400px at -10% 0%, rgba(167, 139, 250, 0.08), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.45;
}

[hidden] { display: none !important; }

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

.page { flex: 1; width: 100%; max-width: 1200px; margin: 0 auto; padding: 16px; }

/* ---------- Telas centrais (carregando, erro, login) ---------- */
.center-view {
  min-height: 60vh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; text-align: center;
}
.login h1 { font-size: clamp(1.7rem, 5vw, 2.4rem); }
.lead { max-width: 44ch; margin: 0; }

.brand-mark {
  display: grid; place-items: center;
  width: 64px; height: 64px; border-radius: 18px;
  background: var(--accent); color: var(--accent-ink);
  font-size: 2rem; font-weight: 800;
  box-shadow: 0 10px 30px rgba(94, 234, 212, 0.25);
}
.brand-mark.small { width: 28px; height: 28px; border-radius: 8px; font-size: 1rem; box-shadow: none; display: inline-grid; vertical-align: middle; }

.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Botões e campos ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease;
}
.btn:hover { border-color: #3a4a70; background: #202b4d; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn-primary:hover { background: #7df0de; border-color: transparent; }
.btn-ghost { background: transparent; }
.btn-icon { width: 40px; height: 40px; padding: 0; font-size: 1.4rem; line-height: 1; }
.btn-discord { background: #5865f2; border-color: transparent; color: #fff; padding: 12px 22px; font-size: 1.05rem; }
.btn-discord:hover { background: #6b77f5; border-color: transparent; }

:focus-visible { outline: 3px solid #a78bfa; outline-offset: 2px; }

.input {
  flex: 1; min-width: 0; padding: 11px 14px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit;
}
.input::placeholder { color: #6c7a99; }
.color {
  width: 46px; height: 44px; padding: 3px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface);
}

.alert {
  margin: 10px 0 0; padding: 10px 14px; border-radius: 10px;
  background: rgba(248, 113, 113, 0.12); border: 1px solid rgba(248, 113, 113, 0.4); color: #fecaca;
}

/* ---------- Topo ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 0 16px; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 1.1rem; display: flex; align-items: center; gap: 10px; }
.user { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar { border-radius: 50%; border: 2px solid var(--border); background: var(--surface); object-fit: cover; }
.user-name { font-weight: 600; max-width: 18ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 6px 0 16px; flex-wrap: wrap; }
.month-nav { display: flex; align-items: center; gap: 10px; }
.month-nav h2 { font-size: 1.35rem; min-width: 11ch; text-align: center; }

/* ---------- Indicadores ---------- */
.indicators { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 18px; }
.card {
  display: flex; flex-direction: column; gap: 6px;
  padding: 16px 18px; border-radius: var(--radius);
  background: linear-gradient(180deg, var(--surface), #10172b); border: 1px solid var(--border);
}
.card-label { color: var(--muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.06em; }
.card-value { font-size: 2.2rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.card-value small { font-size: 0.95rem; font-weight: 500; color: var(--muted); }
.card-hint { color: var(--muted); font-size: 0.8rem; }

/* ---------- Barras de progresso (CSS) ---------- */
.progress {
  height: 8px; border-radius: 999px; background: #0e1427; overflow: hidden;
  border: 1px solid var(--border);
}
.progress-lg { height: 12px; margin-top: 4px; }
.progress-fill {
  width: 0; height: 100%; border-radius: inherit;
  background: var(--habit-color, var(--accent));
  transition: width 0.35s ease;
}
#overall-fill { background: linear-gradient(90deg, var(--accent), #a78bfa); }

/* ---------- Formulário ---------- */
.habit-form { display: flex; gap: 10px; align-items: center; }

.empty {
  padding: 22px; text-align: center; color: var(--muted);
  border: 1px dashed var(--border); border-radius: var(--radius); margin: 16px 0;
}

/* ---------- Grade matricial ---------- */
.grid-wrap {
  margin-top: 16px; overflow-x: auto; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface);
}
.grid { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; }
.grid th, .grid td { border-bottom: 1px solid var(--border); }
.grid tbody tr:last-child th, .grid tbody tr:last-child td { border-bottom: 0; }

.grid thead th { background: #10172b; padding: 8px 0; font-weight: 600; }
.grid th.habit-col, .grid th.habit-cell {
  position: sticky; left: 0; z-index: 2; text-align: left;
  width: var(--first-col); min-width: var(--first-col); max-width: var(--first-col);
  padding: 12px 14px; background: var(--surface); border-right: 1px solid var(--border);
}
.grid thead th.habit-col { background: #10172b; color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; }

.grid th.day { width: var(--cell); min-width: var(--cell); font-size: 0.78rem; color: var(--muted); }
.grid th.day .wd { display: block; font-size: 0.65rem; text-transform: uppercase; opacity: 0.8; }
.grid th.day .dn { display: block; font-variant-numeric: tabular-nums; color: var(--text); }
.grid th.day.is-today .dn { color: var(--accent); }
.grid .is-today { background: rgba(94, 234, 212, 0.06); }

.habit-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.habit-name { font-weight: 600; overflow-wrap: anywhere; }
.habit-meta { display: flex; flex-direction: column; gap: 2px; margin-top: 8px; font-size: 0.78rem; color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 400; }

.icon-btn {
  flex: none; width: 26px; height: 26px; border-radius: 8px; line-height: 1;
  border: 1px solid transparent; background: transparent; color: var(--muted); font-size: 1.15rem; cursor: pointer;
}
.icon-btn:hover { color: var(--danger); border-color: rgba(248, 113, 113, 0.4); }

.cell { text-align: center; padding: 0; height: 88px; }

.check {
  appearance: none; -webkit-appearance: none; margin: 0; cursor: pointer;
  width: 24px; height: 24px; border-radius: 7px;
  border: 2px solid #34436a; background: #0e1427; vertical-align: middle;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}
.check:hover:not(:disabled) { border-color: var(--habit-color, var(--accent)); }
.check:active:not(:disabled) { transform: scale(0.92); }
.check:checked {
  background-color: var(--habit-color, var(--accent)); border-color: var(--habit-color, var(--accent));
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3.5 8.5l3 3 6-7' fill='none' stroke='%23062a25' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-size: 80%; background-position: center; background-repeat: no-repeat;
}
.check:disabled { opacity: 0.25; cursor: not-allowed; }

/* ---------- Rodapé e toast ---------- */
.site-footer {
  padding: 18px 16px 26px; text-align: center; font-size: 0.85rem;
  color: var(--muted); border-top: 1px solid var(--border);
}
.site-footer p { margin: 2px 0; }
.site-footer code {
  padding: 2px 8px; border-radius: 6px; background: var(--surface-2); color: var(--accent);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; overflow-wrap: anywhere;
}

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 20;
  max-width: calc(100vw - 32px); padding: 12px 18px; border-radius: 12px;
  background: var(--surface-2); border: 1px solid var(--border); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}
.toast[data-kind="error"] { border-color: rgba(248, 113, 113, 0.6); color: #fecaca; }

/* ---------- Responsivo ---------- */
@media (max-width: 720px) {
  :root { --cell: 30px; --first-col: 168px; }
  .page { padding: 12px; }
  .indicators { grid-template-columns: 1fr; }
  .card { flex-direction: row; align-items: center; flex-wrap: wrap; justify-content: space-between; }
  .card-hint { flex-basis: 100%; }
  .card-value { font-size: 1.8rem; }
  .progress-lg { flex-basis: 100%; }
  .habit-form { flex-wrap: wrap; }
  .habit-form .input { flex-basis: 100%; }
  .habit-form .btn-primary { flex: 1; }
  .user-name { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
