/* ============================================================
   NôStudy — Design System
   Cor principal: Azul Petróleo Suave · Fonte: Inter · Grid 8px
   ============================================================ */

:root {
  /* Neutros */
  --bg: #FAF9F7;
  --surface: #FFFFFF;
  --border: #E8E8E8;
  --text: #1F2937;
  --text-2: #6B7280;
  --text-3: #9CA3AF;

  /* Cor principal */
  --p-50: #EEF6F8;
  --p-100: #D7EAF0;
  --p-200: #B7D8E3;
  --p-300: #92C2D2;
  --p-400: #69AABF;
  --p-500: #3B82A0;
  --p-600: #316D86;
  --p-700: #28576B;

  /* Semáforo */
  --ok: #8CDEC5;
  --ok-text: #0F5040;
  --warn: #E7C87A;
  --warn-text: #7A5500;
  --alert: #E7A4A4;
  --alert-text: #7A1E1E;

  /* Sombras */
  --shadow-1: 0 2px 8px rgba(0, 0, 0, 0.06);
  --shadow-2: 0 4px 16px rgba(0, 0, 0, 0.08);

  /* Radius */
  --r-btn: 12px;
  --r-card: 16px;
  --r-modal: 20px;
}

[data-theme="dark"] {
  --bg: #111827;
  --surface: #1F2937;
  --border: #374151;
  --text: #F9FAFB;
  --text-2: #9CA3AF;
  --text-3: #6B7280;
  --p-50: #1c2f38;
  --p-100: #234150;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { height: 100%; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.6;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

/* Em desktop, a app vive numa moldura central mobile-first */
.app-shell {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg);
}
@media (min-width: 560px) {
  body { background: color-mix(in srgb, var(--bg) 92%, var(--text) 8%); }
  .app-shell {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}

.view {
  flex: 1;
  padding: 16px 16px 96px;
  outline: none;
  animation: fadein .18s ease;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Tipografia ---------- */
h1, .h1 { font-size: 32px; font-weight: 700; line-height: 1.3; }
h2, .h2 { font-size: 24px; font-weight: 600; line-height: 1.3; }
h3, .h3 { font-size: 20px; font-weight: 600; line-height: 1.3; }
h4, .h4 { font-size: 18px; font-weight: 600; line-height: 1.3; }
.body { font-size: 16px; font-weight: 400; }
.sec { font-size: 14px; color: var(--text-2); }
.cap { font-size: 13px; color: var(--text-2); }
.w500 { font-weight: 500; }
.w600 { font-weight: 600; }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  z-index: 40;
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-decoration: none;
  color: var(--text-2);
  font-size: 11px;
  font-weight: 500;
  padding: 4px 0;
  border-radius: 12px;
}
.tab i { font-size: 24px; line-height: 1; }
.tab.active { color: var(--p-500); }

/* ---------- Header de página ---------- */
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 16px;
}
.page-head .back {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-2);
  background: none;
  border: none;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  padding: 8px 8px 8px 0;
}
.icon-btn {
  width: 40px; height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  border: none; background: none; color: var(--text-2);
  font-size: 20px; cursor: pointer; border-radius: 12px;
}
.icon-btn:hover { background: var(--p-50); color: var(--p-600); }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  padding: 16px;
}
.card + .card { margin-top: 8px; }
.card.tappable { cursor: pointer; transition: border-color .15s; }
.card.tappable:hover { border-color: var(--p-300); }

.section { margin-top: 24px; }
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}

