/* Notely web — bảng màu của app, sáng/tối, 3 cột trên máy tính, 1 cột trên điện thoại. */

:root {
  --ink: #1C1B19;
  --on-ink: #FAF8F4;
  --accent: #8A6A3B;
  --paper: #F5F2EC;
  --surface: #FFFFFF;
  --raised: #FBFAF7;
  --hairline: #E4DFD6;
  --muted: #8A857C;
  --red: #B8483D;
  --accent-soft: color-mix(in srgb, var(--accent) 12%, transparent);
  --ink-soft: color-mix(in srgb, var(--ink) 6%, transparent);
  --shadow: 0 1px 2px rgba(28, 27, 25, .05), 0 8px 28px rgba(28, 27, 25, .08);
  --serif: "New York", "Iowan Old Style", Georgia, "Noto Serif", "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #F2EEE7; --on-ink: #151413; --accent: #CBAA6E; --paper: #0E0E0F; --surface: #1A1A1C;
    --raised: #232325; --hairline: #2E2D2B; --muted: #8E8A83; --red: #D8665A;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 32px rgba(0, 0, 0, .45);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --ink: #F2EEE7; --on-ink: #151413; --accent: #CBAA6E; --paper: #0E0E0F; --surface: #1A1A1C;
  --raised: #232325; --hairline: #2E2D2B; --muted: #8E8A83; --red: #D8665A;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 32px rgba(0, 0, 0, .45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
::selection { background: color-mix(in srgb, var(--accent) 28%, transparent); }
:focus-visible { outline: 2px solid color-mix(in srgb, var(--accent) 70%, transparent); outline-offset: 2px; border-radius: 6px; }

.boot { position: fixed; inset: 0; display: grid; place-items: center; }
.boot img { border-radius: 14px; opacity: .85; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }

/* Nút */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--hairline); background: var(--surface); color: var(--ink);
  font-weight: 500; white-space: nowrap;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { background: var(--raised); }
.btn.primary { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }
.btn.primary:hover { opacity: .9; }
.btn.accent { background: var(--accent); color: var(--on-ink); border-color: var(--accent); }
.btn.danger { color: var(--red); }
.btn.danger.solid { background: var(--red); color: #fff; border-color: var(--red); }
.btn.block { width: 100%; }
.btn.small { height: 32px; padding: 0 12px; font-size: 13.5px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: default; }
.link { color: var(--accent); font-size: 14px; }
.link:hover { text-decoration: underline; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 9px; display: inline-grid; place-items: center;
  color: var(--muted); flex: none; transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--ink-soft); color: var(--ink); }
.icon-btn.accent { color: var(--accent); }
.icon-btn.on { color: var(--accent); }
.spacer { flex: 1; }

/* Đăng nhập */
.auth { position: fixed; inset: 0; overflow: auto; display: grid; place-items: center; padding: 32px 16px; }
.auth-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--hairline);
  border-radius: 18px; padding: 32px 28px 24px; box-shadow: var(--shadow); text-align: center;
}
.auth-logo { border-radius: 15px; display: block; margin: 0 auto 12px; }
.auth-title { font: 600 30px/1.1 var(--serif); margin: 0 0 6px; letter-spacing: -.01em; }
.auth-sub { color: var(--muted); margin: 0 0 22px; font-size: 14px; }
.auth form { text-align: left; display: grid; gap: 14px; }
.auth-links { display: flex; justify-content: center; gap: 16px; min-height: 20px; }
.auth-foot { color: var(--muted); font-size: 12.5px; margin: 18px 0 0; }

.seg { display: flex; padding: 3px; background: var(--paper); border: 1px solid var(--hairline); border-radius: 10px; margin-bottom: 18px; }
.seg button { flex: 1; height: 32px; border-radius: 7px; color: var(--muted); font-size: 14px; font-weight: 500; }
.seg button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 500; }
.field input, .field select, .input {
  height: 42px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--hairline);
  background: var(--raised); outline: none; width: 100%; min-width: 0;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-error { color: var(--red); font-size: 13.5px; margin: 0; }
.form-info { color: var(--muted); font-size: 13.5px; margin: 0; }
.check-row { display: flex; gap: 8px; align-items: center; font-size: 14px; color: var(--ink); }
.check-row input { accent-color: var(--accent); width: 16px; height: 16px; }

/* Bố cục 3 cột */
.app {
  height: 100%; height: 100dvh;
  display: grid; grid-template-columns: 248px minmax(300px, 360px) 1fr;
}
.sidebar {
  background: var(--paper); border-right: 1px solid var(--hairline);
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
}
.pane { min-width: 0; min-height: 0; }
.list { background: var(--raised); border-right: 1px solid var(--hairline); display: flex; flex-direction: column; }
.editor { background: var(--surface); display: flex; flex-direction: column; overflow: hidden; }
.scrim { display: none; }
.only-narrow { display: none; }

