:root {
  --bg: #FBF7F0;
  --card: #FFFFFF;
  --ink: #2B2620;
  --ink-soft: #6E675C;
  --ink-faint: #A39A8C;
  --line: #EAE2D6;
  --primary: #14685B;
  --primary-dark: #0E4E44;
  --gold: #C9A227;
  --danger: #B3402E;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(43, 38, 32, 0.06);
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
  -webkit-tap-highlight-color: transparent;
}

button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; }
.hidden { display: none !important; }

#app { max-width: 640px; margin: 0 auto; min-height: 100%; position: relative; }
.view { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }

/* ---------- Header daftar ---------- */
.app-header { padding: 28px 20px 8px; }
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  width: 52px; height: 52px; flex: 0 0 52px;
  border-radius: 16px;
  background: var(--primary); color: #FDFBF7;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 14px rgba(20, 104, 91, 0.28);
}
.brand h1 {
  font-family: var(--font-display);
  font-size: 28px; font-weight: 700; letter-spacing: 0.2px;
  color: var(--ink); line-height: 1.15;
}
.brand p { font-size: 13px; color: var(--ink-soft); margin-top: 2px; }

/* ---------- Pencarian ---------- */
.search-wrap {
  margin: 14px 20px 6px;
  display: flex; align-items: center; gap: 10px;
  background: var(--card);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 0 8px 0 16px;
  box-shadow: var(--shadow);
}
.search-wrap svg { color: var(--ink-faint); flex: 0 0 auto; }
.search-wrap input {
  flex: 1; min-width: 0;
  border: none; outline: none; background: transparent;
  font-size: 15px; color: var(--ink);
  padding: 13px 0;
}
.search-wrap input::placeholder { color: var(--ink-faint); }
.search-wrap input[type="search"]::-webkit-search-cancel-button { display: none; }

/* ---------- Daftar catatan ---------- */
.notes-list { padding: 10px 20px 110px; display: flex; flex-direction: column; gap: 12px; }
.note-card {
  background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  cursor: pointer; text-align: left; width: 100%;
  display: block;
}
.note-card:active { transform: scale(0.99); }
.note-card.pinned { border-color: var(--gold); }
.note-card h3 {
  font-family: var(--font-display);
  font-size: 18px; font-weight: 700; line-height: 1.3;
  display: flex; align-items: center; gap: 8px;
}
.note-card h3 .pin-mark { color: var(--gold); flex: 0 0 auto; display: inline-flex; }
.note-card .snippet {
  margin-top: 6px; font-size: 14px; color: var(--ink-soft);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; word-break: break-word;
}
.note-card .meta { margin-top: 10px; font-size: 12px; color: var(--ink-faint); }

/* ---------- Status kosong ---------- */
.empty-state { padding: 48px 32px 110px; text-align: center; }
.empty-state h2 { font-family: var(--font-display); font-size: 21px; margin: 18px 0 6px; }
.empty-state p { font-size: 14px; color: var(--ink-soft); }
.empty-art { display: flex; justify-content: center; opacity: 0.9; }

/* ---------- Tombol ---------- */
.btn-primary {
  margin-top: 22px;
  background: var(--primary); color: #FDFBF7;
  border: none; border-radius: 999px;
  font-size: 15px; font-weight: 600;
  padding: 13px 26px;
  box-shadow: 0 4px 14px rgba(20, 104, 91, 0.28);
}
.btn-primary:active { background: var(--primary-dark); }
.btn-ghost {
  background: transparent; color: var(--ink);
  border: 1px solid var(--line); border-radius: 999px;
  font-size: 15px; font-weight: 600; padding: 11px 22px;
}
.btn-danger {
  background: var(--danger); color: #FFF;
  border: none; border-radius: 999px;
  font-size: 15px; font-weight: 600; padding: 11px 22px;
}
.icon-btn {
  width: 40px; height: 40px; flex: 0 0 40px;
  border: none; border-radius: 50%;
  background: transparent; color: var(--ink-soft);
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:active { background: rgba(43, 38, 32, 0.08); }
.icon-btn.large { width: 44px; height: 44px; flex-basis: 44px; }
.icon-btn.danger { color: var(--danger); }
.icon-btn.active { color: var(--gold); }
.icon-btn.active svg { fill: var(--gold); }

.fab {
  position: fixed; right: 20px; bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  width: 58px; height: 58px; border-radius: 50%;
  background: var(--primary); color: #FDFBF7; border: none;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 18px rgba(20, 104, 91, 0.38);
  z-index: 10;
}
.fab:active { background: var(--primary-dark); }

/* ---------- Editor ---------- */
.editor-header {
  display: flex; align-items: center; gap: 6px;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 12px 8px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  position: sticky; top: 0; z-index: 5;
}
.save-state { flex: 1; text-align: center; font-size: 13px; color: var(--ink-faint); }
.editor-body { flex: 1; display: flex; flex-direction: column; padding: 18px 22px calc(24px + env(safe-area-inset-bottom, 0px)); }
#note-title {
  border: none; outline: none; background: transparent;
  font-family: var(--font-display);
  font-size: 26px; font-weight: 700; color: var(--ink);
  padding: 4px 0; width: 100%;
}
#note-title::placeholder { color: #CFC6B8; }
.note-date { font-size: 13px; color: var(--ink-faint); margin: 6px 0 14px; }
#note-body {
  flex: 1; width: 100%; min-height: 50vh;
  border: none; outline: none; background: transparent;
  resize: none;
  font-size: 16px; line-height: 1.75; color: var(--ink);
}
#note-body::placeholder { color: #CFC6B8; }

/* ---------- Dialog ---------- */
.dialog-overlay {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(43, 38, 32, 0.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.dialog {
  background: var(--card);
  border-radius: 20px 20px 0 0;
  width: 100%; max-width: 640px;
  padding: 24px 22px calc(26px + env(safe-area-inset-bottom, 0px));
}
.dialog h2 { font-family: var(--font-display); font-size: 20px; margin-bottom: 6px; }
.dialog p { font-size: 14px; color: var(--ink-soft); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

@media (min-width: 640px) {
  .dialog-overlay { align-items: center; padding: 20px; }
  .dialog { border-radius: 20px; }
}

/* ---------- Kategori ---------- */
.cat-filter {
  display: flex; gap: 8px;
  margin: 10px 20px 0; padding: 2px 2px 6px;
  overflow-x: auto; scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.cat-filter::-webkit-scrollbar { display: none; }
.cat-chip {
  flex: 0 0 auto;
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--card);
  border: 1px solid var(--line); border-radius: 999px;
  font-size: 13px; font-weight: 600; color: var(--ink-soft);
  padding: 8px 13px;
}
.cat-chip .cat-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--cat, var(--ink-faint)); flex: 0 0 auto; }
.cat-chip .cat-count { font-weight: 400; color: var(--ink-faint); font-size: 12px; }
.cat-chip.active {
  border-color: var(--cat, var(--primary));
  color: var(--cat, var(--primary));
  background: var(--cat-soft, #EEF4F2);
}
.cat-chip.active .cat-count { color: var(--cat, var(--primary)); }

.note-card { box-shadow: var(--shadow), inset 4px 0 0 var(--cat, transparent); }
.cat-label {
  display: inline-flex; align-items: center; gap: 5px;
  font-weight: 600; color: var(--ink-soft);
}
.cat-label .cat-dot { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto; }

.cat-picker { margin: 2px 0 16px; }
.cat-picker-label {
  display: block; font-size: 11px; font-weight: 700;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--ink-faint); margin-bottom: 8px;
}
.cat-picker-chips { display: flex; flex-wrap: wrap; gap: 8px; }
