/* Layout: índice fixo à esquerda (tablet deitado) + uma folha pontilhada que rola; no estreito o índice vira gaveta. */
:root {
  --desk: #E3E7E0;      /* mesa atrás do caderno */
  --paper: #F8F9F5;     /* folha */
  --ink: #1E2433;       /* tinta preta-azulada */
  --ink-2: #5C6475;     /* tinta fraca */
  --ink-3: #9AA0AC;     /* lápis */
  --dot: #C9CEC6;       /* pontilhado */
  --rule: #DADFD6;
  --accent: #2F4DA0;    /* caneta azul */
  --accent-soft: #E1E7F6;
  --mark: #F3E07A;      /* marca-texto do "hoje" */
  --warn: #B4472F;      /* tarefa emperrada */
  --warn-soft: #F6E3DC;
  --ok: #3D7A4F;
  --shadow: 0 1px 2px rgba(30,36,51,.06), 0 8px 24px rgba(30,36,51,.07);
  --f-hand: "Kalam", "Segoe Print", "Comic Sans MS", cursive;
  --f-body: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --f-mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --dotgap: 24px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --desk: #14171C; --paper: #1F242C; --ink: #E3E6EC; --ink-2: #A3AAB8; --ink-3: #6B7383;
    --dot: #353C47; --rule: #2E343D; --accent: #93AAF2; --accent-soft: #283352; --mark: #6B5E1F;
    --warn: #F0937A; --warn-soft: #3D2721; --ok: #7CC090;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --desk: #14171C; --paper: #1F242C; --ink: #E3E6EC; --ink-2: #A3AAB8; --ink-3: #6B7383;
  --dot: #353C47; --rule: #2E343D; --accent: #93AAF2; --accent-soft: #283352; --mark: #6B5E1F;
  --warn: #F0937A; --warn-soft: #3D2721; --ok: #7CC090;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--desk); color: var(--ink);
  font: 17px/1.5 var(--f-body);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.shell {
  display: grid; grid-template-columns: 300px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr);
  height: 100%; overflow: hidden;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* ---------- Índice ---------- */
.index {
  overflow-y: auto; padding: 20px 14px 32px max(18px, env(safe-area-inset-left, 0px));
  border-right: 1px solid var(--rule);
}
.index h2 {
  font: 700 30px/1 var(--f-hand); margin: 6px 6px 14px; letter-spacing: .5px;
}
.ix-group { margin: 18px 0 4px 6px; font: 600 11px/1 var(--f-mono); letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); }
.ix-row {
  display: flex; align-items: baseline; gap: 6px; width: 100%;
  padding: 7px 8px; border: 0; background: none; text-align: left; border-radius: 8px; cursor: pointer;
}
.ix-row:hover { background: color-mix(in srgb, var(--paper) 70%, transparent); }
.ix-row.on { background: var(--paper); box-shadow: var(--shadow); }
.ix-row .t { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ix-row .lead { flex: 1 1 auto; border-bottom: 2px dotted var(--dot); transform: translateY(-4px); min-width: 12px; }
.ix-row .n { font: 13px var(--f-mono); color: var(--ink-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.ix-sub { padding-left: 18px; }
.ix-sub .ix-row { padding-block: 4px; font-size: 15px; color: var(--ink-2); }
.ix-add { display: flex; gap: 6px; margin: 8px 6px 0; }
.ix-add input { flex: 1; min-width: 0; }

/* ---------- Folha ---------- */
.sheet { display: flex; flex-direction: column; min-width: 0; height: 100%; }
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px max(16px, env(safe-area-inset-right, 0px)) 10px 20px;
}
.crumbs { flex: 1; min-width: 0; font: 13px var(--f-mono); color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topactions { display: flex; gap: 8px; align-items: center; }
.iconbtn {
  width: 44px; height: 44px; display: grid; place-items: center;
  border: 0; border-radius: 12px; background: none; cursor: pointer; color: var(--ink-2);
}
.iconbtn:hover { background: var(--paper); }
.pill {
  height: 40px; padding: 0 16px; border-radius: 20px; border: 1.5px solid var(--ink);
  background: var(--paper); font-weight: 700; cursor: pointer;
}
.pill.ghost { border-color: var(--rule); font-weight: 400; }
a.pill { color: var(--ink); }
.pill.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.only-narrow, .scrim { display: none; }
.syncst {
  height: 40px; display: inline-flex; align-items: center; gap: 6px; padding: 0 10px; border: 0; background: none;
  border-radius: 12px; color: var(--ink-3); font: 12px var(--f-mono); cursor: pointer; white-space: nowrap;
}
.syncst:hover { background: var(--paper); }
.syncst[data-st="ok"] { color: var(--ok); }
.syncst[data-st="sync"] { color: var(--accent); }
.syncst[data-st="sync"] svg { animation: pulse 1.2s ease-in-out infinite; }
.syncst[data-st="error"] { color: var(--warn); }
@keyframes pulse { 50% { opacity: .35; } }
@media (max-width: 560px) { .syncst span { display: none; } }

.scroller { flex: 1; overflow-y: auto; padding: 0 max(16px, env(safe-area-inset-right, 0px)) 48px 20px; scroll-behavior: smooth; }
.page {
  position: relative; max-width: 860px; margin: 0 auto; min-height: calc(100% - 8px);
  background-color: var(--paper);
  background-image: radial-gradient(circle, var(--dot) 1.1px, transparent 1.4px);
  background-size: var(--dotgap) var(--dotgap); background-position: 12px 12px;
  border-radius: 6px 14px 14px 6px; box-shadow: var(--shadow);
  padding: 28px 40px 48px 52px;
}
.page::before { /* espiral/encadernação sugerida por uma linha de furos */
  content: ""; position: absolute; left: 18px; top: 24px; bottom: 24px; width: 8px;
  background-image: radial-gradient(circle, var(--desk) 3.5px, transparent 4px);
  background-size: 8px 36px; opacity: .9;
}

.pghead { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 10px; }
.pghead h1 { font: 700 40px/1.05 var(--f-hand); margin: 0; flex: 1; min-width: 0; text-wrap: balance; }
.pghead h1 small { display: block; font: 400 18px/1.4 var(--f-hand); color: var(--ink-2); }
.pgnum { font: 13px var(--f-mono); color: var(--ink-3); padding-bottom: 6px; font-variant-numeric: tabular-nums; }
.hl { background: linear-gradient(transparent 55%, var(--mark) 55%, var(--mark) 92%, transparent 92%); padding: 0 .1em; }

h3.sec { font: 700 22px/1.2 var(--f-hand); margin: 26px 0 6px; display: flex; align-items: baseline; gap: 10px; }
h3.sec .aside { font: 13px var(--f-body); color: var(--ink-2); font-weight: 400; }

/* ---------- Banners de ritual ---------- */
.ritual {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  margin: 6px 0 16px; padding: 12px 14px; border-radius: 12px;
  background: var(--accent-soft); border: 1.5px dashed var(--accent);
}
.ritual p { margin: 0; flex: 1 1 240px; min-width: 0; }
.ritual b { font-family: var(--f-hand); font-size: 20px; font-weight: 700; display: block; line-height: 1.1; }

/* ---------- Entradas (rapid log) ---------- */
.log { list-style: none; margin: 0; padding: 0; }
.entry {
  display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; align-items: start;
  min-height: var(--dotgap); position: relative;
}
.entry + .entry { margin-top: 2px; }
.bullet {
  width: 40px; height: 36px; border: 0; background: none; cursor: pointer; padding: 0;
  display: grid; place-items: center; font: 700 22px/1 var(--f-mono); color: var(--ink);
  border-radius: 8px; position: relative;
}
.bullet:hover { background: var(--accent-soft); }
.bullet .prio { position: absolute; left: -8px; top: 6px; font-size: 16px; color: var(--warn); }
.bullet svg { width: 22px; height: 22px; }
.txt {
  padding: 5px 4px; min-height: 36px; outline: none; word-break: break-word; white-space: pre-wrap;
  border-radius: 6px;
}
.txt:focus { background: color-mix(in srgb, var(--accent-soft) 60%, transparent); }
.entry.note .txt { color: var(--ink-2); font-style: italic; }
.entry.event .txt { font-weight: 700; }
.entry.s-done .txt { color: var(--ink-2); }
.entry.s-migrated .txt, .entry.s-scheduled .txt { color: var(--ink-3); }
.entry.s-cancelled .txt { color: var(--ink-3); text-decoration: line-through; text-decoration-thickness: 2px; }
.entry.s-migrated .bullet, .entry.s-scheduled .bullet, .entry.s-cancelled .bullet { color: var(--ink-3); }
.more { width: 40px; height: 36px; border: 0; background: none; border-radius: 8px; color: var(--ink-3); cursor: pointer; font-size: 20px; line-height: 1; }
.more:hover { background: var(--accent-soft); color: var(--ink); }
.chip {
  display: inline-block; margin-left: 6px; padding: 0 7px; border-radius: 10px; font: 600 11px/18px var(--f-mono);
  vertical-align: 2px; background: var(--rule); color: var(--ink-2); white-space: nowrap; font-style: normal;
}
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.link { background: var(--accent-soft); color: var(--accent); cursor: pointer; }
.empty { color: var(--ink-3); font-style: italic; padding: 4px 0 4px 44px; margin: 0; }

/* entrada rápida */
.quick {
  display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px; align-items: center;
  margin-top: 6px; padding: 4px; border-radius: 12px; border: 1.5px solid transparent;
}
.quick:focus-within { border-color: var(--rule); background: var(--paper); }
.typesw { display: flex; gap: 2px; }
.typesw button {
  width: 38px; height: 38px; border-radius: 10px; border: 0; background: none; cursor: pointer;
  font: 700 20px/1 var(--f-mono); color: var(--ink-3);
}
.typesw button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.typesw button svg { width: 18px; height: 18px; vertical-align: middle; }
input.field, .quick input {
  width: 100%; height: 44px; border: 0; background: transparent; font: inherit; color: var(--ink); padding: 0 8px; outline: none;
}
input.box, select.box {
  height: 44px; padding: 0 12px; border-radius: 10px; border: 1.5px solid var(--rule);
  background: var(--paper); font: inherit; color: var(--ink);
}
.hint { font: 12px var(--f-mono); color: var(--ink-3); margin: 2px 0 0 4px; }

/* ---------- Mês ---------- */
.monthgrid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 32px; }
.cal { list-style: none; padding: 0; margin: 0; }
.cal li { display: grid; grid-template-columns: 30px 22px minmax(0, 1fr); align-items: center; min-height: var(--dotgap); border-bottom: 1px solid color-mix(in srgb, var(--rule) 60%, transparent); }
.cal .d { font: 600 14px var(--f-mono); font-variant-numeric: tabular-nums; border: 0; background: none; cursor: pointer; text-align: right; padding: 2px 4px; border-radius: 6px; color: var(--ink); }
.cal .d.has { text-decoration: underline; text-decoration-color: var(--accent); text-underline-offset: 3px; }
.cal .w { font: 13px var(--f-mono); color: var(--ink-3); text-align: center; }
.cal li.we .w, .cal li.we .d { color: var(--ink-3); }
.cal li.today { background: linear-gradient(90deg, var(--mark), transparent 80%); border-radius: 4px; }
.cal .ct { padding: 3px 6px; outline: none; min-height: 28px; font-size: 15px; word-break: break-word; }
.cal .ct:focus { background: var(--accent-soft); border-radius: 6px; }

/* ---------- Registro futuro ---------- */
.future { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px 24px; }
.fm { border-top: 2px solid var(--ink); padding-top: 4px; min-width: 0; }
.fm h4 { margin: 0 0 4px; font: 700 20px/1.3 var(--f-hand); display: flex; justify-content: space-between; }
.fm h4 span { font: 12px var(--f-mono); color: var(--ink-3); font-weight: 400; align-self: center; }
.fm .entry { grid-template-columns: 32px minmax(0, 1fr) auto; }
.fm .bullet { width: 32px; }
.fm .quick { grid-template-columns: minmax(0, 1fr); }
.fm .quick input { height: 38px; font-size: 15px; }

/* ---------- Hábitos ---------- */
.habits-wrap { overflow-x: auto; margin: 0 -8px; padding: 0 8px 8px; }
table.habits { border-collapse: separate; border-spacing: 0; font-variant-numeric: tabular-nums; }
.habits th, .habits td { padding: 0; }
.habits thead th { font: 11px var(--f-mono); color: var(--ink-3); width: 24px; height: 22px; text-align: center; font-weight: 400; }
.habits thead th.today { color: var(--ink); font-weight: 700; background: var(--mark); border-radius: 4px 4px 0 0; }
.habits th.hname { text-align: left; font: 16px var(--f-body); color: var(--ink); padding-right: 10px; white-space: nowrap; max-width: 180px; overflow: hidden; text-overflow: ellipsis; position: sticky; left: 0; background: var(--paper); z-index: 1; }
.habits td button {
  width: 24px; height: 30px; border: 0; background: none; cursor: pointer; display: grid; place-items: center; padding: 0;
}
.habits td button i { width: 16px; height: 16px; border: 1.5px solid var(--dot); border-radius: 3px; display: block; }
.habits td button.on i { background: var(--ink); border-color: var(--ink); transform: rotate(-4deg); border-radius: 2px 5px 3px 4px; }
.habits td.today { background: color-mix(in srgb, var(--mark) 45%, transparent); }
.habits td.we button i { border-style: dashed; }
.habits .cnt { font: 12px var(--f-mono); color: var(--ink-2); padding-left: 8px; white-space: nowrap; }
.habits .del { border: 0; background: none; color: var(--ink-3); cursor: pointer; font-size: 18px; width: 32px; height: 30px; }

/* ---------- Tinta ---------- */
.inkwrap { margin-top: 28px; }
.inkbar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.inkbar .lbl { font: 700 20px var(--f-hand); margin-right: auto; }
.tool {
  height: 40px; min-width: 40px; padding: 0 10px; border-radius: 10px; border: 1.5px solid var(--rule); background: var(--paper);
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px; font-size: 14px;
}
.tool[aria-pressed="true"] { border-color: var(--ink); background: var(--accent-soft); }
.tool .sw { width: 16px; height: 16px; border-radius: 50%; display: inline-block; border: 1.5px solid var(--paper); box-shadow: 0 0 0 1px var(--ink-3); }
.tool svg { width: 18px; height: 18px; }
.inkarea {
  position: relative; border-radius: 10px; border: 1.5px dashed var(--rule);
  touch-action: none; overflow: hidden;
}
.inkarea canvas { display: block; width: 100%; }
.inkarea .ph { position: absolute; inset: 16px auto auto 16px; color: var(--ink-3); font: 18px var(--f-hand); pointer-events: none; }

/* ---------- Modal (folha de baixo) ---------- */
.sheetmodal { position: fixed; inset: 0; z-index: 50; display: grid; align-items: end; justify-items: center; }
.modalback { position: absolute; inset: 0; background: rgba(15,18,25,.35); }
.modalcard {
  position: relative; width: min(640px, 100%); max-height: 88%; overflow-y: auto;
  background: var(--paper); border-radius: 20px 20px 0 0; box-shadow: var(--shadow);
  padding: 18px max(20px, env(safe-area-inset-right, 0px)) calc(22px + env(safe-area-inset-bottom, 0px)) max(20px, env(safe-area-inset-left, 0px));
  animation: up .18s ease-out;
}
@media (min-width: 760px) { .sheetmodal { align-items: center; } .modalcard { border-radius: 20px; max-height: 84%; } }
@keyframes up { from { transform: translateY(24px); opacity: .4; } }
.modalcard h2 { font: 700 28px/1.15 var(--f-hand); margin: 0 0 4px; }
.modalcard .sub { color: var(--ink-2); margin: 0 0 14px; }
.actions { display: grid; gap: 8px; }
.act {
  display: flex; align-items: center; gap: 14px; width: 100%; min-height: 52px; padding: 8px 14px;
  border: 1.5px solid var(--rule); border-radius: 12px; background: var(--paper); cursor: pointer; text-align: left;
}
.act:hover { border-color: var(--ink-3); }
.act .g { width: 28px; font: 700 22px var(--f-mono); text-align: center; flex: none; }
.act .d { display: block; font-size: 13px; color: var(--ink-2); }
.act.danger { color: var(--warn); }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row > * { min-width: 0; }
.spacer { flex: 1; }

/* revisão (rituais) */
.rv { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 10px; }
.rv li { border: 1.5px solid var(--rule); border-radius: 12px; padding: 10px 12px; }
.rv li.decided { opacity: .55; }
.rv .rt { display: flex; gap: 10px; align-items: baseline; }
.rv .rt .g { font: 700 18px var(--f-mono); width: 20px; flex: none; }
.rv .rt .x { flex: 1; min-width: 0; }
.rv .from { font: 12px var(--f-mono); color: var(--ink-3); white-space: nowrap; }
.rv .ask { color: var(--warn); font-size: 14px; margin: 4px 0 0 30px; }
.rv .btns { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0 0 30px; }
.rv .btns button { height: 38px; padding: 0 12px; border-radius: 10px; border: 1.5px solid var(--rule); background: var(--paper); cursor: pointer; font-size: 14px; }
.rv .btns button.sel { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.steps { display: flex; gap: 6px; margin-bottom: 12px; }
.steps i { height: 4px; flex: 1; border-radius: 2px; background: var(--rule); }
.steps i.on { background: var(--ink); }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 12px; z-index: 60;
  display: flex; gap: 14px; align-items: center; box-shadow: var(--shadow); max-width: calc(100% - 32px);
}
.toast button { background: none; border: 0; color: var(--mark); font-weight: 700; cursor: pointer; }

/* ---------- Responsivo ---------- */
@media (max-width: 980px) {
  .monthgrid { grid-template-columns: minmax(0, 1fr); }
  .future { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .only-narrow { display: grid; }
  .index {
    position: fixed; z-index: 40; top: 0; bottom: 0; left: 0; width: min(320px, 86vw);
    background: var(--desk); transform: translateX(-102%); transition: transform .2s ease;
    padding-top: calc(20px + env(safe-area-inset-top, 0px));
  }
  .shell.drawer .index { transform: none; box-shadow: var(--shadow); }
  .scrim { position: fixed; inset: 0; z-index: 39; background: rgba(15,18,25,.3); display: none; }
  .shell.drawer .scrim { display: block; }
  .topbar { padding-left: max(16px, env(safe-area-inset-left, 0px)); }
  .scroller { padding-left: max(16px, env(safe-area-inset-left, 0px)); }
}
@media (max-width: 560px) {
  .page { padding: 20px 14px 40px 30px; }
  .page::before { left: 8px; }
  .pghead h1 { font-size: 32px; }
  .future { grid-template-columns: minmax(0, 1fr); }
  .rv .btns, .rv .ask { margin-left: 0; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }

/* ---------- bullets escritos à mão ---------- */
.typesw .pentg { margin-left: 6px; border: 1.5px solid var(--rule); }
.typesw .pentg[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--paper); }
.quick.penmode { border-color: var(--rule); background: var(--paper); align-items: start; }
.qink {
  position: relative; min-width: 0; border-radius: 10px; touch-action: none;
  background-image: linear-gradient(transparent calc(100% - 22px), var(--rule) calc(100% - 22px), var(--rule) calc(100% - 21px), transparent calc(100% - 21px));
}
.qink canvas { display: block; width: 100%; cursor: crosshair; }
.qph { position: absolute; left: 10px; bottom: 26px; color: var(--ink-3); font: 17px var(--f-hand); pointer-events: none; }
.qtools { position: absolute; right: 2px; top: 2px; display: flex; gap: 2px; }
.qtools button { width: 34px; height: 34px; border: 0; border-radius: 8px; background: color-mix(in srgb, var(--paper) 80%, transparent); color: var(--ink-2); font-size: 18px; cursor: pointer; }
.qtools button:hover { background: var(--accent-soft); color: var(--ink); }
.qbar { position: absolute; left: 0; bottom: 0; height: 3px; width: 0; border-radius: 2px; background: var(--accent); opacity: 0; }
.qbar.run { opacity: 1; animation: qfill 1.5s linear forwards; }
@keyframes qfill { from { width: 0; } to { width: 100%; } }
.txt.inktxt { padding: 2px 4px; cursor: default; }
.inkimg { display: block; max-width: 100%; height: auto; }
.inkimg.dim { opacity: .45; }
.entry.s-cancelled .inktxt { position: relative; }
.entry.s-cancelled .inktxt::after { content: ""; position: absolute; left: 0; right: 0; top: 50%; border-top: 2px solid var(--ink-3); }
.rv .x .inkimg, .modalcard h2 .inkimg { display: inline-block; vertical-align: middle; max-height: 56px; width: auto; }
