/* Bàn nháp — taste deal: palette mint-pink-accounts, type Geist, radius soft */
:root {
  --bg: #f8f8f8;
  --surface: #eeeeee;
  --card: #ffffff;
  --ink: #0a0a0a;
  --muted: #5c5f5d;
  --line: #e2e2e2;
  --accent: #1f6b3a;
  --accent-ink: #ffffff;
  --accent-soft: #e3efe7;
  --amber: #a35a00;
  --amber-soft: #fbeedb;
  --red: #b3261e;
  --red-soft: #fbe4e2;
  --r-sm: 8px;
  --r: 12px;
  --r-lg: 16px;
  --shadow: 0 1px 2px rgba(10, 10, 10, .06), 0 8px 24px rgba(10, 10, 10, .06);
  --font: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --ease: cubic-bezier(.2, .7, .2, 1);
  --top: 60px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 400 15px/1.55 var(--font); -webkit-font-smoothing: antialiased; }
button, input { font: inherit; color: inherit; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: 12px; top: -60px; z-index: 100; background: var(--ink); color: #fff; padding: 10px 14px; border-radius: var(--r-sm); text-decoration: none; }
.skip:focus { top: 10px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- thanh trên ---------- */
.top { position: sticky; top: 0; z-index: 20; height: var(--top); display: flex; align-items: center; gap: 28px; padding: 0 24px; background: rgba(248, 248, 248, .9); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 600; letter-spacing: -.01em; font-size: 16px; }
.brand svg { width: 28px; height: 28px; stroke: none; }
.tabs { display: flex; gap: 4px; height: 100%; }
.tabs a { position: relative; display: flex; align-items: center; gap: 8px; padding: 0 14px; color: var(--muted); text-decoration: none; font-weight: 500; transition: color .2s var(--ease); }
.tabs a::after { content: ""; position: absolute; left: 14px; right: 14px; bottom: -1px; height: 2px; background: var(--ink); transform: scaleX(0); transition: transform .25s var(--ease); }
.tabs a:hover { color: var(--ink); }
.tabs a:hover::after { transform: scaleX(.4); }
.tabs a.on { color: var(--ink); }
.tabs a.on::after { transform: scaleX(1); }
.count { font: 500 11px/1 var(--mono); background: var(--surface); color: var(--muted); padding: 4px 6px; border-radius: 99px; }
.count:empty { display: none; }
.tabs a.on .count { background: var(--accent-soft); color: var(--accent); }
.save-state { margin-left: auto; font-size: 13px; color: var(--muted); }

/* ---------- nút ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 0 14px; border-radius: var(--r-sm); border: 1px solid transparent; background: transparent; font-weight: 500; font-size: 14px; cursor: pointer; white-space: nowrap; transition: background .18s var(--ease), border-color .18s var(--ease), transform .12s var(--ease), box-shadow .18s var(--ease); }
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(1px) scale(.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #18572f; box-shadow: 0 4px 14px rgba(31, 107, 58, .25); }
.btn.soft { background: var(--accent-soft); color: var(--accent); }
.btn.soft:hover { background: #d4e7da; }
.btn.ghost { border-color: var(--line); background: var(--card); }
.btn.ghost:hover { border-color: #cfcfcf; }
.btn.danger { background: var(--red); color: #fff; }
.btn.danger:hover { background: #961f18; }
.btn.danger-text { color: var(--red); }
.btn.danger-text:hover { background: var(--red-soft); border-color: #f2c4c0; }

/* ---------- bố cục ---------- */
.shell { display: grid; grid-template-columns: 320px 1fr; height: calc(100vh - var(--top)); height: calc(100dvh - var(--top)); }
.side { border-right: 1px solid var(--line); background: var(--bg); display: flex; flex-direction: column; min-height: 0; }
.side-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 22px 20px 14px; }
.side-head h1 { margin: 0; font-size: 22px; font-weight: 500; letter-spacing: -.02em; }
.side-head p { margin: 2px 0 0; font-size: 13px; }
.list { list-style: none; margin: 0; padding: 4px 12px 24px; overflow: auto; flex: 1; }
.item { display: block; padding: 12px 12px; border-radius: var(--r); color: var(--ink); text-decoration: none; border: 1px solid transparent; transition: background .16s var(--ease), transform .16s var(--ease), border-color .16s var(--ease); margin-bottom: 2px; }
.item:hover { background: var(--card); border-color: var(--line); transform: translateY(-2px); }
.item.on { background: var(--card); border-color: var(--line); box-shadow: var(--shadow); }
.item-title { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 4px; font-size: 12.5px; color: var(--muted); }
.left { font: 500 11.5px/1 var(--mono); padding: 5px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.left.amber { background: var(--amber-soft); color: var(--amber); }
.left.red { background: var(--red-soft); color: var(--red); }
.empty-list { margin: 8px 20px; padding: 18px; border: 1px dashed #d4d4d4; border-radius: var(--r); color: var(--muted); font-size: 14px; }

.work { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--surface); }
.blank { flex: 1; display: grid; place-items: center; padding: 24px; }
.blank-card { max-width: 420px; text-align: center; }
.blank-card svg { width: 72px; height: 72px; stroke: none; }
.blank-card h2 { font-weight: 500; letter-spacing: -.02em; font-size: 24px; margin: 14px 0 6px; }
.blank-card p { margin: 0 0 20px; }

.doc { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.doc[hidden], .blank[hidden] { display: none; }
.docbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; padding: 10px 20px; background: var(--bg); border-bottom: 1px solid var(--line); }
.back { display: none; }
.fmt { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; }
.fmt .ic, .fmt .tool { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-width: 36px; height: 36px; padding: 0 8px; border: 0; border-radius: var(--r-sm); background: transparent; cursor: pointer; font-size: 15px; transition: background .15s var(--ease), transform .12s var(--ease); }
.fmt .ic:hover, .fmt .tool:hover { background: var(--surface); }
.fmt .ic:active, .fmt .tool:active { transform: scale(.94); }
.fmt .ic circle { fill: currentColor; stroke: none; }
.fmt .tool { font-size: 13.5px; font-weight: 500; padding: 0 10px; }
.fmt .sep { width: 1px; height: 22px; background: var(--line); margin: 0 6px; }
.acts { display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto; }

/* ---------- tờ A4 ngang ---------- */
.paper-scroll { flex: 1; overflow: auto; padding: 28px 24px 64px; }
.paper { width: 297mm; max-width: 100%; min-height: 210mm; margin: 0 auto; background: var(--card); border-radius: 4px; box-shadow: var(--shadow); padding: 12mm; position: relative; }
.paper-meta { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); margin-bottom: 8px; }
.paper-meta span:first-child { font: 500 11px/1 var(--mono); text-transform: uppercase; letter-spacing: .08em; color: var(--accent); }
.title { width: 100%; border: 0; outline: 0; background: transparent; font-size: 28px; font-weight: 500; letter-spacing: -.025em; padding: 2px 0 10px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.title::placeholder { color: #b9b9b9; }
.editor { outline: none; min-height: 140mm; font-size: 15px; line-height: 1.6; word-wrap: break-word; }
.editor:empty::before { content: attr(data-placeholder); color: #a8a8a8; pointer-events: none; }
.editor h2 { font-size: 20px; font-weight: 600; letter-spacing: -.015em; margin: 18px 0 6px; }
.editor p { margin: 0 0 8px; }
.editor ul, .editor ol { margin: 0 0 8px; padding-left: 24px; }
/* ảnh dán: vừa khít cả chiều ngang lẫn chiều dọc của vùng in A4 ngang (186 mm) */
.editor img, .print-body img { display: block; max-width: 100%; max-height: 186mm; width: auto; height: auto; object-fit: contain; margin: 6px 0; border-radius: 2px; }
.editor img[data-uploading] { opacity: .5; }

/* ---------- bảng tính ---------- */
.sheet { margin: 12px 0; max-width: 100%; overflow-x: auto; }
.sheet-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-bottom: 6px; user-select: none; }
.sheet-tools button { height: 30px; padding: 0 10px; border: 1px solid var(--line); background: var(--bg); border-radius: 6px; font-size: 12.5px; font-weight: 500; cursor: pointer; transition: background .15s var(--ease), transform .12s var(--ease); }
.sheet-tools button:hover { background: var(--accent-soft); border-color: #c3dccb; color: var(--accent); transform: translateY(-1px); }
.sheet-tools button:active { transform: translateY(1px); }
.sheet-tools button[data-sheet-act="remove"] { margin-left: auto; color: var(--red); }
.sheet-tools button[data-sheet-act="remove"]:hover { background: var(--red-soft); border-color: #f2c4c0; }
.sheet-help { font: 400 12px var(--mono); color: var(--muted); padding: 0 8px; }
.sheet table { border-collapse: collapse; font-size: 14px; min-width: 50%; }
.sheet th { background: var(--surface); color: var(--muted); font: 500 11.5px var(--mono); padding: 4px 8px; border: 1px solid #d9d9d9; text-align: center; user-select: none; }
.sheet th.corner { width: 32px; }
.sheet td { border: 1px solid #d9d9d9; padding: 0; min-width: 96px; vertical-align: top; }
.sheet td.num .cell { text-align: right; font-variant-numeric: tabular-nums; }
.sheet td.f .cell { color: var(--accent); }
.sheet td.err .cell { color: var(--red); font-family: var(--mono); font-size: 12.5px; }
.sheet .cell { min-height: 32px; padding: 6px 8px; outline: none; white-space: pre-wrap; }
.sheet .cell.editing { box-shadow: inset 0 0 0 2px var(--accent); background: #fbfdfb; text-align: left !important; color: var(--ink) !important; font-family: var(--mono); font-size: 13px; }

/* ---------- hộp thoại ---------- */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(10, 10, 10, .42); display: grid; place-items: center; padding: 20px; }
.modal[hidden] { display: none; }
.modal-card { background: var(--card); border-radius: var(--r-lg); box-shadow: 0 24px 60px rgba(0, 0, 0, .25); padding: 24px; width: 100%; max-width: 440px; animation: pop .2s var(--ease); }
.modal-card h2 { margin: 0 0 6px; font-size: 19px; font-weight: 600; letter-spacing: -.01em; }
.modal-card p { margin: 0 0 20px; }
.modal-acts { display: flex; justify-content: flex-end; gap: 8px; }
@keyframes pop { from { transform: translateY(6px) scale(.98); opacity: 0; } }
.preview { place-items: start center; overflow: auto; background: #3a3b3a; padding: 0; }
.pv-bar { position: sticky; top: 0; z-index: 2; width: 100%; display: flex; align-items: center; gap: 12px; padding: 10px 20px; background: var(--bg); border-bottom: 1px solid var(--line); }
.pv-bar .grow { flex: 1; }
.pv-pages { display: flex; flex-direction: column; align-items: center; gap: 22px; padding: 28px 16px 60px; }
.pv-page { position: relative; background: #fff; box-shadow: 0 10px 30px rgba(0, 0, 0, .35); overflow: hidden; }
.pv-inner { transform-origin: 0 0; }
.pv-clip { overflow: hidden; position: relative; }
.pv-no { position: absolute; right: 10px; bottom: 6px; font: 500 11px var(--mono); color: #9a9a9a; }
.pv-measure { position: absolute; left: -99999px; top: 0; }
.print-body h1 { font-size: 24px; font-weight: 600; letter-spacing: -.02em; margin: 0 0 10px; }
.print-body .editor { min-height: 0; }
.print-body .sheet { overflow: visible; }
.print-body .sheet thead, .print-body .sheet tbody th { display: none; }
.print-body .sheet .cell { min-height: 0; padding: 4px 8px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60; background: var(--ink); color: #fff; padding: 11px 16px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow); animation: pop .2s var(--ease); max-width: calc(100% - 32px); }
.toast[hidden] { display: none; }
#printArea { display: none; }

/* ---------- màn hình hẹp ---------- */
@media (max-width: 1500px) {
  .acts .btn.ghost span { display: none; }
  .acts .btn.ghost { padding: 0 11px; }
}
@media (max-width: 1180px) {
  .acts .btn span { display: none; }
  .acts .btn { padding: 0 11px; }
}
@media (max-width: 860px) {
  :root { --top: 56px; }
  .top { gap: 10px; padding: 0 12px; }
  .brand span { display: none; }
  .tabs a { padding: 0 10px; }
  .save-state { font-size: 12px; max-width: 30vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .shell { grid-template-columns: 1fr; }
  .side { border-right: 0; }
  body.has-doc .side { display: none; }
  body:not(.has-doc) .work { display: none; }
  .back { display: inline-flex; }
  .docbar { padding: 8px 12px; gap: 6px 8px; }
  .acts { margin-left: 0; width: 100%; }
  .acts .btn span { display: none; }
  .acts .btn { min-width: 44px; min-height: 44px; }
  .fmt .ic, .fmt .tool { min-width: 44px; height: 44px; }
  .back { min-height: 44px; }
  .brand { min-width: 44px; min-height: 44px; justify-content: center; }
  .skip { padding: 13px 16px; }
  .fmt .tool span { display: none; }
  .paper-scroll { padding: 12px 8px 40px; }
  .paper { padding: 16px; min-height: 60vh; }
  .title { font-size: 22px; }
  .editor { min-height: 40vh; }
  .sheet-help { display: none; }
  .item { padding: 14px 12px; }
  .side-head .btn { min-height: 44px; }
}

/* ---------- in: A4 ngang ---------- */
@page { size: A4 landscape; margin: 12mm; }
@media print {
  body { background: #fff; }
  body > *:not(#printArea) { display: none !important; }
  #printArea { display: block !important; }
  .print-body { font-size: 15px; line-height: 1.6; color: #000; }
  .print-body img { break-inside: avoid; }
  .print-body .sheet table { break-inside: auto; }
  .print-body tr { break-inside: avoid; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
