/* ================= Token warna ================= */
:root {
  --bg: #f3f3f3;
  --surface: #ffffff;
  --surface-2: #f7f7f7;
  --hover: rgba(0, 0, 0, 0.05);
  --press: rgba(0, 0, 0, 0.09);
  --text: #2c3038;
  --muted: #616161;
  --border: #e3e3e3;
  /* Warna brand Catatan Qta */
  --brand-yellow: #f8bc18;
  --brand-charcoal: #2c3038;
  --accent: #f5b800;          /* latar tombol utama */
  --accent-text: #2c3038;     /* teks di atas --accent */
  --accent-strong: #8f6400;   /* teks/garis aksen di atas latar terang */
  --danger: #c42b1c;
  --online: #13a10e;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 2px 6px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.18);
  --radius: 8px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #1c1c1c;
  --surface: #2b2b2b;
  --surface-2: #242424;
  --hover: rgba(255, 255, 255, 0.06);
  --press: rgba(255, 255, 255, 0.1);
  --text: #f0f0f0;
  --muted: #a8a8a8;
  --border: #3a3a3a;
  --accent: #f8bc18;
  --accent-text: #1c1c1c;
  --accent-strong: #f8c84a;
  --danger: #ff6b5b;
  --online: #54b054;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1c1c;
    --surface: #2b2b2b;
    --surface-2: #242424;
    --hover: rgba(255, 255, 255, 0.06);
    --press: rgba(255, 255, 255, 0.1);
    --text: #f0f0f0;
    --muted: #a8a8a8;
    --border: #3a3a3a;
    --accent: #f8bc18;
    --accent-text: #1c1c1c;
    --accent-strong: #f8c84a;
    --danger: #ff6b5b;
    --online: #54b054;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.6);
    color-scheme: dark;
  }
}