/* ---------- Botões ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  border: none;
  border-radius: var(--r-btn);
  padding: 14px 24px;
  cursor: pointer;
  transition: background .15s, transform .1s;
  text-decoration: none;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--p-500); color: #fff; }
.btn.primary:hover { background: var(--p-600); }
.btn.secondary {
  background: transparent;
  color: var(--p-600);
  border: 1px solid var(--p-300);
}
.btn.secondary:hover { background: var(--p-50); }
.btn.ghost { background: none; color: var(--text-2); font-weight: 500; padding: 8px 16px; }
.btn.ghost:hover { color: var(--text); }
.btn.danger { background: none; color: var(--alert-text); border: 1px solid var(--alert); }
.btn.block { width: 100%; }
.btn.sm { padding: 8px 16px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* FAB */
.fab {
  position: fixed;
  right: calc(50% - 240px + 16px);
  bottom: calc(84px + env(safe-area-inset-bottom));
  width: 56px; height: 56px;
  border-radius: 999px;
  background: var(--p-500);
  color: #fff;
  border: none;
  font-size: 22px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-2);
  z-index: 30;
}
@media (max-width: 560px) { .fab { right: 16px; } }
.fab:hover { background: var(--p-600); }

/* ---------- Badges / pills ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge.ok { background: var(--ok); color: var(--ok-text); }
.badge.warn { background: var(--warn); color: var(--warn-text); }
.badge.alert { background: var(--alert); color: var(--alert-text); }
.badge.neutral { background: var(--p-50); color: var(--p-700); }
.badge.muted { background: var(--border); color: var(--text-2); }

.dot { width: 12px; height: 12px; border-radius: 4px; flex: none; display: inline-block; }
.sidebar-color { width: 4px; align-self: stretch; border-radius: 4px; flex: none; }

/* ---------- Chips ---------- */
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip {
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  white-space: nowrap;
}
.chip.active { background: var(--p-200); border-color: var(--p-200); color: var(--p-700); }

/* ---------- Formulários ---------- */
.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-2);
  margin-bottom: 8px;
}
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="time"], input[type="url"], select, textarea {
  width: 100%;
  font: inherit;
  font-size: 16px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-btn);
  padding: 12px 16px;
}
textarea { resize: vertical; min-height: 96px; }
textarea.small { min-height: 64px; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--p-400);
  box-shadow: 0 0 0 3px var(--p-50);
}
input[type="range"] { width: 100%; accent-color: var(--p-500); }

/* Toggle switch */
.switch { position: relative; display: inline-block; width: 48px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; cursor: pointer;
  background: var(--border); border-radius: 999px; transition: .2s;
}
.switch .slider::before {
  content: ""; position: absolute; height: 22px; width: 22px;
  left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s;
}
.switch input:checked + .slider { background: var(--p-500); }
.switch input:checked + .slider::before { transform: translateX(20px); }

/* ---------- Listas ---------- */
.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
}
.list-item + .list-item { border-top: 1px solid var(--border); }
.list-item .grow { flex: 1; min-width: 0; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Progress bars ---------- */
.progress {
  height: 6px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.progress > div { height: 100%; background: var(--p-400); border-radius: 999px; transition: width .3s; }

/* ---------- Sessão de estudo ---------- */
.pomo-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  height: 48px;
  margin-bottom: 8px;
}
.pomo-bar .time { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.pomo-bar .progress { flex: 1; height: 4px; }

.study-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  min-height: 50dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 32px 24px;
  text-align: center;
  margin: 16px 0;
}
.study-card.answer { padding: 0; justify-content: stretch; align-items: stretch; text-align: left; }
.study-card .front-half {
  background: var(--bg);
  padding: 24px;
  font-size: 14px;
  color: var(--text-2);
  border-bottom: 1px solid var(--border);
  border-radius: var(--r-card) var(--r-card) 0 0;
}
.study-card .back-half { padding: 24px; flex: 1; }
.why-box {
  background: var(--p-50);
  border-radius: 8px;
  padding: 16px;
  margin: 0 24px 24px;
}
.why-box .label { font-size: 14px; color: var(--text-2); font-weight: 500; margin-bottom: 4px; }

.rate-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.rate-row .btn { padding: 14px 8px; font-size: 14px; }
.rate-again { background: var(--alert); color: var(--alert-text); }
.rate-hard { background: var(--warn); color: var(--warn-text); }
.rate-good { background: var(--border); color: var(--text); }
.rate-easy { background: var(--ok); color: var(--ok-text); }

.session-overlay {
  position: fixed; inset: 0;
  background: var(--bg);
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 24px;
  text-align: center;
}

/* ---------- Calendário ---------- */
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  text-align: center;
}
.cal-grid .dow { font-size: 13px; color: var(--text-3); padding: 8px 0; font-weight: 500; }
.cal-day {
  aspect-ratio: 1;
  border: none;
  background: none;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  position: relative;
}
.cal-day.other { color: var(--text-3); }
.cal-day.today { color: var(--p-500); font-weight: 700; }
.cal-day.selected { background: var(--p-100); }
.cal-day .dots { display: flex; gap: 2px; height: 5px; }
.cal-day .dots i { width: 5px; height: 5px; border-radius: 50%; display: block; }

