/* ================= Notas ================= */
:root {
  --bg: #f2f2f7;
  --surface: #ffffff;
  --sidebar: #f5f5f7;
  --text: #1c1c1e;
  --muted: #8a8a8e;
  --faint: #c7c7cc;
  --sep: rgba(60, 60, 67, .16);
  --accent: #d99a00;
  --accent-strong: #e5a50a;
  --sel: #fde68a;
  --sel-muted: rgba(0, 0, 0, .07);
  --danger: #ff3b30;
  --field: rgba(118, 118, 128, .12);
  --shadow: 0 10px 40px rgba(0, 0, 0, .16), 0 1px 3px rgba(0, 0, 0, .08);
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --sidebar: #161618;
    --text: #f2f2f7;
    --muted: #98989f;
    --faint: #48484a;
    --sep: rgba(84, 84, 88, .55);
    --accent: #ffd60a;
    --accent-strong: #ffd60a;
    --sel: #5c4b12;
    --sel-muted: rgba(255, 255, 255, .09);
    --danger: #ff453a;
    --field: rgba(118, 118, 128, .24);
    --shadow: 0 10px 40px rgba(0, 0, 0, .6), 0 0 0 .5px rgba(255, 255, 255, .1);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.4 var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
svg { width: 22px; height: 22px; flex: none; }
.spacer { flex: 1; }

/* ---------- Botões ---------- */
.icon-btn {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px; border-radius: 8px;
  color: var(--accent);
}
.icon-btn:hover { background: var(--sel-muted); }
.icon-btn:disabled { color: var(--faint); background: none; cursor: default; }
.icon-btn.on { background: var(--sel-muted); }
.text-btn { color: var(--accent); font-weight: 500; padding: 6px 8px; border-radius: 8px; }
.text-btn:hover { background: var(--sel-muted); }
.back-btn {
  display: none; align-items: center; gap: 2px;
  color: var(--accent); font-size: 17px; padding: 6px 6px 6px 0; margin-left: -6px;
}
.back-btn svg { width: 24px; height: 24px; }
.back-btn span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 110px; }
.mobile-only { display: none; }

