* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; color: var(--text); font: 16px/1.55 var(--sans); }
::selection { background: var(--sel); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 24px 80px; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* thanh trên */
.top { display: flex; flex-wrap: wrap; gap: 14px 20px; align-items: center; padding: 28px 0 16px; }
.tools { margin-left: auto; }
.tabs { display: flex; gap: 4px; }
.tab { border: 1px solid transparent; background: none; padding: 7px 16px; border-radius: 8px; color: var(--muted); font-weight: 500; }
.tab.on { background: var(--raise); color: var(--text); border-color: var(--line); }
.tools { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.search input, select { height: 40px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.search input { width: min(300px, 70vw); }
.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { height: 38px; width: 42px; display: grid; place-items: center; border: 0; background: none; color: var(--muted); }
.seg button[aria-pressed=true] { background: var(--raise); color: var(--text); }
.ghost { height: 40px; padding: 0 14px; border: 1px solid var(--line); border-radius: 8px; background: none; }
.ghost[aria-pressed=true] { background: var(--raise); }
.ghost[aria-pressed=false] { color: var(--muted); }

/* chip tag */
.chips { display: flex; flex-wrap: wrap; gap: 8px; padding-bottom: 12px; }
.chip { border: 1px solid var(--line); background: none; border-radius: 999px; padding: 3px 12px; font-size: .9rem; color: var(--text); }
.chip.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.chip small { color: var(--muted); margin-left: 4px; }
.chip.on small { color: inherit; opacity: .8; }
.status { color: var(--muted); margin: 40px 0; text-align: center; }
.status:empty { display: none; }

/* mỗi mục: một cấu trúc DOM, hai kiểu bày */
.items { display: grid; }
.item { position: relative; display: grid; align-items: center; gap: 4px 16px; border-bottom: 1px solid var(--line); }
.item[hidden] { display: none; }
.thumb { position: relative; display: block; overflow: hidden; border-radius: 8px; border: 1px solid var(--line); background: var(--raise); aspect-ratio: 16 / 10; color: inherit; }
.ph { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 650; font-size: 1.6rem; }
.ph svg { width: 28px; height: 28px; opacity: .55; }
.ph b { display: none; }
.h0 .ph { background: color-mix(in srgb, var(--purple) 18%, var(--raise)); color: var(--purple); }
.h1 .ph { background: color-mix(in srgb, var(--accent) 22%, var(--raise)); color: var(--link); }
.h2 .ph { background: color-mix(in srgb, var(--green) 20%, var(--raise)); color: var(--green); }
.h3 .ph { background: color-mix(in srgb, var(--red) 18%, var(--raise)); color: var(--red); }
.h4 .ph { background: color-mix(in srgb, var(--blue) 20%, var(--raise)); color: var(--blue); }
.h5 .ph { background: color-mix(in srgb, var(--yellow) 22%, var(--raise)); color: var(--yellow); }
.h6 .ph { background: var(--raise); color: var(--muted); }
.h7 .ph { background: color-mix(in srgb, var(--cyan) 20%, var(--raise)); color: var(--cyan); }
.frame { position: absolute; left: 0; top: 0; border: 0; transform-origin: 0 0; background: #fff; opacity: 0; transition: opacity .25s; pointer-events: none; }
.frame.ready { opacity: 1; }
.titlebox { min-width: 0; }
.title { display: block; font-family: var(--serif); font-weight: 650; font-size: 1.125rem; line-height: 1.35; color: var(--text); text-decoration: none; overflow-wrap: anywhere; }
.title:hover { text-decoration: underline; }
.mini { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; min-width: 0; }
.tag { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; background: none; cursor: pointer; font-size: .85rem; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 0 9px; }
.kind { font-size: .8rem; font-weight: 600; letter-spacing: .02em; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 0 6px; }
.when, .sz { color: var(--muted); font-size: .9375rem; }
.access { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border: 1px solid var(--line); border-radius: 999px; background: none; font-size: .9375rem; color: var(--muted); }
.access.pub { color: var(--text); border-color: var(--accent); }
.more { width: 38px; height: 38px; display: grid; place-items: center; border: 0; border-radius: 8px; background: none; color: var(--text); }
.more svg { stroke-width: 3; }
.more:hover, .access:hover, .tab:hover, .ghost:hover, .seg button:hover { background: var(--raise); color: var(--text); }
.archived-note { color: var(--muted); font-size: .85rem; }

/* kiểu danh sách */
.list .item { grid-template-columns: 120px minmax(0, 1fr) 130px 140px 44px; padding: 14px 4px; }
.list .thumb { width: 120px; }
.list .sub { display: flex; gap: 8px; align-items: center; margin-top: 2px; }
.list .when { grid-column: 3; }
.list .access { grid-column: 4; justify-self: start; } .list .more { grid-column: 5; }
.list .titlebox { grid-column: 2; }
.list .thumb { grid-row: 1; grid-column: 1; }

/* kiểu lưới */
.grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 24px 20px; padding-top: 8px; }
.grid .item { grid-template-columns: minmax(0, 1fr) auto auto; align-content: start; border: 0; gap: 10px 8px; }
.grid .thumb { grid-column: 1 / -1; }
.grid .titlebox { grid-column: 1 / -1; }
.grid .when { grid-column: 1; }
.grid .access { grid-column: 2; } .grid .more { grid-column: 3; }
.grid .sub { display: flex; gap: 8px; align-items: center; }

@media (max-width: 760px) {
  .wrap { padding: 0 16px 64px; }
  .list .item { grid-template-columns: 88px minmax(0, 1fr) auto 40px; gap: 4px 12px; }
  .list .thumb { width: 88px; }
  .list .when { grid-column: 2; grid-row: 2; }
  .list .access { grid-column: 3; grid-row: 1; padding: 0 10px; } .list .access span { display: none; }
  .list .more { grid-column: 4; grid-row: 1; }
  .list .titlebox { grid-column: 2; grid-row: 1; }
  .top { padding-top: 16px; gap: 10px 12px; }
  .tabs { flex: 1; }
  #logout { order: 2; }
  .tools { order: 3; width: 100%; margin-left: 0; gap: 8px; }
  .search { flex: 1 1 100%; } .search input { width: 100%; }
  #sort { flex: 1; min-width: 0; }
}

/* menu ⋯, hộp thoại, thông báo */
.menu { position: fixed; z-index: 30; min-width: 220px; padding: 6px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); }
.menu[hidden] { display: none; }
.menu button, .menu a { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 12px; border: 0; border-radius: 8px; background: none; color: var(--text); text-align: left; text-decoration: none; font-size: .9375rem; }
.menu button:hover, .menu a:hover, .menu button:focus-visible, .menu a:focus-visible { background: var(--raise); }
.menu .danger { color: var(--danger); } .menu hr { border: 0; border-top: 1px solid var(--line); margin: 6px 4px; }
.dlg { width: min(480px, calc(100vw - 32px)); padding: 24px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.dlg::backdrop { background: rgba(0, 0, 0, .55); }
.dlg h2 { margin: 0 0 8px; font-family: var(--serif); font-size: 1.3rem; }
.dlg p { margin: 0 0 16px; color: var(--muted); }
.dlg .name { color: var(--text); font-weight: 600; overflow-wrap: anywhere; }
.dlg label { display: block; margin: 0 0 14px; font-size: .9375rem; color: var(--muted); }
.dlg input { display: block; width: 100%; height: 42px; margin-top: 6px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.dlg .suggest { display: flex; flex-wrap: wrap; gap: 6px; margin: -6px 0 14px; }
.dlg .row { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.dlg .btn { height: 40px; padding: 0 18px; border-radius: 8px; border: 1px solid var(--line); background: none; }
.dlg .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.dlg .btn.danger { background: var(--danger); border-color: var(--danger); color: var(--on-danger); font-weight: 600; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 40; display: flex; align-items: center; gap: 14px; max-width: calc(100vw - 32px); padding: 12px 16px; border-radius: 12px; background: var(--text); color: var(--bg); box-shadow: var(--shadow); }
.toast[hidden] { display: none; }
.toast button { border: 0; background: none; color: inherit; font-weight: 700; text-decoration: underline; padding: 0; }

/* trang đăng nhập */
body.login { display: grid; place-items: center; min-height: 100vh; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 28px; width: min(400px, calc(100vw - 32px)); }
.card h1 { margin: 0 0 4px; font-family: var(--serif); font-size: 1.6rem; color: var(--strong); } .muted { color: var(--muted); margin: 0 0 16px; }
form { display: flex; flex-direction: column; gap: 14px; }
.card label { display: flex; flex-direction: column; gap: 6px; font-size: .9375rem; color: var(--muted); }
.card input { height: 42px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.card button { height: 42px; border-radius: 8px; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-text); font-weight: 600; }
.error { color: var(--danger); margin: 0; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
