:root {
  --bg: #faf8f3; --panel: #ffffff; --side: #f1ede4; --line: #e4ddd0; --text: #26221c; --muted: #7a7266;
  --brand: #17905a; --brand-2: #0f6e44; --brand-soft: #dff3e8; --accent: #a8703d; --danger: #c8402f;
  --hover: rgba(60, 45, 20, .07); --sel: #e3f1e8; --shadow: 0 8px 30px rgba(40, 30, 10, .16); --hl: #fff2a8;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #171a18; --panel: #1e2220; --side: #131614; --line: #2e3531; --text: #ece8df; --muted: #9a9a8e;
    --brand: #3fc586; --brand-2: #2aa96d; --brand-soft: #1d3a2c; --accent: #d49c63; --danger: #ef6a58;
    --hover: rgba(255, 255, 255, .07); --sel: #223a2e; --shadow: 0 8px 30px rgba(0, 0, 0, .5); --hl: #6b5a12;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #171a18; --panel: #1e2220; --side: #131614; --line: #2e3531; --text: #ece8df; --muted: #9a9a8e;
  --brand: #3fc586; --brand-2: #2aa96d; --brand-soft: #1d3a2c; --accent: #d49c63; --danger: #ef6a58;
  --hover: rgba(255, 255, 255, .07); --sel: #223a2e; --shadow: 0 8px 30px rgba(0, 0, 0, .5); --hl: #6b5a12;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; overflow: hidden; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
input, select, textarea { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; outline: none; min-width: 0; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); }
a { color: var(--brand); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
.ic { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.sp { flex: 1; }
.muted { color: var(--muted); }
.only-m { display: none !important; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 10px; border: 2px solid transparent; background-clip: content-box; }

#app { display: flex; height: 100dvh; }

/* ---------- Sidebar ---------- */
#sidebar { width: 252px; flex: none; background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 10px; padding: 16px 16px 10px; font-weight: 700; font-size: 18px; letter-spacing: -.2px; }
.brand img { width: 34px; height: 34px; border-radius: 9px; box-shadow: 0 2px 6px rgba(0, 0, 0, .18); }
.newrow { display: flex; gap: 1px; padding: 6px 14px 10px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 8px 14px; border-radius: 9px; background: var(--brand); color: #fff; font-weight: 600; white-space: nowrap; }
.btn:hover { background: var(--brand-2); }
:root[data-theme="dark"] .btn, .btn.dk { color: #fff; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); font-weight: 500; }
.btn.ghost:hover { background: var(--hover); }
.btn.danger { background: var(--danger); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.newrow .btn:first-child { flex: 1; border-radius: 9px 0 0 9px; }
.newrow .btn:last-child { border-radius: 0 9px 9px 0; padding: 8px 9px; }
.nav { flex: 1; overflow-y: auto; padding: 0 8px 12px; }
.nav-i { display: flex; align-items: center; gap: 9px; width: 100%; padding: 7px 9px; border-radius: 8px; text-align: left; color: var(--text); }
.nav-i:hover { background: var(--hover); }
.nav-i.on { background: var(--sel); color: var(--brand-2); font-weight: 600; }
:root[data-theme="dark"] .nav-i.on { color: var(--brand); }
.nav-i .lbl { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-i .cnt { font-size: 12px; color: var(--muted); font-weight: 400; }
.nav-i.sub { padding-left: 34px; font-size: 13.5px; }
.nav-i.sub2 { padding-left: 52px; font-size: 13.5px; }
.nav-h { display: flex; align-items: center; padding: 14px 9px 4px; font-size: 11.5px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase; color: var(--muted); }
.nav-h button { padding: 2px; border-radius: 6px; color: var(--muted); }
.nav-h button:hover { background: var(--hover); color: var(--text); }
.side-foot { display: flex; gap: 4px; padding: 8px 12px; border-top: 1px solid var(--line); }
.ib { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-width: 34px; height: 34px; padding: 0 8px; border-radius: 8px; color: var(--muted); }
.ib:hover { background: var(--hover); color: var(--text); }
.ib.on { color: #e9a200; }
.ib.on .ic { fill: currentColor; }

/* ---------- Lista ---------- */
#listpane { width: 340px; flex: none; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; }
.lp-head { display: flex; align-items: center; gap: 4px; padding: 14px 10px 6px 16px; }
.lp-head h2 { font-size: 19px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lp-sub { padding: 0 16px 8px; font-size: 12.5px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.qwrap { position: relative; margin: 0 12px 10px; }
.qwrap .ic { position: absolute; left: 10px; top: 9px; color: var(--muted); }
#q { width: 100%; padding-left: 34px; background: var(--bg); }
#list { flex: 1; overflow-y: auto; border-top: 1px solid var(--line); }
.ni { display: flex; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); cursor: pointer; }
.ni:hover { background: var(--hover); }
.ni.on { background: var(--sel); box-shadow: inset 3px 0 0 var(--brand); }
.ni-b { flex: 1; min-width: 0; }
.ni-t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ni-s { color: var(--muted); font-size: 13px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 1.4em; }
.ni-m { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 5px; font-size: 12px; color: var(--muted); }
.ni-m .ic { width: 13px; height: 13px; }
.ni-th { width: 62px; height: 62px; object-fit: cover; border-radius: 8px; flex: none; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 20px; background: var(--brand-soft); color: var(--brand-2); font-size: 12px; white-space: nowrap; }
:root[data-theme="dark"] .chip { color: var(--brand); }
.chip button { color: inherit; opacity: .6; line-height: 1; }
.chip button:hover { opacity: 1; }
.chip.warn { background: #fde9c8; color: #8a5a00; }
#list.compact .ni-s, #list.compact .ni-th { display: none; }
#list.compact .ni { padding: 8px 16px; }
#list.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 10px; align-content: start; background: var(--bg); }
#list.cards .ni { flex-direction: column-reverse; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); padding: 10px; height: 170px; overflow: hidden; }
#list.cards .ni.on { box-shadow: 0 0 0 2px var(--brand); }
#list.cards .ni-th { width: 100%; height: 60px; }
#list.cards .ni-s { -webkit-line-clamp: 3; }
.empty { padding: 48px 24px; text-align: center; color: var(--muted); }
.empty img { width: 88px; border-radius: 22px; opacity: .9; margin-bottom: 12px; }
.empty h3 { color: var(--text); margin-bottom: 4px; }

/* ---------- Principal / Editor ---------- */
#main { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--panel); }
body.full #listpane { display: none; }
body.full #main { background: var(--bg); }
body.focus #sidebar, body.focus #listpane { display: none; }
.ed-head { display: flex; align-items: center; gap: 4px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.ed-head select { border: 0; background: transparent; padding: 6px; max-width: 200px; color: var(--muted); }
.ed-head select:hover { background: var(--hover); }
.saved { font-size: 12px; color: var(--muted); margin-left: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; padding: 5px 10px; border-bottom: 1px solid var(--line); }
.tb::-webkit-scrollbar { display: none; }
.tb button { min-width: 30px; height: 30px; padding: 0 6px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; flex: none; color: var(--text); }
.tb button:hover { background: var(--hover); }
.tb button.rec { background: var(--danger); color: #fff; }
.tb select { border: 0; background: transparent; padding: 4px 2px; height: 30px; flex: none; }
.tb select:hover { background: var(--hover); }
.tb .sep { width: 1px; height: 20px; background: var(--line); margin: 0 4px; flex: none; }
.tb input[type=color] { width: 26px; height: 26px; padding: 1px; border-radius: 6px; flex: none; cursor: pointer; }
.banner { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 16px; background: var(--brand-soft); font-size: 13.5px; }
.banner.trash { background: #fbe3df; color: #7a2418; }
:root[data-theme="dark"] .banner.trash { background: #4a211b; color: #ffc9c0; }
.ed-scroll { flex: 1; overflow-y: auto; }
.ed-in { max-width: 820px; margin: 0 auto; padding: 22px 32px 60px; }
#title { width: 100%; border: 0; background: transparent; font-size: 30px; font-weight: 700; padding: 0; letter-spacing: -.4px; }
.meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 4px 0 14px; font-size: 12.5px; color: var(--muted); }
#body { min-height: 300px; outline: none; font-size: 16px; line-height: 1.65; word-wrap: break-word; }
#body:empty::before { content: "Comece a escrever…"; color: var(--muted); }
#body h1 { font-size: 1.7em; margin: .7em 0 .3em; } #body h2 { font-size: 1.35em; margin: .7em 0 .3em; } #body h3 { font-size: 1.13em; margin: .7em 0 .3em; }
#body p { margin: 0 0 .5em; }
#body img { max-width: 100%; border-radius: 8px; }
#body audio { max-width: 100%; display: block; margin: 6px 0; }
#body blockquote { margin: .6em 0; padding: 4px 14px; border-left: 4px solid var(--brand); color: var(--muted); background: var(--bg); border-radius: 0 8px 8px 0; }
#body pre { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; font: 13.5px/1.5 Consolas, "Cascadia Code", monospace; white-space: pre-wrap; }
#body hr { border: 0; border-top: 2px solid var(--line); margin: 1em 0; }
#body table { border-collapse: collapse; width: 100%; margin: .6em 0; }
#body td, #body th { border: 1px solid var(--line); padding: 6px 9px; min-width: 40px; vertical-align: top; }
#body ul.checklist { list-style: none; padding-left: 4px; }
#body ul.checklist li { position: relative; padding-left: 30px; }
#body ul.checklist li::before { content: ""; position: absolute; left: 2px; top: 5px; width: 17px; height: 17px; border: 2px solid var(--muted); border-radius: 5px; cursor: pointer; }
#body ul.checklist li.done { color: var(--muted); text-decoration: line-through; }
#body ul.checklist li.done::before { border-color: var(--brand); background: var(--brand) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12l5 5L19 7'/%3E%3C/svg%3E") center/13px no-repeat; }
#body a.attach { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; margin: 2px 0; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); color: var(--text); text-decoration: none; font-size: 14px; cursor: pointer; }
#body a.attach::before { content: ""; width: 9px; height: 13px; border: 2px solid var(--accent); border-radius: 6px; border-top-color: transparent; transform: rotate(35deg); }
#body a.notelink { background: var(--brand-soft); border-radius: 5px; padding: 0 5px; text-decoration: none; cursor: pointer; }
.note-tasks { margin-top: 26px; border-top: 1px dashed var(--line); padding-top: 12px; }
.note-tasks h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin-bottom: 6px; }
.ed-tags { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 8px 14px; border-top: 1px solid var(--line); color: var(--muted); }
.ed-tags input { border: 0; background: transparent; padding: 3px 4px; width: 150px; }

/* ---------- Visões cheias ---------- */
.fv { flex: 1; overflow-y: auto; }
.fv-in { max-width: 1040px; margin: 0 auto; padding: 24px 28px 60px; }
.fv-head { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.fv-head h1 { font-size: 26px; letter-spacing: -.4px; flex: 1; min-width: 0; }
.hero { border-radius: 18px; padding: 26px 28px; margin-bottom: 18px; color: #fff; background: linear-gradient(135deg, #2fae6f, #0d6641); display: flex; align-items: center; gap: 18px; }
.hero img { width: 76px; height: 76px; border-radius: 20px; box-shadow: 0 6px 18px rgba(0, 0, 0, .25); }
.hero h1 { font-size: 26px; } .hero p { margin: 4px 0 0; opacity: .9; }
.wgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.w { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; min-width: 0; }
.w.wide { grid-column: 1 / -1; }
.w-h { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-weight: 700; }
.w-h button.lnk { font-weight: 500; color: var(--brand); font-size: 13px; }
.recents { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 6px; }
.rc { flex: none; width: 170px; height: 170px; border: 1px solid var(--line); border-radius: 12px; padding: 12px; cursor: pointer; background: var(--bg); display: flex; flex-direction: column; overflow: hidden; }
.rc:hover { border-color: var(--brand); }
.rc b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rc span { flex: 1; font-size: 12.5px; color: var(--muted); overflow: hidden; }
.rc small { color: var(--muted); }
#scratch { width: 100%; height: 150px; resize: vertical; background: #fff8d9; color: #3b3312; border-color: #eadf9f; }
.row { display: flex; align-items: center; gap: 8px; padding: 7px 4px; border-bottom: 1px solid var(--line); min-width: 0; }
.row:last-child { border-bottom: 0; }
.row.click { cursor: pointer; } .row.click:hover { background: var(--hover); }
.row .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--brand); flex: none; }
.task { flex-wrap: wrap; }
.task input[type=text] { flex: 1 1 150px; border: 0; background: transparent; padding: 3px 4px; }
.task.done input[type=text] { text-decoration: line-through; color: var(--muted); }
.task input[type=date] { border: 0; background: transparent; padding: 2px; width: 128px; font-size: 12.5px; color: var(--muted); }
.task .late { color: var(--danger) !important; }
.task .ib { min-width: 28px; height: 28px; padding: 0 4px; }
.task .ib.flag.on { color: var(--danger); }
.addrow { display: flex; gap: 8px; margin: 6px 0 4px; }
.addrow input { flex: 1; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.tab { padding: 5px 13px; border-radius: 20px; border: 1px solid var(--line); background: var(--panel); }
.tab.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.cal .dow { background: var(--side); text-align: center; font-size: 12px; font-weight: 700; padding: 6px 0; color: var(--muted); }
.cal .day { background: var(--panel); min-height: 92px; padding: 5px 6px; cursor: pointer; overflow: hidden; }
.cal .day.out { background: var(--bg); color: var(--muted); }
.cal .day.sel { box-shadow: inset 0 0 0 2px var(--brand); }
.cal .day .n { font-size: 12.5px; font-weight: 600; display: inline-flex; width: 22px; height: 22px; align-items: center; justify-content: center; border-radius: 50%; }
.cal .day.today .n { background: var(--brand); color: #fff; }
.ev { font-size: 11.5px; border-radius: 4px; padding: 0 5px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: var(--brand-soft); }
.ev.t { background: #fde9c8; color: #6b4600; } .ev.r { background: #e2e6fb; color: #2a357a; }

/* ---------- Modal / menu / toast ---------- */
.ov { position: fixed; inset: 0; background: rgba(20, 15, 5, .45); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.modal { background: var(--panel); border-radius: 16px; box-shadow: var(--shadow); width: 460px; max-width: 100%; max-height: 90dvh; display: flex; flex-direction: column; }
.modal.wide { width: 760px; }
.m-h { display: flex; align-items: center; padding: 14px 16px 6px 20px; }
.m-h h3 { flex: 1; font-size: 17px; }
.m-b { padding: 8px 20px 14px; overflow-y: auto; }
.m-b label { display: block; font-size: 12.5px; color: var(--muted); margin: 8px 0 3px; }
.m-b input[type=text], .m-b input[type=datetime-local], .m-b select, .m-b textarea { width: 100%; }
.m-f { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 20px 16px; flex-wrap: wrap; }
.pop { position: fixed; z-index: 120; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 5px; min-width: 210px; max-height: 70dvh; overflow-y: auto; }
.pop button { display: flex; align-items: center; gap: 9px; width: 100%; padding: 7px 10px; border-radius: 7px; text-align: left; }
.pop button:hover { background: var(--hover); }
.pop button.danger { color: var(--danger); }
.pop hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
#toast { position: fixed; left: 50%; bottom: 76px; transform: translateX(-50%); background: #2b2a26; color: #fff; padding: 10px 18px; border-radius: 12px; z-index: 200; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; }
#sketch { border: 1px solid var(--line); border-radius: 10px; background: #fff; width: 100%; touch-action: none; cursor: crosshair; display: block; }
.hist { display: grid; grid-template-columns: 210px 1fr; gap: 12px; min-height: 300px; }
.hist-prev { border: 1px solid var(--line); border-radius: 10px; padding: 12px; overflow: auto; max-height: 55dvh; }
.hist-prev img { max-width: 100%; }
#bottomnav, #scrim { display: none; }

/* ---------- Mobile ---------- */
@media (max-width: 820px) {
  .only-m { display: inline-flex !important; }
  .only-d { display: none !important; }
  #sidebar { position: fixed; top: 0; bottom: 0; left: 0; width: 290px; max-width: 86vw; z-index: 60; transform: translateX(-102%); transition: transform .22s; box-shadow: var(--shadow); padding-top: env(safe-area-inset-top); }
  body.side-open #sidebar { transform: none; }
  body.side-open #scrim { display: block; position: fixed; inset: 0; background: rgba(20, 15, 5, .45); z-index: 55; }
  #listpane { width: auto; flex: 1; border: 0; padding-top: env(safe-area-inset-top); }
  #main { display: none; padding-top: env(safe-area-inset-top); }
  body.full #main, body.m-main #main { display: flex; }
  body.m-main #listpane { display: none; }
  #app { height: calc(100dvh - 58px - env(safe-area-inset-bottom)); }
  body.m-main:not(.full) #app { height: 100dvh; }
  #bottomnav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; height: calc(58px + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: var(--panel); border-top: 1px solid var(--line); z-index: 50; }
  body.m-main:not(.full) #bottomnav { display: none; }
  #bottomnav button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; color: var(--muted); }
  #bottomnav button.on { color: var(--brand); }
  #bottomnav .ic { width: 22px; height: 22px; }
  #bottomnav .fab { flex: none; width: 52px; height: 52px; margin: -14px 8px 0; border-radius: 50%; background: var(--brand); color: #fff; box-shadow: 0 6px 16px rgba(13, 102, 65, .45); }
  .tb { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .ed-in { padding: 16px 16px 60px; }
  #title { font-size: 24px; }
  .fv-in { padding: 16px 16px 40px; }
  .hero { padding: 18px; } .hero img { width: 58px; height: 58px; border-radius: 16px; } .hero h1 { font-size: 21px; }
  .wgrid { grid-template-columns: 1fr; }
  .cal .day { min-height: 58px; padding: 3px; } .ev { font-size: 0; height: 5px; padding: 0; }
  .hist { grid-template-columns: 1fr; }
  .ov { align-items: flex-end; padding: 0; }
  .modal, .modal.wide { width: 100%; border-radius: 18px 18px 0 0; padding-bottom: env(safe-area-inset-bottom); }
  .task input[type=date] { width: 108px; }
  .ed-head select { max-width: 130px; }
}

@media print {
  #sidebar, #listpane, #bottomnav, .ed-head, .tb, .ed-tags, .banner, .note-tasks, #toast { display: none !important; }
  body, #app, #main, .ed-scroll { overflow: visible; height: auto; display: block; background: #fff; color: #000; }
}
