/* Command Center: one sidebar + one main column. Follows the device's light/dark setting. */
:root {
  /* Warm neutrals, always light (even when the device is in dark mode). */
  --bg: #f7f3ec; --surface: #fffdf9; --sunken: #efe9de; --fg: #2b2620; --muted: #756c60; --line: #e0d8ca;
  --accent: #9a5b2e; --accent-fg: #ffffff; --accent-soft: #f1e2d2; --due: #98681a; --due-soft: #f6e9cc;
  --late: #b04a3a; --ok: #4f7a54;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "Roboto Mono", monospace;
  --side-w: 272px; --r: 10px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--fg); font: 15px/1.5 var(--sans); -webkit-text-size-adjust: 100%; }
a { color: var(--accent); }
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.i { width: 18px; height: 18px; flex: none; }
[hidden] { display: none !important; }

.shell { display: grid; grid-template-columns: var(--side-w) 1fr; grid-template-rows: minmax(0, 1fr); height: 100%; }
.shell.side-closed { grid-template-columns: 0 1fr; }
.shell.side-closed .sidebar { visibility: hidden; }

/* ---------- sidebar ---------- */
.sidebar { background: var(--sunken); border-right: 1px solid var(--line); display: flex; flex-direction: column;
  min-width: 0; overflow: hidden; padding-top: env(safe-area-inset-top, 0px); }
.side-top { display: flex; gap: 8px; padding: 12px 10px 6px; }
.btn-new { flex: 1; display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 9px;
  background: var(--surface); border: 1px solid var(--line); color: var(--fg); text-decoration: none; font-weight: 500; }
