:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-soft: #fbfaf8;
  --border: #e3e0da;
  --text: #23211e;
  --muted: #7a756c;
  --accent: #2f6f4e;
  --accent-hover: #275f42;
  --accent-soft: #e8f1ec;
  --danger: #a8332b;
  --danger-soft: #fbeceb;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(35, 33, 30, .05), 0 8px 24px rgba(35, 33, 30, .04);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a;
    --surface: #1f2124;
    --surface-soft: #23262a;
    --border: #33373d;
    --text: #eceae6;
    --muted: #9a958c;
    --accent: #62b98c;
    --accent-hover: #7ac9a0;
    --accent-soft: #22322a;
    --danger: #e88b83;
    --danger-soft: #35211f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 32px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }

/* Atribut hidden harus selalu menang atas display milik komponen. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}

h1, h2 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.35rem; }
h2 { font-size: .82rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }

.muted { color: var(--muted); }
.small, .hint { font-size: .82rem; }

/* --- top bar --- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .85rem clamp(1rem, 3vw, 2rem);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  font-weight: 700;
  letter-spacing: -.02em;
  font-size: 1.05rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: .5rem;
}

/* Tombol/link harus tampil sama walau elemennya <a>. */
a.btn {
  display: inline-block;
  text-decoration: none;
  line-height: 1.2;
}

.brand-mark {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  background: var(--accent);
  position: relative;
  flex: none;
}

.brand-mark::after {
  content: "";
  position: absolute;
  inset: 6px 5px;
  background: repeating-linear-gradient(
    to bottom,
    #fff 0 1.6px,
    transparent 1.6px 4px
  );
  opacity: .95;
}

/* --- layout --- */
.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
  gap: 1rem;
  padding: clamp(.75rem, 2vw, 1.5rem);
  max-width: 1240px;
  width: 100%;
  margin: 0 auto;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-height: 0;
  /* Cegah judul catatan yang nowrap melebarkan kolom grid di layar sempit. */
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.list-panel { padding: .9rem .5rem .5rem; }
.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 0 .6rem .6rem;
  border-bottom: 1px solid var(--border);
}

.status {
  margin: .6rem .6rem 0;
  font-size: .84rem;
  color: var(--muted);
  min-height: 1.2em;
}
.status.error { color: var(--danger); }

/* --- pencarian --- */
.search-row { padding: .6rem .6rem 0; }

.search-row input {
  padding: .5rem .7rem;
  font-size: .92rem;
}

.more {
  margin: .35rem .6rem .1rem;
  width: calc(100% - 1.2rem);
  text-align: center;
}

mark {
  background: color-mix(in srgb, var(--accent) 26%, transparent);
  color: inherit;
  border-radius: 3px;
  padding: 0 1px;
}