.banner {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--warn);
  color: var(--warn-text);
  border-radius: var(--r-btn);
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 16px;
}

/* ---------- Estatísticas ---------- */
.metric-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  padding: 16px;
}
.metric-card .value { font-size: 28px; font-weight: 700; line-height: 1.2; }
.metric-card .label { font-size: 13px; color: var(--text-2); margin-top: 4px; }

.bars {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 140px;
  padding-top: 24px;
}
.bars .bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.bars .bar { width: 100%; max-width: 32px; background: var(--p-500); border-radius: 6px 6px 0 0; min-height: 2px; }
.bars .val { font-size: 12px; color: var(--text-2); font-weight: 500; }
.bars .day { font-size: 12px; color: var(--text-3); }

/* Accordion */
.accordion-item { border-bottom: 1px solid var(--border); }
.accordion-head {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  background: none;
  border: none;
  font: inherit;
  padding: 16px 0;
  cursor: pointer;
  text-align: left;
}
.accordion-body { padding: 0 0 16px; }

/* ---------- Stepper ---------- */
.stepper { display: flex; gap: 8px; margin-bottom: 24px; }
.stepper .step { flex: 1; height: 4px; border-radius: 999px; background: var(--border); }
.stepper .step.done { background: var(--p-500); }

/* ---------- Modais ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 60;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal {
  background: var(--surface);
  border-radius: var(--r-modal) var(--r-modal) 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 85dvh;
  overflow-y: auto;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-2);
  animation: slideup .22s ease;
}
@keyframes slideup { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (min-width: 560px) {
  .modal-backdrop { align-items: center; }
  .modal { border-radius: var(--r-modal); }
}

/* ---------- Toast ---------- */
#toast-root {
  position: fixed;
  bottom: calc(96px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: max-content;
  max-width: 90vw;
}
.toast {
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  padding: 10px 20px;
  border-radius: 999px;
  box-shadow: var(--shadow-2);
  animation: slideup .2s ease;
}

/* ---------- Estado vazio ---------- */
.empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-2);
}
.empty i { font-size: 48px; color: var(--p-300); display: block; margin-bottom: 16px; }
.empty p { margin-bottom: 16px; }

/* ---------- Markdown nos cartões ---------- */
.md code {
  font-family: ui-monospace, monospace;
  font-size: .9em;
  background: var(--p-50);
  padding: 1px 6px;
  border-radius: 6px;
}

/* ---------- Utilitários ---------- */
.row { display: flex; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 8px; }
.mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; } .mb-16 { margin-bottom: 16px; } .mb-24 { margin-bottom: 24px; }
.text-center { text-align: center; }
.link { color: var(--p-500); text-decoration: none; font-weight: 500; cursor: pointer; background: none; border: none; font-size: 14px; font-family: inherit; }
.link:hover { color: var(--p-600); }
.muted { color: var(--text-3); }
.hidden { display: none !important; }