.side-nav { padding: 2px 10px; display: grid; gap: 1px; }
.side-section-toggle { width: 100%; display: flex; align-items: center; justify-content: space-between; border: 0; background: none; color: inherit; cursor: pointer; padding: 0; text-align: left; }
.side-section-toggle:hover { background: color-mix(in srgb, var(--surface) 55%, transparent); border-radius: 8px; }
.side-section-toggle .sub { flex: 1; }
.tools-chevron { width: 15px; height: 15px; margin-right: 9px; color: var(--muted); transition: transform .15s ease; }
.tool-letter { width: 20px; height: 20px; display: inline-grid; place-items: center; border-radius: 5px; background: #dceef1; color: #1f6675; font-weight: 800; font-size: 12px; flex: 0 0 20px; }
.side-section-toggle[aria-expanded="false"] .tools-chevron { transform: rotate(-90deg); }
.side-scroll { flex: 1; overflow-y: auto; padding: 0 10px 16px; }
.row { display: flex; align-items: center; gap: 9px; padding: 7px 10px; border-radius: 8px; color: var(--fg);
  text-decoration: none; min-width: 0; }
.row:hover { background: color-mix(in srgb, var(--surface) 70%, transparent); }
.row.active { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.row .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kbd { font: 11px var(--mono); color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
.count { font: 500 11px var(--mono); background: var(--due-soft); color: var(--due); border-radius: 99px; padding: 1px 8px; }
.sec { display: flex; justify-content: space-between; align-items: center; padding: 16px 10px 4px; }
.label { font: 500 11px var(--mono); letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
.plus { color: var(--muted); text-decoration: none; font-size: 18px; line-height: 1; padding: 0 4px; }
.sub { font: 10.5px var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 8px 10px 2px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex: none; }
.dot.off { background: transparent; border: 1px solid var(--line); }
.more-links { display: flex; gap: 6px; padding: 4px 10px; font-size: 13px; color: var(--muted); }
.more-links a { text-decoration: none; }
.side-foot { padding: 8px 14px calc(10px + env(safe-area-inset-bottom, 0px)); font-size: 12px; color: var(--muted);
  border-top: 1px solid var(--line); }
.empty-side { color: var(--muted); font-size: 13px; padding: 4px 10px; }

/* ---------- main ---------- */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100%; overflow: hidden; }
.topbar { display: flex; align-items: center; gap: 10px; padding: calc(8px + env(safe-area-inset-top, 0px)) 14px 8px;
  border-bottom: 1px solid var(--line); background: var(--bg); min-height: 52px; }
.topbar-title { flex: 1; min-width: 0; display: flex; align-items: center; white-space: nowrap; overflow-x: auto;
  scrollbar-width: none; }
.topbar-title::-webkit-scrollbar { display: none; }
.breadcrumb-link { color: var(--muted); font-weight: 400; text-decoration: none; border-radius: 5px; padding: 2px 3px;
  max-width: min(34vw, 300px); overflow: hidden; text-overflow: ellipsis; flex: 0 1 auto; }
.breadcrumb-link:hover { color: var(--fg); background: var(--sunken); }
.breadcrumb-link.current { color: var(--fg); font-weight: 600; }
.breadcrumb-sep { color: var(--muted); padding: 0 2px; flex: none; }
.nav-back { flex: none; }
.topbar-actions { display: flex; gap: 6px; }
.icon-btn { background: none; border: 0; padding: 6px; border-radius: 8px; color: var(--muted); cursor: pointer; display: grid; place-items: center; }
.icon-btn:hover { background: var(--sunken); color: var(--fg); }
.view { flex: 1; overflow-y: auto; min-height: 0; }
.wrap { max-width: 860px; margin: 0 auto; padding: 20px 16px 32px; display: grid; gap: 16px; }
h1 { font-size: 24px; margin: 0; line-height: 1.25; }
h2 { font-size: 17px; margin: 0; }
.muted { color: var(--muted); }
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 7px 14px; cursor: pointer; text-decoration: none; color: var(--fg); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.chip { display: inline-flex; gap: 4px; font-size: 12px; border: 1px solid var(--line); border-radius: 6px; padding: 1px 7px; color: var(--muted); background: var(--surface); white-space: nowrap; }
.status { font-size: 12px; border: 1px solid currentColor; border-radius: 99px; padding: 0 9px; color: var(--ok); }
.status.quiet { color: var(--muted); } .status.closed { color: var(--late); }
input.field, textarea.field, select.field { width: 100%; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); padding: 8px 10px; }
.form { display: grid; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }
.form label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }

/* ---------- chat ---------- */
.chat { display: flex; flex-direction: column; height: 100%; }
.thread { flex: 1; overflow-y: auto; }
.thread .wrap { gap: 18px; }
.msg-user { justify-self: end; background: var(--sunken); border-radius: 14px; padding: 9px 14px; max-width: min(78%, 620px); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-ai { max-width: 100%; overflow-wrap: anywhere; }
.msg-ai p { margin: 0 0 10px; } .msg-ai p:last-child { margin-bottom: 0; }
.msg-ai ul, .msg-ai ol { margin: 0 0 10px; padding-left: 22px; }
.msg-ai code { font: 13px var(--mono); background: var(--sunken); border-radius: 4px; padding: 1px 4px; }
.msg-ai pre { background: var(--sunken); border-radius: 8px; padding: 10px; white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; max-width: 100%; box-sizing: border-box; }
.msg-ai pre code { white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; }
.msg-ai table { display: block; max-width: 100%; overflow-x: auto; }
.msg-ai img, .msg-ai video { max-width: 100%; height: auto; }
.thread { overflow-x: hidden; }
.thread .wrap > *, .msg-ai > * { min-width: 0; max-width: 100%; }
.msg-sys { color: var(--late); font-size: 13px; }
.working { color: var(--muted); font-size: 13px; display: flex; gap: 8px; align-items: center; }
.working::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1s infinite alternate; }
@keyframes pulse { from { opacity: .25 } to { opacity: 1 } }
@media (prefers-reduced-motion: reduce) { .working::before { animation: none; } }
.hello { padding: 12vh 16px 0; text-align: center; display: grid; gap: 6px; }
.hello h1 { font-size: 26px; }

.composer-wrap { padding: 8px 16px calc(12px + env(safe-area-inset-bottom, 0px)); }
.composer { max-width: 860px; margin: 0 auto; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); padding: 8px; display: grid; gap: 6px; }
.composer textarea { border: 0; outline: 0; resize: none; background: transparent; padding: 6px 8px; max-height: 40vh; min-height: 24px; line-height: 1.45; }
.composer .bar { display: flex; align-items: center; gap: 6px; }
.composer .bar .spacer { flex: 1; }
.composer .send { width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-fg); display: grid; place-items: center; cursor: pointer; }
.composer .send:disabled { opacity: .4; cursor: default; }
.thorough { border: 1px solid var(--line); background: transparent; color: var(--muted); border-radius: 99px; padding: 3px 11px; font-size: 13px; cursor: pointer; }
.thorough[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); font-weight: 500; }
.actions { list-style: none; margin: 10px 0 0; padding: 8px 10px; display: grid; gap: 3px; border-left: 2px solid var(--ok); background: var(--sunken); border-radius: 0 8px 8px 0; font-size: 13px; color: var(--muted); }
.actions li { display: flex; gap: 6px; align-items: center; }
.i.small { width: 14px; height: 14px; color: var(--ok); }
.pending { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 6px; }
.pending .chip { color: var(--fg); }
.pending .chip button { border: 0; background: none; padding: 0; cursor: pointer; color: var(--muted); }

