/* Thule — design system mobile-first */
:root {
  /* Cor */
  --bg: #0a1422;
  --bg-elev: #0f1c2e;
  --surface: #152538;
  --surface-2: #1c2f47;
  --line: rgba(255,255,255,0.06);
  --line-strong: rgba(255,255,255,0.12);

  --text: #f0f4f8;
  --text-2: #8b9bab;
  --text-3: #5a6b7c;

  --accent: #6ba8c9;
  --accent-ink: #07131e;
  --accent-2: #c4a8e0;
  --ok: #7dc8a0;
  --warn: #e8b96b;
  --danger: #e07a7a;

  /* Forma */
  --r-sm: 10px; --r-md: 14px; --r-lg: 20px; --r-xl: 28px; --r-pill: 999px;

  /* Espaço (4pt) */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px; --s8: 32px; --s10: 40px;

  /* App */
  --maxw: 440px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 64px;

  --shadow-1: 0 1px 0 rgba(255,255,255,.03) inset, 0 1px 2px rgba(0,0,0,.3);
  --shadow-2: 0 8px 24px rgba(0,0,0,.35);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg:#f2f5f9; --bg-elev:#ffffff; --surface:#ffffff; --surface-2:#f6f8fb;
    --line: rgba(0,0,0,.06); --line-strong: rgba(0,0,0,.12);
    --text:#0d1b2a; --text-2:#5a6b7c; --text-3:#8b9bab;
    --accent:#2f6f8e; --accent-ink:#ffffff; --accent-2:#7a5fb0;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", Inter, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 15px; line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
body {
  min-height: 100dvh;
  display: flex; justify-content: center;
  background: radial-gradient(60% 80% at 50% 0%, var(--bg-elev), var(--bg) 70%);
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
img, svg { display: block; }

.noscript { padding: var(--s8); text-align: center; color: var(--warn); }

.frame {
  width: 100%; max-width: var(--maxw);
  min-height: 100dvh;
  background: var(--bg);
  display: flex; flex-direction: column;
  position: relative;
  box-shadow: var(--shadow-2);
}

/* Header (small/large) */
.appbar {
  position: sticky; top: 0; z-index: 20;
  padding: calc(var(--safe-top) + var(--s3)) var(--s4) var(--s3);
  background: linear-gradient(180deg, var(--bg) 70%, rgba(10,20,34,0));
  display: grid; grid-template-columns: 40px 1fr 40px;
  align-items: center; gap: var(--s2);
}
.appbar h1 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -.01em; text-align: center; }
.appbar.hide-back .left { visibility: hidden; }
.appbar.hide-right .right { visibility: hidden; }
.appbar.large {
  grid-template-columns: 1fr auto;
  padding-top: calc(var(--safe-top) + var(--s5));
  padding-bottom: var(--s2);
}
.appbar.large h1 { text-align: left; font-size: 28px; font-weight: 700; letter-spacing: -.02em; }
.appbar.large .left { display: none; }

.content {
  flex: 1;
  padding: var(--s2) var(--s4) calc(var(--tabbar-h) + var(--safe-bot) + var(--s4));
}
.content.no-tabbar { padding-bottom: calc(var(--safe-bot) + var(--s4)); }

/* Tabbar */
.tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: var(--maxw); z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 0 var(--s2) var(--safe-bot);
  background: color-mix(in oklab, var(--bg) 88%, transparent);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  border-top: 1px solid var(--line);
}
.tab {
  height: var(--tabbar-h);
  display: grid; place-items: center; gap: 2px;
  color: var(--text-3); position: relative;
}
.tab svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 1.8; }
.tab small { font-size: 10px; font-weight: 500; letter-spacing: .02em; }
.tab[aria-current="true"] { color: var(--accent); }
.tab[aria-current="true"]::after {
  content: ""; position: absolute; top: 6px; width: 4px; height: 4px; border-radius: 50%;
  background: var(--accent);
}

/* FAB */
.fab {
  position: fixed; left: 50%; transform: translateX(calc(var(--maxw)/2 - 72px));
  bottom: calc(var(--tabbar-h) + var(--safe-bot) + var(--s4));
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; z-index: 25;
  box-shadow: 0 8px 24px rgba(0,0,0,.4), 0 2px 4px rgba(0,0,0,.3);
}
.fab svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 2.2; }

/* Botões de ícone */
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; color: var(--text);
}
.icon-btn:active { background: var(--surface); }
.icon-btn svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; }

/* Botões */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  height: 48px; padding: 0 var(--s5);
  background: var(--accent); color: var(--accent-ink);
  border-radius: var(--r-pill);
  font-weight: 600; font-size: 15px;
  transition: transform .08s ease, opacity .15s ease;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .4; pointer-events: none; }
