:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --ink: #1f2328;
  --navy: #1e2460;
  --muted: #646b75;
  --line: #dde1e6;
  --accent: #1e2460;
  --accent-ink: #ffffff;
  --accent-soft: #e3f4fd;
  --danger: #c4314b;
  --radius: 8px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 2px 8px rgb(0 0 0 / 0.06);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); font-size: 14px; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
[hidden] { display: none !important; }

.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 6px; padding: 6px 12px; cursor: pointer; white-space: nowrap; }
a.btn { color: var(--ink); text-decoration: none; display: inline-block; }
.btn:hover { background: #f6f7f9; }
a.btn.how-to { background: #0277bd; border-color: #0277bd; color: #fff; font-weight: 600; white-space: nowrap; }
a.btn.how-to:hover { background: #01609a; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.link { border: 0; background: none; padding: 4px 6px; color: var(--muted); }
.input { border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px; background: var(--surface); width: 100%; }
.input:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.brand { display: flex; align-items: center; gap: 8px; font-family: Georgia, 'Times New Roman', serif; font-weight: 700; font-size: 18px; color: var(--navy); text-decoration: none; }
.brand .logo { width: 32px; height: 32px; object-fit: contain; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth .card { width: min(380px, 100%); background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); padding: 28px; }
.auth-logo { display: block; width: 200px; max-width: 100%; height: auto; margin: 0 auto; }
.auth h1 { font-size: 20px; margin: 18px 0 4px; }
.auth p { color: var(--muted); margin: 0 0 18px; }
.auth label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 4px; }
.auth .btn.primary { width: 100%; margin-top: 18px; padding: 9px; }
.auth .switch { margin-top: 14px; text-align: center; color: var(--muted); }
.error { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 10px; }

/* ---------- library ---------- */
.appbar { display: flex; align-items: center; gap: 16px; padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.appbar .search { flex: 1; max-width: 520px; }
.appbar .me { margin-left: auto; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.library { max-width: 1040px; margin: 0 auto; padding: 24px 16px; }
.library .head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.library h2 { margin: 0; font-size: 18px; flex: 1; }
.tabs { display: flex; gap: 2px; background: #e8eaee; border-radius: 7px; padding: 2px; }
.tabs button { border: 0; background: none; padding: 5px 12px; border-radius: 5px; cursor: pointer; color: var(--muted); }
.tabs button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.doclist { background: var(--surface); border-radius: 10px; box-shadow: var(--shadow); overflow: hidden; }
.docrow { display: grid; grid-template-columns: 1fr 140px 110px 120px auto; gap: 12px; align-items: center; padding: 10px 16px; border-top: 1px solid var(--line); }
.docrow:first-child { border-top: 0; }
.docrow.header { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; background: #fafbfc; }
.docrow .title { display: flex; align-items: center; gap: 10px; min-width: 0; color: var(--ink); text-decoration: none; font-weight: 550; }
.docrow .title span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.docrow .icon { width: 22px; height: 28px; border-radius: 3px; background: var(--accent-soft); border: 1px solid #c9d6f5; flex: none; }
.docrow .muted { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.docrow .actions { display: flex; gap: 2px; }
.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: #eef0f3; color: var(--muted); }
.empty { padding: 48px 16px; text-align: center; color: var(--muted); }
@media (max-width: 720px) {
  .docrow { grid-template-columns: 1fr auto; }
  .docrow > :nth-child(2), .docrow > :nth-child(3), .docrow > :nth-child(4) { display: none; }
  .appbar { padding: 10px 16px; gap: 10px; }
  .appbar .me .name { display: none; }
}

/* ---------- editor chrome ---------- */
/* Equal side columns keep the document's name in the center of the page. */
.docbar { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, min(520px, calc(100vw - 1040px))) minmax(0, 1fr); align-items: center; gap: 8px 12px; padding: 8px 16px; background: var(--surface); }
.doc-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.back-to-docs { white-space: nowrap; }
.docbar .title-input { border: 1px solid transparent; border-radius: 5px; padding: 4px 8px; font-size: 18px; font-weight: 600; width: 100%; min-width: 0; text-align: center; text-overflow: ellipsis; background: none; }
.docbar .status { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.doc-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; }
.file-menu { position: relative; }
.file-menu summary { list-style: none; white-space: nowrap; }
.file-menu summary::-webkit-details-marker { display: none; }
.file-items { position: absolute; right: 0; top: calc(100% + 4px); z-index: 30; min-width: 170px; padding: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.file-items .btn { display: block; width: 100%; border: 0; text-align: left; }
/* Below this width the buttons don't fit beside a centered name, so they take their own row. */
@media (max-width: 1240px) {
  .docbar { grid-template-columns: minmax(0, 1fr) minmax(0, 420px) minmax(0, 1fr); }
  .doc-actions { grid-column: 1 / -1; }
}
@media (max-width: 640px) {
  .docbar { grid-template-columns: minmax(0, 1fr); }
  .doc-actions { grid-column: auto; }
}
.docbar .title-input:hover:not([readonly]) { border-color: var(--line); }
.docbar .title-input:focus { border-color: var(--accent); outline: none; }
.status { color: var(--muted); font-size: 13px; white-space: nowrap; }
.status.saved { color: #1a7f37; font-weight: 600; }
.status.offline { color: var(--danger); }
.avatars { display: flex; }
.avatar { width: 28px; height: 28px; border-radius: 50%; color: #fff; display: grid; place-items: center; font-size: 12px; font-weight: 600; border: 2px solid var(--surface); margin-left: -6px; }
.toolbar { display: flex; align-items: center; gap: 2px; padding: 5px 12px; background: var(--surface); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); flex-wrap: wrap; position: sticky; top: 0; z-index: 4; }
.toolbar .sep { width: 1px; height: 26px; background: var(--line); margin: 0 6px; }
.toolbar button { border: 0; background: none; min-width: 38px; height: 38px; border-radius: 6px; cursor: pointer; display: grid; place-items: center; padding: 0 7px; color: #3a4048; font-size: 18px; }
.toolbar button:hover { background: #eef0f3; }
.toolbar button.on { background: var(--accent-soft); color: var(--accent); }
.toolbar select { border: 1px solid transparent; border-radius: 6px; height: 38px; background: none; padding: 0 4px; cursor: pointer; font-size: 15px; }
.toolbar select:hover { border-color: var(--line); }
.toolbar .color { position: relative; display: grid; place-items: center; min-width: 38px; height: 38px; border-radius: 6px; cursor: pointer; color: #3a4048; }
.toolbar .color:hover { background: #eef0f3; }
.toolbar .color input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
.toolbar button.add-comment { display: flex; align-items: center; gap: 6px; background: #be172d; color: #fff; font-size: 15px; font-weight: 600; padding: 0 12px; margin: 0 2px; }
.toolbar button.add-comment:hover { background: #9c1125; }
.toolbar button.add-comment:focus-visible { outline: 2px solid #1e2460; outline-offset: 2px; }
.toolbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.toolbar.readonly > :not(.always) { opacity: .4; pointer-events: none; }

.workspace { display: flex; align-items: flex-start; }
.canvas { flex: 1; overflow: auto; padding: 24px 16px 80px; min-width: 0; }
#overlay { position: absolute; inset: 0; pointer-events: none; }
.rcaret { position: absolute; width: 2px; }
.rcaret .flag { position: absolute; bottom: 100%; left: -1px; color: #fff; font: 600 11px/1 system-ui, sans-serif; padding: 3px 5px; border-radius: 3px 3px 3px 0; white-space: nowrap; }
.rsel { position: absolute; opacity: .22; }

/* ---------- document content ---------- */
.ed { outline: none; white-space: pre-wrap; overflow-wrap: break-word; font-family: var(--doc-font, Calibri, Carlito, 'Segoe UI', sans-serif); font-size: var(--doc-size, 11pt); line-height: var(--doc-line, 1.5); color: #111; caret-color: #111; }
.ed p, .ed h1, .ed h2, .ed h3 { margin: 0 0 var(--doc-after, 0.35em); position: relative; }
.ed h1 { font-size: 20pt; margin: 0.6em 0 0.3em; font-weight: 650; }
.ed h2 { font-size: 16pt; margin: 0.6em 0 0.25em; font-weight: 650; }
.ed h3 { font-size: 13pt; margin: 0.5em 0 0.2em; font-weight: 650; color: #333; }
.ed .plain { font-size: inherit; font-weight: 400; color: inherit; margin: 0 0 var(--doc-after, 0.35em); }
.ed .li { padding-left: 0.3in; margin-bottom: 0.1em; }
.ed .li::before { content: attr(data-marker); position: absolute; left: 0.05in; width: 0.25in; text-align: left; }
.ed .bold { font-weight: 700; }
.ed .italic { font-style: italic; }
.ed .underline { text-decoration: underline; }
.ed .strike { text-decoration: line-through; }
.ed .caps { text-transform: uppercase; }
.ed .underline.strike { text-decoration: underline line-through; }
.ed a { color: #1155cc; text-decoration: underline; cursor: text; }
.ed[contenteditable="false"] { caret-color: transparent; }
.ed .ins { color: var(--rc); text-decoration: underline; text-decoration-color: var(--rc); }
.ed .del { color: var(--rc); text-decoration: line-through; text-decoration-color: var(--rc); opacity: .75; }
.ed .fmt { border-bottom: 2px dotted var(--rc); }
.ed .cmt { background: #fff1b8; border-bottom: 2px solid #f5c400; cursor: pointer; }
.ed .cmt.active { background: #ffd84d; }
.ed .ins.underline, .ed .del.underline { text-decoration-line: underline; }

/* ---------- review ---------- */
.mode { font-weight: 550; }
.mode.suggesting { color: #2f9e44; }
.count { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 6px; border-radius: 99px; background: var(--accent); color: #fff; font-size: 11px; line-height: 18px; text-align: center; }
.thread { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; cursor: pointer; background: var(--surface); }
.thread.active { border-color: #f5c400; box-shadow: 0 0 0 2px #fff1b8; }
.thread.resolved { opacity: .75; }
.thread .quote { border-left: 3px solid #f5c400; padding-left: 8px; color: var(--muted); font-size: 12px; margin-bottom: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread .quote.gone { border-color: var(--line); font-style: italic; }
.msg { margin-bottom: 8px; }
.msg .by { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.msg .by strong { color: var(--ink); }
.msg .body { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 2px; }
.mention { color: var(--accent); font-weight: 600; }
.composer { position: relative; margin-top: 6px; }
.composer textarea { width: 100%; min-height: 56px; resize: vertical; border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; font: inherit; }
.composer textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.composer .actions { display: flex; gap: 6px; justify-content: flex-end; margin-top: 6px; }
.change .composer { grid-column: 2; }
.change .composer textarea { min-height: 38px; }
.change-thread { grid-column: 2; font-size: 12px; background: var(--bg); border-radius: 6px; padding: 6px 8px; cursor: pointer; overflow-wrap: anywhere; }
.change-thread strong { font-weight: 600; }
.suggest-list { position: absolute; left: 0; right: 0; top: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; box-shadow: var(--shadow); z-index: 5; max-height: 180px; overflow: auto; }
.suggest-list button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 6px 10px; cursor: pointer; }
.suggest-list button:hover, .suggest-list button.on { background: var(--accent-soft); }
.change { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; padding: 10px 0; border-top: 1px solid var(--line); cursor: pointer; }
.change .kind { font-weight: 600; }
.change .kind .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.change .excerpt { grid-column: 2; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.change .excerpt.del { text-decoration: line-through; }
.change .meta { grid-column: 2; color: var(--muted); font-size: 12px; }
.change .row { grid-column: 2; margin: 4px 0 0; }
.bulk { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.bell { position: relative; }
.bell .count { position: absolute; top: -6px; right: -6px; margin: 0; }
.notes { position: absolute; right: 0; top: calc(100% + 6px); width: min(340px, calc(100vw - 32px)); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); z-index: 30; max-height: 420px; overflow: auto; }
.notes a { display: block; padding: 10px 14px; border-top: 1px solid var(--line); color: var(--ink); text-decoration: none; }
.notes a:first-child { border-top: 0; }
.notes a.unread { background: #f4f7ff; }
.notes a small { display: block; color: var(--muted); margin-top: 2px; }
.notes .empty { padding: 20px; }

/* ---------- side panel ---------- */
.panel { width: 340px; flex: none; background: var(--surface); border-left: 1px solid var(--line); align-self: stretch; min-height: calc(100vh - 100px); padding: 16px; position: sticky; top: 42px; max-height: calc(100vh - 42px); overflow: auto; }
.panel h3 { margin: 0 0 12px; font-size: 15px; display: flex; align-items: center; justify-content: space-between; }
.panel .row { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; }
.panel .member { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.panel .member .who { flex: 1; min-width: 0; }
.panel .member .who div:last-child { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
.panel select { border: 1px solid var(--line); border-radius: 6px; padding: 5px; background: var(--surface); }
.panel .version { padding: 10px 0; border-top: 1px solid var(--line); }
.panel .version .meta { color: var(--muted); font-size: 12px; margin: 2px 0 6px; }
.panel .hint { color: var(--muted); font-size: 12px; margin: 6px 0 12px; }
.panel label.check { display: flex; gap: 6px; align-items: center; color: var(--muted); font-size: 13px; margin-bottom: 10px; }
@media (max-width: 860px) { .panel { position: fixed; inset: auto 0 0 0; width: auto; max-height: 60vh; min-height: 0; border-left: 0; border-top: 1px solid var(--line); z-index: 10; box-shadow: 0 -4px 20px rgb(0 0 0 / .12); } }

.modal { position: fixed; inset: 0; background: rgb(20 24 30 / .5); z-index: 20; overflow: auto; padding: 24px 16px; }
.modal .bar { max-width: 8.5in; margin: 0 auto 12px; display: flex; gap: 8px; align-items: center; color: #fff; }
.modal .bar strong { flex: 1; }
.blocker { position: fixed; inset: 0; background: rgb(255 255 255 / .85); display: grid; place-items: center; z-index: 30; text-align: center; padding: 16px; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: #1f2328; color: #fff; padding: 10px 16px; border-radius: 8px; opacity: 0; transition: .2s; pointer-events: none; z-index: 40; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media print {
  body { background: #fff; }
  .docbar, .toolbar, .panel, #overlay, #toast { display: none !important; }
  .canvas { padding: 0; overflow: visible; }
  .ed .cmt { background: none; border: 0; }
  @page { size: letter; margin: 1in; }
}