.filecard { display: inline-flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 9px; padding: 7px 10px; background: var(--surface); max-width: 100%; cursor: pointer; text-align: left; color: var(--fg); }
.filecard .meta { font-size: 12px; color: var(--muted); }
.filecard .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 280px; }
.files-row { display: flex; flex-wrap: wrap; gap: 8px; }
.thumb { max-width: 260px; max-height: 200px; border-radius: 8px; border: 1px solid var(--line); display: block; cursor: zoom-in; }

/* ---------- topic page ---------- */
.topic-head { display: grid; gap: 6px; }
.topic-head .where { font-size: 13px; color: var(--muted); }
.summary { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; display: grid; gap: 8px; }
.summary .md p { margin: 0 0 8px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 12px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tabs button.on { color: var(--fg); border-color: var(--accent); font-weight: 500; }
.tabs .n { font: 11px var(--mono); }
.log-entry { display: grid; grid-template-columns: 88px 1fr; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.log-entry .d { font: 12px var(--mono); color: var(--muted); padding-top: 2px; }
.log-entry .src { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.list { display: grid; }
.list-item { display: flex; align-items: center; gap: 10px; padding: 10px 4px; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--fg); min-width: 0; }
.list-item .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { color: var(--muted); padding: 14px 4px; }

/* ---------- links to topics and people ---------- */
a.mention { color: inherit; text-decoration: underline dotted var(--accent); text-underline-offset: 3px; text-decoration-thickness: 1.5px; }
a.mention:hover { color: var(--accent); }
.tagline { color: var(--muted); font-size: 14px; }
.hovercard { position: fixed; z-index: 30; background: var(--surface); color: var(--fg); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; box-shadow: 0 10px 30px rgba(10, 16, 26, .18); display: grid; gap: 4px; justify-items: start; font-size: 14px; }
.hovercard .hc-name { font-weight: 600; }
.hovercard .hc-kind { font-size: 12px; color: var(--muted); }
.hovercard .hc-line { margin: 2px 0 6px; }

/* ---------- tasks ---------- */
.group-label { font: 500 11px var(--mono); letter-spacing: .07em; text-transform: uppercase; color: var(--muted); margin-top: 8px; }
.group-label.late { color: var(--late); }
.task { display: grid; grid-template-columns: 26px 1fr auto; gap: 10px; align-items: start; padding: 10px 2px; border-bottom: 1px solid var(--line); }
.task input[type=checkbox] { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--accent); }
.task .meta { font-size: 12.5px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 10px; }
.task .meta a { text-decoration: none; }
.task .due { font: 500 12px var(--mono); color: var(--due); white-space: nowrap; padding-top: 3px; }
.task .due.late { color: var(--late); }

/* ---------- search ---------- */
.search-box { display: flex; gap: 8px; }
.hit { display: grid; gap: 2px; padding: 10px 4px; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--fg); }
.hit .k { font: 11px var(--mono); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.hit .s { color: var(--muted); font-size: 13.5px; overflow-wrap: anywhere; }
.hit mark { background: var(--due-soft); color: var(--fg); border-radius: 3px; }

/* ---------- preview, toast ---------- */
dialog.preview { width: min(1000px, 96vw); height: min(90vh, 900px); border: 0; border-radius: 12px; padding: 0; background: var(--surface); color: var(--fg); }
dialog.preview::backdrop { background: rgba(8, 12, 18, .7); }
.preview-bar { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.preview-bar #preview-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.preview-bar .spacer { flex: 1; }
.preview-body { height: calc(100% - 52px); display: grid; place-items: center; overflow: auto; background: var(--sunken); }
.preview-body img, .preview-body video { max-width: 100%; max-height: 100%; }
.preview-body iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 9px 16px; border-radius: 10px; font-size: 14px; max-width: 90vw; z-index: 20; }

/* ---------- phone ---------- */
.hide-wide { display: none; }
@media (max-width: 760px) {
  .shell, .shell.side-closed { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(86vw, 320px); z-index: 10; transform: translateX(-102%); transition: transform .2s; visibility: visible !important; }
  .shell.side-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .25); }
  .scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 9; }
  .hide-wide { display: grid; }
  .hide-narrow { display: none; }
  .log-entry { grid-template-columns: 1fr; gap: 2px; }
  .row { padding: 10px; }
  .msg-user { max-width: 88%; }
}
@media (prefers-reduced-motion: reduce) { .sidebar { transition: none; } }