.btn.block { width: 100%; }
.btn.secondary { background: color-mix(in oklab, var(--accent) 15%, transparent); color: var(--accent); }
.btn.ghost { background: transparent; color: var(--text); }
.btn.danger { background: color-mix(in oklab, var(--danger) 18%, transparent); color: var(--danger); }
.btn.small { height: 36px; padding: 0 var(--s3); font-size: 13px; }

/* Inputs */
.field { display: grid; gap: var(--s2); margin-bottom: var(--s4); }
.field label { font-size: 13px; color: var(--text-2); padding-left: var(--s1); }
.input, .textarea, .select {
  width: 100%; min-height: 48px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--s3) var(--s4); color: var(--text);
  transition: border-color .15s ease;
}
.input:focus, .textarea:focus, .select:focus { outline: none; border-color: var(--accent); }
.textarea { min-height: 180px; resize: vertical; line-height: 1.55; }
.input::placeholder, .textarea::placeholder { color: var(--text-3); }

/* Cards / Posts */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--s4);
  margin-bottom: var(--s3);
}
.post-head {
  display: grid; grid-template-columns: 40px 1fr auto; gap: var(--s3); align-items: center;
  margin-bottom: var(--s3);
}
.post-author { font-weight: 600; font-size: 14px; line-height: 1.2; }
.post-meta { font-size: 12px; color: var(--text-3); }
.post-body { font-size: 15px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.post-cat {
  display: inline-block; margin-top: var(--s3);
  font-size: 11px; color: var(--accent);
  background: color-mix(in oklab, var(--accent) 15%, transparent);
  padding: 4px var(--s2); border-radius: var(--r-pill); font-weight: 500;
}
.post-actions {
  display: flex; gap: var(--s2); margin-top: var(--s3);
  padding-top: var(--s3); border-top: 1px solid var(--line);
}
.post-actions .action {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px;
  color: var(--text-2); padding: var(--s2);
  border-radius: var(--r-md); font-size: 13px;
}
.post-actions .action svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; }
.post-actions .action:active { background: var(--surface-2); }
.post-actions .action[aria-pressed="true"] { color: var(--accent); }
.post-actions .action[aria-pressed="true"] svg { fill: currentColor; stroke: none; }

/* Avatar */
.avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center;
  color: var(--accent-ink); font-weight: 700; font-size: 14px;
  overflow: hidden; flex-shrink: 0;
}
.avatar img, .avatar svg { width: 100%; height: 100%; object-fit: cover; }
.avatar.lg { width: 96px; height: 96px; font-size: 32px; }
.avatar.xl { width: 112px; height: 112px; font-size: 38px; }
.avatar-ring { padding: 3px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--accent-2)); display: inline-block; }
.avatar-ring .avatar { background: var(--bg); }

/* Segmented / chips */
.segments {
  display: flex; gap: var(--s2);
  overflow-x: auto; padding: var(--s1) 0 var(--s4);
  scrollbar-width: none;
}
.segments::-webkit-scrollbar { display: none; }
.segment {
  flex-shrink: 0;
  padding: 8px var(--s3);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  color: var(--text-2); font-size: 13px; font-weight: 500;
}
.segment[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: transparent; }

/* Mood */
.moods { display: grid; grid-template-columns: repeat(5, 1fr); gap: var(--s2); }
.mood {
  aspect-ratio: 1;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md);
  display: grid; place-items: center; gap: 4px;
  color: var(--text-2);
}
.mood svg { width: 26px; height: 26px; stroke: currentColor; fill: none; stroke-width: 1.6; }
.mood small { font-size: 10px; }
.mood[aria-pressed="true"] {
  border-color: var(--accent); color: var(--accent);
  background: color-mix(in oklab, var(--accent) 10%, transparent);
}

/* Lista de rows */
.list { display: flex; flex-direction: column; background: var(--surface); border-radius: var(--r-lg); border: 1px solid var(--line); overflow: hidden; }
.row {
  display: grid; grid-template-columns: 28px 1fr auto;
  align-items: center; gap: var(--s3);
  padding: var(--s3) var(--s4); min-height: 52px;
  width: 100%; text-align: left; color: var(--text);
  border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }
.row svg.lead { width: 22px; height: 22px; stroke: var(--text-2); fill: none; stroke-width: 1.8; }
.row .row-title { font-size: 15px; }
.row .row-value { color: var(--text-3); font-size: 13px; display: inline-flex; align-items: center; gap: 4px; }
.row .row-value svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2; }
.row.danger .row-title, .row.danger svg.lead { color: var(--danger); stroke: var(--danger); }

.section-title {
  margin: var(--s5) var(--s2) var(--s3);
  font-size: 12px; color: var(--text-3);
  text-transform: uppercase; letter-spacing: .08em;
}

