:root {
  --accent: #3f5a87; --accent-dark: #34496e; --accent-light: #e7ecf3; --accent-border: #b5c1d4;
  --ink: #2b2f36; --muted: #6b717c; --line: #dee1e6; --bg: #e5e7eb; --panel: #fcfcfd; --hover: #eef1f5;
  --paper: #ffffff; color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --accent: #8fa7d1; --accent-dark: #1f2a3d; --accent-light: #2a3446; --accent-border: #46536b;
    --ink: #e6e8ec; --muted: #a2a8b3; --line: #353a44; --bg: #16181d; --panel: #1d2026; --hover: #262a32; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --accent: #8fa7d1; --accent-dark: #1f2a3d; --accent-light: #2a3446; --accent-border: #46536b;
  --ink: #e6e8ec; --muted: #a2a8b3; --line: #353a44; --bg: #16181d; --panel: #1d2026; --hover: #262a32; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 13px/1.4 "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif; color: var(--ink); background: var(--bg); display: flex; flex-direction: column; overflow: hidden; }
button, select, input { font: inherit; color: inherit; }
svg { display: block; }

/* ---------- title strip with tabs ---------- */
.strip { background: var(--accent-dark); color: #fff; display: flex; align-items: center; gap: 6px; padding: 0 10px; height: 48px; flex: none; }
.logo { display: grid; place-items: center; width: 32px; height: 32px; flex: none; }
.logo img { width: 26px; height: 26px; border-radius: 6px; }
.strip .pill { background: rgba(255,255,255,.18); border: 0; color: #fff; border-radius: 8px; padding: 6px 14px; cursor: pointer; flex: none; }
.strip .pill:hover { background: rgba(255,255,255,.28); }
.strip .icon-btn { background: transparent; border: 0; color: #fff; width: 32px; height: 32px; border-radius: 8px; cursor: pointer; display: grid; place-items: center; flex: none; }
.strip .icon-btn:hover { background: rgba(255,255,255,.16); }
.strip .icon-btn svg { width: 18px; height: 18px; }
.tabs { display: flex; align-self: flex-end; gap: 2px; margin-left: 8px; overflow-x: auto; scrollbar-width: none; flex: none; }
.tabs button { border: 0; background: transparent; color: #dfe6f1; padding: 8px 16px 9px; border-radius: 8px 8px 0 0; cursor: pointer; white-space: nowrap; font-size: 13px; }
.tabs button:hover { background: rgba(255,255,255,.1); }
.tabs button.on { background: var(--panel); color: var(--accent); font-weight: 600; }
.docname { flex: 1 1 120px; min-width: 60px; background: transparent; border: 1px solid transparent; color: #fff; border-radius: 6px; padding: 4px 8px; text-align: center; }
.docname:hover, .docname:focus { border-color: rgba(255,255,255,.35); outline: none; background: rgba(255,255,255,.08); }
.strip select { background: rgba(255,255,255,.14); color: #fff; border: 0; border-radius: 8px; padding: 5px 6px; max-width: 120px; flex: none; }
.strip select option { color: #000; }
.get-app { color: #fff; text-decoration: none; background: #ffffff26; border-radius: 8px; padding: 6px 12px; white-space: nowrap; flex: none; }
.get-app:hover { background: #fff4; }

/* ---------- ribbon ---------- */
.ribbon { background: var(--panel); border-bottom: 1px solid var(--line); display: flex; align-items: stretch; gap: 0; padding: 6px 6px 2px; overflow-x: auto; scrollbar-width: thin; flex: none; min-height: 96px; }
.group { display: flex; flex-direction: column; padding: 0 8px; border-right: 1px solid var(--line); flex: none; }
.group:last-child { border-right: 0; }
.group .body { display: flex; align-items: flex-start; gap: 2px; flex: 1; }
.group .label { text-align: center; color: var(--muted); font-size: 11px; padding: 3px 0 1px; white-space: nowrap; }
.col { display: flex; flex-direction: column; gap: 2px; }
.row { display: flex; align-items: center; gap: 2px; }
.tb { min-width: 28px; height: 28px; border: 1px solid transparent; background: transparent; border-radius: 6px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 4px; padding: 0 4px; position: relative; color: var(--ink); white-space: nowrap; }
.tb:hover { background: var(--hover); }
.tb.on { background: var(--accent-light); border-color: var(--accent-border); }
.tb svg { width: 18px; height: 18px; flex: none; }
.tb .swatch { position: absolute; left: 6px; right: 6px; bottom: 3px; height: 3px; border-radius: 2px; }
.tb.big { flex-direction: column; height: 66px; min-width: 54px; padding: 4px 6px; gap: 3px; font-size: 12px; }
.tb.big svg { width: 26px; height: 26px; }
.tb.text { padding: 0 8px; }
.tb .caret { font-size: 9px; color: var(--muted); }
.ribbon select { height: 28px; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); padding: 0 4px; color: var(--ink); }
.ribbon select.font { width: 150px; }
.ribbon select.size { width: 58px; }
.ribbon input[type=color] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; border: 0; padding: 0; }
.styles { display: flex; gap: 4px; }
.style-card { width: 76px; height: 54px; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 2px; color: #222; }
.style-card:hover { border-color: var(--accent-border); }
.style-card.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.style-card .s { font-size: 14px; line-height: 1.1; max-width: 70px; overflow: hidden; white-space: nowrap; }
.style-card .n { font-size: 10.5px; color: #666; max-width: 70px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- document ---------- */
.workspace { flex: 1; overflow: auto; padding: 24px 12px 80px; position: relative; }
.zoomer { transform-origin: top center; width: max-content; min-width: 100%; }
.sheet { position: relative; margin: 0 auto; background: var(--paper); box-shadow: 0 1px 3px rgba(0,0,0,.1), 0 8px 26px rgba(0,0,0,.09); color: #000; --pw: 595.3pt; --ph: 841.9pt; --mt: 56.7pt; --mb: 56.7pt; --ml: 85pt; --mr: 42.5pt; width: var(--pw); min-height: var(--ph); }
.page { outline: none; padding: 0 var(--mr) 0 var(--ml); min-height: calc(var(--ph) - var(--mt) - var(--mb)); font-family: Calibri, Carlito, "Segoe UI", Arial, sans-serif; font-size: 11pt; line-height: 1.15; word-wrap: break-word; white-space: pre-wrap; tab-size: 36pt; -moz-tab-size: 36pt; position: relative; z-index: 1; }
.hf { padding: 0 var(--mr) 0 var(--ml); outline: none; font-family: Calibri, Carlito, "Segoe UI", Arial, sans-serif; font-size: 11pt; color: #444; white-space: pre-wrap; position: relative; z-index: 1; min-height: var(--mt); padding-top: 22pt; }
.hf.footer { min-height: var(--mb); padding-top: 8pt; padding-bottom: 18pt; }
.hf:empty::before, .hf.blank::before { content: attr(data-ph); color: #b4b9c2; font-size: 10pt; }
.hf:not(:focus):empty { opacity: .0; }
.sheet:hover .hf:empty, .hf:focus:empty { opacity: 1; }
.hf:focus { background: #f6f8fb; box-shadow: inset 0 -1px 0 #c9d2e0; }
.page:empty::before { content: attr(data-placeholder); color: #9aa0a8; }
.page p, .page h1, .page h2, .page h3, .page h4, .page h5, .page h6, .hf p { margin: 0; }
.page h1, .page h2, .page h3, .page h4, .page h5, .page h6 { font-weight: 400; }
.page h1:not([style]) { font-size: 20pt; color: #233355; margin: 12pt 0 4pt; font-weight: 600; }
.page h2:not([style]) { font-size: 15pt; color: #34496e; margin: 10pt 0 3pt; font-weight: 600; }
.page h3:not([style]) { font-size: 13pt; color: #3f5a87; margin: 8pt 0 3pt; font-weight: 600; }
.page p:not([style]) { margin: 0 0 6pt; }
.page .title:not([style]) { font-size: 28pt; color: #233355; font-weight: 400; }
.page blockquote { margin: 6pt 0; padding: 2pt 0 2pt 12pt; border-left: 3px solid #c7cdd6; color: #4a4f58; }
.page pre { font-family: Consolas, "Courier New", monospace; font-size: 10pt; background: #f4f5f7; padding: 8pt; border-radius: 4px; }
.page table { border-collapse: collapse; margin: 0; }
.page table:not([style]) { width: 100%; margin: 4pt 0; }
.page td, .page th { vertical-align: top; min-width: 18px; }
.page table:not([style]) td, .page table:not([style]) th { border: 0.75pt solid #000; padding: 0 5.4pt; }
.page img { max-width: 100%; }
.page img.selected { outline: 2px solid var(--accent); }
.page a { color: #0563c1; }
.page .mk { display: inline-block; text-indent: 0; user-select: none; }
.page sup.fn { color: #0563c1; }
.page .note { font-size: 9pt; }
.page .notes-rule { border: 0; border-top: 1px solid #999; width: 30%; margin: 18pt 0 6pt; }
.page hr:not(.page-break):not(.notes-rule) { border: 0; border-top: 1px solid #b8bec8; margin: 8pt 0; }
.page hr.page-break { border: 0; height: 0; margin: 0; break-after: page; position: relative; }
.page hr.page-break::after { content: attr(data-label); display: block; border-top: 1px dashed #b5bccb; text-align: center; color: #9aa0a8; font: 10px "Segoe UI", sans-serif; margin: 6pt -4pt; line-height: 0; }
.page ul, .page ol { margin: 0 0 4pt; padding-left: 24pt; }
.page .textbox { display: inline-block; border: 1px dashed #c8ced8; padding: 2pt 4pt; }
mark.find-hit { background: #ffd54f; color: inherit; }
mark.find-hit.cur { background: #ff9800; }
.breaks { position: absolute; inset: 0; pointer-events: none; z-index: 0; }
.breaks .b { position: absolute; left: 0; right: 0; border-top: 1px dashed #c2c8d3; }
.breaks .b span { position: absolute; right: 8px; top: -9px; background: var(--paper); color: #a6acb7; font-size: 10px; padding: 0 4px; }

/* ---------- status ---------- */
.status { background: var(--panel); border-top: 1px solid var(--line); padding: 3px 12px; display: flex; gap: 16px; align-items: center; color: var(--muted); font-size: 12px; flex: none; }
.status .grow { flex: 1; }
.status input[type=range] { width: 110px; }
.zbtn { border: 0; background: transparent; cursor: pointer; font-size: 16px; color: var(--muted); padding: 0 4px; }

/* ---------- menus, dialogs ---------- */
.menu { position: fixed; z-index: 50; background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.18); padding: 6px; min-width: 220px; display: none; max-height: 70vh; overflow: auto; }
.menu.open { display: block; }
.menu button { display: flex; width: 100%; align-items: center; gap: 10px; background: transparent; border: 0; padding: 7px 10px; border-radius: 6px; cursor: pointer; text-align: left; }
.menu button:hover { background: var(--hover); }
.menu button.on::after { content: "✓"; margin-left: auto; color: var(--accent); }
.menu .kbd { margin-left: auto; color: var(--muted); font-size: 12px; }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.menu .grid { display: grid; grid-template-columns: repeat(8, 18px); gap: 3px; padding: 6px; }
.menu .grid i { width: 18px; height: 18px; border: 1px solid var(--line); background: var(--paper); border-radius: 2px; cursor: pointer; }
.menu .grid i.on { background: var(--accent-light); border-color: var(--accent); }
.menu .gridlabel { text-align: center; color: var(--muted); padding: 2px 0 4px; }
.menu .sw { display: grid; grid-template-columns: repeat(8, 20px); gap: 4px; padding: 6px; }
.menu .sw i { width: 20px; height: 20px; border-radius: 3px; cursor: pointer; border: 1px solid rgba(0,0,0,.15); }
.findbar { display: none; position: fixed; right: 18px; top: 150px; z-index: 40; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.16); padding: 10px; gap: 6px; flex-wrap: wrap; width: 330px; }
.findbar.open { display: flex; }
.findbar input { flex: 1 1 100%; border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; background: var(--paper); }
.findbar button { border: 1px solid var(--line); background: var(--paper); border-radius: 6px; padding: 4px 10px; cursor: pointer; }
.findbar .count { color: var(--muted); font-size: 12px; align-self: center; margin-right: auto; }
.toast { position: fixed; left: 50%; bottom: 46px; transform: translateX(-50%); background: #2b2f36; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.25); opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 60; max-width: 90vw; }
.toast.show { opacity: 1; }
.busy { position: fixed; inset: 0; background: rgba(255,255,255,.55); display: none; place-items: center; z-index: 80; }
.busy.show { display: grid; }
.busy > * { grid-area: 1 / 1; }
.busy span { margin-top: 70px; color: var(--accent-dark); font-weight: 600; }
.spinner { width: 36px; height: 36px; border: 4px solid var(--accent-light); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.dropzone { position: fixed; inset: 0; background: rgba(63,90,135,.18); border: 3px dashed var(--accent); display: none; place-items: center; z-index: 70; font-size: 20px; color: var(--accent-dark); font-weight: 600; }
.dropzone.show { display: grid; }
dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--ink); padding: 18px; max-width: 420px; width: 92vw; }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog h3 { margin: 0 0 12px; font-size: 16px; }
dialog label { display: block; margin: 8px 0 4px; color: var(--muted); font-size: 12px; }
dialog input { width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; background: var(--paper); }
dialog .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
dialog .hint { color: var(--muted); font-size: 12px; margin: 8px 0 0; }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
dialog .actions button { border: 1px solid var(--line); background: var(--paper); border-radius: 8px; padding: 7px 14px; cursor: pointer; }
dialog .actions button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---------- small screens ---------- */
@media (max-width: 860px) {
  .get-app, #langSel, .status .hide-sm { display: none; }
  .docname { display: none; }
  .tabs { margin-left: 2px; flex: 1; }
  .tabs button { padding: 8px 10px 9px; }
  .ribbon { min-height: 0; }
  .group .label { display: none; }
  .tb.big { height: 32px; min-width: 32px; flex-direction: row; font-size: 0; padding: 0 4px; }
  .tb.big svg { width: 20px; height: 20px; }
  .styles .style-card { width: 60px; height: 32px; }
  .styles .style-card .n { display: none; }
  .workspace { padding: 8px 0 60px; }
  /* phone: reflow to the screen width (the real page size is kept for .docx export) */
  .zoomer { width: auto !important; min-width: 0; transform: none !important; height: auto !important; }
  .sheet { width: auto !important; min-height: 0 !important; margin: 0 6px; }
  .page, .hf { padding-left: 14px !important; padding-right: 14px !important; }
  .page { min-height: 60vh; overflow-x: auto; }
  .page table { width: 100% !important; margin-left: 0 !important; }
  .page col { width: auto !important; }
  .hf { min-height: 0; padding-top: 10px; }
  .hf.footer { padding-bottom: 12px; }
  .breaks { display: none; }
  .tb.text span { display: none; }
  .group .col { flex-direction: row; }
  .status input[type=range], .zbtn, #zoomLabel { display: none; }
}

@media print {
  @page { margin: 0; }
  body { display: block; overflow: visible; background: #fff; }
  .strip, .ribbon, .status, .findbar, .menu, .toast, .dropzone, .busy, .breaks { display: none !important; }
  .workspace { overflow: visible; padding: 0; }
  .zoomer { transform: none !important; }
  .sheet { box-shadow: none; margin: 0; min-height: 0; }
  .hf:empty { display: none; }
  .page hr.page-break::after { display: none; }
}
