:root {
  --ink: #271F2F;
  --blue: #3055BF;
  --cream: #FFFDE9;
  --muted: #6b6472;
  --line: #e7e3ea;
  --bg: #f6f5f3;
  --card: #ffffff;
  --radius: 10px;
  --sans: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --mono: 'DM Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: var(--sans); color: var(--ink); background: var(--bg); }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }

/* ---- topbar ---- */
.topbar { display: flex; justify-content: space-between; align-items: center;
  padding: 12px 24px; background: var(--ink); color: #fff; }
.brand { color: #fff; font-weight: 700; letter-spacing: .3px; }
.brand span { color: var(--cream); font-weight: 500; }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.whoami { font-family: var(--mono); font-size: 12px; color: var(--cream); }
.topbar .btn-ghost { color: #fff; border-color: rgba(255,255,255,.35); }

.page { max-width: 1920px; margin: 0 auto; padding: 24px 20px; }

/* ---- buttons ---- */
button, .btn-ghost, .btn-primary { font-family: var(--sans); cursor: pointer; }
.btn-primary { background: var(--blue); color: #fff; border: 1px solid var(--blue);
  padding: 8px 14px; border-radius: 8px; font-weight: 600; font-size: 14px; text-decoration: none; }
.btn-primary:hover { filter: brightness(1.06); text-decoration: none; }
.btn-ghost { background: transparent; border: 1px solid var(--line); color: var(--ink);
  padding: 7px 12px; border-radius: 8px; font-size: 14px; }
.btn-ghost:hover { border-color: var(--blue); text-decoration: none; }
.btn-tiny { background: transparent; border: 1px solid var(--line); border-radius: 6px;
  padding: 3px 8px; font-size: 12px; color: var(--muted); margin-top: 4px; }
.btn-tiny:hover { border-color: var(--blue); color: var(--blue); }

/* ---- login ---- */
.login-wrap { min-height: 80vh; display: flex; align-items: center; justify-content: center; }
.login-card { background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 32px; width: 340px; display: flex; flex-direction: column; gap: 14px; box-shadow: 0 8px 30px rgba(39,31,47,.06); }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.login-card input { padding: 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 15px; }
.login-error { background: #fdecec; color: #b3261e; padding: 8px 10px; border-radius: 8px; font-size: 13px; }

/* ---- dashboard ---- */
.dash-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.dash-head h1 { font-size: 24px; margin: 0; }
.search { padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; width: 320px; font-size: 14px; }
.chips { display: flex; gap: 8px; margin: 18px 0; flex-wrap: wrap; }
.chip { --chip: var(--muted); background: #fff; border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 14px; font-size: 13px; color: var(--ink); }
.chip span { color: var(--muted); font-family: var(--mono); font-size: 12px; margin-left: 4px; }
.chip.active { border-color: var(--chip); box-shadow: inset 0 0 0 1px var(--chip); color: var(--chip); font-weight: 600; }
.chip.active span { color: var(--chip); }

.grid { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.grid th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); padding: 12px 14px; border-bottom: 1px solid var(--line); background: #faf9f8; }
.grid td { padding: 13px 14px; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: top; }
.row { cursor: pointer; }
.row:hover { background: #fbfaf9; }
.t-title { font-weight: 600; max-width: 560px; }
.pill { --pill: #888; display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px;
  font-weight: 600; color: var(--pill); background: color-mix(in srgb, var(--pill) 12%, #fff); white-space: nowrap; }
.cbadge { display: inline-block; min-width: 20px; text-align: center; padding: 2px 7px; border-radius: 999px;
  background: var(--blue); color: #fff; font-size: 12px; font-weight: 600; }
.tag-edited { display: inline-block; margin-left: 8px; font-size: 11px; font-weight: 600; color: #B0741C;
  background: #fbf0dc; padding: 1px 7px; border-radius: 6px; vertical-align: middle; }
.empty { text-align: center; color: var(--muted); padding: 40px; }

/* ---- editor ---- */
.ed-head { border-bottom: 1px solid var(--line); padding-bottom: 14px; margin-bottom: 18px; }
.back { font-size: 13px; }
.ed-title { font-size: 26px; margin: 8px 0 12px; line-height: 1.2; }
.ed-title[contenteditable] { border-radius: 6px; padding: 2px 6px; margin-left: -6px; transition: background .12s, box-shadow .12s; }
.ed-title[contenteditable]:hover { background: #fbfbf6; }
.ed-title[contenteditable]:focus { outline: none; background: #fffdf0; box-shadow: 0 0 0 2px #ece4bf; }
.ed-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.status-select { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.status-select select { padding: 7px 8px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; color: var(--ink); }
.saved-flag { font-family: var(--mono); font-size: 12px; color: #2E7D46; min-width: 60px; }
.ed-meta { margin-top: 10px; font-size: 13px; display: flex; gap: 8px; align-items: center; }

.ed-body { display: grid; grid-template-columns: minmax(0,1fr) 500px; gap: 28px; align-items: start; }
.doc-pane { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: clamp(20px,3vw,40px); min-width: 0; }
.doc { max-width: 760px; margin: 0 auto; }
.doc p { font-size: 17px; line-height: 1.65; }
.doc h3 { font-size: 26px; margin: 36px 0 10px; }
.doc h4 { font-size: 20px; margin: 26px 0 8px; }

/* editable affordances */
[data-avt-id] { position: relative; border-radius: 4px; transition: background .12s, box-shadow .12s; }
[data-avt-id]:hover { background: #fbfbf6; }
[data-avt-id]:focus { outline: none; background: #fffdf0; box-shadow: 0 0 0 2px #ece4bf; }
[data-avt-id].dirty { box-shadow: inset 3px 0 0 #B0741C; }
[data-avt-id].avt-has-comment { box-shadow: inset 3px 0 0 var(--blue); }
/* Count badge via pseudo-element so it never contaminates the block's innerHTML. */
[data-avt-id][data-cmts]:not([data-cmts="0"])::after {
  content: attr(data-cmts); position: absolute; top: -6px; right: -32px;
  background: var(--blue); color: #fff; font-size: 10px; font-weight: 700; border-radius: 999px; padding: 1px 6px;
}
/* Shared floating comment button (lives on <body>, not inside any block). */
#cmtFloat { position: absolute; z-index: 40; width: 26px; height: 26px; border: 1px solid var(--line);
  background: #fff; border-radius: 7px; font-size: 13px; line-height: 1; display: none;
  align-items: center; justify-content: center; box-shadow: 0 2px 8px rgba(39,31,47,.12); }
#cmtFloat.show { display: flex; }

.avt-thread { border: 1px solid var(--line); background: #faf9f8; border-radius: 8px; padding: 12px; margin: 10px 0 18px; }
.avt-thread .c { border-bottom: 1px solid var(--line); padding: 6px 0; font-size: 14px; }
.avt-thread .c:last-of-type { border-bottom: none; }
.avt-thread .c.resolved { opacity: .5; }
.c-meta { font-size: 11px; color: var(--muted); font-family: var(--mono); margin-bottom: 2px; }
.c-actions { margin-top: 4px; }
.avt-thread textarea, .comment-form textarea { width: 100%; border: 1px solid var(--line); border-radius: 8px;
  padding: 8px; font: inherit; font-size: 14px; resize: vertical; }

/* sidebar */
.side { position: sticky; top: 16px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.side-tabs { display: flex; border-bottom: 1px solid var(--line); }
.tab { flex: 1; background: #faf9f8; border: none; padding: 12px; font-size: 13px; font-weight: 600; color: var(--muted); }
.tab.active { background: #fff; color: var(--ink); box-shadow: inset 0 -2px 0 var(--blue); }
.tab span { display: inline-block; min-width: 18px; padding: 0 5px; background: var(--blue); color: #fff;
  border-radius: 999px; font-size: 11px; margin-left: 4px; }
.tab-panel { padding: 14px; }
.side-note { font-size: 12px; color: var(--muted); margin-bottom: 12px; line-height: 1.5; }
.comment-form { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.history { list-style: none; margin: 0; padding: 0; }
.history li { padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.h-main { font-weight: 600; }
.a-cmt { border-bottom: 1px solid var(--line); padding: 8px 0; font-size: 14px; }
.a-cmt:last-child { border-bottom: none; }

/* changes tab + inline redline */
.changes { list-style: none; margin: 0; padding: 0; }
.changes li { padding: 10px 0; border-bottom: 1px solid var(--line); }
.changes li:last-child { border-bottom: none; }
.changes li[data-jump] { cursor: pointer; border-radius: 6px; }
.changes li[data-jump]:hover { background: #fbfaf9; }
.changes .diff { font-size: 14px; line-height: 1.55; margin-top: 4px; }
.avt-changes del, .redline-block del { background: #fde2e1; color: #a3231b; text-decoration: line-through; border-radius: 3px; padding: 0 2px; }
.avt-changes ins, .redline-block ins { background: #d8f5e0; color: #1c6b34; text-decoration: none; border-radius: 3px; padding: 0 2px; }
#redlineToggle.active { border-color: var(--blue); color: var(--blue); font-weight: 600; }
.doc.redline-mode [data-avt-id] { cursor: default; }
.doc.redline-mode [data-avt-id]:hover { background: transparent; }
.flash { animation: avt-flash 1.2s ease; }
@keyframes avt-flash { 0%, 100% { background: transparent; } 20% { background: #fff3c4; } }

@media (max-width: 900px) {
  .ed-body { grid-template-columns: 1fr; }
  .cmt-btn, .cmt-count { right: 2px; }
}