/* Thanh bên */
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 10px; }
.brand img { width: 28px; height: 28px; border-radius: 7px; }
.brand b { font: 600 20px/1 var(--serif); letter-spacing: -.01em; }
.side-scroll { flex: 1; overflow: auto; padding: 6px 10px 12px; }
.side-new { margin: 6px 10px 8px; }
.side-new .btn { width: 100%; justify-content: flex-start; }
.nav-h { display: flex; align-items: center; justify-content: space-between; margin: 18px 8px 4px; font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.nav-h .icon-btn { width: 24px; height: 24px; border-radius: 6px; }
.nav-h .icon-btn svg { width: 15px; height: 15px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%; height: 34px; padding: 0 10px;
  border-radius: 8px; color: var(--ink); text-align: left; font-size: 14.5px;
}
.nav-item svg { color: var(--muted); flex: none; }
.nav-item .label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .count { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.nav-item:hover { background: var(--ink-soft); }
.nav-item[aria-current="true"] { background: var(--accent-soft); }
.nav-item[aria-current="true"] svg, .nav-item[aria-current="true"] .label { color: var(--accent); }
.nav-item[aria-current="true"] .label { font-weight: 600; }
.nav-empty { color: var(--muted); font-size: 13px; padding: 2px 10px; }
.side-foot {
  border-top: 1px solid var(--hairline); padding: 10px 12px; display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; color: var(--muted);
}
.side-foot .status { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; overflow: hidden; }
.side-foot .status span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-foot .status svg { width: 15px; height: 15px; flex: none; }
.spin svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Danh sách */
.list-head { padding: 14px 14px 10px; display: grid; gap: 10px; border-bottom: 1px solid var(--hairline); }
.list-head .row { display: flex; align-items: center; gap: 4px; }
.list-title { font: 600 21px/1.2 var(--serif); margin: 0 0 0 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; letter-spacing: -.01em; }
.search {
  display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 10px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--hairline);
}
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-ico { color: var(--muted); display: grid; }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; height: 100%; }
.search input::-webkit-search-cancel-button { filter: grayscale(1); opacity: .5; }
.search kbd { font: 11px var(--sans); color: var(--muted); border: 1px solid var(--hairline); border-radius: 5px; padding: 1px 5px; }

.notices:empty { display: none; }
.notices { padding: 10px 12px 0; display: grid; gap: 8px; }
.notice {
  display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 10px; font-size: 13px;
  background: var(--accent-soft); color: var(--ink); border: 1px solid color-mix(in srgb, var(--accent) 22%, transparent);
}
.notice.warn { background: color-mix(in srgb, var(--red) 9%, transparent); border-color: color-mix(in srgb, var(--red) 25%, transparent); }
.notice p { margin: 0; flex: 1; }
.notice .link { font-size: 13px; white-space: nowrap; }