/* Empty / hint */
.empty { text-align: center; padding: var(--s8) var(--s4); color: var(--text-2); }
.empty svg { width: 56px; height: 56px; stroke: var(--text-3); fill: none; stroke-width: 1.2; margin: 0 auto var(--s3); }
.empty h3 { margin: 0 0 var(--s1); color: var(--text); font-size: 16px; font-weight: 600; }
.empty p { margin: 0; font-size: 13px; }
.hint { color: var(--text-3); font-size: 12px; }

/* Toast */
.toast {
  position: fixed; left: 50%; transform: translate(-50%, 20px);
  bottom: calc(var(--tabbar-h) + var(--safe-bot) + var(--s4));
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line-strong);
  padding: var(--s3) var(--s4); border-radius: var(--r-pill);
  box-shadow: var(--shadow-2);
  opacity: 0; transition: opacity .2s, transform .2s;
  pointer-events: none; max-width: calc(100% - var(--s8));
  z-index: 100; font-size: 13px; font-weight: 500;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Bottom sheet */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  z-index: 200; display: grid; place-items: end center;
  opacity: 0; transition: opacity .2s ease;
}
.sheet-backdrop.open { opacity: 1; }
.sheet {
  width: 100%; max-width: var(--maxw); background: var(--bg-elev);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  padding: var(--s2) var(--s4) calc(var(--s5) + var(--safe-bot));
  transform: translateY(100%); transition: transform .25s cubic-bezier(.2,.8,.2,1);
}
.sheet-backdrop.open .sheet { transform: translateY(0); }
.sheet-handle { width: 36px; height: 4px; border-radius: 2px; background: var(--line-strong); margin: var(--s2) auto var(--s4); }
.sheet h2 { margin: 0 0 var(--s3); font-size: 17px; font-weight: 600; }
.sheet .sheet-actions { display: flex; gap: var(--s2); margin-top: var(--s4); }
.sheet .sheet-actions .btn { flex: 1; }
.sheet .options { display: flex; flex-direction: column; gap: var(--s1); }
.sheet .options label { display: flex; align-items: center; gap: var(--s3); padding: var(--s3); border-radius: var(--r-md); }
.sheet .options label:active { background: var(--surface); }
.sheet .options input { accent-color: var(--accent); width: 20px; height: 20px; }

/* Onboarding / Auth */
.center-page {
  flex: 1; display: flex; flex-direction: column; justify-content: center;
  padding: var(--s6) var(--s5) calc(var(--s5) + var(--safe-bot));
  gap: var(--s5);
}
.brand { text-align: center; margin-bottom: var(--s5); }
.brand .logo {
  width: 80px; height: 80px; margin: 0 auto var(--s4);
  border-radius: 24px; overflow: hidden;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.brand .logo svg { width: 100%; height: 100%; }
.brand h1 { margin: 0; font-size: 32px; font-weight: 700; letter-spacing: -.02em; }
.brand p  { margin: var(--s2) 0 0; color: var(--text-2); font-size: 14px; font-style: italic; }

.auth-actions { display: flex; flex-direction: column; gap: var(--s3); }
.auth-divider { display: flex; align-items: center; gap: var(--s3); color: var(--text-3); font-size: 12px; }
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.consent-list { display: flex; flex-direction: column; gap: var(--s3); margin: var(--s4) 0; }
.consent {
  display: grid; grid-template-columns: 24px 1fr; gap: var(--s3);
  align-items: flex-start; padding: var(--s3);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md); cursor: pointer;
}
.consent input { margin-top: 2px; accent-color: var(--accent); width: 18px; height: 18px; }
.consent span { font-size: 13px; line-height: 1.4; }

/* Crisis */
.crisis {
  background: color-mix(in oklab, var(--danger) 14%, var(--surface));
  border: 1px solid color-mix(in oklab, var(--danger) 40%, transparent);
  border-radius: var(--r-lg);
  padding: var(--s4); margin-bottom: var(--s4);
}
.crisis h3 { margin: 0 0 var(--s2); color: var(--danger); font-size: 15px; }
.crisis p  { margin: 0 0 var(--s2); font-size: 13px; }

/* Avatar picker */
.avatar-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--s3); }
.avatar-grid button {
  aspect-ratio: 1; border-radius: 50%;
  background: var(--surface); border: 2px solid transparent;
  overflow: hidden; padding: 0;
}
.avatar-grid button[aria-pressed="true"] { border-color: var(--accent); }
.avatar-grid img, .avatar-grid svg { width: 100%; height: 100%; object-fit: cover; }

/* Diary */
.diary-entry {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: var(--s3) var(--s4); margin-bottom: var(--s2);
}
.diary-entry .meta { font-size: 11px; color: var(--text-3); margin-bottom: var(--s1); text-transform: uppercase; letter-spacing: .05em; }

/* Field foot */
.field-foot { display: flex; justify-content: space-between; align-items: center; padding: 0 var(--s1); }
.field-foot .count { font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; }

/* A11y */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