.note-list {
  list-style: none;
  margin: .35rem 0 0;
  padding: 0 .25rem .25rem;
  overflow-y: auto;
  flex: 1;
  /* Scrollbar bawaan disembunyikan; penggantinya indikator .scroll-thumb. */
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.note-list::-webkit-scrollbar {
  width: 0;
  height: 0;
}

/* Wadah daftar + indikator gulir tipis yang hanya muncul saat digulir. */
.list-scroll {
  position: relative;
  display: flex;
  flex: 1;
  min-height: 0;
}

.scroll-thumb {
  position: absolute;
  top: 0;
  right: 1px;
  width: 4px;
  height: 0;
  border-radius: 999px;
  background: var(--muted);
  opacity: 0;
  transition: opacity .2s ease;
  pointer-events: none;
  will-change: transform, opacity;
}

.scroll-thumb.visible {
  opacity: .55;
}

/* Halaman (mobile) memakai scroll dokumen: scrollbar bawaan disembunyikan,
   indikator ini yang tampil selama menggulir. */
html {
  scrollbar-width: none;
  -ms-overflow-style: none;
}

html::-webkit-scrollbar {
  width: 0;
  height: 0;
}

.page-thumb {
  position: fixed;
  top: 2px;
  right: 2px;
  z-index: 5;
}

.note-item {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 9px;
  padding: .6rem .7rem;
  margin-bottom: .15rem;
  font: inherit;
  color: inherit;
  cursor: pointer;
  display: block;
}

.note-item:hover { background: var(--surface-soft); border-color: var(--border); }
.note-item.active { background: var(--accent-soft); border-color: var(--accent); }
.note-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.note-item-title {
  display: block;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-item-excerpt,
.note-item-date {
  display: block;
  font-size: .8rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-item-date { font-size: .74rem; margin-top: .15rem; }

.empty { padding: 1.5rem 1rem; text-align: center; color: var(--muted); }
.empty p { margin: .2rem 0; }

/* --- editor panel --- */
.editor-panel {
  padding: clamp(1rem, 2.5vw, 1.75rem);
  overflow-y: auto;
  /* Scrollbar bawaan disembunyikan; penggantinya .scroll-thumb di .editor-wrap. */
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.editor-panel::-webkit-scrollbar {
  width: 0;
  height: 0;
}

/* Pembungkus supaya indikator gulir bisa menimpa panel (bukan ikut tergulir). */
.editor-wrap {
  position: relative;
  display: flex;
  min-width: 0;
  min-height: 0;
}

.editor-wrap > .editor-panel {
  flex: 1;
  min-width: 0;
  min-height: 0;
}

.placeholder { margin: auto 0; max-width: 46ch; }
.placeholder h1 { margin-bottom: .5rem; }
.placeholder code {
  font-family: var(--mono);
  font-size: .85em;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: .05em .35em;
}

.detail { display: flex; flex-direction: column; gap: 1rem; }
.detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: .85rem;
  border-bottom: 1px solid var(--border);
}

/* Blok judul boleh menyusut; tombol aksi tidak ikut terdorong keluar layar. */
.detail-head > div:first-child { min-width: 0; flex: 1 1 auto; }
.detail-actions { display: flex; gap: .4rem; flex: none; }
.detail-head h1 { overflow-wrap: anywhere; }
.meta { margin: .3rem 0 0; font-size: .8rem; color: var(--muted); }
.meta span { white-space: nowrap; }

.detail-content {
  margin: 0;
  font-family: var(--font);
  font-size: .95rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.7;
}

/* --- form --- */
.form { display: flex; flex-direction: column; gap: .9rem; height: 100%; }
.form h1 { margin-bottom: .2rem; }

.field { display: flex; flex-direction: column; gap: .35rem; }
.field > span { font-size: .82rem; font-weight: 600; color: var(--muted); }
.field-grow { flex: 1; min-height: 0; }

input[type="text"],
input[type="search"],
input[type="password"],
textarea {
  width: 100%;
  font: inherit;
  color: inherit;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: .6rem .7rem;
  transition: border-color .15s, box-shadow .15s;
}

textarea {
  resize: vertical;
  min-height: 220px;
  flex: 1;
  font-family: var(--font);
  line-height: 1.65;
}

input[type="text"]:focus,
input[type="search"]:focus,
input[type="password"]:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

.form-actions {
  display: flex;
  align-items: center;
  gap: .6rem;
  flex-wrap: wrap;
}

.hint { margin-left: auto; }

/* --- buttons --- */
.btn {
  font: inherit;
  font-weight: 600;
  font-size: .9rem;
  padding: .5rem .95rem;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}

.btn:hover { background: var(--surface-soft); border-color: var(--muted); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

@media (prefers-color-scheme: dark) {
  .btn-primary { color: #13221a; }
}

.btn-ghost { background: transparent; }

.btn-danger {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 35%, var(--border));
}

.btn-danger:hover {
  background: var(--danger-soft);
  border-color: var(--danger);
}

/* --- messages --- */
.error {
  margin: 0;
  padding: .55rem .7rem;
  border-radius: 8px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: .87rem;
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  max-width: min(360px, calc(100vw - 2rem));
  padding: .7rem 1rem;
  border-radius: 10px;
  font-size: .9rem;
  font-weight: 500;
  color: #fff;
  background: #2b2b2b;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
  animation: toast-in .18s ease-out;
}

.toast.success { background: var(--accent); color: #fff; }
.toast.error { background: #8f2f28; }
@media (prefers-color-scheme: dark) {
  .toast.success { color: #13221a; }
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- halaman login --- */
.login-body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(1rem, 4vw, 2rem);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(1.2rem, 4vw, 1.75rem);
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
}

.login-head h1 { font-size: 1.25rem; margin-bottom: .25rem; }
.login-head p { margin: 0; font-size: .88rem; }

.login-card form {
  display: flex;
  flex-direction: column;
  gap: .85rem;
}

.login-card .btn {
  width: 100%;
  padding: .7rem 1rem;
  margin-top: .15rem;
}

.login-foot {
  margin: 0;
  font-size: .78rem;
  text-align: center;
}

@media (prefers-color-scheme: dark) {
  .login-card { background: var(--surface); }
}

/* --- responsive --- */
.btn-label-short { display: none; }

@media (max-width: 380px) {
  /* Layar 320px: label tombol utama dipendekkan agar header tidak meluber. */
  .btn-label-full { display: none; }
  .btn-label-short { display: inline; }
}

@media (max-width: 420px) {
  /* Header dengan dua tombol harus tetap muat di layar 320px. */
  .topbar { gap: .5rem; padding: .7rem .9rem; }
  .brand { font-size: .98rem; gap: .45rem; }
  .topbar-actions { gap: .35rem; }
  .topbar-actions .btn { padding: .5rem .7rem; font-size: .85rem; }
}

@media (max-width: 820px) {
  /* Di layar kecil biar halaman yang menggulir, bukan panel editor yang dipaksa
     muat dalam sisa tinggi layar (itu yang bikin tombol menimpa textarea). */
  html, body { height: auto; min-height: 100%; }

  .layout {
    flex: 0 0 auto;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
  }

  .list-panel { max-height: 42vh; }
  .note-list { max-height: 30vh; }
  .editor-panel { padding: 1rem; overflow: visible; }
  .hint { display: none; }

  /* Form mengikuti tinggi isinya supaya Simpan/Batal selalu di bawah field Isi. */
  .form { height: auto; }
  .field-grow { flex: none; }

  textarea {
    flex: none;
    min-height: 200px;
  }

  /* Tanggal dibuat/diubah ditumpuk supaya tidak melebar keluar layar. */
  .meta {
    display: flex;
    flex-direction: column;
    gap: .1rem;
  }
  .meta-sep { display: none; }

  /* Tombol aksi tetap di alur normal, tepat di bawah field Isi. */
  .form-actions { flex-wrap: nowrap; }

  .btn { padding: .6rem 1.1rem; }
}

@media (min-width: 821px) {
  .layout { height: calc(100vh - 57px); }
}
