[hidden] { display: none !important; }
:root {
  --green: #00a82d; --green-d: #008f26; --side: #1a1a1a; --side-2: #2b2b2b; --side-t: #ccc;
  --bg: #fff; --bg2: #f8f8f8; --line: #e6e6e6; --t: #333; --muted: #8a8a8a; --sel: #eef8f0;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; color: var(--t); background: var(--bg); }
button, select, input { font: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 5px 10px; color: var(--t); }
button:hover { background: var(--bg2); }
button.primary { background: var(--green); border-color: var(--green); color: #fff; }
button.primary:hover { background: var(--green-d); }
button.link { border: 0; background: none; color: var(--green-d); padding: 4px 0; }
button.icon { border: 0; background: none; font-size: 20px; padding: 2px 8px; }
.muted { color: var(--muted); font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.only-mobile { display: none; }

#app { display: grid; grid-template-columns: 250px 360px 1fr; height: 100vh; height: 100dvh; }

/* Cột trái */
#side { background: var(--side); color: var(--side-t); display: flex; flex-direction: column; min-height: 0; }
.side-head { padding: 14px 12px 8px; }
.brand { font-weight: 600; color: #fff; margin-bottom: 10px; }
.btn-new { width: 100%; background: var(--green); color: #fff; border: 0; border-radius: 20px; padding: 8px; font-weight: 600; }
.btn-new:hover { background: var(--green-d); }
.side-scroll { overflow-y: auto; flex: 1; padding: 4px 0 20px; }
.sec { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #888; padding: 14px 14px 4px; display: flex; justify-content: space-between; align-items: center; }
.mini { background: none; border: 0; color: #aaa; padding: 0 4px; font-size: 16px; }
.nav-item { display: flex; justify-content: space-between; gap: 6px; padding: 6px 14px; color: var(--side-t); text-decoration: none; cursor: pointer; font-size: 14px; }
.nav-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item b { font-weight: 400; color: #888; font-size: 12px; }
.nav-item:hover { background: var(--side-2); }
.nav-item.active { background: #3a3a3a; color: #fff; }
.nav-item.sub { padding-left: 26px; }
.nb-group { padding: 8px 14px 2px; font-size: 12px; color: #9a9a9a; }
.tag-filter { margin: 2px 12px 6px; width: calc(100% - 24px); background: var(--side-2); border: 0; color: #eee; border-radius: 4px; padding: 5px 8px; font-size: 13px; }
.btn-like { cursor: pointer; }

/* Cột giữa */
#list { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: var(--bg2); }
.list-head { padding: 12px 12px 6px; border-bottom: 1px solid var(--line); background: #fff; }
.list-head h2 { font-size: 18px; margin: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-head .row + .row { margin-top: 8px; }
#q { flex: 1; padding: 7px 10px; border: 1px solid var(--line); border-radius: 18px; background: var(--bg2); }
#filters { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 6px 10px; margin-top: 10px; font-size: 12px; color: var(--muted); }
#filters label { display: flex; flex-direction: column; gap: 2px; }
#filters select, #filters input { padding: 4px 6px; border: 1px solid var(--line); border-radius: 4px; color: var(--t); background: #fff; width: 100%; min-width: 0; }
.pair { display: flex; gap: 4px; }
.filter-actions { grid-column: 1 / -1; text-align: right; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.chip { background: var(--sel); color: var(--green-d); border-radius: 12px; padding: 2px 8px; font-size: 12px; cursor: pointer; }
.chip::after { content: " ✕"; }
.bulk { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; align-items: center; font-size: 13px; }
.bulk select { max-width: 150px; }
.notes { overflow-y: auto; flex: 1; }
.card { display: flex; gap: 10px; padding: 12px; border-bottom: 1px solid var(--line); background: #fff; cursor: pointer; }
.card:hover { background: #fbfbfb; }
.card.active { background: var(--sel); box-shadow: inset 3px 0 var(--green); }
.card .c-main { flex: 1; min-width: 0; }
.card h3 { font-size: 14px; margin: 0 0 4px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card p { margin: 0 0 6px; font-size: 13px; color: #666; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; word-break: break-word; }
.card .c-meta { font-size: 12px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; }
.card .price { color: var(--green-d); font-weight: 600; }
.card .st { color: #c0392b; }
.card img { width: 64px; height: 64px; object-fit: cover; border-radius: 4px; flex: none; background: #eee; }
.card input[type=checkbox] { margin-top: 3px; transform: scale(1.2); }
.more { margin: 10px auto; display: block; }
.list-foot { border-top: 1px solid var(--line); padding: 4px 12px; background: #fff; }

/* Bên phải */
#view { overflow-y: auto; min-height: 0; }
.empty { color: var(--muted); text-align: center; margin-top: 30vh; }
#note { max-width: 900px; margin: 0 auto; padding: 0 28px 60px; }
.note-head { position: sticky; top: 0; background: #fff; padding: 12px 0 8px; border-bottom: 1px solid var(--line); z-index: 2; }
#noteNb { padding: 4px 6px; border: 1px solid var(--line); border-radius: 4px; max-width: 260px; }
.tags-row { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; align-items: center; }
.tag { background: #f0f0f0; border-radius: 12px; padding: 2px 4px 2px 10px; font-size: 12px; display: inline-flex; gap: 4px; align-items: center; }
.tag button { border: 0; background: none; padding: 0 4px; color: #999; }
.tag-add { border: 1px dashed #ccc; border-radius: 12px; padding: 2px 10px; font-size: 12px; width: 130px; }
.meta { font-size: 12px; color: var(--muted); margin-top: 6px; display: flex; flex-wrap: wrap; gap: 10px; }
.meta b { color: var(--t); font-weight: 600; }
.note-title { font-size: 22px; margin: 18px 0 12px; line-height: 1.35; outline: none; word-break: break-word; }
.note-body { font-size: 15px; line-height: 1.6; word-break: break-word; outline: none; }
.note-body img { max-width: 100%; height: auto; border-radius: 4px; margin: 4px 0; }
.note-body table { border-collapse: collapse; max-width: 100%; display: block; overflow-x: auto; }
.note-body td, .note-body th { border: 1px solid #ddd; padding: 4px 8px; vertical-align: top; }
.note-body table.kv th { text-align: left; background: var(--bg2); white-space: nowrap; }
.note-body a { color: #0b6bcb; word-break: break-all; }
.note-body a.att { display: inline-block; padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px; text-decoration: none; margin: 4px 0; }
.editing .note-title, .editing .note-body { background: #fffef5; outline: 1px dashed #e0d890; padding: 6px; border-radius: 4px; }
.toolbar { position: sticky; top: 0; display: flex; flex-wrap: wrap; gap: 4px; padding: 8px 0; background: #fff; }
mark { background: #fff2a8; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #333; color: #fff; padding: 8px 16px; border-radius: 6px; z-index: 50; max-width: 90vw; }
dialog { border: 0; border-radius: 8px; max-width: min(640px, 92vw); box-shadow: 0 6px 30px rgba(0,0,0,.25); }
dialog menu { padding: 0; text-align: right; }
#dlgBody { white-space: pre-wrap; font-size: 13px; max-height: 60vh; overflow: auto; }
#scrim { display: none; }

/* Điện thoại / máy tính bảng hẹp */
@media (max-width: 1100px) { #app { grid-template-columns: 220px 320px 1fr; } }
@media (max-width: 820px) {
  #app { display: block; }
  .only-mobile { display: inline-block; }
  #side { position: fixed; inset: 0 auto 0 0; width: 82vw; max-width: 300px; z-index: 30; transform: translateX(-100%); transition: transform .2s; }
  #app.side-open #side { transform: none; }
  #app.side-open #scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; }
  #list, #view { position: fixed; inset: 0; }
  #app.show-list #view { display: none; }
  #app.show-note #list { display: none; }
  #note { padding: 0 14px 60px; }
  .note-title { font-size: 19px; }
  .card img { width: 56px; height: 56px; }
  #filters { grid-template-columns: 1fr; }
  .nav-item { padding: 9px 14px; }
}
.user-box { margin-top: 14px; padding: 8px 14px 0; border-top: 1px solid #333; font-size: 12px; color: #aaa; word-break: break-all; }
.user-box .nav-item { padding-left: 0; }
.auth { max-width: 360px; margin: 12vh auto; padding: 28px; background: #fff; border-radius: 10px; box-shadow: 0 4px 24px rgba(0,0,0,.08); font-family: system-ui, sans-serif; }
.auth h1 { font-size: 20px; margin: 0 0 18px; color: #00a82d; }
.auth label { display: block; font-size: 13px; color: #555; margin: 12px 0 4px; }
.auth input { width: 100%; box-sizing: border-box; padding: 10px; font-size: 16px; border: 1px solid #ccc; border-radius: 6px; }
.auth button { width: 100%; margin-top: 18px; padding: 11px; font-size: 16px; background: #00a82d; color: #fff; border: 0; border-radius: 6px; cursor: pointer; }
.auth .msg { color: #c0392b; font-size: 14px; min-height: 20px; margin-top: 12px; }
body.auth-page { background: #f2f2f2; margin: 0; }