/* ---------- Layout desktop: 3 colunas ---------- */
.app {
  display: grid;
  grid-template-columns: 260px 330px 1fr;
  height: 100vh; height: 100dvh;
  transition: grid-template-columns .2s ease;
}
.app.no-sidebar { grid-template-columns: 0 330px 1fr; }
.app.no-sidebar .sidebar { visibility: hidden; }
.pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }
.pane-head { padding: 10px 14px 8px; flex: none; }
.head-row { display: flex; align-items: center; gap: 4px; min-height: 36px; }
.pane-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 0 10px 16px; }
.pane-foot {
  flex: none; display: flex; align-items: center; gap: 6px;
  padding: 6px 10px calc(6px + var(--safe-b));
}
.big-title { font-size: 22px; font-weight: 700; margin: 4px 4px 10px; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar { background: var(--sidebar); border-right: 1px solid var(--sep); }
.list { background: var(--surface); border-right: 1px solid var(--sep); }
.editor { background: var(--surface); }
.list .pane-foot { display: none; }

/* ---------- Pastas ---------- */
.group { display: flex; flex-direction: column; gap: 1px; }
.group-label { font-size: 12px; font-weight: 600; color: var(--muted); margin: 14px 10px 4px; text-transform: uppercase; letter-spacing: .03em; }
.folder {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border-radius: 8px; cursor: pointer; user-select: none;
  min-height: 36px;
}
.folder:hover { background: var(--sel-muted); }
.folder.active { background: var(--sel-muted); font-weight: 600; }
.folder svg { color: var(--accent); }
.folder .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder .count { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.folder .more { display: none; color: var(--muted); width: 26px; height: 26px; border-radius: 6px; place-items: center; }
.folder .more svg { width: 18px; height: 18px; color: var(--muted); }
.folder:hover .more, .folder.active .more { display: inline-grid; }
.folder:hover .more + .count, .folder.active .more + .count { display: none; }
.folder .chev { display: none; color: var(--faint); width: 18px; height: 18px; }
.folder.drop { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ---------- Busca ---------- */
.search {
  display: flex; align-items: center; gap: 6px;
  background: var(--field); border-radius: 10px; padding: 0 8px; height: 36px; margin: 0 2px;
}
.search svg { width: 17px; height: 17px; color: var(--muted); }
.search input { flex: 1; border: 0; outline: 0; background: none; height: 100%; font-size: 15px; min-width: 0; }
.search input::placeholder { color: var(--muted); }
.search input::-webkit-search-cancel-button { filter: grayscale(1); }

/* ---------- Lista de notas ---------- */
.trash-hint { color: var(--muted); font-size: 13px; text-align: center; margin: 4px 12px 10px; }
.note-group-label { font-size: 13px; font-weight: 700; margin: 16px 10px 4px; }
.note-group-label:first-child { margin-top: 6px; }
.note-group-label .pin { width: 13px; height: 13px; vertical-align: -1px; color: var(--accent); margin-right: 3px; }
.note-item {
  position: relative; display: block; width: 100%; text-align: left;
  padding: 10px 12px; border-radius: 9px; cursor: default; user-select: none;
}
.note-item + .note-item::before {
  content: ""; position: absolute; top: 0; left: 12px; right: 12px; border-top: 1px solid var(--sep);
}
.note-item.active, .note-item.active + .note-item::before { border-color: transparent; }
.note-item.active { background: var(--sel); }
.list:not(:focus-within) .note-item.active { background: var(--sel); }
.note-item .t { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-item .s { display: flex; gap: 7px; font-size: 13.5px; margin-top: 2px; white-space: nowrap; overflow: hidden; }
.note-item .d { color: var(--text); flex: none; }
.note-item .p { color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.note-item .f { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.note-item .f svg { width: 13px; height: 13px; }
.note-item mark { background: rgba(255, 214, 10, .45); color: inherit; border-radius: 2px; }
.empty { text-align: center; color: var(--muted); font-size: 17px; padding: 60px 20px; }

/* ---------- Editor ---------- */
.editor-bar {
  flex: none; display: flex; align-items: center; gap: 2px;
  padding: 10px 14px 6px; min-height: 52px;
}
.tools { display: flex; gap: 2px; }
.save-state { font-size: 12px; color: var(--muted); margin-left: 6px; white-space: nowrap; }
.save-state.err { color: var(--danger); }
.editor-scroll { flex: 1; overflow-y: auto; position: relative; padding: 0 0 40vh; }
.note-date { text-align: center; color: var(--muted); font-size: 12.5px; padding: 4px 0 14px; }
.note-body {
  max-width: 760px; margin: 0 auto; padding: 0 28px;
  outline: none; font-size: 16px; line-height: 1.5; word-wrap: break-word; overflow-wrap: anywhere;
  caret-color: var(--accent-strong); min-height: 50vh;
}
.note-body.is-empty::before {
  content: attr(data-placeholder); color: var(--muted); position: absolute; pointer-events: none;
  font-size: 28px; font-weight: 700;
}
.note-body h1 { font-size: 28px; line-height: 1.2; font-weight: 700; margin: 0 0 6px; letter-spacing: -.01em; }
.note-body h2 { font-size: 22px; line-height: 1.25; font-weight: 700; margin: 10px 0 4px; }
.note-body h3 { font-size: 18px; line-height: 1.3; font-weight: 600; margin: 8px 0 2px; }
.note-body p { margin: 0; }
.note-body pre { font-family: var(--mono); font-size: 14px; background: var(--field); padding: 10px 12px; border-radius: 8px; white-space: pre-wrap; margin: 6px 0; }
.note-body blockquote { border-left: 3px solid var(--faint); margin: 6px 0; padding-left: 12px; color: var(--muted); }
.note-body a { color: var(--accent); text-decoration: underline; }
.note-body ul, .note-body ol { margin: 2px 0; padding-left: 26px; }
.note-body hr { border: 0; border-top: 1px solid var(--sep); margin: 14px 0; }
.note-body ul.checklist { list-style: none; padding-left: 0; }
.note-body ul.checklist ul.checklist { padding-left: 30px; }
.note-body ul.checklist > li { position: relative; padding: 3px 0 3px 32px; }
.note-body ul.checklist > li::before {
  content: ""; position: absolute; left: 1px; top: 4px;
  width: 20px; height: 20px; border-radius: 50%;
  border: 1.5px solid var(--faint); cursor: pointer;
}
.note-body ul.checklist > li.checked { color: var(--muted); }
.note-body ul.checklist > li.checked::before {
  border-color: var(--accent-strong);
  background: var(--accent-strong) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='m6.5 12.5 3.5 3.5 7.5-8' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/14px no-repeat;
}
.note-body[contenteditable="false"] { cursor: default; }
.note-body[contenteditable="false"] ul.checklist > li::before { cursor: default; }

.trash-banner {
  max-width: 760px; margin: 0 auto 10px; padding: 10px 14px;
  display: flex; align-items: center; gap: 10px;
  background: var(--field); border-radius: 10px; font-size: 13.5px; color: var(--muted);
}
.trash-banner span { flex: 1; }
.no-note {
  position: absolute; inset: 0; display: none; flex-direction: column; align-items: center; justify-content: center;
  color: var(--faint); gap: 8px; background: var(--surface);
}
.no-note svg { width: 56px; height: 56px; }
.no-note p { margin: 0; font-size: 16px; color: var(--muted); }
.editor.empty-state .no-note { display: flex; }
.editor.empty-state .tools, .editor.empty-state .save-state { visibility: hidden; }

/* ---------- Popover / menu ---------- */
.popover {
  position: fixed; z-index: 50; background: var(--surface); color: var(--text);
  border-radius: 14px; box-shadow: var(--shadow); padding: 8px;
  animation: pop .14s ease-out;
}
@keyframes pop { from { opacity: 0; transform: scale(.96); } }
.format-pop { width: 320px; }
.fmt-styles { display: flex; flex-wrap: wrap; gap: 4px; padding-bottom: 6px; }
.fmt-styles button { flex: none; padding: 6px 10px; border-radius: 8px; white-space: nowrap; }
.fmt-styles button:hover, .fmt-row button:hover { background: var(--sel-muted); }
.fmt-styles button.on { background: var(--accent-strong); color: #000; }
.fmt-h1 { font-weight: 700; font-size: 17px; }
.fmt-h2 { font-weight: 700; font-size: 15px; }
.fmt-h3 { font-weight: 600; font-size: 14px; }
.fmt-body { font-size: 14px; }
.fmt-mono { font-family: var(--mono); font-size: 13px; }
.fmt-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--sep); border-radius: 9px; overflow: hidden; margin-top: 6px; }
.fmt-row button { background: var(--field); height: 38px; font-size: 16px; }
.fmt-row button.on { background: var(--accent-strong); color: #000; }

.menu { min-width: 210px; padding: 6px; }
.menu button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px 10px; border-radius: 8px; text-align: left; font-size: 15px;
}
.menu button:hover { background: var(--sel-muted); }
.menu button svg { width: 19px; height: 19px; color: var(--muted); }
.menu button.danger, .menu button.danger svg { color: var(--danger); }
.menu button.current { font-weight: 600; }
.menu .menu-sep { height: 1px; background: var(--sep); margin: 4px 6px; }
.menu .menu-label { font-size: 12px; color: var(--muted); padding: 6px 10px 2px; }

/* ---------- Modal (estilo alerta) ---------- */
.modal-back {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center;
  background: rgba(0, 0, 0, .3); animation: fade .15s;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  width: 280px; background: var(--surface); border-radius: 14px; overflow: hidden;
  text-align: center; box-shadow: var(--shadow); animation: pop .15s ease-out;
}
.modal h2 { font-size: 17px; margin: 18px 16px 2px; }
.modal p { font-size: 13.5px; margin: 4px 16px 0; color: var(--muted); }
.modal p:empty { display: none; }
.modal input {
  width: calc(100% - 32px); margin: 14px 16px 0; padding: 8px 10px;
  border: 1px solid var(--sep); border-radius: 8px; background: var(--bg); outline: none; font-size: 15px;
}
.modal input:focus { border-color: var(--accent); }
.modal-actions { display: flex; border-top: 1px solid var(--sep); margin-top: 18px; }
.modal-actions button { flex: 1; padding: 12px; font-size: 17px; color: var(--accent); }
.modal-actions button + button { border-left: 1px solid var(--sep); font-weight: 600; }
.modal-actions button:hover { background: var(--sel-muted); }
.modal-actions button.danger { color: var(--danger); }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%); z-index: 70;
  background: rgba(30, 30, 32, .92); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px;
  box-shadow: var(--shadow); max-width: calc(100vw - 32px); animation: fade .2s;
}

/* ================= Celular (estilo iPhone) ================= */
@media (max-width: 760px) {
  .app { display: block; position: relative; }
  .pane { position: absolute; inset: 0; display: none; background: var(--bg); border: 0; padding-top: var(--safe-t); }
  .app[data-view="folders"] .sidebar,
  .app[data-view="list"] .list,
  .app[data-view="editor"] .editor { display: flex; animation: slide .22s ease-out; }
  @keyframes slide { from { transform: translateX(24px); opacity: .6; } }
  .desk-only { display: none !important; }
  .mobile-only { display: inline-grid; }
  .back-btn { display: inline-flex; }

  .pane-head { padding: 8px 16px 6px; }
  .big-title { font-size: 32px; line-height: 1.1; margin: 2px 0 10px; white-space: normal; }
  .pane-body { padding: 0 16px 20px; }
  .pane-foot { background: var(--bg); border-top: 1px solid var(--sep); padding: 6px 12px calc(6px + var(--safe-b)); }
  .list .pane-foot { display: flex; }
  .foot-count { font-size: 12px; color: var(--text); }
  .icon-btn { width: 40px; height: 40px; }
  .icon-btn svg { width: 25px; height: 25px; }
  .icon-btn:hover { background: none; }

  .group, #noteList .note-group { background: var(--surface); border-radius: var(--radius); overflow: hidden; gap: 0; }
  .group-label { margin: 18px 4px 6px; }
  .folder { border-radius: 0; padding: 11px 14px; min-height: 46px; font-size: 17px; position: relative; }
  .folder + .folder::before { content: ""; position: absolute; top: 0; left: 48px; right: 0; border-top: 1px solid var(--sep); }
  .folder.active { background: none; font-weight: 400; }
  .folder:active { background: var(--sel-muted); }
  .folder .count { font-size: 17px; display: inline !important; }
  .folder .more { display: inline-grid; order: 3; }
  .folder .chev { display: block; order: 4; }
  .group-label + .group .folder:first-child::before { display: none; }

  .search { height: 38px; margin: 0; }
  .search input { font-size: 17px; }

  .note-group-label { font-size: 20px; margin: 22px 4px 8px; }
  .note-item { border-radius: 0; padding: 11px 16px; }
  .note-item + .note-item::before { left: 16px; right: 0; }
  .note-item.active { background: none; }
  .note-item:active { background: var(--sel-muted); }
  .note-item .t { font-size: 17px; }
  .note-item .s { font-size: 15px; }

  .editor { background: var(--surface); }
  .editor-bar { padding: 6px 10px 4px 16px; min-height: 48px; }
  .tools { gap: 0; }
  .save-state { display: none; }
  .editor-scroll { padding-bottom: 50vh; }
  .note-body { padding: 0 18px; font-size: 17px; }
  .note-body h1 { font-size: 28px; }
  .trash-banner { margin: 0 16px 10px; }

  .format-pop { left: 8px !important; right: 8px; width: auto; top: auto !important; bottom: calc(8px + var(--safe-b)); }
  .menu { min-width: 230px; }
}

/* ================= Telas de login / instalação ================= */
body.auth { display: grid; place-items: center; min-height: 100%; padding: 24px 16px; overflow: auto; }
.auth-card {
  width: 100%; max-width: 360px; background: var(--surface); border-radius: 18px;
  padding: 28px 22px 22px; text-align: center; box-shadow: 0 1px 3px rgba(0, 0, 0, .06);
}
.auth-icon { width: 72px; height: 72px; border-radius: 17px; box-shadow: 0 2px 8px rgba(0, 0, 0, .12); }
.auth-card h1 { font-size: 26px; margin: 12px 0 16px; }
.auth-card form { display: flex; flex-direction: column; gap: 10px; }
.auth-card input {
  height: 46px; padding: 0 14px; border-radius: 11px; border: 1px solid var(--sep);
  background: var(--bg); font-size: 16px; outline: none;
}
.auth-card input:focus { border-color: var(--accent); }
.auth-btn {
  display: block; height: 46px; line-height: 46px; border-radius: 11px; margin-top: 4px;
  background: var(--accent-strong); color: #000; font-weight: 600; font-size: 16px; text-decoration: none;
}
.auth-btn:hover { filter: brightness(1.05); }
.auth-error { color: var(--danger); font-size: 14px; margin: 0 0 12px; }
.auth-hint { color: var(--muted); font-size: 14px; margin: 0 0 14px; }
.auth-pre { text-align: left; white-space: pre-wrap; font-size: 12px; background: var(--bg); padding: 10px; border-radius: 8px; color: var(--muted); }
.auth-switch { font-size: 14px; color: var(--muted); margin: 16px 0 0; }
.auth-switch a { color: var(--accent); }
.auth code { font-family: var(--mono); font-size: 13px; }