/* ---------- home + calm topic pages ---------- */
.home { padding: 6vh 16px 0; max-width: 720px; margin: 0 auto; display: grid; gap: 22px; }
.home h1 { font-size: 26px; margin: 0; }
.home .card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 6px 14px 10px; }
.home .card h2 { font: 500 11px var(--mono); letter-spacing: .07em; text-transform: uppercase; color: var(--muted); margin: 10px 0 2px; }
.home .more { font-size: 13px; display: inline-block; padding: 6px 0 2px; }
.fold { max-height: 9.5em; overflow: hidden; position: relative; }
.fold::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 3em; background: linear-gradient(transparent, var(--surface)); }
.linkbtn { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 6px 0 0; font-size: 13px; }

.icon-btn.recording { color: #fff; background: var(--late); border-radius: 50%; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--late) 25%, transparent); } }

/* ---------- color themes (chosen in the sidebar footer; remembered on this device) ---------- */
:root[data-theme="mist"] { --bg: #eef2f6; --surface: #fbfcfd; --sunken: #e3e9f0; --fg: #1f2933; --muted: #5d6a79; --line: #d3dbe4;
  --accent: #3b6ea5; --accent-fg: #ffffff; --accent-soft: #dce8f4; --due: #8a6a1f; --due-soft: #f1eacd; --late: #b24a3d; --ok: #3f7d5c; }
:root[data-theme="clean"] { --bg: #f6f7f8; --surface: #ffffff; --sunken: #eceff2; --fg: #22272e; --muted: #67707b; --line: #dfe3e8;
  --accent: #4a6a8a; --accent-fg: #ffffff; --accent-soft: #e5ecf3; --due: #8a6a1f; --due-soft: #f3edd6; --late: #b24a3d; --ok: #3f7d5c; }
.look { float: right; font-size: 12px; color: var(--muted); }
.look select { font-size: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 1px 4px; }

.filecard { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.filecard .fc-text { min-width: 0; }
.filecard .dl { margin-left: 8px; padding: 3px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface);
  color: var(--accent); font-size: 12.5px; text-decoration: none; white-space: nowrap; }
.filecard .dl:hover { background: var(--accent-soft); }

.spin { width: 12px; height: 12px; margin-left: 6px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: sp .9s linear infinite; flex: none; }
@keyframes sp { to { transform: rotate(360deg); } }
.backlink { display: inline-block; margin: 4px 0 10px; padding: 5px 12px 5px 8px; border: 1px solid var(--line); border-radius: 99px; background: var(--surface);
  color: var(--accent); text-decoration: none; font-size: 13.5px; }
.backlink:hover { background: var(--accent-soft); }

.vstat { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--accent); margin-right: 8px; }

.appbar { display: flex; flex-wrap: wrap; gap: 4px 12px; margin: 4px 0 2px; }
.appbar .linkbtn { padding: 2px 0; font-size: 12.5px; }

.list-item.sub { padding-left: 22px; font-size: 14px; }

.sub-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; }
.sub-chip { font-size: 14px; padding: 5px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--fg); text-decoration: none; }
.sub-chip:hover { border-color: var(--accent, #244061); }

.row .t.two { display: flex; flex-direction: column; white-space: normal; line-height: 1.2; }
.row .t.two > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .t.two .n2 { font-size: 11.5px; color: var(--muted); font-weight: 400; margin-top: 1px; }

.ubar { margin: 10px 0 14px; }
.urow { display: flex; justify-content: space-between; gap: 12px; padding: 2px 0; }
.urow.small { font-size: 14px; color: var(--muted); }
.utrack { height: 10px; border-radius: 6px; background: color-mix(in srgb, var(--muted) 18%, transparent); overflow: hidden; margin: 5px 0; }
.ufill { height: 100%; background: var(--accent, #244061); border-radius: 6px; }
.ufill.warm { background: #d08a1f; }
.ufill.hot { background: #c0392b; }
.ugrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 8px 0; }
.big { font-size: 26px; font-weight: 600; }
.small { font-size: 13px; }
.warnbox { margin: 8px 0; padding: 8px 12px; border-radius: 8px; background: #fbe9d0; color: #6b4200; font-size: 14px; }
.okbox { margin: 8px 0; padding: 8px 12px; border-radius: 8px; background: #e5f3e8; color: #245b30; font-size: 14px; }
.setup-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; }
.setup-card h2 { margin: 0 0 8px; }
.setup-card p { margin: 8px 0; }
.settings-grid { display: grid; grid-template-columns: minmax(90px, auto) minmax(0, 1fr); gap: 5px 14px; margin: 10px 0; overflow-wrap: anywhere; }
.tool-status { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.tool-workflow { margin: 8px 0 0; padding-left: 22px; }
.tool-workflow li { margin: 5px 0; }
.ksef-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.ksef > * { min-width: 0; }
.ksef .warnbox, .ksef .okbox { overflow-wrap: anywhere; }
.checkline { display: flex !important; grid-template-columns: auto 1fr; align-items: center; gap: 8px !important; color: var(--fg) !important; }
.checkline input { width: 19px; height: 19px; accent-color: var(--accent); }
.invoice-preview { background: #fff; color: #242424; border: 1px solid #cfcfcf; border-radius: 8px; padding: clamp(16px, 4vw, 38px); display: grid; gap: 18px; box-shadow: 0 3px 16px rgba(0,0,0,.08); }
.invoice-preview p { margin: 2px 0; }
.invoice-title, .invoice-parties { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 28px; }
.invoice-title > :last-child { text-align: right; }
.invoice-parties > div { border-top: 2px solid #555; padding-top: 8px; overflow-wrap: anywhere; }
.invoice-meta { display: grid; grid-template-columns: minmax(112px, 1fr) minmax(0, 1fr) minmax(112px, 1fr) minmax(0, 1.2fr); gap: 4px 9px; border: 1px solid #bbb; padding: 7px 9px; align-items: baseline; font-size: 11.5px; line-height: 1.35; }
.invoice-meta > :nth-child(4n+3), .invoice-meta > :nth-child(4n+4) { text-align: right; }
.invoice-title > *, .invoice-parties > *, .invoice-meta > * { min-width: 0; overflow-wrap: anywhere; }
.invoice-preview .tablewrap { overflow-x: visible; }
.invoice-preview .mdtable { table-layout: fixed; font-size: 11px; }
.invoice-preview .mdtable th, .invoice-preview .mdtable td { padding: 4px 5px; white-space: normal; overflow-wrap: anywhere; }
.invoice-preview .mdtable .num { white-space: normal; }
.invoice-line-table th:first-child, .invoice-line-table td:first-child { width: 46%; }
.invoice-line-table th:not(:first-child), .invoice-line-table td:not(:first-child) { width: 18%; }
.invoice-total { display: flex; justify-content: flex-end; align-items: baseline; gap: 18px; font-size: 18px; }
.invoice-total strong { font-size: 22px; }
.invoice-summary-grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(210px, 1fr); gap: 22px; align-items: start; }
.vat-table { margin: 0; }
.vat-table .mdtable { font-size: 10.5px; }
.vat-table .mdtable th, .vat-table .mdtable td { padding: 4px; }
.invoice-totals { display: grid; grid-template-columns: 1fr auto; gap: 7px 14px; align-items: baseline; font-size: 11.5px; }
.invoice-totals strong { font-size: 15px; }
.invoice-note { border: 1px solid #ddd; background: #fafafa; padding: 12px; }
.invoice-services { margin: 6px 0 0; padding-left: 22px; }
.invoice-signatures { display: grid; grid-template-columns: 1fr 1fr; gap: 70px; margin-top: 110px; }
.invoice-signatures > div { border-top: 1px solid #777; padding-top: 6px; text-align: center; color: #555; }
@media (max-width: 700px) { .invoice-title, .invoice-parties, .invoice-summary-grid { grid-template-columns: 1fr; gap: 16px; } .invoice-title > :last-child { text-align: left; } .invoice-meta { grid-template-columns: minmax(0, 1.35fr) minmax(82px, .65fr); } .invoice-meta > * { text-align: left !important; } }
.secret-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: center; }
@media (max-width: 520px) { .secret-row { grid-template-columns: 1fr; } }

.spark { display: flex; align-items: flex-end; gap: 4px; height: 64px; margin: 6px 0 8px; }
.sp { flex: 1; background: var(--accent, #244061); border-radius: 3px 3px 0 0; opacity: .8; }

.approval { margin: 10px 0; padding: 12px 14px; border: 1px solid #d08a1f; border-radius: 10px; background: #fff7e8; color: #3d2a00; }
.approval .ap-title { font-weight: 600; margin-bottom: 4px; }
.approval .ap-buttons { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.approval .ap-done { margin-top: 8px; font-weight: 600; }
.btn.danger { background: #b3382c; color: #fff; border-color: #b3382c; }

.actions.drive { margin-top: 6px; }
.drive-warn { color: #b3382c; font-weight: 600; }

.draftmark { color: var(--muted); font-size: 12px; }
.wrap { grid-template-columns: minmax(0, 1fr); }

.approval .ap-list { margin: 8px 0; max-height: 320px; overflow-y: auto; }
.approval .ap-row { display: flex; gap: 8px; align-items: flex-start; padding: 3px 0; font-size: 14px; overflow-wrap: anywhere; }
.approval .ap-row.bad { color: #b3382c; }
.approval .ap-old { text-decoration: line-through; opacity: .7; }

.tablewrap { max-width: 100%; overflow-x: auto; margin: 8px 0 12px; border: 1px solid var(--line); border-radius: 8px; }
.mdtable { border-collapse: collapse; width: 100%; font-size: 14px; }
.mdtable th, .mdtable td { padding: 6px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.mdtable th { background: var(--sunken); font-weight: 600; white-space: nowrap; }
.mdtable tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--sunken) 45%, transparent); }
.mdtable tbody tr:last-child td { border-bottom: 0; }
.mdtable .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Online video players in chat */
.vembed{display:block;max-width:640px;margin:8px 0}
.vframe{display:block;position:relative;width:100%;aspect-ratio:16/9;border-radius:10px;overflow:hidden;background:#000}
.vframe.tall{aspect-ratio:auto;height:352px}
.vframe iframe{position:absolute;inset:0;width:100%;height:100%;border:0}
.vembed video{display:block;max-width:100%;border-radius:10px;background:#000}
.vembed audio{width:100%}
.vlink{display:inline-block;margin-top:4px;font-size:12.5px}