/* Warna catatan ala Sticky Notes */
[data-color="yellow"]   { --n-bar: #ffe66e; --n-bg: #fff7d1; --n-text: #1b1b1b; }
[data-color="green"]    { --n-bar: #a1ef9b; --n-bg: #e4f9e0; --n-text: #1b1b1b; }
[data-color="pink"]     { --n-bar: #ffafdf; --n-bg: #ffe4f1; --n-text: #1b1b1b; }
[data-color="purple"]   { --n-bar: #d7afff; --n-bg: #f2e6ff; --n-text: #1b1b1b; }
[data-color="blue"]     { --n-bar: #9edfff; --n-bg: #e2f1ff; --n-text: #1b1b1b; }
[data-color="gray"]     { --n-bar: #e0e0e0; --n-bg: #f3f2f1; --n-text: #1b1b1b; }
[data-color="charcoal"] { --n-bar: #7a7a7a; --n-bg: #616161; --n-text: #ffffff; }

:root[data-theme="dark"] [data-color] {
  --n-bg: color-mix(in srgb, var(--n-bar) 16%, #262626);
  --n-text: #f0f0f0;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) [data-color] {
    --n-bg: color-mix(in srgb, var(--n-bar) 16%, #262626);
    --n-text: #f0f0f0;
  }
}

/* ================= Dasar ================= */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; font-weight: 600; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round;
}
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.spacer { flex: 1; }

.boot { position: fixed; inset: 0; display: grid; place-items: center; }
.boot img { opacity: 0.8; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(0.92); opacity: 0.5; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* ================= Tombol & form ================= */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 8px 16px;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--text); font-weight: 500;
}
.btn:hover { background: var(--hover); }
.btn:active { background: var(--press); }
.btn.primary { background: var(--accent); border-color: transparent; color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { background: transparent; border-color: var(--border); color: var(--danger); }
.btn.danger-outline { background: transparent; border-color: color-mix(in srgb, var(--danger) 45%, transparent); color: var(--danger); }
.btn.block { width: 100%; }
.btn.small { min-height: 32px; padding: 4px 12px; font-size: 13px; }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn span[data-icon] { display: inline-flex; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px; padding: 0;
  border: 0; border-radius: 6px; background: transparent; color: inherit;
}
.icon-btn:hover { background: var(--hover); }
.icon-btn:active { background: var(--press); }
.icon-btn.small { width: 32px; height: 32px; }
.icon-btn.small .icon { width: 18px; height: 18px; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 600; }
.field input {
  width: 100%; height: 42px; padding: 0 12px;
  border: 1px solid var(--border); border-bottom: 2px solid var(--muted); border-radius: 6px;
  background: var(--surface); font-size: 16px; /* 16px mencegah zoom otomatis di iPhone */
}
.field input:focus { outline: none; border-bottom-color: var(--accent-strong); }
.link-btn {
  display: block; margin: -6px 0 14px auto; padding: 4px 0;
  border: 0; background: none; color: var(--accent-strong); font-size: 14px; font-weight: 600;
}
.link-btn:hover { text-decoration: underline; }
.check { display: flex; gap: 10px; align-items: flex-start; margin: 4px 0 8px; font-size: 14px; }
.check input { margin-top: 3px; width: 18px; height: 18px; accent-color: var(--accent); }
.form-error { margin: 0 0 12px; color: var(--danger); font-size: 14px; }
.notice {
  margin: 0 0 16px; padding: 10px 12px; border-radius: 6px;
  background: color-mix(in srgb, var(--accent) 12%, transparent); font-size: 14px;
}

/* ================= Login ================= */
.auth {
  min-height: 100%; display: grid; place-items: center;
  padding: calc(24px + var(--safe-top)) 16px calc(24px + var(--safe-bottom));
}
.auth-card {
  width: 100%; max-width: 340px; padding: 22px 18px;
  background: var(--surface); border-radius: 12px; box-shadow: var(--shadow);
}
.auth-brand { display: block; margin: 4px auto 0; width: min(230px, 100%); height: auto; }
.auth { grid-template-rows: 1fr auto; }
.auth-version { margin: 12px 0 0; }
.logo-dark { display: none !important; }
:root[data-theme="dark"] .logo-light { display: none !important; }
:root[data-theme="dark"] .logo-dark { display: block !important; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .logo-light { display: none !important; }
  :root:not([data-theme="light"]) .logo-dark { display: block !important; }
}
.wordmark { display: flex; align-items: center; gap: 8px; font-weight: 800; letter-spacing: -0.01em; }
.wordmark img { width: 28px; height: 28px; flex: none; }
.wordmark .qta { color: var(--brand-yellow); }
.auth-card > .muted { text-align: center; margin: 4px 0 20px; }
.tabs { display: flex; gap: 4px; padding: 4px; margin-bottom: 18px; border-radius: 8px; background: var(--surface-2); }
.tabs button {
  flex: 1; height: 36px; border: 0; border-radius: 6px; background: transparent; font-weight: 600; color: var(--muted);
}
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.btn.google { gap: 10px; min-height: 44px; background: var(--surface); }
.g-logo { width: 20px; height: 20px; flex: none; }
.divider {
  display: flex; align-items: center; gap: 12px; margin: 16px 0;
  color: var(--muted); font-size: 13px;
}
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.account-google { display: flex; align-items: center; gap: 8px; margin: 12px 0 0; color: var(--muted); }
.account-google .g-logo { width: 16px; height: 16px; }

/* ================= Tata letak aplikasi ================= */
.app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }
.list-pane { display: flex; flex-direction: column; width: 100%; min-width: 0; background: var(--bg); }
.topbar {
  display: flex; align-items: center; gap: 4px;
  padding: calc(6px + var(--safe-top)) 8px 6px;
  min-height: calc(52px + var(--safe-top));
}
.topbar-title { flex: 1; font-size: 18px; padding: 0 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.icon-btn.sync { color: var(--muted); }
.icon-btn.sync[data-status="syncing"] .icon { animation: spin 1s linear infinite; }
.icon-btn.sync[data-status="error"] { color: var(--danger); }

.install-banner {
  display: flex; align-items: center; gap: 8px;
  margin: 0 12px 8px; padding: 8px 8px 8px 12px; border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow); font-size: 13px;
}
.install-banner span { flex: 1; }

.search {
  display: flex; align-items: center; gap: 8px;
  margin: 0 12px 10px; padding: 0 12px; height: 40px;
  border-radius: 6px; background: var(--surface); border: 1px solid var(--border);
}
.search:focus-within { border-color: var(--accent-strong); }
.search-icon { display: inline-flex; color: var(--muted); }
.search input { flex: 1; min-width: 0; height: 100%; border: 0; background: transparent; outline: none; font-size: 16px; }

.note-list {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 2px 12px calc(16px + var(--safe-bottom));
  display: flex; flex-direction: column; gap: 10px;
}
.note-card {
  position: relative; flex: none;
  background: var(--n-bg); color: var(--n-text);
  border-radius: 4px; box-shadow: var(--shadow);
  padding: 22px 14px 12px; cursor: pointer;
  border-top: 4px solid var(--n-bar);
  outline-offset: 2px;
}
.note-card:hover { filter: brightness(0.98); }
.note-card.active { outline: 2px solid var(--accent-strong); }
.note-card-date { position: absolute; top: 4px; right: 10px; font-size: 12px; opacity: 0.65; }
.note-card-content {
  max-height: 7.3em; overflow: hidden; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical;
}
.note-card-content ul, .note-card-content ol { margin: 0; padding-left: 20px; }
.note-card-pending { position: absolute; top: 6px; left: 10px; width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: 0.4; }

.empty { flex: 1; display: grid; place-content: center; justify-items: center; text-align: center; padding: 24px; color: var(--muted); }
.empty img { opacity: 0.85; margin-bottom: 8px; }

/* ================= Editor ================= */
.editor-pane {
  position: fixed; inset: 0; z-index: 10;
  display: flex; flex-direction: column; background: var(--bg);
  transform: translateX(100%); visibility: hidden;
  /* Saat menutup: sembunyikan setelah animasi selesai. */
  transition: transform 0.22s ease, visibility 0s linear 0.22s;
}
/* Saat membuka: langsung terlihat agar editor bisa langsung difokus. */
.app.editing .editor-pane { transform: none; visibility: visible; transition: transform 0.22s ease, visibility 0s; }
.editor-placeholder { display: none; }

.editor {
  flex: 1; display: flex; flex-direction: column; min-height: 0;
  background: var(--n-bg); color: var(--n-text);
}
.editor-bar {
  display: flex; align-items: center; gap: 2px;
  padding: calc(4px + var(--safe-top)) 6px 4px;
  background: var(--n-bar); color: #1b1b1b;
}
[data-color="charcoal"] .editor-bar { color: #ffffff; }
.editor-bar .icon-btn:hover { background: rgba(0, 0, 0, 0.08); }
.desktop-only { display: none !important; }

.editor-menu {
  display: flex; flex-direction: column; gap: 4px;
  padding: 8px; background: var(--surface); color: var(--text);
  box-shadow: var(--shadow);
}
.swatches { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.swatch {
  height: 40px; border: 1px solid rgba(0, 0, 0, 0.12); border-radius: 4px;
  background: var(--n-bar); display: grid; place-items: center; color: #1b1b1b;
}
.swatch[data-color="charcoal"] { color: #ffffff; }
.swatch .icon { width: 18px; height: 18px; visibility: hidden; }
.swatch[aria-checked="true"] .icon { visibility: visible; }
.menu-item {
  display: flex; align-items: center; gap: 10px; height: 40px; padding: 0 10px;
  border: 0; border-radius: 4px; background: transparent; text-align: left;
}
.menu-item:hover { background: var(--hover); }
.menu-item span { display: inline-flex; }
.menu-item.danger { color: var(--danger); }

.editor-body {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 16px 18px; outline: none;
  font-size: 16px; line-height: 1.55; overflow-wrap: anywhere;
}
.editor-body:empty::before { content: attr(data-placeholder); opacity: 0.5; pointer-events: none; }
.editor-body ul, .editor-body ol { margin: 0; padding-left: 24px; }

.format-bar {
  display: flex; align-items: center; gap: 2px;
  padding: 4px 6px calc(4px + var(--safe-bottom));
  border-top: 1px solid rgba(0, 0, 0, 0.06);
}
.fmt {
  width: 38px; height: 36px; display: grid; place-items: center;
  border: 0; border-radius: 4px; background: transparent; color: inherit; opacity: 0.8;
}
.fmt:hover { background: rgba(0, 0, 0, 0.07); opacity: 1; }
.fmt.on { background: rgba(0, 0, 0, 0.12); opacity: 1; }
.editor-meta { font-size: 12px; opacity: 0.6; padding-right: 6px; white-space: nowrap; }

/* Desktop / tablet lebar: dua panel berdampingan */
@media (min-width: 820px) {
  .list-pane { width: 340px; flex: none; border-right: 1px solid var(--border); }
  .editor-pane {
    position: static; transform: none; visibility: visible; transition: none;
    flex: 1; padding: 20px; z-index: auto;
  }
  .editor {
    max-width: 760px; width: 100%; margin: 0 auto;
    border-radius: 6px; overflow: hidden; box-shadow: var(--shadow-lg);
  }
  .editor-bar { padding-top: 4px; }
  .editor-placeholder:not([hidden]) {
    flex: 1; display: grid; place-content: center; justify-items: center; gap: 8px;
    color: var(--muted); text-align: center;
  }
  .editor-placeholder img { opacity: 0.6; }
  .editor [data-action="back"] { display: none; }
  .desktop-only { display: inline-grid !important; }
  .format-bar { padding-bottom: 4px; }
}

/* ================= Pengaturan ================= */
.settings {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(0, 0, 0, 0.35);
  display: flex; justify-content: flex-end;
}
.settings-panel {
  width: 100%; max-width: 520px; height: 100%;
  display: flex; flex-direction: column; background: var(--bg);
  box-shadow: var(--shadow-lg);
  animation: slide-in 0.2s ease;
}
@keyframes slide-in { from { transform: translateX(40px); opacity: 0; } }
.settings-body {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 4px 16px calc(24px + var(--safe-bottom));
  display: flex; flex-direction: column; gap: 14px;
}
.card { background: var(--surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card h3 { font-size: 15px; margin-bottom: 10px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.card-head h3 { margin: 0; }
.card > p { margin: 0 0 12px; }

.account { display: flex; align-items: center; gap: 12px; }
.avatar {
  width: 44px; height: 44px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 600;
  background: var(--accent); color: var(--accent-text);
}
.account-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.account-info > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.device-list { list-style: none; margin: 0 0 12px; padding: 0; }
.device { display: flex; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); }
.device:first-child { border-top: 0; }
.device-icon {
  position: relative; width: 40px; height: 40px; flex: none;
  display: grid; place-items: center; border-radius: 8px; background: var(--surface-2);
}
.device-icon .icon { width: 22px; height: 22px; }
.device-icon .dot {
  position: absolute; right: -2px; bottom: -2px; width: 12px; height: 12px;
  border-radius: 50%; background: var(--online); border: 2px solid var(--surface);
}
.device-info { flex: 1; min-width: 0; }
.device-name { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; font-weight: 600; overflow-wrap: anywhere; }
.badge {
  font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 99px;
  background: color-mix(in srgb, var(--accent) 22%, transparent); color: var(--accent-strong);
}
.device-meta { font-size: 13px; color: var(--muted); }
.device-meta .online { color: var(--online); font-weight: 600; }
.device-actions { display: flex; align-items: flex-start; }

.install-info p { margin: 0 0 8px; }
.install-info ol { margin: 0; padding-left: 20px; }
.install-info li { margin-bottom: 6px; }
.install-info .inline-icon { display: inline-flex; vertical-align: -4px; color: var(--accent-strong); }
.install-info .ok { display: flex; align-items: center; gap: 8px; color: var(--online); font-weight: 600; }

.sub-title { margin: 16px 0 8px; font-size: 14px; font-weight: 600; }
#pin-hint .muted { margin: 0; }
#pin-hint .inline-icon { display: inline-flex; vertical-align: -4px; }
#pin-hint .inline-icon .icon { width: 16px; height: 16px; }

/* Jendela "Tempel di layar" (Document Picture-in-Picture) */
body.pip { display: flex; flex-direction: column; overflow: hidden; background: var(--n-bg, #fff7d1); }
body.pip .pip-note { flex: 1; max-width: none; margin: 0; border-radius: 0; box-shadow: none; }
body.pip .pip-bar { padding: 2px 4px 2px 12px; min-height: 36px; }
body.pip .pip-title { font-size: 12px; font-weight: 700; opacity: 0.65; }
body.pip .editor-body { padding: 10px 14px; font-size: 15px; }
.version-line { margin: 0 0 4px; }
#version-status { margin: 0 0 12px; }
#version-status.outdated { color: var(--danger); font-weight: 600; }
.update-bar {
  position: fixed; left: 50%; bottom: calc(16px + var(--safe-bottom)); z-index: 90;
  transform: translateX(-50%); width: max-content; max-width: calc(100% - 24px);
  display: flex; align-items: center; gap: 12px; padding: 8px 8px 8px 14px; border-radius: 8px;
  background: var(--brand-charcoal); color: #fff; font-size: 14px; box-shadow: var(--shadow-lg);
}
.segmented { display: flex; gap: 4px; padding: 4px; border-radius: 8px; background: var(--surface-2); }
.segmented button { flex: 1; height: 34px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font-weight: 600; }
.segmented button[aria-checked="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ================= Dialog & toast ================= */
.dialog {
  width: min(420px, calc(100% - 32px)); padding: 0; border: 0; border-radius: 10px;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
.dialog-form { padding: 20px; }
.dialog-title { font-size: 18px; margin-bottom: 8px; }
.dialog-message { margin: 0 0 16px; white-space: pre-line; }
.dialog-message:empty { display: none; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.dialog .btn.primary.danger { background: var(--danger); color: #fff; border-color: transparent; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); z-index: 100;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 8px;
  background: #2b2b2b; color: #fff; font-size: 14px; box-shadow: var(--shadow-lg);
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