.notes { flex: 1; overflow: auto; padding: 4px 12px 24px; overscroll-behavior: contain; }
.group-h { font-size: 12px; font-weight: 600; color: var(--muted); margin: 16px 6px 6px; letter-spacing: .02em; }
.card {
  display: block; width: 100%; text-align: left; padding: 12px 14px; margin-bottom: 6px;
  background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--radius);
  transition: border-color .15s, box-shadow .15s;
}
.card:hover { border-color: color-mix(in srgb, var(--accent) 35%, var(--hairline)); }
.card[aria-current="true"] { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.card-title { display: flex; gap: 6px; align-items: baseline; font-weight: 600; font-size: 15px; line-height: 1.35; }
.card-title span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.card-title svg { width: 13px; height: 13px; color: var(--accent); flex: none; align-self: center; }
.card-snippet {
  color: var(--muted); font-size: 13.5px; margin-top: 3px; line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere;
}
.card-meta { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 12px; color: var(--muted); min-width: 0; }
.card-meta .date { flex: none; font-variant-numeric: tabular-nums; }
.card-meta .nb { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 45%; }
.card-meta .tags { display: flex; gap: 4px; overflow: hidden; min-width: 0; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 7px; border-radius: 999px;
  background: var(--ink-soft); color: var(--muted); font-size: 11.5px; white-space: nowrap;
}
.empty { text-align: center; color: var(--muted); padding: 56px 20px; font-size: 14px; }
.empty h3 { font: 600 18px var(--serif); color: var(--ink); margin: 0 0 6px; }

/* Trình soạn thảo */
.ed-bar {
  display: flex; align-items: center; gap: 4px; padding: 10px 14px; border-bottom: 1px solid var(--hairline);
  min-height: 55px; flex-wrap: nowrap;
}
.ed-bar .meta { color: var(--muted); font-size: 12.5px; margin-right: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.nb-pick {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 10px; border-radius: 8px;
  color: var(--muted); font-size: 13.5px; max-width: 220px; min-width: 0;
}
.nb-pick:hover { background: var(--ink-soft); color: var(--ink); }
.nb-pick span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ed-scroll { flex: 1; overflow: auto; }
.ed-inner { max-width: 760px; margin: 0 auto; padding: 32px 40px 120px; }
.ed-title {
  display: block; width: 100%; border: 0; outline: 0; resize: none; background: none; overflow: hidden;
  font: 600 30px/1.25 var(--serif); letter-spacing: -.015em; padding: 0; margin: 0 0 6px;
}
.ed-title::placeholder, .ed-body::placeholder { color: color-mix(in srgb, var(--muted) 70%, transparent); }
.ed-tags { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 6px 0 18px; }
.ed-tags .chip { height: 24px; font-size: 12.5px; padding: 0 4px 0 9px; }
.ed-tags .chip button { width: 18px; height: 18px; display: grid; place-items: center; border-radius: 50%; color: var(--muted); }
.ed-tags .chip button:hover { background: var(--ink-soft); color: var(--ink); }
.ed-tags .chip button svg { width: 12px; height: 12px; }
.ed-tags input {
  border: 0; outline: 0; background: none; font-size: 13px; color: var(--muted); width: 120px; height: 24px; padding: 0 4px;
}
.ed-tags input:focus { color: var(--ink); }
.ed-body {
  display: block; width: 100%; min-height: 50vh; border: 0; outline: 0; resize: none; background: none; padding: 0;
  font: 16px/1.7 var(--sans); overflow: hidden; tab-size: 4;
}
.ed-locked { text-align: center; padding: 80px 20px; color: var(--muted); }
.ed-locked h3 { font: 600 22px var(--serif); color: var(--ink); margin: 10px 0 6px; }
.ed-locked .big { font-size: 40px; }
.ed-banner {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 10px 14px; margin: 0 0 20px;
  border-radius: 10px; background: color-mix(in srgb, var(--red) 8%, transparent); color: var(--ink); font-size: 14px;
}
.ed-banner p { margin: 0; flex: 1; min-width: 160px; }
.ed-empty { flex: 1; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 24px; }
.ed-empty img { width: 56px; height: 56px; border-radius: 14px; opacity: .9; }
.ed-empty h3 { font: 600 20px var(--serif); color: var(--ink); margin: 14px 0 4px; }
.ed-empty p { margin: 0 0 16px; font-size: 14px; }
.kbd-hints { font-size: 12.5px; color: var(--muted); margin-top: 12px; }
.kbd-hints kbd { font: 11px var(--sans); border: 1px solid var(--hairline); border-radius: 5px; padding: 1px 5px; }

/* Markdown */
.md { font-size: 16px; line-height: 1.7; overflow-wrap: anywhere; cursor: text; min-height: 40vh; }
.md.placeholder { color: color-mix(in srgb, var(--muted) 70%, transparent); }
.md > :first-child { margin-top: 0; }
.md p { margin: 0 0 .8em; }
.md h2, .md h3, .md h4 { font-family: var(--serif); font-weight: 600; line-height: 1.3; letter-spacing: -.01em; margin: 1.3em 0 .45em; }
.md h2 { font-size: 24px; } .md h3 { font-size: 20px; } .md h4 { font-size: 17px; }
.md ul, .md ol { margin: 0 0 .8em; padding-left: 1.5em; }
.md li { margin: .15em 0; }
.md li::marker { color: var(--muted); }
.md ul.checklist { list-style: none; padding-left: 0; }
.md li.check { display: flex; gap: 10px; align-items: flex-start; }
.md li.check .box {
  width: 18px; height: 18px; margin-top: 4px; flex: none; border-radius: 5px;
  border: 1.5px solid color-mix(in srgb, var(--muted) 80%, transparent); display: grid; place-items: center;
}
.md li.check .box:hover { border-color: var(--accent); }
.md li.check.done .box { background: var(--accent); border-color: var(--accent); }
.md li.check.done .box::after { content: ""; width: 9px; height: 5px; border: 2px solid var(--on-ink); border-top: 0; border-right: 0; transform: translateY(-1px) rotate(-45deg); }
.md li.check.done > span { color: var(--muted); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--muted) 60%, transparent); }
.md blockquote { margin: 0 0 .8em; padding: 2px 0 2px 14px; border-left: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); color: var(--muted); }
.md hr { border: 0; border-top: 1px solid var(--hairline); margin: 1.4em 0; }
.md a { color: var(--accent); text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent); text-underline-offset: 2px; }
.md code { font: .9em var(--mono); background: var(--ink-soft); padding: 1px 5px; border-radius: 5px; }
.md pre { background: var(--raised); border: 1px solid var(--hairline); border-radius: 10px; padding: 12px 14px; overflow: auto; }
.md pre code { background: none; padding: 0; }
.md strong { font-weight: 650; }

