/* Note Catatan Rapih — tampilan. Warna utama biru tinta + kuning kertas. */
:root {
  --brand: #2B4C9B; --brand2: #3D63C4; --accent: #F4B740;
  --bg: #F6F3EC; --surface: #FFFFFF; --surface2: #FBF8F1; --line: #E6E0D2;
  --text: #1F2433; --muted: #6B7084; --bad: #C2410C; --ok: #15803D;
  --shadow: 0 1px 2px rgba(31,36,51,.06), 0 6px 18px rgba(31,36,51,.07);
  --r: 16px;
  --n-default: #FFFFFF; --n-yellow: #FFF3C4; --n-green: #DDF3E4; --n-blue: #DCE8FF; --n-purple: #ECE1FF; --n-pink: #FFE0EC; --n-orange: #FFE5CC; --n-gray: #ECECEC;
  --paper: #FFFDF7; --paper-line: #DCE3F2;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --brand: #8FAAF0; --brand2: #A9BFF5; --accent: #F4B740;
  --bg: #14161D; --surface: #1D2029; --surface2: #232733; --line: #2E3342;
  --text: #ECEEF4; --muted: #9AA0B4; --bad: #FB923C; --ok: #4ADE80;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 18px rgba(0,0,0,.25);
  --n-default: #1D2029; --n-yellow: #3A3420; --n-green: #1E3328; --n-blue: #1F2B45; --n-purple: #2D2440; --n-pink: #3B2230; --n-orange: #3B2A1C; --n-gray: #2A2D34;
  --paper: #1B1E26; --paper-line: #2B3142;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--brand2); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.grow { flex: 1; }

#app { max-width: 1200px; margin: 0 auto; padding-bottom: 150px; min-height: 100%; }

/* ---------- bilah atas ---------- */
.top { display: flex; align-items: center; gap: 12px; padding: 14px 16px 6px; padding-top: max(14px, env(safe-area-inset-top)); }
.brand { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.brand img { border-radius: 9px; flex: none; }
.brand-t { display: flex; flex-direction: column; min-width: 0; }
.brand-t b { font-size: 18px; letter-spacing: -.2px; }
.brand-t small { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-act { display: flex; gap: 6px; }
.ic { width: 40px; height: 40px; border-radius: 12px; border: 0; background: transparent; display: inline-grid; place-items: center; font-size: 18px; flex: none; }
.ic:hover { background: var(--surface2); }
.avatar { background: var(--surface); box-shadow: var(--shadow); border-radius: 50%; overflow: hidden; font-weight: 700; color: var(--brand); }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.big { width: 48px; height: 48px; display: inline-grid; place-items: center; font-size: 20px; }
#syncBtn .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--muted); opacity: .5; }
#syncBtn[data-s="ok"] .dot { background: var(--ok); opacity: 1; }
#syncBtn[data-s="sync"] .dot { background: var(--accent); opacity: 1; animation: pulse 1s infinite; }
#syncBtn[data-s="offline"] .dot, #syncBtn[data-s="err"] .dot { background: var(--bad); opacity: 1; }
@keyframes pulse { 50% { transform: scale(.6); } }

.search { padding: 6px 16px; }
.search input { width: 100%; padding: 12px 16px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); outline: none; }
.search input:focus { border-color: var(--brand2); }
.chips { display: flex; gap: 8px; padding: 6px 16px 10px; overflow-x: auto; scrollbar-width: none; }
.chips button { flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 7px 14px; font-size: 14px; }
.chips button.on { background: var(--brand); border-color: var(--brand); color: #fff; }
:root[data-theme="dark"] .chips button.on { color: #10131a; }

.nudge { margin: 4px 16px 10px; padding: 12px 14px; border-radius: var(--r); background: var(--surface); border: 1px dashed var(--brand2); display: flex; gap: 12px; align-items: center; }
.nudge div { flex: 1; }

/* ---------- kartu catatan ---------- */
.grid { padding: 4px 12px; columns: 2 170px; column-gap: 12px; }
@media (min-width: 700px) { .grid { columns: 4 220px; } }
.note {
  break-inside: avoid; margin: 0 0 12px; border-radius: var(--r); padding: 12px 14px; cursor: pointer;
  background: var(--n-default); border: 1px solid var(--line); box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.note h4 { margin: 0 0 4px; font-size: 15px; line-height: 1.3; word-break: break-word; }
.note p { margin: 0; color: var(--text); opacity: .85; font-size: 13.5px; white-space: pre-line; word-break: break-word; display: -webkit-box; -webkit-line-clamp: 8; -webkit-box-orient: vertical; overflow: hidden; }
.note canvas { width: 100%; height: auto; display: block; border-radius: 8px; background: var(--paper); margin-top: 4px; }
.note .meta { margin-top: 8px; display: flex; gap: 6px; align-items: center; font-size: 11.5px; color: var(--muted); flex-wrap: wrap; }
.note .pin { position: absolute; top: 8px; right: 10px; font-size: 13px; }
.kind { padding: 1px 7px; border-radius: 999px; background: rgba(43,76,155,.1); color: var(--brand); font-weight: 600; }
.note[data-c="yellow"], .page[data-c="yellow"] { background: var(--n-yellow); }
.note[data-c="green"], .page[data-c="green"] { background: var(--n-green); }
.note[data-c="blue"], .page[data-c="blue"] { background: var(--n-blue); }
.note[data-c="purple"], .page[data-c="purple"] { background: var(--n-purple); }
.note[data-c="pink"], .page[data-c="pink"] { background: var(--n-pink); }
.note[data-c="orange"], .page[data-c="orange"] { background: var(--n-orange); }
.note[data-c="gray"], .page[data-c="gray"] { background: var(--n-gray); }

.empty { text-align: center; padding: 60px 24px; color: var(--muted); }
.empty h2 { color: var(--text); margin: 14px 0 4px; }

.house-ad { position: fixed; left: 12px; right: 96px; bottom: 16px; max-width: 520px; display: flex; gap: 10px; align-items: center; padding: 10px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); z-index: 5; }
.house-ad div { flex: 1; font-size: 13px; line-height: 1.35; }
.house-ad .tag { font-size: 10px; font-weight: 700; padding: 2px 5px; border-radius: 4px; background: var(--accent); color: #3a2a00; align-self: flex-start; }

/* ---------- tombol tambah ---------- */
.fab-wrap { position: fixed; right: 18px; bottom: max(18px, env(safe-area-inset-bottom)); z-index: 6; display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.fab { width: 62px; height: 62px; border-radius: 20px; border: 0; background: var(--brand); color: #fff; font-size: 32px; box-shadow: 0 8px 24px rgba(43,76,155,.35); transition: transform .15s; }
:root[data-theme="dark"] .fab { color: #10131a; }
.fab.open { transform: rotate(45deg); }
.fab-menu { display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.fab-menu button { display: flex; align-items: center; gap: 10px; border: 0; background: var(--surface); box-shadow: var(--shadow); padding: 10px 16px; border-radius: 14px; font-weight: 600; }
.fab-menu span { font-size: 20px; }

/* ---------- halaman penuh (editor, pengaturan) ---------- */
.page { position: fixed; inset: 0; z-index: 20; background: var(--bg); display: flex; flex-direction: column; overflow: hidden; }
#editor { background: var(--n-default); }
.ed-top { display: flex; align-items: center; gap: 4px; padding: 8px 8px 4px; padding-top: max(8px, env(safe-area-inset-top)); max-width: 1000px; width: 100%; margin: 0 auto; }
.ed-kind { font-size: 13px; color: var(--muted); padding-left: 4px; }
.ai-btn { background: linear-gradient(135deg, #F4B740, #F59E0B); color: #3a2a00; }
.ed-title { border: 0; background: transparent; outline: none; font-size: 22px; font-weight: 700; padding: 6px 18px 0; max-width: 1000px; width: 100%; margin: 0 auto; display: block; }
.ed-meta { font-size: 12px; color: var(--muted); padding: 0 18px 4px; max-width: 1000px; width: 100%; margin: 0 auto; }
.color-bar { display: flex; gap: 10px; padding: 6px 18px; max-width: 1000px; margin: 0 auto; width: 100%; flex-wrap: wrap; }
.color-bar button { width: 32px; height: 32px; border-radius: 50%; border: 2px solid var(--line); }
.color-bar button.on { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand); }
.pop { position: absolute; right: 10px; top: 54px; z-index: 30; background: var(--surface); border-radius: 14px; box-shadow: 0 10px 40px rgba(0,0,0,.2); padding: 6px; display: flex; flex-direction: column; min-width: 200px; }
.pop button { border: 0; background: transparent; text-align: left; padding: 10px 14px; border-radius: 10px; }
.pop button:hover { background: var(--surface2); }
.bad { color: var(--bad) !important; }

.text-wrap { flex: 1; display: flex; flex-direction: column; min-height: 0; max-width: 1000px; width: 100%; margin: 0 auto; }
.fmt { display: flex; gap: 2px; padding: 4px 12px; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--line); }
.fmt button { flex: none; min-width: 38px; height: 36px; border: 0; background: transparent; border-radius: 10px; font-size: 16px; }
.fmt button:hover { background: rgba(127,127,127,.12); }
.ed-body { flex: 1; overflow-y: auto; padding: 12px 18px 120px; outline: none; font-size: 16px; line-height: 1.65; word-break: break-word; }
.ed-body:empty::before { content: attr(data-ph); color: var(--muted); }
.ed-body h2 { font-size: 19px; margin: 14px 0 4px; }
.ed-body h3 { font-size: 17px; margin: 12px 0 4px; }
.ed-body p { margin: 0 0 6px; }
.ed-body ul, .ed-body ol { padding-left: 24px; margin: 4px 0 8px; }
.ed-body ul.check { list-style: none; padding-left: 4px; }
.ed-body ul.check li { position: relative; padding-left: 30px; }
.ed-body ul.check li::before { content: ""; position: absolute; left: 2px; top: .3em; width: 18px; height: 18px; border: 2px solid var(--brand2); border-radius: 5px; background: var(--surface); }
.ed-body ul.check li[data-c="1"] { text-decoration: line-through; opacity: .6; }
.ed-body ul.check li[data-c="1"]::before { background: var(--brand2); content: "✓"; color: #fff; font-size: 13px; line-height: 18px; text-align: center; }
.ed-body blockquote { border-left: 3px solid var(--accent); margin: 6px 0; padding: 2px 12px; color: var(--muted); }
.ed-body hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }
.ed-body code { background: rgba(127,127,127,.15); padding: 1px 5px; border-radius: 5px; }

/* ---------- tulisan tangan ---------- */
.ink-wrap { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.ink-tools { display: flex; gap: 4px; align-items: center; padding: 6px 10px; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--line); max-width: 1000px; width: 100%; margin: 0 auto; }
.ink-tools > button { flex: none; min-width: 40px; height: 38px; border: 0; background: transparent; border-radius: 10px; font-size: 18px; }
.ink-tools > button.on { background: rgba(43,76,155,.15); box-shadow: inset 0 0 0 2px var(--brand2); }
.ink-tools select { flex: none; height: 36px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); padding: 0 6px; }
.ink-tools .sep { width: 1px; height: 24px; background: var(--line); flex: none; margin: 0 4px; }
.ink-colors { display: flex; gap: 6px; flex: none; }
.ink-colors button { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--line); }
.ink-colors button.on { box-shadow: 0 0 0 2px var(--brand2); }
.ink-scroll { flex: 1; overflow: auto; padding: 12px; -webkit-overflow-scrolling: touch; }
.ink-scroll.hand { cursor: grab; }
#ink { display: block; margin: 0 auto; width: 100%; max-width: 900px; background: var(--paper); border-radius: 12px; box-shadow: var(--shadow); touch-action: none; }
.ink-scroll.hand #ink { touch-action: pan-x pan-y; }

/* ---------- pengaturan ---------- */
.set-body { overflow-y: auto; flex: 1; padding: 8px 14px 40px; max-width: 720px; width: 100%; margin: 0 auto; }
.card { background: var(--surface); border-radius: var(--r); padding: 14px 16px; margin: 10px 0; box-shadow: var(--shadow); }
.card h3 { margin: 0 0 8px; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--surface2); border: 1px solid var(--line); color: var(--muted); font-weight: 600; }
.badge.on { background: var(--accent); color: #3a2a00; border-color: var(--accent); }
.perks { margin: 0 0 8px; padding-left: 4px; list-style: none; }
.perks li { margin: 3px 0; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
.row-btns input { flex: 1; min-width: 160px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface2); }
.btn { border: 1px solid var(--line); background: var(--surface2); border-radius: 12px; padding: 10px 16px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
:root[data-theme="dark"] .btn.primary { color: #10131a; }
.btn.sm { padding: 7px 12px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: default; }
.acc-row { display: flex; gap: 12px; align-items: center; }
.g-wrap { position: relative; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; min-height: 44px; }
.msg { margin: 8px 0 0; font-size: 14px; }
.msg.bad { color: var(--bad); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin-bottom: 10px; }
.seg button { border: 0; background: transparent; padding: 8px 14px; }
.seg button.on { background: var(--brand); color: #fff; }
:root[data-theme="dark"] .seg button.on { color: #10131a; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.row select { padding: 8px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface2); }
details summary { cursor: pointer; color: var(--brand2); font-weight: 600; margin: 6px 0; }

/* ---------- AI ---------- */
dialog.sheet { border: 0; padding: 0; background: transparent; max-width: 640px; width: calc(100% - 20px); margin: auto auto 10px; max-height: 88vh; }
dialog.sheet::backdrop { background: rgba(10,12,20,.45); }
@media (min-width: 700px) { dialog.sheet { margin: auto; } }
.sheet-in { background: var(--surface); color: var(--text); border-radius: 20px; padding: 14px 16px 16px; max-height: 86vh; overflow-y: auto; }
.sheet-in header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.ai-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.ai-pick button { border: 1px solid var(--line); background: var(--surface2); border-radius: 14px; padding: 12px; text-align: left; font-weight: 600; }
.ai-pick button small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; margin-top: 2px; }
.ai-pick button:hover { border-color: var(--brand2); }
#aiPrompt { width: 100%; border-radius: 14px; border: 1px solid var(--line); background: var(--surface2); padding: 12px; resize: vertical; }
.ai-busy { padding: 24px; text-align: center; color: var(--muted); }
.spin { display: inline-block; width: 18px; height: 18px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: sp 0.8s linear infinite; vertical-align: -4px; margin-right: 6px; }
@keyframes sp { to { transform: rotate(360deg); } }
.ai-result { border: 1px solid var(--line); background: var(--surface2); border-radius: 14px; padding: 10px 14px; max-height: 46vh; overflow-y: auto; }
.ai-result h2 { font-size: 17px; margin: 8px 0 4px; }
.ai-result ul.check { list-style: none; padding-left: 4px; }
.ai-result ul.check li::before { content: "☐ "; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: 96px; z-index: 50; background: #222634; color: #fff; padding: 10px 16px; border-radius: 12px; box-shadow: var(--shadow); max-width: calc(100% - 32px); display: flex; gap: 14px; align-items: center; }
.toast button { background: transparent; border: 0; color: var(--accent); font-weight: 700; }

@media print {
  .top, .search, .chips, .fab-wrap, .house-ad, .nudge { display: none !important; }
}