/* Menu & hộp thoại */
.menu {
  position: fixed; z-index: 50; min-width: 200px; max-width: calc(100vw - 32px); max-height: 70vh; overflow: auto;
  background: var(--surface); border: 1px solid var(--hairline); border-radius: 12px; box-shadow: var(--shadow); padding: 5px;
}
.menu button {
  display: flex; align-items: center; gap: 10px; width: 100%; height: 34px; padding: 0 10px; border-radius: 7px; text-align: left; font-size: 14px;
}
.menu button:hover, .menu button:focus-visible { background: var(--ink-soft); outline: none; }
.menu button svg { color: var(--muted); }
.menu button.danger { color: var(--red); }
.menu button.danger svg { color: var(--red); }
.menu button .tick { margin-left: auto; color: var(--accent); }
.menu hr { border: 0; border-top: 1px solid var(--hairline); margin: 5px 4px; }
.menu .menu-h { font-size: 11.5px; color: var(--muted); padding: 6px 10px 2px; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }

.modal {
  border: 1px solid var(--hairline); border-radius: 16px; padding: 0; background: var(--surface); color: var(--ink);
  width: min(460px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); box-shadow: var(--shadow);
}
.modal::backdrop { background: rgba(14, 14, 15, .38); backdrop-filter: blur(2px); }
.modal form, .modal .m-wrap { display: grid; gap: 14px; padding: 22px; }
.modal h3 { font: 600 21px/1.25 var(--serif); margin: 0; letter-spacing: -.01em; }
.modal p { margin: 0; color: var(--muted); font-size: 14px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.modal.wide { width: min(560px, calc(100vw - 32px)); }
.code-box {
  font: 600 18px/1.4 var(--mono); letter-spacing: .06em; text-align: center; padding: 14px; border-radius: 10px;
  background: var(--raised); border: 1px dashed var(--accent); color: var(--ink); user-select: all; overflow-wrap: anywhere;
}

/* Cài đặt */
.set-sec { border-top: 1px solid var(--hairline); padding-top: 14px; display: grid; gap: 10px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 14px; flex-wrap: wrap; }
.set-row .k { color: var(--muted); }
.set-row .v { font-weight: 500; overflow-wrap: anywhere; text-align: right; }
.set-h { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.usage { display: grid; gap: 4px; font-size: 13px; }
.usage .top { display: flex; justify-content: space-between; gap: 8px; }
.usage .top span:last-child { color: var(--muted); font-variant-numeric: tabular-nums; }
.bar { height: 6px; border-radius: 999px; background: var(--ink-soft); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.bar i.full { background: var(--red); }
.plan-badge { display: inline-block; padding: 2px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 13px; }
.seg.small { margin: 0; }
.seg.small button { height: 28px; font-size: 13px; padding: 0 12px; white-space: nowrap; flex: none; }

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

/* Máy tính bảng: thanh bên thành ngăn kéo */
@media (max-width: 1099px) {
  .app { grid-template-columns: minmax(280px, 340px) 1fr; }
  .only-narrow { display: inline-grid; }
  .sidebar {
    position: fixed; z-index: 30; top: 0; bottom: 0; left: 0; width: min(280px, 86vw);
    transform: translateX(-102%); transition: transform .22s ease; box-shadow: var(--shadow);
  }
  .app.drawer .sidebar { transform: none; }
  .app.drawer .scrim { display: block; position: fixed; inset: 0; z-index: 20; background: rgba(14, 14, 15, .3); }
}

/* Điện thoại: một cột */
@media (max-width: 759px) {
  body { font-size: 16px; }
  .app { grid-template-columns: 100%; }
  .list, .editor { grid-column: 1; grid-row: 1; border-right: 0; }
  .app[data-view="list"] .editor { display: none; }
  .app[data-view="editor"] .list { display: none; }
  .list-head { padding: 12px 16px 10px; }
  .notes { padding: 4px 16px 32px; }
  .notices { padding: 10px 16px 0; }
  .ed-bar { padding: 8px 10px; }
  .ed-inner { padding: 20px 16px 120px; }
  .ed-title { font-size: 26px; }
  .search kbd { display: none; }
  .ed-bar .meta { display: none; }
  .nb-pick { max-width: 140px; }
  .modal form, .modal .m-wrap { padding: 18px 16px; }
}

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

.only-phone { display: none; }
@media (max-width: 759px) { .only-phone { display: inline-grid; } }
