:root {
  --bg: #ffffff; --bg-side: #f7f7f5; --bg-elev: #ffffff; --bg-hover: rgba(55, 53, 47, .06); --bg-active: rgba(55, 53, 47, .1);
  --text: #37352f; --muted: #787774; --faint: #a5a29a; --border: #e9e9e7; --accent: #2383e2; --accent-text: #fff;
  --danger: #eb5757; --code-bg: rgba(135, 131, 120, .15); --code-text: #eb5757; --callout: #f1f1ef; --mark: #fdecc8;
  --shadow: 0 0 0 1px rgba(15, 15, 15, .05), 0 3px 6px rgba(15, 15, 15, .1), 0 9px 24px rgba(15, 15, 15, .2);
  --today: #eb5757; --grid: #ededec; --radius: 6px;
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Roboto, Arial, sans-serif;
  --mono: "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  --sb-w: 260px; --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #191919; --bg-side: #202020; --bg-elev: #252525; --bg-hover: rgba(255, 255, 255, .055); --bg-active: rgba(255, 255, 255, .1);
    --text: #e6e6e4; --muted: #9b9b9b; --faint: #6b6b6b; --border: #2f2f2f; --code-text: #ff7369; --callout: #2a2a2a; --mark: #59563b;
    --shadow: 0 0 0 1px rgba(255, 255, 255, .08), 0 3px 6px rgba(0, 0, 0, .3), 0 9px 24px rgba(0, 0, 0, .5); --grid: #2a2a2a;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #191919; --bg-side: #202020; --bg-elev: #252525; --bg-hover: rgba(255, 255, 255, .055); --bg-active: rgba(255, 255, 255, .1);
  --text: #e6e6e4; --muted: #9b9b9b; --faint: #6b6b6b; --border: #2f2f2f; --code-text: #ff7369; --callout: #2a2a2a; --mark: #59563b;
  --shadow: 0 0 0 1px rgba(255, 255, 255, .08), 0 3px 6px rgba(0, 0, 0, .3), 0 9px 24px rgba(0, 0, 0, .5); --grid: #2a2a2a;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; overflow: hidden; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input, select, textarea { font: inherit; color: inherit; }
kbd { font: 11px var(--font); color: var(--faint); margin-left: auto; }
.muted { color: var(--muted); } .small { font-size: 12.5px; } .pad { padding: 6px 10px; } .spacer { flex: 1; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--faint); font-weight: 600; }

#app { display: flex; height: 100vh; height: 100dvh; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--bg-elev); white-space: nowrap; transition: background .12s; }
.btn:hover { background: var(--bg-hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); } .btn.danger:not(.ghost) { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 4px 10px; font-size: 13.5px; }
.btn:disabled { opacity: .6; pointer-events: none; }
.icon-btn { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: var(--radius); color: var(--muted); font-size: 17px; flex: none; }
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn.sm { width: 24px; height: 24px; font-size: 14px; } .icon-btn.xs { width: 20px; height: 20px; font-size: 13px; }
.link-btn { color: var(--accent); font-size: 13.5px; } .link-btn:hover { text-decoration: underline; }

/* ---------- sidebar ---------- */
.sidebar { width: var(--sb-w); flex: none; background: var(--bg-side); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; transition: margin .2s, transform .2s; user-select: none; }
body.sb-collapsed .sidebar { margin-left: calc(-1 * var(--sb-w)); }
.sb-head { display: flex; align-items: center; padding: 12px 10px 6px 14px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; flex: 1; }
.brand img { width: 22px; height: 22px; border-radius: 5px; }
.sb-close { display: none; }
.sb-nav { padding: 4px 6px; display: flex; flex-direction: column; gap: 1px; }
.nav-item { display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-radius: var(--radius); color: var(--muted); font-weight: 500; font-size: 14px; text-align: left; }
.nav-item:hover, .nav-item.active { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: var(--bg-active); }
.ni-icon { width: 20px; text-align: center; }
.sb-section { padding: 10px 6px 0; display: flex; flex-direction: column; min-height: 0; }
.sb-section.grow { flex: 1; }
.sb-title { display: flex; align-items: center; justify-content: space-between; padding: 0 8px 4px; font-size: 12px; font-weight: 600; color: var(--faint); }
.tree { overflow-y: auto; flex: 1; padding-bottom: 12px; }
.tree-row { display: flex; align-items: center; gap: 4px; height: 30px; padding-right: 6px; border-radius: var(--radius); cursor: pointer; color: var(--muted); font-size: 14px; font-weight: 500; position: relative; }
.tree-row:hover { background: var(--bg-hover); }
.tree-row.active { background: var(--bg-active); color: var(--text); }
.tree-row.drop-into { background: rgba(35, 131, 226, .18); }
.tree-row.drop-above::before, .tree-row.drop-below::after { content: ''; position: absolute; left: 8px; right: 8px; height: 2px; background: var(--accent); }
.tree-row.drop-above::before { top: 0; } .tree-row.drop-below::after { bottom: 0; }
.tw { width: 20px; height: 20px; border-radius: 4px; display: grid; place-items: center; color: var(--faint); transition: transform .12s; font-size: 15px; flex: none; }
.tw:hover { background: var(--bg-active); }
.tw.open { transform: rotate(90deg); }
.tw.leaf { opacity: .35; }
.tr-icon { width: 20px; text-align: center; flex: none; }
.tr-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tr-actions { display: none; gap: 2px; }
.tree-row:hover .tr-actions { display: flex; }
.tree-empty { padding: 6px 10px; color: var(--muted); font-size: 14px; text-align: left; }
.upcoming { display: flex; flex-direction: column; gap: 1px; max-height: 220px; overflow-y: auto; }
.up-item { display: flex; align-items: stretch; gap: 8px; padding: 4px 8px; border-radius: var(--radius); text-align: left; }
.up-item:hover { background: var(--bg-hover); }
.up-item .bar { width: 3px; border-radius: 2px; background: var(--c); flex: none; }
.up-item.live .bar { box-shadow: 0 0 0 2px color-mix(in srgb, var(--c) 30%, transparent); }
.up-text { display: flex; flex-direction: column; min-width: 0; }
.up-title { font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-foot { border-top: 1px solid var(--border); padding: 6px; }
.sync-status { display: flex; align-items: center; gap: 8px; width: 100%; padding: 6px 8px; border-radius: var(--radius); text-align: left; font-size: 13px; }
.sync-status:hover { background: var(--bg-hover); }
.ss-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.ss-text > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.sb-backdrop { display: none; }

/* ---------- main ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { height: 45px; display: flex; align-items: center; gap: 6px; padding: 0 10px; flex: none; }
.menu-btn { display: none; }
body.sb-collapsed .menu-btn { display: inline-grid; }
.crumbs { display: flex; align-items: center; gap: 2px; min-width: 0; overflow: hidden; }
.crumb { padding: 2px 6px; border-radius: 4px; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.crumb:hover:not(.static) { background: var(--bg-hover); }
.crumbs .sep { color: var(--faint); }
.top-actions { display: flex; align-items: center; gap: 8px; }
.content-area { flex: 1; display: flex; min-height: 0; }
.view { flex: 1; min-width: 0; overflow-y: auto; }
.view-calendar { overflow: hidden; display: flex; flex-direction: column; }
.empty-state { padding: 80px 20px; text-align: center; color: var(--muted); }
.trash-banner { background: var(--danger); color: #fff; text-align: center; padding: 8px; font-size: 14px; }
.trash-banner .btn { margin-left: 8px; }

/* ---------- page editor ---------- */
.page-scroll { min-height: 100%; }
.page-view { max-width: 760px; margin: 0 auto; padding: 48px 56px 30vh; }
.page-view.peek { padding: 16px 28px 30vh; }
.page-icon { font-size: 64px; line-height: 1.1; padding: 4px; border-radius: 8px; margin-left: -4px; }
.page-icon:hover { background: var(--bg-hover); }
.page-icon.empty { font-size: 13.5px; color: var(--faint); opacity: 0; transition: opacity .15s; padding: 4px 8px; }
.page-head:hover .page-icon.empty, .page-icon.empty:focus { opacity: 1; }
.page-view.peek .page-icon { font-size: 44px; }
.page-title { font-size: 40px; font-weight: 700; line-height: 1.2; outline: none; margin: 6px 0 10px; word-break: break-word; }
.page-view.peek .page-title { font-size: 30px; }
.page-title:empty::before { content: attr(data-placeholder); color: var(--faint); opacity: .6; }
.page-props { display: flex; flex-direction: column; gap: 2px; margin-bottom: 14px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.prop { display: flex; align-items: flex-start; gap: 8px; min-height: 32px; font-size: 14px; }
.prop-label { width: 120px; flex: none; color: var(--muted); padding-top: 5px; }
.prop-value { display: flex; align-items: center; gap: 6px; flex: 1; min-height: 32px; }
.prop-value.wrap { flex-wrap: wrap; padding: 2px 0; }
.prop-empty { color: var(--faint); padding: 4px 6px; border-radius: 4px; font-size: 14px; }
.prop-empty:hover { background: var(--bg-hover); color: var(--muted); }
.prop-input { border: 1px solid transparent; background: transparent; padding: 3px 6px; border-radius: 4px; }
.prop-input:hover, .prop-input:focus { background: var(--bg-hover); outline: none; }
.event-chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 8px; border-radius: 4px; background: color-mix(in srgb, var(--c) 14%, transparent); font-size: 13.5px; max-width: 100%; text-align: left; }
.event-chip:hover { background: color-mix(in srgb, var(--c) 24%, transparent); }
.event-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); flex: none; }
.event-chip-title { font-weight: 550; }

.blocks { position: relative; }
.blocks-tail { min-height: 120px; cursor: text; }
.block { position: relative; display: flex; align-items: flex-start; padding-left: calc(var(--indent, 0) * 26px); margin: 1px 0; border-radius: 3px; }
.block.dragging { opacity: .4; }
.block.drop-above { box-shadow: 0 -2px 0 var(--accent); } .block.drop-below { box-shadow: 0 2px 0 var(--accent); }
.handle { position: absolute; left: calc(var(--indent, 0) * 26px - 24px); top: 3px; width: 20px; height: 24px; display: grid; place-items: center; color: var(--faint); border-radius: 4px; cursor: grab; opacity: 0; font-size: 12px; letter-spacing: -2px; user-select: none; touch-action: none; }
.block:hover .handle { opacity: 1; }
.handle:hover { background: var(--bg-hover); }
.content { flex: 1; min-width: 0; outline: none; padding: 3px 2px; word-break: break-word; white-space: pre-wrap; min-height: 1.5em; }
.content:empty::before { content: attr(data-placeholder); color: var(--faint); pointer-events: none; }
.type-p .content:empty::before { content: ''; }
.type-p.focused .content:empty::before { content: attr(data-placeholder); }
.content a { color: inherit; text-decoration: underline; text-decoration-color: var(--faint); text-underline-offset: 2px; }
.content code { font-family: var(--mono); font-size: 85%; background: var(--code-bg); color: var(--code-text); padding: .15em .35em; border-radius: 4px; }
.content mark { background: var(--mark); color: inherit; border-radius: 2px; padding: 0 1px; }
.type-h1 { margin-top: 1.4em; } .type-h1 .content { font-size: 1.9em; font-weight: 700; line-height: 1.25; }
.type-h2 { margin-top: 1.1em; } .type-h2 .content { font-size: 1.45em; font-weight: 650; line-height: 1.3; }
.type-h3 { margin-top: .8em; } .type-h3 .content { font-size: 1.2em; font-weight: 600; line-height: 1.3; }
.prefix { flex: none; width: 24px; min-height: 1.5em; padding-top: 3px; display: flex; justify-content: center; user-select: none; }
.type-bullet .prefix { font-size: 1.2em; line-height: 1.25; }
.prefix.num { width: auto; min-width: 24px; padding-right: 4px; justify-content: flex-end; font-variant-numeric: tabular-nums; }
.todo-cb { width: 16px; height: 16px; margin: 4px 0 0; accent-color: var(--accent); cursor: pointer; }
.block.checked .content { text-decoration: line-through; color: var(--faint); }
.type-quote .content { border-left: 3px solid currentColor; padding-left: 14px; font-size: 1.05em; }
.type-callout { background: var(--callout); border-radius: var(--radius); padding: 12px 14px 12px calc(14px + var(--indent, 0) * 26px); margin: 4px 0; }
.type-callout .handle { left: -24px; }
.callout-icon { font-size: 20px; padding-top: 0; width: 28px; margin-right: 6px; border-radius: 4px; }
.callout-icon:hover { background: var(--bg-hover); }
.type-code .content { font-family: var(--mono); font-size: 13.5px; background: var(--callout); border-radius: var(--radius); padding: 14px 16px; tab-size: 2; }
.content-static { flex: 1; padding: 3px 2px; min-width: 0; }
.content-static hr { border: 0; border-top: 1px solid var(--border); margin: 10px 0; }
.type-divider .content-static { cursor: pointer; }
.page-link { display: flex; align-items: center; gap: 6px; cursor: pointer; border-radius: 4px; padding: 3px 4px; font-weight: 500; }
.page-link:hover { background: var(--bg-hover); }
.pl-title { text-decoration: underline; text-decoration-color: var(--border); text-underline-offset: 3px; }

/* inline toolbar */
.inline-toolbar { position: fixed; z-index: 60; display: none; background: var(--bg-elev); box-shadow: var(--shadow); border-radius: var(--radius); padding: 3px; gap: 1px; }
.inline-toolbar.show { display: flex; }
.tb-btn { min-width: 30px; height: 30px; padding: 0 6px; border-radius: 4px; font-size: 14px; }
.tb-btn:hover { background: var(--bg-hover); }
.tb-btn.b { font-weight: 800; } .tb-btn.i { font-style: italic; font-family: Georgia, serif; } .tb-btn.u { text-decoration: underline; } .tb-btn.s { text-decoration: line-through; }

/* ---------- popovers / menus ---------- */
.popover { position: fixed; z-index: 80; background: var(--bg-elev); box-shadow: var(--shadow); border-radius: 8px; padding: 4px; max-width: calc(100vw - 16px); animation: pop .12s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(-4px); } }
.menu { display: flex; flex-direction: column; min-width: 210px; }
.menu-scroll { max-height: 60vh; overflow-y: auto; }
.menu-item { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-radius: 4px; font-size: 14px; text-align: left; }
.menu-item:hover { background: var(--bg-hover); }
.menu-item.danger { color: var(--danger); }
.menu-icon { width: 20px; text-align: center; color: var(--muted); font-size: 13px; }
.menu-sep { height: 1px; background: var(--border); margin: 4px 0; }
.slash-pop { width: 320px; }
.slash-menu { max-height: 340px; overflow-y: auto; }
.slash-title { font-size: 12px; color: var(--faint); padding: 6px 8px 4px; font-weight: 600; }
.slash-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 5px 8px; border-radius: 4px; text-align: left; }
.slash-item.active { background: var(--bg-active); }
.slash-icon { width: 44px; height: 44px; border: 1px solid var(--border); border-radius: 6px; display: grid; place-items: center; background: var(--bg); font-weight: 600; font-size: 15px; flex: none; }
.slash-text { display: flex; flex-direction: column; min-width: 0; }
.slash-text b { font-weight: 500; font-size: 14px; } .slash-text small { color: var(--muted); font-size: 12px; }
.slash-empty { padding: 8px; color: var(--muted); font-size: 14px; }
.emoji-picker { width: 300px; }
.emoji-head { display: flex; justify-content: space-between; align-items: center; padding: 4px 6px 6px; font-size: 13px; color: var(--muted); }
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; max-height: 240px; overflow-y: auto; }
.emoji { font-size: 21px; height: 34px; border-radius: 4px; }
.emoji:hover { background: var(--bg-hover); }

/* ---------- modal ---------- */
.modal-backdrop { position: fixed; inset: 0; z-index: 70; background: rgba(15, 15, 15, .45); display: flex; align-items: flex-start; justify-content: center; padding: 10vh 16px 16px; opacity: 0; transition: opacity .12s; overflow-y: auto; }
.modal-backdrop.open { opacity: 1; }
.modal { background: var(--bg-elev); border-radius: 12px; box-shadow: var(--shadow); width: 100%; max-width: 520px; padding: 20px; }
.modal.small { max-width: 400px; } .modal.small p { margin: 0 0 16px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; align-items: center; }
.modal input:not([type=checkbox]), .modal select, .modal textarea { border: 1px solid var(--border); background: var(--bg); border-radius: var(--radius); padding: 6px 8px; min-width: 0; }
.modal input:focus, .modal select:focus, .modal textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 50%, transparent); outline-offset: -1px; }
.event-modal { max-width: 560px; }
.event-form textarea { width: 100%; resize: vertical; }
.ev-head { margin-bottom: 10px; }
.modal input.ev-title { width: 100%; font-size: 22px; font-weight: 650; border: 0; background: transparent; padding: 4px 0; }
.modal input.ev-title:focus { outline: none; }
.ev-row { display: flex; gap: 12px; align-items: flex-start; padding: 6px 0; }
.ev-ico { width: 22px; flex: none; text-align: center; padding-top: 6px; color: var(--muted); }
.ev-times { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.ev-line { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; }
.color-row { display: flex; gap: 8px; padding-top: 4px; flex-wrap: wrap; }
.color-dot { width: 22px; height: 22px; border-radius: 50%; box-shadow: inset 0 0 0 2px rgba(0, 0, 0, .08); }
.color-dot.sel { box-shadow: 0 0 0 2px var(--bg-elev), 0 0 0 4px currentColor; }
.ev-note { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; flex: 1; }
.note-link { display: inline-flex; gap: 6px; padding: 6px 10px; border-radius: var(--radius); background: var(--bg-hover); text-align: left; }
.note-link:hover { background: var(--bg-active); }
.search-modal { max-width: 620px; padding: 0; overflow: hidden; }
.modal input.search-input { width: 100%; border: 0; border-bottom: 1px solid var(--border); border-radius: 0; padding: 16px 18px; font-size: 17px; background: transparent; }
.modal input.search-input:focus { outline: none; }
.search-results { max-height: 55vh; overflow-y: auto; padding: 6px; }
.sr-item { display: flex; gap: 10px; width: 100%; padding: 8px 10px; border-radius: 6px; text-align: left; align-items: center; }
.sr-item.active, .sr-item:hover { background: var(--bg-hover); }
.sr-icon { width: 22px; text-align: center; flex: none; }
.sr-text { display: flex; flex-direction: column; min-width: 0; }
.sr-text > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.settings h2 { margin: 0 0 8px; font-size: 20px; }
.settings h3 { margin: 0 0 6px; font-size: 14px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.settings section { padding: 14px 0; border-bottom: 1px solid var(--border); }
.settings p { margin: 0 0 10px; }
.settings .row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.settings details { padding-top: 12px; font-size: 14px; } .settings summary { cursor: pointer; color: var(--muted); }
.auth-form { display: flex; flex-direction: column; gap: 8px; }
.error { color: var(--danger); font-size: 13.5px; min-height: 0; }
.field { display: flex; align-items: center; gap: 10px; margin-top: 8px; } .field > span { width: 120px; color: var(--muted); font-size: 14px; } .field input { flex: 1; }

/* ---------- calendar ---------- */
.calendar { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.cal-toolbar { display: flex; align-items: center; gap: 8px; padding: 6px 16px 10px; flex-wrap: wrap; }
.nav-arrows { display: flex; }
.nav-arrows .icon-btn { font-size: 22px; }
.cal-title { font-size: 19px; margin: 0 4px; font-weight: 650; white-space: nowrap; }
.segmented { display: flex; background: var(--bg-hover); border-radius: 7px; padding: 2px; }
.seg { padding: 3px 12px; border-radius: 5px; font-size: 13.5px; color: var(--muted); }
.seg.active { background: var(--bg-elev); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }
.cal-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.month-grid { flex: 1; display: grid; grid-template-columns: repeat(7, 1fr); grid-template-rows: auto repeat(6, 1fr); border-top: 1px solid var(--border); min-height: 0; overflow-y: auto; }
.month-dow { text-align: center; font-size: 12px; color: var(--muted); padding: 6px 0; border-bottom: 1px solid var(--border); }
.month-cell { border-right: 1px solid var(--grid); border-bottom: 1px solid var(--grid); padding: 2px 4px 4px; min-height: 92px; overflow: hidden; display: flex; flex-direction: column; gap: 2px; cursor: pointer; min-width: 0; }
.month-cell:nth-child(7n + 7) { border-right: 0; }
.month-cell:hover { background: var(--bg-hover); }
.month-cell.drop { background: rgba(35, 131, 226, .12); }
.month-cell.other { background: color-mix(in srgb, var(--bg-side) 60%, transparent); }
.month-cell.other .month-num { color: var(--faint); }
.month-num { align-self: flex-end; font-size: 12.5px; padding: 1px 6px; border-radius: 12px; min-width: 24px; text-align: center; }
.month-num:hover { background: var(--bg-active); }
.month-cell.today .month-num { background: var(--today); color: #fff; font-weight: 600; }
.month-items { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.m-item { display: flex; gap: 4px; align-items: center; font-size: 12px; padding: 1px 5px; border-radius: 4px; overflow: hidden; white-space: nowrap; cursor: pointer; min-width: 0; }
.m-item:hover { background: var(--bg-active); }
.m-item::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--c); flex: none; }
.m-item.allday { background: color-mix(in srgb, var(--c) 18%, transparent); }
.m-item.allday::before { display: none; }
.m-item.page::before { display: none; }
.m-item.page { color: var(--muted); }
.m-time { color: var(--muted); font-variant-numeric: tabular-nums; }
.m-title { overflow: hidden; text-overflow: ellipsis; }
.more { white-space: nowrap; font-size: 12px; color: var(--muted); text-align: left; padding: 0 5px; }
.more:hover { color: var(--text); }

.week { flex: 1; display: flex; flex-direction: column; min-height: 0; border-top: 1px solid var(--border); }
.wk-head, .wk-allday { display: grid; flex: none; overflow-y: hidden; scrollbar-gutter: stable; }
.wk-gutter { font-size: 11px; color: var(--faint); text-align: right; padding: 4px 8px 0 0; }
.wk-gutter.tz { align-self: end; padding-bottom: 6px; }
.wk-day { display: flex; flex-direction: column; align-items: center; padding: 6px 0; gap: 0; border-radius: 6px; }
.wk-day:hover { background: var(--bg-hover); }
.wk-day .dow { font-size: 12px; color: var(--muted); }
.wk-day .dnum { font-size: 20px; font-weight: 600; width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%; line-height: 1; }
.wk-day.today .dnum { background: var(--today); color: #fff; }
.wk-day.today .dow { color: var(--today); }
.wk-allday { border-bottom: 1px solid var(--border); min-height: 28px; }
.ad-col { border-left: 1px solid var(--grid); padding: 2px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ad-item { font-size: 12px; padding: 2px 6px; border-radius: 4px; background: color-mix(in srgb, var(--c, #888) 20%, transparent); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.ad-item:hover { filter: brightness(.95); }
.ad-item.page { background: var(--bg-hover); color: var(--muted); }
.cal-scroll { flex: 1; overflow-y: auto; min-height: 0; scrollbar-gutter: stable; }
.wk-grid { display: grid; position: relative; }
.wk-hours { position: relative; }
.hour-label { position: absolute; right: 8px; transform: translateY(-50%); font-size: 11px; color: var(--faint); font-variant-numeric: tabular-nums; }
.wk-col { position: relative; border-left: 1px solid var(--grid); background-image: repeating-linear-gradient(to bottom, var(--grid) 0 1px, transparent 1px var(--hour, 48px)); cursor: cell; }
.wk-col.today { background-color: color-mix(in srgb, var(--today) 3%, transparent); }
.now-line { position: absolute; left: -1px; right: 0; height: 2px; background: var(--today); z-index: 3; pointer-events: none; }
.now-line::before { content: ''; position: absolute; left: -5px; top: -4px; width: 10px; height: 10px; border-radius: 50%; background: var(--today); }
.ev-block { position: absolute; z-index: 2; border-radius: 5px; padding: 2px 6px; overflow: hidden; cursor: pointer; font-size: 12px; line-height: 1.3;
  background: color-mix(in srgb, var(--c) 18%, var(--bg)); border-left: 3px solid var(--c); color: var(--text); touch-action: pan-y; user-select: none; box-shadow: 0 0 0 1px var(--bg); }
.ev-block:hover { background: color-mix(in srgb, var(--c) 26%, var(--bg)); }
.ev-block.dragging { z-index: 5; opacity: .9; box-shadow: var(--shadow); cursor: grabbing; }
.ev-block.short { display: flex; gap: 6px; align-items: center; padding-top: 0; padding-bottom: 0; }
.ev-block.short .ev-b-time { order: 2; }
.ev-b-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev-b-time { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.ev-resize { position: absolute; left: 0; right: 0; bottom: 0; height: 8px; cursor: ns-resize; touch-action: none; }
.ev-block.preview { --c: var(--accent); pointer-events: none; font-weight: 600; opacity: .85; }

/* peek panel (calendar + note side-by-side) */
.peek-panel { display: none; }
body.peek-open .view-calendar + .peek-panel { display: flex; flex-direction: column; width: min(520px, 45%); border-left: 1px solid var(--border); background: var(--bg); min-height: 0; }
.peek-bar { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-bottom: 1px solid var(--border); flex: none; }
.peek-body { flex: 1; overflow-y: auto; }

/* trash */
.trash { max-width: 760px; margin: 0 auto; padding: 40px 24px; }
.trash-head { display: flex; align-items: center; justify-content: space-between; }
.trash-item { display: flex; align-items: center; gap: 10px; padding: 8px 6px; border-bottom: 1px solid var(--border); }
.trash-title { flex: 1; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trash-title:hover { text-decoration: underline; }

/* toasts */
#toasts { position: fixed; bottom: calc(20px + var(--safe-b)); left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: #2f3437; color: #fff; padding: 8px 16px; border-radius: 8px; font-size: 14px; box-shadow: var(--shadow); transition: opacity .3s, transform .3s; }
.toast.out { opacity: 0; transform: translateY(8px); }

.tabbar { display: none; }

/* ---------- mobile ---------- */
@media (max-width: 760px) {
  body { font-size: 16px; }
  .sidebar { position: fixed; z-index: 50; top: 0; bottom: 0; left: 0; width: min(86vw, 320px); transform: translateX(-100%); box-shadow: var(--shadow); padding-top: env(safe-area-inset-top); }
  body.sb-open .sidebar { transform: none; }
  body.sb-open .sb-backdrop { display: block; position: fixed; inset: 0; z-index: 45; background: rgba(0, 0, 0, .35); }
  body.sb-collapsed .sidebar { margin-left: 0; }
  .sb-close { display: inline-grid; }
  .menu-btn { display: inline-grid; }
  .tr-actions { display: flex; }
  .tr-actions .icon-btn { width: 28px; height: 28px; }
  .tree-row { height: 38px; }
  .nav-item { padding: 9px 8px; font-size: 15px; }
  .main { padding-top: env(safe-area-inset-top); }
  .content-area { padding-bottom: calc(56px + var(--safe-b)); }
  .hide-sm { display: none; }
  .page-view { padding: 16px 20px 40vh 30px; }
  .page-icon { font-size: 48px; }
  .page-title { font-size: 30px; }
  .prop-label { width: 92px; }
  .handle { opacity: 0; left: calc(var(--indent, 0) * 26px - 26px); }
  .block.focused .handle { opacity: .7; }
  .tabbar { display: flex; position: fixed; z-index: 40; left: 0; right: 0; bottom: 0; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-top: 1px solid var(--border); padding-bottom: var(--safe-b); }
  .tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 6px 0; font-size: 11px; color: var(--muted); }
  .tab.active { color: var(--text); }
  .tab-icon { font-size: 20px; line-height: 1.2; }
  .cal-toolbar { padding: 4px 10px 8px; gap: 6px; }
  .cal-title { font-size: 17px; order: -1; width: 100%; margin: 0 0 2px 2px; }
  .new-ev { display: none; }
  .month-cell { min-height: 64px; padding: 2px; }
  .m-item { font-size: 11px; padding: 0 3px; }
  .m-time { display: none; }
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal { border-radius: 14px 14px 0 0; max-width: none; padding: 18px 16px calc(18px + var(--safe-b)); max-height: 92vh; overflow-y: auto; }
  .search-modal { border-radius: 14px 14px 0 0; }
  .ev-line input[type=date] { flex: 1 1 130px; }
  .inline-toolbar { overflow-x: auto; max-width: calc(100vw - 16px); }
  body.peek-open .peek-panel { display: none !important; }
}
@media (hover: none) { .tr-actions { display: flex; } .page-icon.empty { opacity: 1; } }

/* =====================================================================
   v2: motion, media blocks, reminders, templates, connected apps
   ===================================================================== */
:root { --ease: cubic-bezier(.2, .8, .2, 1); --ease-out: cubic-bezier(.16, 1, .3, 1); }

/* ---------- motion ---------- */
.btn, .icon-btn, .nav-item, .tree-row, .seg, .tab, .slash-item, .menu-item, .chat-item, .mail-item, .tpl-card, .send-btn { transition: background .15s, color .15s, transform .12s var(--ease), box-shadow .15s, opacity .15s; }
.btn:active, .icon-btn:active, .tab:active, .send-btn:active, .tpl-card:active { transform: scale(.96); }
.seg.active { transition: background .2s, box-shadow .2s; }
.view-enter > * { animation: viewIn .28s var(--ease-out); }
@keyframes viewIn { from { opacity: 0; transform: translateY(8px); } }

.modal-backdrop { transition: opacity .18s ease; }
.modal-backdrop .modal { transform: translateY(14px) scale(.97); opacity: 0; transition: transform .28s var(--ease-out), opacity .2s ease; }
.modal-backdrop.open .modal { transform: none; opacity: 1; }
.modal-backdrop.closing { opacity: 0; }
.modal-backdrop.closing .modal { transform: translateY(8px) scale(.98); opacity: 0; transition-duration: .16s; }
.popover { transform-origin: top left; animation: pop .16s var(--ease-out); }
@keyframes pop { from { opacity: 0; transform: translateY(-6px) scale(.97); } }
.popover.closing { opacity: 0; transform: scale(.97); transition: opacity .12s, transform .12s; }
.cal-body.slide-next > * { animation: slideNext .3s var(--ease-out); }
.cal-body.slide-prev > * { animation: slidePrev .3s var(--ease-out); }
@keyframes slideNext { from { opacity: .2; transform: translateX(36px); } }
@keyframes slidePrev { from { opacity: .2; transform: translateX(-36px); } }
.tree-children { animation: fadeDown .2s var(--ease-out); }
@keyframes fadeDown { from { opacity: 0; transform: translateY(-4px); } }
.block { animation: blockIn .18s ease-out; }
@keyframes blockIn { from { opacity: 0; } }
.ev-block, .m-item, .ad-item { transition: background .15s, box-shadow .15s, transform .12s; }
.ev-block:not(.dragging):hover { transform: translateY(-1px); box-shadow: 0 2px 8px rgba(0, 0, 0, .12); }
.toast { animation: toastIn .3s var(--ease-out); }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px) scale(.96); } }
.sidebar { transition: margin .25s var(--ease), transform .3s var(--ease-out); }
.sb-backdrop { transition: opacity .25s; }
.peek-panel { animation: peekIn .3s var(--ease-out); }
@keyframes peekIn { from { opacity: 0; transform: translateX(24px); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* ---------- media blocks ---------- */
.content-static.media { padding: 4px 0; }
.img-block { margin: 4px 0; display: flex; flex-direction: column; align-items: center; }
.img-block .img-holder { position: relative; border-radius: 6px; overflow: hidden; background: var(--bg-hover); min-height: 60px; min-width: 120px; max-width: 100%; }
.img-block.w-normal .img-holder { max-width: 520px; } .img-block.w-wide .img-holder { width: 100%; } .img-block.w-full { margin: 4px -56px; } .img-block.w-full .img-holder { width: 100%; border-radius: 0; }
.img-block img { display: block; max-width: 100%; height: auto; cursor: zoom-in; opacity: 0; transition: opacity .3s; }
.img-block.loaded img { opacity: 1; }
.img-block.loaded .img-holder { background: none; min-height: 0; }
.img-missing { padding: 24px; color: var(--muted); font-size: 13px; text-align: center; }
.img-block figcaption { font-size: 13px; color: var(--muted); padding: 6px 4px 0; outline: none; text-align: center; min-width: 120px; }
.img-block figcaption:empty::before { content: attr(data-placeholder); color: var(--faint); opacity: 0; transition: opacity .15s; }
.block:hover .img-block figcaption:empty::before, .img-block figcaption:focus:empty::before { opacity: 1; }
.file-block { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; display: flex; flex-direction: column; gap: 8px; background: var(--bg-elev); }
.file-row { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.file-icon { font-size: 22px; width: 32px; text-align: center; flex: none; }
.file-meta { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.file-meta b { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-block audio, .file-block video { width: 100%; max-height: 420px; border-radius: 6px; }
.cloud-link { font-size: 13px; color: var(--accent); text-decoration: none; }
.cloud-link:hover { text-decoration: underline; }
.bookmark { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; color: inherit; text-decoration: none; min-height: 92px; transition: background .15s, box-shadow .2s; }
.bookmark:hover { background: var(--bg-hover); box-shadow: 0 2px 10px rgba(0, 0, 0, .06); }
.bookmark.loading { opacity: .6; }
.bm-text { flex: 1; min-width: 0; padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; }
.bm-text b { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bm-text small { color: var(--muted); font-size: 12.5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.bm-url { display: flex; align-items: center; gap: 6px; font-size: 12px; margin-top: auto; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.bm-url img { width: 14px; height: 14px; }
.bm-img { width: 30%; max-width: 220px; flex: none; background: center / cover no-repeat var(--bg-hover); }
.link-pop, .rec-pop { display: flex; gap: 6px; align-items: center; padding: 4px; }
.link-input { border: 1px solid var(--border); background: var(--bg); border-radius: 6px; padding: 6px 8px; width: min(340px, 70vw); font-size: 14px; }
.link-input:focus { outline: 2px solid color-mix(in srgb, var(--accent) 50%, transparent); }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: pulse 1s infinite; }
.rec-time { font-variant-numeric: tabular-nums; min-width: 40px; }
@keyframes pulse { 50% { opacity: .3; } }
.lightbox { position: fixed; inset: 0; z-index: 120; background: rgba(0, 0, 0, .85); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 20px; opacity: 0; transition: opacity .2s; cursor: zoom-out; }
.lightbox.open { opacity: 1; }
.lightbox img { max-width: 100%; max-height: 88vh; border-radius: 6px; transform: scale(.94); transition: transform .3s var(--ease-out); }
.lightbox.open img { transform: none; }
.lb-caption { color: #ddd; margin-top: 10px; font-size: 14px; }

/* ---------- reminders ---------- */
#reminders { position: fixed; top: calc(12px + env(safe-area-inset-top)); right: 12px; z-index: 110; display: flex; flex-direction: column; gap: 10px; width: min(380px, calc(100vw - 24px)); }
.reminder-card { display: flex; align-items: center; gap: 12px; background: var(--bg-elev); border-radius: 12px; padding: 12px 12px 12px 14px; box-shadow: var(--shadow); border-left: 4px solid var(--c); animation: remIn .4s var(--ease-out); transition: opacity .25s, transform .25s; }
.reminder-card.out { opacity: 0; transform: translateX(30px); }
@keyframes remIn { from { opacity: 0; transform: translateY(-16px) scale(.96); } }
.rc-bell { font-size: 24px; animation: ring 1.2s ease-in-out 2; transform-origin: top center; }
@keyframes ring { 0%, 100% { transform: rotate(0); } 15% { transform: rotate(18deg); } 30% { transform: rotate(-16deg); } 45% { transform: rotate(10deg); } 60% { transform: rotate(-6deg); } 75% { transform: rotate(3deg); } }
.rc-text { flex: 1; display: flex; flex-direction: column; min-width: 0; font-size: 14px; }
.rc-text span { color: var(--muted); font-size: 13px; }
.rc-actions { display: flex; gap: 4px; align-items: center; }

/* ---------- templates ---------- */
.tpl-modal { max-width: 760px; }
.tpl-picker h2 { margin: 0 0 4px; } .tpl-picker h3 { margin: 18px 0 8px; font-size: 14px; color: var(--muted); }
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; margin-top: 12px; }
.tpl-card { position: relative; display: flex; gap: 12px; align-items: flex-start; text-align: left; padding: 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); }
.tpl-card:hover { background: var(--bg-hover); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); box-shadow: 0 4px 14px rgba(0, 0, 0, .06); transform: translateY(-1px); }
.tpl-icon { font-size: 26px; line-height: 1; }
.tpl-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tpl-text b { font-weight: 600; font-size: 14px; } .tpl-text small { color: var(--muted); font-size: 12px; }
.tpl-del { position: absolute; top: 6px; right: 8px; color: var(--faint); font-size: 12px; padding: 2px 4px; border-radius: 4px; }
.tpl-del:hover { background: var(--bg-active); color: var(--danger); }

/* ---------- connect page ---------- */
.connect-page { max-width: 780px; margin: 0 auto; padding: 32px 24px 80px; }
.connect-page h1 { margin: 0 0 16px; } .connect-page h2 { font-size: 16px; margin: 28px 0 10px; color: var(--muted); }
.conn-card { border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; margin-bottom: 12px; background: var(--bg-elev); animation: viewIn .3s var(--ease-out) both; }
.conn-head { display: flex; align-items: center; gap: 12px; }
.conn-icon { font-size: 24px; width: 32px; text-align: center; }
.conn-title { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.conn-body { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.conn-body:empty { display: none; }
.conn-body > input, .conn-body .row input { border: 1px solid var(--border); background: var(--bg); border-radius: 6px; padding: 7px 9px; font-size: 14px; }
.conn-body .row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.conn-body p { margin: 0; font-size: 14px; }
.conn-guide summary { cursor: pointer; color: var(--accent); font-size: 14px; }
.guide { margin: 8px 0 4px; padding-left: 20px; font-size: 13.5px; display: flex; flex-direction: column; gap: 4px; }
.guide a { color: var(--accent); }
.field.col { flex-direction: column; align-items: stretch; gap: 4px; } .field.col > span { width: auto; font-size: 13px; }
code.uri { font-family: var(--mono); font-size: 12px; background: var(--code-bg); padding: 6px 8px; border-radius: 6px; word-break: break-all; flex: 1; }
.warn { background: color-mix(in srgb, #f59e0b 14%, transparent); border-radius: 8px; padding: 8px 10px; font-size: 13px !important; }
.pill { font-size: 12px; padding: 3px 8px; border-radius: 99px; background: var(--bg-hover); color: var(--muted); white-space: nowrap; max-width: 46%; overflow: hidden; text-overflow: ellipsis; }
.pill.ok { background: color-mix(in srgb, #16a34a 15%, transparent); color: #16a34a; }
.qr-wrap { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.qr { width: 220px; height: 220px; border-radius: 8px; background: #fff; padding: 6px; }

/* ---------- connected app views (mail / chat / cloud) ---------- */
.view-mail, .view-chat { overflow: hidden; }
.app-split { display: flex; height: 100%; min-height: 0; border-top: 1px solid var(--border); }
.app-side { width: 340px; flex: none; border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.app-toolbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; }
.app-tabs .seg { padding: 3px 10px; }
.app-search { margin: 0 12px 8px; border: 1px solid var(--border); background: var(--bg-side); border-radius: 8px; padding: 7px 10px; font-size: 14px; }
.app-search:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); }
.mail-list, .chat-list { flex: 1; overflow-y: auto; padding: 0 6px 12px; }
.mail-item { display: flex; flex-direction: column; gap: 1px; width: 100%; text-align: left; padding: 9px 10px; border-radius: 8px; animation: viewIn .25s var(--ease-out) both; }
.mail-item:hover { background: var(--bg-hover); } .mail-item.active { background: var(--bg-active); }
.mi-top { display: flex; justify-content: space-between; gap: 8px; }
.mi-from { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-item.unread .mi-from, .mail-item.unread .mi-subject { font-weight: 700; }
.mail-item.unread::before { content: ''; position: absolute; }
.mi-subject { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mi-snippet { font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-reader, .chat-thread { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 0; }
.mail-reader { overflow-y: auto; padding: 0 24px 40px; }
.reader-bar { display: flex; align-items: center; gap: 8px; padding: 8px 0; position: sticky; top: 0; background: var(--bg); z-index: 2; }
.chat-thread .reader-bar { padding: 8px 14px; border-bottom: 1px solid var(--border); }
.back-btn { display: none; font-size: 26px; }
.reader-subject { margin: 6px 0 8px; font-size: 22px; }
.reader-meta { display: flex; flex-wrap: wrap; gap: 4px; align-items: baseline; font-size: 14px; margin-bottom: 12px; }
.reader-date { margin-left: auto; }
.mail-frame { width: 100%; border: 0; min-height: 300px; border-radius: 8px; background: #fff; }
.attach-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.attach-chip { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 99px; background: var(--bg-hover); font-size: 13px; color: inherit; text-decoration: none; }
.attach-chip:hover { background: var(--bg-active); }
.spinner-row { display: flex; justify-content: center; padding: 30px; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 2.5px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.big-icon { font-size: 44px; margin-bottom: 8px; }
.load-more { display: block; margin: 10px auto; }

.chat-item { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 8px 8px; border-radius: 10px; }
.chat-item:hover { background: var(--bg-hover); } .chat-item.active { background: var(--bg-active); }
.avatar { width: 42px; height: 42px; flex: none; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; background: linear-gradient(135deg, hsl(var(--hue) 65% 58%), hsl(calc(var(--hue) + 40) 60% 48%)); }
.avatar.sm { width: 32px; height: 32px; font-size: 14px; }
.ci-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ci-top { display: flex; justify-content: space-between; gap: 6px; }
.ci-top b { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item.unread .ci-top b { font-weight: 700; }
.ci-last { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; min-width: 20px; height: 20px; border-radius: 10px; display: grid; place-items: center; padding: 0 6px; animation: pop .3s var(--ease-out); }
.thread-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msgs { flex: 1; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; background: color-mix(in srgb, var(--bg-side) 70%, var(--bg)); }
.day-sep { align-self: center; font-size: 12px; color: var(--muted); background: var(--bg-elev); padding: 2px 10px; border-radius: 99px; margin: 10px 0 6px; box-shadow: 0 1px 2px rgba(0, 0, 0, .06); }
.bubble { max-width: min(76%, 560px); align-self: flex-start; background: var(--bg-elev); border-radius: 14px 14px 14px 4px; padding: 7px 10px 4px; box-shadow: 0 1px 1px rgba(0, 0, 0, .06); display: flex; flex-direction: column; gap: 4px; animation: bubbleIn .25s var(--ease-out); word-break: break-word; }
.bubble.me { align-self: flex-end; background: color-mix(in srgb, var(--accent) 16%, var(--bg-elev)); border-radius: 14px 14px 4px 14px; }
.bubble.pending { opacity: .7; } .bubble.failed { outline: 1px solid var(--danger); }
@keyframes bubbleIn { from { opacity: 0; transform: translateY(6px) scale(.98); } }
.b-sender { font-size: 12px; font-weight: 600; color: var(--accent); }
.b-text { font-size: 14.5px; line-height: 1.45; }
.b-text a { color: var(--accent); }
.b-time { font-size: 11px; color: var(--faint); align-self: flex-end; }
.b-img { max-width: 100%; max-height: 320px; border-radius: 10px; cursor: zoom-in; display: block; }
.b-video { max-width: 100%; max-height: 320px; border-radius: 10px; }
.b-audio { width: 260px; max-width: 100%; height: 40px; }
.b-file { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; padding: 4px 2px; }
.b-file > span:first-child { font-size: 24px; } .b-file > span:last-child { display: flex; flex-direction: column; } .b-file small { color: var(--muted); }
.attach-preview { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px; }
.attach-preview:not(:empty) { padding: 8px 12px 0; }
.composer { display: flex; align-items: flex-end; gap: 6px; padding: 10px 12px; border-top: 1px solid var(--border); background: var(--bg); }
.composer-input { flex: 1; resize: none; border: 1px solid var(--border); background: var(--bg-side); border-radius: 20px; padding: 8px 14px; font-size: 15px; line-height: 1.4; max-height: 140px; }
.composer-input:focus { outline: none; border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }
.send-btn { width: 38px; height: 38px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 16px; flex: none; }
.send-btn:hover { filter: brightness(1.08); }
.icon-btn.recording { color: #fff; background: var(--danger); animation: pulse 1s infinite; }

.cloud-page { max-width: 820px; margin: 0 auto; padding: 20px 20px 80px; }
.cloud-page .app-toolbar { padding: 0 0 8px; }
.cloud-drop { border: 2px dashed var(--border); border-radius: 12px; padding: 22px; text-align: center; color: var(--muted); margin: 8px 0 14px; transition: background .2s, border-color .2s; }
.cloud-drop.over { background: color-mix(in srgb, var(--accent) 8%, transparent); border-color: var(--accent); }
.cloud-list { display: flex; flex-direction: column; }
.cloud-item { display: flex; align-items: center; gap: 10px; padding: 9px 6px; border-bottom: 1px solid var(--border); animation: viewIn .25s var(--ease-out) both; }
.cloud-item.uploading { color: var(--muted); }

@media (max-width: 760px) {
  .app-split { position: relative; overflow: hidden; }
  .app-side { width: 100%; border-right: 0; }
  .mail-reader, .chat-thread { position: absolute; inset: 0; background: var(--bg); transform: translateX(100%); transition: transform .32s var(--ease-out); z-index: 5; }
  body.reader-open .mail-reader, body.reader-open .chat-thread { transform: none; }
  .back-btn { display: inline-grid; }
  .mail-reader { padding: 0 14px 30px; }
  .bubble { max-width: 86%; }
  .img-block.w-full { margin: 4px -20px; }
  .bm-img { display: none; }
  #reminders { right: 12px; left: 12px; width: auto; }
  .tpl-grid { grid-template-columns: 1fr 1fr; }
  .tpl-card { flex-direction: column; gap: 6px; }
  .connect-page { padding: 16px 14px 80px; }
  body.reader-open .tabbar { transform: translateY(110%); }
  .tabbar { transition: transform .3s var(--ease-out); }
  body.reader-open .content-area { padding-bottom: 0; }
  .chat-thread .composer { padding-bottom: calc(10px + var(--safe-b)); }
}

a.btn { text-decoration: none; color: inherit; }

/* =====================================================================
   v3: Telegram-style messenger
   ===================================================================== */
:root { --tg-side: #fff; --tg-active: #3390ec; --tg-hover: #f4f4f5; --tg-in: #fff; --tg-out: #e3fee0; --tg-meta-in: #a0acb6; --tg-meta-out: #4fae4e; --tg-tick: #4fae4e;
  --tg-bg1: #a7d29b; --tg-bg2: #d8e6a3; --tg-bg3: #87c0a5; --tg-link: #3390ec; --tg-badge: #3390ec; --tg-text: #000; --tg-sub: #707579; --tg-reply: #3390ec; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --tg-side: #17212b; --tg-active: #2b5278; --tg-hover: #202b36; --tg-in: #182533; --tg-out: #2b5278; --tg-meta-in: #6d7f8f; --tg-meta-out: #7da8d3; --tg-tick: #64b5ef; --tg-bg1: #0e1621; --tg-bg2: #14202c; --tg-bg3: #0b131b; --tg-link: #6ab2f2; --tg-badge: #4f9ad8; --tg-text: #f5f5f5; --tg-sub: #7f91a4; --tg-reply: #6ab2f2; } }
:root[data-theme="dark"] { --tg-side: #17212b; --tg-active: #2b5278; --tg-hover: #202b36; --tg-in: #182533; --tg-out: #2b5278; --tg-meta-in: #6d7f8f; --tg-meta-out: #7da8d3; --tg-tick: #64b5ef; --tg-bg1: #0e1621; --tg-bg2: #14202c; --tg-bg3: #0b131b; --tg-link: #6ab2f2; --tg-badge: #4f9ad8; --tg-text: #f5f5f5; --tg-sub: #7f91a4; --tg-reply: #6ab2f2; }

.tg { display: flex; height: 100%; min-height: 0; border-top: 1px solid var(--border); color: var(--tg-text); }
.tg-side { width: 380px; flex: none; background: var(--tg-side); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.tg-side-head { display: flex; gap: 6px; align-items: center; padding: 10px 10px 6px; }
.tg-search { flex: 1; border: 0; border-radius: 22px; background: var(--tg-hover); padding: 9px 16px; font-size: 15px; outline: 2px solid transparent; transition: outline-color .15s, background .15s; }
.tg-search:focus { outline-color: var(--tg-active); background: var(--tg-side); }
.tg-folders { padding: 0 6px; border-bottom: 1px solid var(--border); }
.tg-ftabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tg-folder { position: relative; padding: 10px 12px; font-size: 14px; font-weight: 500; color: var(--tg-sub); white-space: nowrap; display: flex; gap: 6px; align-items: center; border-radius: 8px 8px 0 0; }
.tg-folder:hover { background: var(--tg-hover); }
.tg-folder.active { color: var(--tg-active); }
.tg-folder.active::after { content: ''; position: absolute; left: 10px; right: 10px; bottom: 0; height: 3px; border-radius: 3px 3px 0 0; background: var(--tg-active); animation: tabIn .25s var(--ease-out); }
@keyframes tabIn { from { transform: scaleX(.3); opacity: 0; } }
.tg-fcount { background: var(--tg-sub); color: #fff; font-size: 11px; border-radius: 10px; padding: 0 6px; min-width: 18px; text-align: center; }
.tg-folder.active .tg-fcount { background: var(--tg-active); }
.tg-pchips { display: flex; gap: 6px; padding: 8px 4px; overflow-x: auto; scrollbar-width: none; }
.tg-pchip { padding: 4px 10px; border-radius: 14px; font-size: 12.5px; background: var(--tg-hover); color: var(--tg-sub); white-space: nowrap; }
.tg-pchip.active { background: var(--pc, var(--tg-active)); color: #fff; }
.tg-list { flex: 1; overflow-y: auto; padding: 6px; }
.tg-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 9px; border-radius: 12px; text-align: left; transition: background .12s; }
.tg-item:hover { background: var(--tg-hover); }
.tg-item.active { background: var(--tg-active); color: #fff; }
.tg-item.active .tg-last, .tg-item.active .tg-time, .tg-item.active .tg-ticks { color: rgba(255, 255, 255, .85) !important; }
.tg-item.active .tg-badge { background: #fff; color: var(--tg-active); }
.tg-item-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.tg-row { display: flex; align-items: center; gap: 6px; min-width: 0; }
.tg-name { flex: 1; font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tg-gicon { font-size: 12px; margin-right: 4px; }
.tg-time { font-size: 12px; color: var(--tg-sub); flex: none; display: flex; gap: 3px; align-items: center; }
.tg-last { flex: 1; font-size: 14px; color: var(--tg-sub); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tg-badge { background: var(--tg-badge); color: #fff; font-size: 12px; font-weight: 600; min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px; display: grid; place-items: center; flex: none; animation: pop .3s var(--ease-out); }
.tg-badge.muted { background: #c4c9cc; }
.tg-pin { font-size: 12px; opacity: .6; }
.tg-error { font-size: 12.5px; color: var(--danger); padding: 6px 10px; }
.tg-none { text-align: center; color: var(--tg-sub); padding: 30px 10px; font-size: 14px; }
.tg-none.chip { align-self: center; background: rgba(0, 0, 0, .18); color: #fff; border-radius: 14px; padding: 6px 14px; margin: auto; }
.tg-skel { display: flex; gap: 10px; padding: 9px; align-items: center; }
.tg-skel .sk-av { width: 52px; height: 52px; border-radius: 50%; background: var(--tg-hover); }
.tg-skel .sk-lines { flex: 1; display: flex; flex-direction: column; gap: 8px; }
.tg-skel i { height: 11px; border-radius: 6px; background: var(--tg-hover); width: 70%; animation: shimmer 1.2s infinite; } .tg-skel i + i { width: 45%; }
@keyframes shimmer { 50% { opacity: .45; } }

.tg-avatar { position: relative; flex: none; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 600; background: linear-gradient(160deg, hsl(var(--hue) 75% 66%), hsl(calc(var(--hue) + 25) 65% 52%)); user-select: none; }
.tg-avatar img { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.tg-prov { position: absolute; right: -2px; bottom: -2px; width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; font-size: 10px; color: #fff; box-shadow: 0 0 0 2px var(--tg-side); }

.tg-thread { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 0; position: relative;
  background: radial-gradient(circle at 20% 20%, var(--tg-bg2), transparent 55%), radial-gradient(circle at 80% 70%, var(--tg-bg3), transparent 55%), var(--tg-bg1); }
.tg-thread::before { content: ''; position: absolute; inset: 0; pointer-events: none; opacity: .14;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120' viewBox='0 0 120 120'%3E%3Cg fill='none' stroke='%23000' stroke-width='1.6' stroke-linecap='round'%3E%3Cpath d='M15 20c6-6 14-6 20 0'/%3E%3Ccircle cx='85' cy='22' r='7'/%3E%3Cpath d='M60 55l8 8m0-8l-8 8'/%3E%3Cpath d='M20 90h16M28 82v16'/%3E%3Cpath d='M88 88c4 6 12 6 16 0'/%3E%3Cpath d='M45 105l6-10 6 10z'/%3E%3C/g%3E%3C/svg%3E"); }
.tg-thread.drop::after { content: 'Thả tệp để gửi'; position: absolute; inset: 12px; border: 3px dashed var(--tg-active); border-radius: 16px; display: grid; place-items: center; font-size: 20px; font-weight: 600; color: var(--tg-active); background: rgba(255, 255, 255, .75); z-index: 20; }
.tg-empty { margin: auto; z-index: 1; } .tg-empty span { background: rgba(0, 0, 0, .2); color: #fff; padding: 6px 14px; border-radius: 16px; font-size: 14px; }
.tg-head { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--tg-side); border-bottom: 1px solid var(--border); z-index: 2; }
.tg-head-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.tg-head-text b { font-size: 15.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tg-head-text small { color: var(--tg-sub); font-size: 13px; }
.tg-chatsearch { display: flex; gap: 6px; padding: 0 12px; background: var(--tg-side); z-index: 2; }
.tg-chatsearch:not(:empty) { padding: 6px 12px; border-bottom: 1px solid var(--border); }
.tg-chatsearch input { flex: 1; border: 0; background: var(--tg-hover); border-radius: 16px; padding: 7px 14px; font-size: 14px; }
.tg-body { flex: 1; min-height: 0; position: relative; display: flex; }
.tg-msgs { flex: 1; overflow-y: auto; padding: 10px max(12px, calc((100% - 760px) / 2)) 8px; display: flex; flex-direction: column; z-index: 1; overscroll-behavior: contain; }
.tg-day { position: sticky; top: 4px; z-index: 3; align-self: center; margin: 10px 0 8px; pointer-events: none; }
.tg-day span { background: rgba(0, 0, 0, .22); color: #fff; font-size: 13px; font-weight: 500; padding: 3px 10px; border-radius: 14px; backdrop-filter: blur(6px); }

.tg-msg { display: flex; flex-direction: column; margin-top: 2px; max-width: 100%; }
.tg-msg.first { margin-top: 8px; }
.tg-msg.in { align-items: flex-start; } .tg-msg.out { align-items: flex-end; }
.tg-msg.dim { opacity: .35; }
.tg-msg.flash .tg-bubble { animation: flash 1.2s; }
@keyframes flash { 30% { box-shadow: 0 0 0 4px rgba(51, 144, 236, .5); } }
.tg-bubble { position: relative; max-width: min(78%, 520px); background: var(--tg-in); border-radius: 15px; padding: 5px 9px 6px; box-shadow: 0 1px 2px rgba(16, 35, 47, .15); word-break: break-word; animation: tgIn .22s var(--ease-out); }
@keyframes tgIn { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.tg-msg.out .tg-bubble { background: var(--tg-out); }
.tg-msg.in.last .tg-bubble { border-bottom-left-radius: 4px; }
.tg-msg.out.last .tg-bubble { border-bottom-right-radius: 4px; }
.tg-msg.in.last .tg-bubble::before, .tg-msg.out.last .tg-bubble::before { content: ''; position: absolute; bottom: 0; width: 10px; height: 16px; background: inherit; }
.tg-msg.in.last .tg-bubble::before { left: -6px; clip-path: path('M10 0 C10 10 8 14 0 16 L10 16 Z'); }
.tg-msg.out.last .tg-bubble::before { right: -6px; clip-path: path('M0 0 C0 10 2 14 10 16 L0 16 Z'); }
.tg-msg.pending .tg-bubble { opacity: .85; }
.tg-bubble.failed { box-shadow: 0 0 0 1.5px var(--danger); }
.tg-retry { font-size: 12px; color: var(--danger); margin-top: 2px; }
.tg-sender { font-size: 13.5px; font-weight: 600; margin-bottom: 1px; }
.tg-reply { border-left: 3px solid var(--tg-reply); background: color-mix(in srgb, var(--tg-reply) 10%, transparent); border-radius: 4px 6px 6px 4px; padding: 3px 8px; margin: 2px 0 4px; cursor: pointer; display: flex; flex-direction: column; font-size: 13.5px; max-width: 100%; }
.tg-msg.out .tg-reply { --tg-reply: var(--tg-tick); }
.tg-reply b { color: var(--tg-reply); font-weight: 600; }
.tg-reply span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: .85; }
.tg-text { font-size: 15px; line-height: 1.35; }
.tg-text a { color: var(--tg-link); }
.tg-text mark { background: #ffd966; color: #000; border-radius: 2px; }
.tg-meta { float: right; margin: 6px 0 -4px 10px; font-size: 11.5px; color: var(--tg-meta-in); display: inline-flex; gap: 3px; align-items: center; white-space: nowrap; user-select: none; }
.tg-msg.out .tg-meta { color: var(--tg-meta-out); }
.tg-ticks { color: var(--tg-meta-out); font-size: 12px; letter-spacing: -3px; padding-right: 3px; } .tg-ticks.read { color: var(--tg-tick); }
.tg-meta-row { display: flex; justify-content: flex-end; }
.tg-meta-row.over { position: absolute; right: 8px; bottom: 8px; }
.tg-meta-row.over .tg-meta { background: rgba(0, 0, 0, .4); color: #fff; padding: 1px 6px; border-radius: 10px; margin: 0; }
.tg-media { margin: -1px -5px 3px; border-radius: 12px; overflow: hidden; }
.tg-bubble.media-only { padding: 3px; }
.tg-bubble.media-only .tg-media { margin: 0; }
.tg-img { display: block; max-width: 100%; max-height: 360px; min-width: 120px; object-fit: cover; cursor: zoom-in; background: rgba(0, 0, 0, .06); }
.tg-voice { display: flex; align-items: center; gap: 6px; padding: 2px 0; }
.tg-voice-icon { width: 36px; height: 36px; border-radius: 50%; background: var(--tg-active); color: #fff; display: grid; place-items: center; flex: none; }
.tg-voice audio { height: 36px; width: 230px; max-width: 100%; }
.tg-file { display: flex; gap: 10px; align-items: center; color: inherit; text-decoration: none; padding: 4px 2px; }
.tg-file-ic { width: 44px; height: 44px; border-radius: 50%; background: var(--tg-active); color: #fff; display: grid; place-items: center; font-size: 20px; flex: none; }
.tg-file-meta { display: flex; flex-direction: column; min-width: 0; }
.tg-file-meta b { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
.tg-file-meta small { color: var(--tg-sub); }
.tg-unsup { color: var(--tg-sub); font-size: 13px; font-style: italic; }
.tg-reacts { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.tg-react { display: inline-flex; gap: 3px; align-items: center; padding: 2px 8px; border-radius: 14px; background: color-mix(in srgb, var(--tg-active) 14%, transparent); font-size: 14px; transition: transform .12s; }
.tg-react:active { transform: scale(.9); }
.tg-react.mine { background: var(--tg-active); color: #fff; }
.tg-react small { font-size: 12px; font-weight: 600; }

.tg-ctx-pop { padding: 0; overflow: hidden; border-radius: 14px; }
.tg-ctx .menu { padding: 4px; }
.tg-reactbar { display: flex; gap: 2px; padding: 6px; border-bottom: 1px solid var(--border); }
.tg-reactbar button { font-size: 22px; width: 36px; height: 36px; border-radius: 50%; transition: transform .15s var(--ease-out), background .15s; }
.tg-reactbar button:hover { transform: scale(1.25); background: var(--bg-hover); }

.tg-fab { position: absolute; right: 18px; bottom: 14px; z-index: 4; width: 46px; height: 46px; border-radius: 50%; background: var(--tg-side); color: var(--tg-sub); font-size: 22px; box-shadow: 0 2px 8px rgba(0, 0, 0, .2); opacity: 0; transform: translateY(20px) scale(.8); pointer-events: none; transition: opacity .2s, transform .25s var(--ease-out); }
.tg-fab.show { opacity: 1; transform: none; pointer-events: auto; }
.tg-fab-count:not(:empty) { position: absolute; top: -6px; right: -4px; background: var(--tg-badge); color: #fff; font-size: 11px; border-radius: 10px; padding: 1px 6px; }

.tg-composer-wrap { z-index: 2; padding: 6px max(10px, calc((100% - 780px) / 2)) calc(10px + var(--safe-b)); }
.tg-replybar { display: flex; align-items: center; gap: 10px; background: var(--tg-side); border-radius: 14px 14px 0 0; padding: 7px 10px; margin: 0 56px 0 0; animation: slideUp .2s var(--ease-out); }
@keyframes slideUp { from { opacity: 0; transform: translateY(10px); } }
.tg-rb-ic { color: var(--tg-active); font-size: 20px; }
.tg-rb-text { flex: 1; min-width: 0; display: flex; flex-direction: column; border-left: 2px solid var(--tg-active); padding-left: 8px; font-size: 13.5px; }
.tg-rb-text b { color: var(--tg-active); } .tg-rb-text span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--tg-sub); }
.tg-attach-row { display: flex; gap: 8px; overflow-x: auto; background: var(--tg-side); padding: 8px 10px; margin-right: 56px; border-radius: 14px 14px 0 0; }
.tg-replybar + .tg-attach-row { border-radius: 0; }
.tg-attach { position: relative; flex: none; width: 72px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; }
.tg-attach img, .tg-attach-ic { width: 64px; height: 64px; border-radius: 10px; object-fit: cover; background: var(--tg-hover); display: grid; place-items: center; font-size: 26px; }
.tg-attach-name { max-width: 70px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--tg-sub); }
.tg-attach-x { position: absolute; top: -4px; right: 0; width: 20px; height: 20px; border-radius: 50%; background: rgba(0, 0, 0, .6); color: #fff; font-size: 11px; }
.tg-composer { display: flex; align-items: flex-end; gap: 8px; }
.tg-inputbox { flex: 1; display: flex; align-items: flex-end; gap: 2px; background: var(--tg-side); border-radius: 18px; padding: 4px 6px; box-shadow: 0 1px 2px rgba(16, 35, 47, .15); min-height: 48px; }
.tg-replybar ~ .tg-composer .tg-inputbox, .tg-attach-row ~ .tg-composer .tg-inputbox { border-top-left-radius: 0; border-top-right-radius: 0; }
.tg-inputbox .icon-btn { width: 38px; height: 38px; font-size: 21px; color: var(--tg-sub); }
.tg-input { flex: 1; border: 0; resize: none; background: transparent; font-size: 16px; line-height: 1.35; padding: 9px 4px; max-height: 160px; outline: none; color: var(--tg-text); }
.tg-send, .tg-mic { width: 48px; height: 48px; flex: none; border-radius: 50%; display: grid; place-items: center; font-size: 20px; box-shadow: 0 1px 2px rgba(16, 35, 47, .2); transition: transform .2s var(--ease-out), opacity .2s; }
.tg-send { background: var(--tg-active); color: #fff; }
.tg-mic { background: var(--tg-side); color: var(--tg-sub); }
.tg-send.hide, .tg-mic.hide { display: none; }
.tg-send:active, .tg-mic:active { transform: scale(.9); }
.tg-composer.recording { background: var(--tg-side); border-radius: 18px; padding: 6px 6px 6px 16px; align-items: center; gap: 10px; box-shadow: 0 1px 2px rgba(16, 35, 47, .15); }
.tg-rec-time { font-variant-numeric: tabular-nums; font-weight: 600; }
.tg-rec-hint { flex: 1; color: var(--tg-sub); font-size: 14px; }
.tg-emoji-pop { padding: 6px; }
.tg-emoji { display: grid; grid-template-columns: repeat(9, 34px); gap: 2px; max-height: 260px; overflow-y: auto; }
.tg-emoji button { font-size: 22px; height: 34px; border-radius: 8px; }
.tg-emoji button:hover { background: var(--bg-hover); }
.tg-shared-pop { width: min(380px, 92vw); max-height: 70vh; overflow-y: auto; padding: 10px 12px; }
.tg-shared h3 { font-size: 13px; margin: 6px 0; color: var(--muted); }
.tg-shared-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; }
.tg-shared-grid img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 4px; cursor: zoom-in; }
.tg-shared-file { font-size: 13px; padding: 4px 0; border-bottom: 1px solid var(--border); }

.img-viewer { position: fixed; inset: 0; z-index: 130; background: rgba(0, 0, 0, .9); display: flex; align-items: center; justify-content: center; opacity: 0; transition: opacity .2s; }
.img-viewer.open { opacity: 1; }
.img-viewer > img { max-width: 92vw; max-height: 84vh; border-radius: 4px; transform: scale(.95); transition: transform .3s var(--ease-out); }
.img-viewer.open > img { transform: none; }
.iv-bar { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 8px; padding: calc(10px + env(safe-area-inset-top)) 14px 10px; color: #fff; }
.iv-btn { color: #fff; font-size: 20px; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; text-decoration: none; }
.iv-btn:hover { background: rgba(255, 255, 255, .12); }
.iv-nav { position: absolute; top: 50%; transform: translateY(-50%); color: #fff; font-size: 44px; width: 56px; height: 80px; }
.iv-nav.prev { left: 6px; } .iv-nav.next { right: 6px; }
.iv-count { font-size: 14px; opacity: .8; }

@media (max-width: 760px) {
  .tg { position: relative; overflow: hidden; }
  .tg-side { width: 100%; border-right: 0; }
  .tg-thread { position: absolute; inset: 0; z-index: 5; transform: translateX(100%); transition: transform .32s var(--ease-out); }
  body.reader-open .tg-thread { transform: none; }
  .tg-bubble { max-width: 86%; }
  .tg-replybar, .tg-attach-row { margin-right: 56px; }
  .tg-emoji { grid-template-columns: repeat(8, 36px); }
  .tg-msgs { padding: 8px 8px 6px; }
}

/* ---------- storage browser ---------- */
.view-cloud { overflow-y: auto; }
.st-page { max-width: 1180px; margin: 0 auto; padding: 18px 22px 90px; min-height: 100%; position: relative; }
.st-page.drop::after { content: '⬆ Thả tệp để tải lên'; position: fixed; inset: 60px 20px 20px; border: 3px dashed var(--accent); border-radius: 18px; display: grid; place-items: center; font-size: 22px; font-weight: 600; color: var(--accent); background: color-mix(in srgb, var(--bg) 85%, transparent); z-index: 30; }
.st-head { display: flex; align-items: flex-end; gap: 20px; flex-wrap: wrap; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.st-head h1 { margin: 0 0 10px; font-size: 26px; }
.st-tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.st-tab { position: relative; display: flex; align-items: center; gap: 7px; padding: 10px 14px; font-weight: 500; color: var(--muted); white-space: nowrap; border-radius: 8px 8px 0 0; }
.st-tab:hover { background: var(--bg-hover); color: var(--text); }
.st-tab.active { color: var(--text); }
.st-tab.active::after { content: ''; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 3px; border-radius: 3px 3px 0 0; background: var(--accent); animation: tabIn .25s var(--ease-out); }
.st-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); } .st-dot.ok { background: #16a34a; }
.st-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.st-crumbs { display: flex; align-items: center; gap: 2px; min-width: 0; flex-wrap: wrap; }
.st-crumb { padding: 4px 8px; border-radius: 6px; font-weight: 500; } .st-crumb:hover { background: var(--bg-hover); }
.st-crumbs .sep { color: var(--faint); }
.st-search { border: 1px solid var(--border); background: var(--bg-side); border-radius: 8px; padding: 6px 10px; width: 180px; font-size: 14px; }
.st-toggle { padding: 5px 10px; border-radius: 8px; border: 1px solid var(--border); font-size: 13px; color: var(--muted); }
.st-toggle.on { background: color-mix(in srgb, var(--accent) 14%, transparent); border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); color: var(--text); }
.st-note { font-size: 13px; color: var(--muted); background: var(--bg-hover); border-radius: 8px; padding: 8px 12px; margin-bottom: 12px; }
.st-uploading { font-size: 13.5px; background: color-mix(in srgb, var(--accent) 12%, transparent); border-radius: 8px; padding: 8px 12px; margin-bottom: 12px; animation: pulse 1.4s infinite; }
.st-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.st-card { position: relative; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--bg-elev); cursor: pointer; transition: transform .15s var(--ease), box-shadow .2s, border-color .2s; animation: viewIn .3s var(--ease-out) both; outline: none; }
.st-card:hover, .st-card:focus-visible { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0, 0, 0, .08); border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); }
.st-card.sk { height: 190px; animation: shimmer 1.2s infinite; background: var(--bg-hover); }
.st-prev { position: relative; aspect-ratio: 4 / 3; background: var(--bg-side); display: grid; place-items: center; overflow: hidden; }
.st-prev img { width: 100%; height: 100%; object-fit: cover; transition: filter .35s, transform .35s; }
.st-card:hover .st-prev img { transform: scale(1.03); }
.st-ic { font-size: 44px; }
.st-prev.k-folder { background: color-mix(in srgb, #f59e0b 12%, var(--bg-side)); }
.st-card.blurred .st-prev img { filter: blur(22px) saturate(.6); transform: scale(1.15); }
.st-card.blurred .st-prev .st-ic { filter: blur(6px); }
.st-veil { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-align: center; color: #fff; background: rgba(20, 20, 24, .38); padding: 8px; }
.st-veil-ic { font-size: 22px; }
.st-veil b { font-size: 13.5px; } .st-veil small { font-size: 11.5px; opacity: .85; }
.st-info { display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto auto; padding: 8px 6px 8px 10px; column-gap: 4px; }
.st-name { font-size: 13.5px; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.st-meta { font-size: 12px; color: var(--muted); grid-row: 2; }
.st-more { grid-row: 1 / span 2; grid-column: 2; align-self: center; opacity: .5; } .st-card:hover .st-more { opacity: 1; }
.st-list { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.st-list .st-card { display: flex; align-items: center; border: 0; border-bottom: 1px solid var(--border); border-radius: 0; animation-duration: .2s; }
.st-list .st-card:hover { transform: none; box-shadow: none; background: var(--bg-hover); }
.st-list .st-prev { width: 52px; height: 52px; aspect-ratio: auto; flex: none; margin: 6px; border-radius: 8px; }
.st-list .st-ic { font-size: 24px; }
.st-list .st-veil b, .st-list .st-veil small { display: none; }
.st-list .st-info { flex: 1; min-width: 0; }
@media (max-width: 760px) {
  .st-page { padding: 12px 12px 90px; }
  .st-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .st-search { width: 100%; order: 10; }
  .st-head h1 { font-size: 22px; }
}

/* ---------- calendar v3 ---------- */
:root { --shade: rgba(55, 53, 47, .035); --hol: #dc2626; }
:root[data-theme="dark"] { --shade: rgba(0, 0, 0, .22); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --shade: rgba(0, 0, 0, .22); } }
.cal-wrap { flex: 1; display: flex; min-height: 0; }
.cal-main { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 0; }
.cal-title { display: flex; flex-direction: column; line-height: 1.15; }
.cal-sub { font-size: 12px; font-weight: 500; color: var(--muted); }
.icon-btn.active { background: var(--bg-active); color: var(--text); }
.qa-wrap { position: relative; flex: 0 1 380px; min-width: 160px; }
.qa-input { width: 100%; border: 1px solid var(--border); background: var(--bg-side); border-radius: 8px; padding: 6px 10px; font-size: 13.5px; transition: border-color .15s, box-shadow .15s; }
.qa-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); background: var(--bg); }
.qa-hint { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 10; font-size: 12.5px; background: var(--bg-elev); box-shadow: var(--shadow); border-radius: 8px; padding: 6px 10px; opacity: 0; transform: translateY(-4px); pointer-events: none; transition: opacity .15s, transform .15s; }
.qa-hint.show { opacity: 1; transform: none; }
.zoom { display: flex; gap: 2px; }

.cal-side { width: 236px; flex: none; border-right: 1px solid var(--border); padding: 4px 12px 16px; overflow-y: auto; animation: fadeDown .25s var(--ease-out); }
.mini-head { display: flex; align-items: center; gap: 2px; padding: 4px 0 6px; font-size: 14px; }
.mini-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; text-align: center; }
.mini-dow { font-size: 10.5px; color: var(--faint); padding: 2px 0; }
.mini-day { position: relative; font-size: 12px; height: 28px; border-radius: 50%; aspect-ratio: 1; margin: auto; width: 28px; display: grid; place-items: center; }
.mini-day:hover { background: var(--bg-hover); }
.mini-day.other { color: var(--faint); }
.mini-day.range { background: color-mix(in srgb, var(--accent) 12%, transparent); border-radius: 6px; }
.mini-day.sel { background: var(--accent); color: #fff; }
.mini-day.today:not(.sel) { color: var(--today); font-weight: 700; }
.mini-day.busy::after { content: ''; position: absolute; bottom: 2px; width: 4px; height: 4px; border-radius: 50%; background: var(--accent); }
.mini-day.sel.busy::after { background: #fff; }
.lunar-card { display: flex; gap: 10px; align-items: center; margin: 14px 0 6px; padding: 10px; border-radius: 10px; background: linear-gradient(135deg, color-mix(in srgb, #ef4444 12%, transparent), color-mix(in srgb, #f59e0b 12%, transparent)); }
.lc-day { font-size: 32px; font-weight: 800; color: #dc2626; min-width: 40px; text-align: center; }
.lunar-card > div:last-child { display: flex; flex-direction: column; font-size: 13px; }
.lunar-card small { color: var(--muted); } .lc-hol { color: var(--hol) !important; font-weight: 600; }
.side-title { font-size: 12px; font-weight: 600; color: var(--faint); margin: 16px 0 6px; }
.cat-list { display: flex; flex-direction: column; gap: 2px; }
.cat-item { display: flex; align-items: center; gap: 8px; font-size: 13.5px; padding: 3px 4px; border-radius: 6px; cursor: pointer; }
.cat-item:hover { background: var(--bg-hover); }
.cat-dot { width: 10px; height: 10px; border-radius: 3px; }

.month-dow.wkend { color: var(--hol); }
.month-cell.wkend:not(.other) { background: color-mix(in srgb, var(--bg-side) 55%, transparent); }
.month-cell.holiday .month-num { color: var(--hol); font-weight: 700; }
.month-cell.today .month-num { color: #fff; }
.mc-head { display: flex; align-items: center; gap: 4px; min-height: 22px; }
.mc-hol { flex: 1; font-size: 10.5px; font-weight: 600; color: var(--hol); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mc-lunar { font-size: 10.5px; color: var(--faint); font-variant-numeric: tabular-nums; }
.mc-lunar.strong { color: var(--hol); font-weight: 600; }
.month-cell .month-num { align-self: auto; }
.m-item.past { opacity: .55; }
.month-grid { grid-template-rows: auto repeat(6, minmax(96px, 1fr)); }

.wk-lunar { font-size: 10.5px; color: var(--faint); margin-top: 1px; }
.wk-lunar.strong { color: var(--hol); font-weight: 600; }
.wk-day.wkend .dow { color: var(--hol); }
.wk-col.wkend { background-color: color-mix(in srgb, var(--bg-side) 50%, transparent); }
.wk-col.workhours { background-image: repeating-linear-gradient(to bottom, var(--grid) 0 1px, transparent 1px var(--hour, 48px)), linear-gradient(to bottom, var(--shade) calc(var(--hour, 48px) * 8), transparent calc(var(--hour, 48px) * 8), transparent calc(var(--hour, 48px) * 18), var(--shade) calc(var(--hour, 48px) * 18)); }
.ad-item.hol { background: color-mix(in srgb, var(--hol) 10%, transparent); color: var(--hol); font-weight: 600; cursor: default; }
.now-time { position: absolute; left: -48px; top: -9px; font-size: 10.5px; font-weight: 700; color: #fff; background: var(--today); border-radius: 8px; padding: 1px 5px; display: none; }
.ev-block.past { opacity: .6; }
.ev-block.free { background: repeating-linear-gradient(45deg, color-mix(in srgb, var(--c) 14%, var(--bg)) 0 6px, color-mix(in srgb, var(--c) 6%, var(--bg)) 6px 12px); }
.ev-b-loc { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.agenda { flex: 1; overflow-y: auto; padding: 8px 20px 60px; max-width: 900px; width: 100%; margin: 0 auto; }
.ag-day { display: flex; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--border); animation: viewIn .3s var(--ease-out) both; }
.ag-date { width: 78px; flex: none; display: flex; flex-direction: column; align-items: center; padding-top: 2px; }
.ag-num { font-size: 26px; font-weight: 700; line-height: 1; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; }
.ag-day.today .ag-num { background: var(--today); color: #fff; }
.ag-dow { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.ag-lunar { font-size: 11px; color: var(--faint); }
.ag-items { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.ag-item { display: flex; align-items: center; gap: 10px; text-align: left; padding: 7px 10px; border-radius: 8px; width: 100%; }
.ag-item:hover { background: var(--bg-hover); }
.ag-item.past { opacity: .55; }
.ag-time { width: 96px; flex: none; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.ag-bar { width: 4px; align-self: stretch; border-radius: 2px; background: var(--c, var(--faint)); flex: none; }
.ag-title { display: flex; flex-direction: column; min-width: 0; }
.ag-title b { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ag-title small { color: var(--muted); font-size: 12px; }
.ag-hol { font-size: 13px; color: var(--hol); font-weight: 600; padding: 4px 10px; }
.ag-empty { font-size: 13px; color: var(--faint); padding: 8px 10px; }

.peek-pop { width: min(380px, calc(100vw - 16px)); padding: 0; overflow: hidden; border-radius: 12px; }
.peek { display: flex; flex-direction: column; }
.peek-top { display: flex; gap: 10px; padding: 14px 12px 10px 14px; align-items: flex-start; }
.peek-color { width: 14px; height: 14px; border-radius: 4px; background: var(--c); margin-top: 4px; flex: none; }
.peek-title { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.peek-title b { font-size: 17px; line-height: 1.3; }
.peek-title small { font-size: 13px; }
.peek-row { display: flex; gap: 10px; align-items: center; padding: 4px 14px; font-size: 13.5px; }
.peek-row a { color: var(--accent); overflow: hidden; text-overflow: ellipsis; }
.peek-row a.btn { color: #fff; }
.peek-desc { margin: 6px 14px; padding: 8px 10px; background: var(--bg-hover); border-radius: 8px; font-size: 13px; white-space: pre-wrap; max-height: 140px; overflow-y: auto; }
.peek-actions { display: flex; gap: 6px; padding: 10px 14px 12px; border-top: 1px solid var(--border); margin-top: 6px; flex-wrap: wrap; }

.event-modal { max-width: 620px; }
.ev-field { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.ev-field > input, .ev-field > select, .ev-field > textarea, .ev-line > input:not([type=checkbox]):not([type=date]):not([type=time]) { width: 100%; }
.ev-line > input[placeholder] { flex: 1; min-width: 0; }
.lunar-hint { font-size: 12px; }
.rc-box:empty { display: none; }
.rc-box { display: flex; flex-direction: column; gap: 8px; padding: 10px; border-radius: 8px; background: var(--bg-hover); }
.rc-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 14px; }
.modal input.rc-num { width: 64px; }
.rc-days { display: flex; gap: 4px; flex-wrap: wrap; }
.rc-day { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border); font-size: 12.5px; font-weight: 600; background: var(--bg); }
.rc-day.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 4px 3px 10px; border-radius: 14px; background: var(--bg-hover); font-size: 13px; animation: pop .2s var(--ease-out); }
.chip button { width: 18px; height: 18px; border-radius: 50%; font-size: 10px; color: var(--muted); }
.chip button:hover { background: var(--bg-active); color: var(--text); }
.modal select.chip-add { border-style: dashed; font-size: 13px; padding: 4px 8px; color: var(--muted); }
.modal input.chip-input { flex: 1; min-width: 180px; border: 0; background: transparent; padding: 4px 2px; }
.modal input.chip-input:focus { outline: none; }
.scope { display: flex; flex-direction: column; gap: 6px; }
.scope h3 { margin: 0 0 6px; }
.scope-opt { text-align: left; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; }
.scope-opt:hover { background: var(--bg-hover); border-color: var(--accent); }
.fab-add { position: fixed; right: 18px; bottom: calc(72px + var(--safe-b)); z-index: 35; width: 56px; height: 56px; border-radius: 18px; background: var(--accent); color: #fff; font-size: 28px; box-shadow: 0 6px 18px rgba(35, 131, 226, .45); transition: transform .2s var(--ease-out); }
.fab-add:active { transform: scale(.92); }

@media (max-width: 760px) {
  .qa-wrap { order: 20; flex: 1 1 100%; }
  .zoom { display: none; }
  .cal-toolbar .segmented .seg { padding: 3px 8px; }
  .month-grid { grid-template-rows: auto repeat(6, minmax(70px, 1fr)); }
  .mc-lunar { font-size: 9px; }
  .month-cell.has-items .month-items .m-item { font-size: 10.5px; }
  .agenda { padding: 4px 10px 100px; }
  .ag-date { width: 54px; }
  .ag-time { width: 70px; font-size: 12px; }
  .ag-day { gap: 8px; }
}

/* =====================================================================
   v4 design system — modern refresh
   ===================================================================== */
:root {
  --bg: #ffffff; --bg-side: #f7f7f9; --bg-elev: #ffffff; --bg-hover: rgba(17, 24, 39, .05); --bg-active: rgba(99, 91, 255, .1);
  --text: #1d1f24; --muted: #6b7280; --faint: #9ca3af; --border: #ebebef; --grid: #f0f0f3;
  --accent: #635bff; --accent-2: #8b5cf6; --accent-soft: rgba(99, 91, 255, .12); --accent-text: #fff;
  --callout: #f5f5f8; --code-bg: rgba(99, 91, 255, .08); --code-text: #5b45e0;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 10px 30px rgba(16, 24, 40, .1); --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06), 0 2px 8px rgba(16, 24, 40, .05);
  --radius: 10px; --sb-w: 268px;
  --font: 'Inter', ui-sans-serif, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg: #111215; --bg-side: #16171b; --bg-elev: #1c1d22; --bg-hover: rgba(255, 255, 255, .05); --bg-active: rgba(139, 131, 255, .18);
  --text: #ececf1; --muted: #9a9aa6; --faint: #6b6b76; --border: #26272d; --grid: #1f2025; --accent: #8b83ff; --accent-2: #a78bfa; --accent-soft: rgba(139, 131, 255, .16);
  --callout: #1d1e23; --code-bg: rgba(139, 131, 255, .14); --code-text: #b3adff; --shadow: 0 0 0 1px rgba(255, 255, 255, .06), 0 12px 32px rgba(0, 0, 0, .5); --shadow-sm: 0 0 0 1px rgba(255, 255, 255, .05);
} }
:root[data-theme="dark"] {
  --bg: #111215; --bg-side: #16171b; --bg-elev: #1c1d22; --bg-hover: rgba(255, 255, 255, .05); --bg-active: rgba(139, 131, 255, .18);
  --text: #ececf1; --muted: #9a9aa6; --faint: #6b6b76; --border: #26272d; --grid: #1f2025; --accent: #8b83ff; --accent-2: #a78bfa; --accent-soft: rgba(139, 131, 255, .16);
  --callout: #1d1e23; --code-bg: rgba(139, 131, 255, .14); --code-text: #b3adff; --shadow: 0 0 0 1px rgba(255, 255, 255, .06), 0 12px 32px rgba(0, 0, 0, .5); --shadow-sm: 0 0 0 1px rgba(255, 255, 255, .05);
}
body { font-family: var(--font); font-feature-settings: 'cv11', 'ss01'; letter-spacing: -.005em; }
.ic { flex: none; display: block; }
::selection { background: color-mix(in srgb, var(--accent) 25%, transparent); }
* { scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--muted) 35%, transparent) transparent; }

/* buttons */
.btn { border-radius: 9px; font-weight: 500; padding: 7px 14px; box-shadow: var(--shadow-sm); border-color: var(--border); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border-color: transparent; box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 35%, transparent); }
.btn.primary:hover { filter: brightness(1.06); transform: translateY(-1px); }
.btn.ghost { box-shadow: none; }
.icon-btn { border-radius: 8px; }
.icon-btn .ic { width: 18px; height: 18px; }
.link-btn { color: var(--accent); font-weight: 500; }

/* ---------- sidebar ---------- */
.sidebar { background: var(--bg-side); border-right: 1px solid var(--border); padding: 10px 10px 8px; gap: 2px; }
.sb-head { display: flex; align-items: center; gap: 4px; padding: 2px 0 8px; }
.sb-user { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 10px; text-align: left; }
.sb-user:hover { background: var(--bg-hover); }
.sb-avatar { width: 34px; height: 34px; border-radius: 10px; flex: none; display: grid; place-items: center; color: #fff; font-weight: 700; background: linear-gradient(135deg, hsl(var(--hue) 75% 62%), hsl(calc(var(--hue) + 45) 70% 52%)); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .25); }
.sb-user-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.sb-user-text b { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-user-text small { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-collapse { color: var(--faint); }
.sb-search { display: flex; align-items: center; gap: 8px; margin: 0 2px 8px; padding: 8px 10px; border-radius: 10px; background: var(--bg-elev); border: 1px solid var(--border); color: var(--muted); font-size: 14px; box-shadow: var(--shadow-sm); transition: border-color .15s, box-shadow .15s; }
.sb-search:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.sb-search kbd { margin-left: auto; font-size: 11px; border: 1px solid var(--border); border-radius: 5px; padding: 0 5px; }
.sb-nav { padding: 0; gap: 1px; }
.nav-item { gap: 10px; padding: 7px 10px; border-radius: 9px; color: var(--muted); font-size: 14px; font-weight: 500; position: relative; }
.nav-item .ni-icon { width: 20px; display: grid; place-items: center; }
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.ni-badge:empty { display: none; }
.ni-badge { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent); color: #fff; font-size: 11.5px; font-weight: 700; display: grid; place-items: center; animation: pop .25s var(--ease-out); }
.sb-scroll { flex: 1; overflow-y: auto; min-height: 0; margin: 8px -4px 0; padding: 0 4px; }
.sb-section { padding: 10px 0 0; }
.sb-section.grow { flex: none; }
.sb-title { padding: 0 10px 4px; font-size: 11.5px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--faint); }
.tree { overflow: visible; padding-bottom: 4px; }
.tree-row { height: 32px; border-radius: 8px; font-size: 14px; color: var(--muted); gap: 6px; }
.tree-row:hover { color: var(--text); }
.tree-row.active { background: var(--accent-soft); color: var(--text); font-weight: 600; }
.tree-row.fav { width: 100%; padding-left: 10px; text-align: left; }
.tw { width: 18px; height: 18px; color: var(--faint); }
.tw .ic { width: 14px; height: 14px; }
.tr-icon { display: grid; place-items: center; color: var(--faint); }
.sb-new { display: flex; align-items: center; gap: 8px; width: 100%; padding: 6px 10px; border-radius: 8px; color: var(--faint); font-size: 13.5px; }
.sb-new:hover { background: var(--bg-hover); color: var(--text); }
.sb-foot { border-top: 1px solid var(--border); padding: 6px 0 0; margin-top: 6px; display: flex; flex-direction: column; gap: 1px; }
.sb-foot .nav-item { padding: 6px 10px; font-size: 13.5px; }
.sync-status { border-radius: 9px; }
body.sb-collapsed .sidebar { margin-left: calc(-1 * var(--sb-w) - 20px); }

/* ---------- top bar ---------- */
.topbar { height: 50px; padding: 0 14px; border-bottom: 1px solid transparent; background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: saturate(1.6) blur(12px); -webkit-backdrop-filter: saturate(1.6) blur(12px); position: relative; z-index: 5; }
.crumb { font-weight: 500; border-radius: 7px; padding: 4px 8px; }
.fav-btn.on { color: #f5a524; }
.fav-btn.on .ic { fill: #f5a524; }

/* ---------- page editor ---------- */
.page-view { max-width: 820px; padding: 56px 64px 30vh; }
.page-view.full { max-width: none; padding-left: 96px; padding-right: 96px; }
.page-view.small-text { font-size: 14px; }
.page-view.font-serif { font-family: 'Iowan Old Style', 'Palatino Linotype', Georgia, 'Times New Roman', serif; }
.page-view.font-mono { font-family: var(--mono); font-size: 14px; }
.page-view.has-cover { padding-top: 0; }
.page-cover { position: relative; height: min(32vh, 260px); background: center / cover no-repeat var(--bg-side); animation: fadeIn .35s ease; }
@keyframes fadeIn { from { opacity: 0; } }
.cover-tools { position: absolute; right: 20px; bottom: 14px; display: flex; gap: 6px; opacity: 0; transition: opacity .15s; }
.page-cover:hover .cover-tools { opacity: 1; }
.pt-btn { display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; color: var(--muted); padding: 4px 10px; border-radius: 7px; }
.pt-btn:hover { background: var(--bg-hover); color: var(--text); }
.pt-btn.glass { background: rgba(255, 255, 255, .85); color: #333; backdrop-filter: blur(8px); box-shadow: 0 2px 8px rgba(0, 0, 0, .15); }
.page-tools { display: flex; gap: 4px; margin: 0 0 4px -8px; opacity: 0; transition: opacity .15s; min-height: 30px; }
.page-head:hover .page-tools, .page-tools:focus-within { opacity: 1; }
.page-view.has-cover .page-icon { margin-top: -52px; position: relative; z-index: 2; }
.page-icon { font-size: 76px; line-height: 1; padding: 4px; border-radius: 14px; }
.page-view.has-cover .page-icon { text-shadow: 0 6px 20px rgba(0, 0, 0, .18); }
.page-title { font-size: 44px; font-weight: 800; letter-spacing: -.025em; line-height: 1.15; margin: 4px 0 14px; }
.page-props { border-bottom: 1px solid var(--border); padding-bottom: 14px; margin-bottom: 18px; }
.prop-label { color: var(--faint); font-weight: 500; }
.block { margin: 2px 0; }
.content { line-height: 1.65; padding: 3px 2px; }
.type-h1 .content { font-size: 1.9em; font-weight: 750; letter-spacing: -.02em; }
.type-h2 .content { font-size: 1.45em; font-weight: 700; letter-spacing: -.015em; }
.type-h3 .content { font-size: 1.2em; font-weight: 650; }
.type-quote .content { border-left: 3px solid var(--accent); color: color-mix(in srgb, var(--text) 85%, var(--muted)); font-style: italic; }
.type-callout { background: var(--callout); border: 1px solid var(--border); border-radius: 12px; }
.type-code .content { border-radius: 12px; border: 1px solid var(--border); }
.todo-cb { accent-color: var(--accent); width: 17px; height: 17px; border-radius: 5px; }
.add-btn { position: absolute; left: calc(var(--indent, 0) * 26px - 50px); top: 3px; width: 22px; height: 24px; display: grid; place-items: center; color: var(--faint); border-radius: 6px; opacity: 0; transition: opacity .12s, background .12s; }
.add-btn:hover { background: var(--bg-hover); color: var(--text); }
.block:hover .add-btn { opacity: 1; }
.type-callout .add-btn { left: -50px; }
.cover-popover { width: 320px; padding: 12px; }
.cover-pop { display: flex; flex-direction: column; gap: 10px; }
.cover-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.cover-swatch { height: 48px; border-radius: 9px; background-size: cover; transition: transform .15s; }
.cover-swatch:hover { transform: scale(1.06); }
.slash-icon { border-radius: 9px; background: var(--bg-elev); box-shadow: var(--shadow-sm); }
.slash-item.active { background: var(--accent-soft); }
.popover { border-radius: 12px; box-shadow: var(--shadow); border: 1px solid var(--border); }
.menu-item { border-radius: 7px; }
.modal { border-radius: 16px; border: 1px solid var(--border); }
.mobile-bar { display: none; }

/* ---------- home ---------- */
.view-home { overflow-y: auto; }
.home { max-width: 1120px; margin: 0 auto; padding: 28px 28px 100px; }
.home-hero { position: relative; border-radius: 20px; padding: 28px 28px 22px; color: #fff; overflow: hidden; background: radial-gradient(120% 140% at 0% 0%, #7c6cff 0%, #5b45e0 45%, #2e1f8f 100%); box-shadow: 0 18px 40px rgba(91, 69, 224, .28); animation: viewIn .4s var(--ease-out) both; }
.home-hero::after { content: ''; position: absolute; right: -60px; top: -80px; width: 320px; height: 320px; border-radius: 50%; background: radial-gradient(circle, rgba(255, 255, 255, .22), transparent 65%); pointer-events: none; }
.home-hero h1 { margin: 0 0 4px; font-size: 30px; font-weight: 800; letter-spacing: -.02em; }
.home-hero p { margin: 0; opacity: .85; font-size: 14px; }
.hh-hol { font-weight: 600; }
.home-qa-wrap { position: relative; margin-top: 18px; max-width: 640px; }
.home-qa-wrap .qa-ic { position: absolute; left: 14px; top: 13px; color: #6d5efc; }
.home-qa { width: 100%; border: 0; border-radius: 14px; padding: 13px 16px 13px 42px; font-size: 15px; background: rgba(255, 255, 255, .96); color: #1d1f24; box-shadow: 0 6px 20px rgba(0, 0, 0, .15); }
.home-qa:focus { outline: 3px solid rgba(255, 255, 255, .45); }
.home-qa-hint { font-size: 13px; margin-top: 6px; opacity: .9; min-height: 18px; }
.home-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.ha-btn { display: inline-flex; align-items: center; gap: 7px; padding: 8px 14px; border-radius: 11px; background: rgba(255, 255, 255, .16); color: #fff; font-weight: 500; font-size: 14px; backdrop-filter: blur(6px); transition: background .15s, transform .12s; }
.ha-btn:hover { background: rgba(255, 255, 255, .26); transform: translateY(-1px); }
.home-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 20px; }
.home-card { background: var(--bg-elev); border: 1px solid var(--border); border-radius: 16px; padding: 14px 16px 12px; box-shadow: var(--shadow-sm); animation: viewIn .4s var(--ease-out) both; min-width: 0; }
.home-card:nth-child(2) { animation-delay: .05s; } .home-card:nth-child(3) { animation-delay: .1s; } .home-card:nth-child(4) { animation-delay: .15s; }
.hc-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.hc-ic { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.hc-head b { font-size: 15px; }
.hc-count { font-size: 12px; font-weight: 700; background: var(--accent-soft); color: var(--accent); border-radius: 10px; padding: 1px 8px; }
.hc-list { display: flex; flex-direction: column; gap: 2px; }
.hc-empty { color: var(--muted); font-size: 14px; padding: 14px 4px; }
.hc-ev, .hc-chat { display: flex; align-items: center; gap: 10px; padding: 8px 6px; border-radius: 10px; text-align: left; width: 100%; }
.hc-ev:hover, .hc-chat:hover { background: var(--bg-hover); }
.hc-ev.live { background: color-mix(in srgb, var(--c) 10%, transparent); }
.hc-time { width: 46px; flex: none; display: flex; flex-direction: column; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.hc-time small { color: var(--faint); font-weight: 500; }
.hc-date { width: 36px; flex: none; display: flex; flex-direction: column; align-items: center; line-height: 1.1; }
.hc-date b { font-size: 18px; } .hc-date small { font-size: 11px; color: var(--muted); }
.hc-bar { width: 4px; align-self: stretch; border-radius: 3px; background: var(--c); flex: none; min-height: 28px; }
.hc-ev-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.hc-ev-text b { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hc-ev-text small { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hc-todo { display: flex; align-items: center; gap: 10px; padding: 7px 6px; border-radius: 9px; cursor: pointer; }
.hc-todo:hover { background: var(--bg-hover); }
.hc-todo .todo-cb { margin: 0; }
.hc-todo-text { flex: 1; min-width: 0; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hc-todo-page { font-size: 12px; color: var(--muted); max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border-radius: 6px; padding: 2px 6px; }
.hc-todo-page:hover { background: var(--bg-active); color: var(--text); }
.home-h2 { font-size: 16px; margin: 28px 0 12px; font-weight: 700; }
.hc-notes { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.hc-note { position: relative; display: flex; flex-direction: column; gap: 4px; text-align: left; padding: 0 14px 12px; border-radius: 14px; border: 1px solid var(--border); background: var(--bg-elev); overflow: hidden; min-height: 150px; box-shadow: var(--shadow-sm); transition: transform .15s var(--ease), box-shadow .2s, border-color .2s; }
.hc-note:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: color-mix(in srgb, var(--accent) 30%, var(--border)); }
.hc-note-cover { height: 54px; margin: 0 -14px; background: var(--bg-side) center / cover; }
.hc-note-icon { font-size: 26px; margin-top: -16px; line-height: 1; }
.hc-note b { font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hc-note small { font-size: 12.5px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.hc-note-time { margin-top: auto; font-size: 11.5px; color: var(--faint); }
.hc-note.new { align-items: center; justify-content: center; color: var(--muted); border-style: dashed; background: transparent; box-shadow: none; padding-top: 12px; }
.hc-tpls { display: flex; flex-wrap: wrap; gap: 8px; }
.hc-tpl { display: inline-flex; align-items: center; gap: 8px; padding: 9px 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--bg-elev); font-weight: 500; font-size: 14px; box-shadow: var(--shadow-sm); }
.hc-tpl:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- media gallery ---------- */
.media-gallery { position: fixed; inset: 0; z-index: 140; background: rgba(8, 8, 12, .94); display: flex; flex-direction: column; opacity: 0; transition: opacity .2s; color: #fff; }
.media-gallery.open { opacity: 1; }
.mg-bar { display: flex; align-items: center; gap: 8px; padding: calc(10px + env(safe-area-inset-top)) 14px 8px; }
.mg-info { display: flex; gap: 10px; align-items: baseline; min-width: 0; }
.mg-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mg-count { font-size: 13px; opacity: .7; }
.mg-btn { color: #fff; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-size: 18px; text-decoration: none; }
.mg-btn:hover { background: rgba(255, 255, 255, .12); }
.mg-stage { flex: 1; min-height: 0; position: relative; display: flex; align-items: center; justify-content: center; overflow: hidden; padding: 8px 64px; }
.mg-media { max-width: 100%; max-height: 100%; border-radius: 6px; animation: mgIn .3s var(--ease-out); }
.mg-media.img { cursor: zoom-in; transition: transform .2s ease; touch-action: none; user-select: none; }
.mg-media.img.zoomed { cursor: grab; transition: none; }
.mg-media.from-right { animation-name: mgRight; } .mg-media.from-left { animation-name: mgLeft; }
@keyframes mgIn { from { opacity: 0; transform: scale(.96); } }
@keyframes mgRight { from { opacity: 0; transform: translateX(40px); } }
@keyframes mgLeft { from { opacity: 0; transform: translateX(-40px); } }
video.mg-media { width: min(100%, 1100px); background: #000; }
.mg-speed { position: absolute; right: 74px; top: 14px; background: rgba(0, 0, 0, .55); color: #fff; border: 1px solid rgba(255, 255, 255, .25); border-radius: 8px; padding: 3px 6px; }
.mg-audio { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.mg-audio-ic { font-size: 64px; } .mg-audio audio { width: min(420px, 80vw); }
.mg-pdf { width: min(1000px, 100%); height: 100%; border: 0; border-radius: 8px; background: #fff; }
.mg-spin { position: absolute; width: 34px; height: 34px; border: 3px solid rgba(255, 255, 255, .2); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
.mg-nav { position: absolute; top: 50%; transform: translateY(-50%); z-index: 2; width: 52px; height: 52px; border-radius: 50%; color: #fff; font-size: 34px; background: rgba(255, 255, 255, .08); }
.mg-nav:hover { background: rgba(255, 255, 255, .18); }
.mg-nav.prev { left: 10px; } .mg-nav.next { right: 10px; }
.mg-strip { display: flex; gap: 6px; padding: 8px 14px calc(12px + env(safe-area-inset-bottom)); overflow-x: auto; justify-content: safe center; }
.mg-strip:empty { display: none; }
.mg-thumb { position: relative; flex: none; width: 56px; height: 56px; border-radius: 8px; overflow: hidden; opacity: .5; border: 2px solid transparent; background: rgba(255, 255, 255, .08); color: #fff; transition: opacity .15s; }
.mg-thumb img { width: 100%; height: 100%; object-fit: cover; }
.mg-thumb.active { opacity: 1; border-color: #fff; }
.mg-play { position: absolute; inset: 0; display: grid; place-items: center; font-size: 16px; text-shadow: 0 1px 4px #000; }

/* ---------- storage media ---------- */
.st-kinds { display: flex; gap: 4px; flex-wrap: wrap; }
.st-kind { padding: 5px 10px; border-radius: 16px; font-size: 13px; color: var(--muted); border: 1px solid var(--border); background: var(--bg-elev); }
.st-kind.on { background: var(--accent-soft); color: var(--accent); border-color: transparent; font-weight: 600; }
.st-prev video { width: 100%; height: 100%; object-fit: cover; background: #000; pointer-events: none; }
.st-play { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; background: rgba(0, 0, 0, .55); color: #fff; font-size: 17px; padding-left: 3px; backdrop-filter: blur(4px); transition: transform .2s var(--ease-out); pointer-events: none; }
.st-card:hover .st-play { transform: translate(-50%, -50%) scale(1.12); }
.st-card { border-radius: 14px; }

/* ---------- messenger additions ---------- */
:root { --tg-active: var(--accent); --tg-badge: var(--accent); --tg-link: var(--accent); --tg-reply: var(--accent); }
.tg-head-text small.typing, .tg-last.typing { color: var(--tg-active); font-style: italic; }
.tg-head-text small.online { color: #22c55e; }
.tg-draft { color: #e53935; }
.tg-badge.dot { min-width: 12px; width: 12px; height: 12px; padding: 0; }
.tg-muted-ic { font-size: 12px; }
.tg-pinbar:empty, .tg-selectbar:empty { display: none; }
.tg-pinbar { display: flex; align-items: center; gap: 6px; padding: 6px 12px; background: var(--tg-side); border-bottom: 1px solid var(--border); z-index: 2; animation: slideUp .2s var(--ease-out); }
.tg-pin-text { flex: 1; min-width: 0; display: flex; flex-direction: column; text-align: left; border-left: 2px solid var(--tg-active); padding-left: 8px; font-size: 13px; }
.tg-pin-text b { color: var(--tg-active); font-size: 12.5px; } .tg-pin-text span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tg-selectbar { display: flex; align-items: center; gap: 8px; padding: 6px 12px; background: var(--accent-soft); z-index: 2; }
.tg-msg { position: relative; flex-direction: row; gap: 6px; align-items: flex-end; }
.tg-msg.in { justify-content: flex-start; } .tg-msg.out { justify-content: flex-end; }
.tg-msg.selected { background: color-mix(in srgb, var(--accent) 12%, transparent); border-radius: 10px; }
.tg-check { position: absolute; left: 4px; bottom: 8px; width: 22px; height: 22px; border-radius: 50%; border: 2px solid #fff; background: rgba(0, 0, 0, .15); color: #fff; font-size: 13px; display: grid; place-items: center; z-index: 2; }
.tg-msg.selected .tg-check { background: var(--accent); border-color: var(--accent); }
.tg-msg:has(.tg-check).in { padding-left: 32px; }
.tg-av-space { width: 32px; flex: none; }
.tg-msg.grp .tg-avatar { margin-bottom: 1px; }
.tg-bubble { transition: transform .15s ease; }
.tg-msg.swipe-ready::before { content: '↩'; position: absolute; left: 6px; top: 50%; transform: translateY(-50%); color: var(--accent); font-size: 20px; }
.tg-unread-sep { align-self: stretch; text-align: center; margin: 10px -16px; background: color-mix(in srgb, var(--tg-side) 80%, transparent); padding: 4px 0; font-size: 13px; font-weight: 600; color: var(--tg-sub); }
.tg-fwd { font-size: 12.5px; color: var(--tg-active); font-weight: 500; }
.tg-media.video { position: relative; cursor: pointer; }
.tg-play { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 50px; height: 50px; border-radius: 50%; background: rgba(0, 0, 0, .5); color: #fff; display: grid; place-items: center; font-size: 18px; padding-left: 3px; pointer-events: none; backdrop-filter: blur(3px); }
.tg-play.sm { width: 30px; height: 30px; font-size: 11px; }
.voice-player { display: flex; align-items: center; gap: 8px; min-width: 230px; padding: 2px 0; }
.vp-btn { width: 40px; height: 40px; border-radius: 50%; background: var(--tg-active); color: #fff; font-size: 13px; flex: none; }
.tg-msg.out .vp-btn { background: var(--tg-tick); }
.vp-mid { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.vp-bar { -webkit-appearance: none; appearance: none; width: 100%; height: 4px; border-radius: 2px; background: linear-gradient(to right, var(--tg-active) var(--p, 0%), color-mix(in srgb, var(--tg-sub) 30%, transparent) var(--p, 0%)); }
.vp-bar::-webkit-slider-thumb { -webkit-appearance: none; width: 12px; height: 12px; border-radius: 50%; background: var(--tg-active); }
.vp-time { font-size: 11.5px; color: var(--tg-sub); font-variant-numeric: tabular-nums; }
.vp-speed { font-size: 11.5px; font-weight: 700; padding: 2px 6px; border-radius: 8px; background: color-mix(in srgb, var(--tg-sub) 15%, transparent); }
.voice-player audio { display: none; }
.tg-link { display: flex; gap: 8px; margin-top: 6px; border-left: 3px solid var(--tg-active); background: color-mix(in srgb, var(--tg-active) 8%, transparent); border-radius: 4px 8px 8px 4px; padding: 6px 8px; color: inherit; text-decoration: none; max-width: 420px; }
.tg-link:empty { display: none; }
.tg-link-text { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: 13px; }
.tg-link-text b { color: var(--tg-active); font-size: 12.5px; }
.tg-link-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tg-link-text small { color: var(--tg-sub); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tg-link-img { width: 64px; height: 64px; flex: none; border-radius: 6px; background: center / cover; }
.tg-react-more { font-size: 18px !important; color: var(--muted); }
.tg-fwd-pop { width: min(400px, calc(100vw - 16px)); padding: 10px; }
.tg-fwd { display: flex; flex-direction: column; gap: 8px; }
.tg-fwd-list, .tg-search-res { max-height: 50vh; overflow-y: auto; display: flex; flex-direction: column; }
.tg-searchbox { display: flex; flex-direction: column; gap: 8px; }
.tg-sr { text-align: left; padding: 8px; border-radius: 8px; display: flex; flex-direction: column; gap: 2px; font-size: 13.5px; }
.tg-sr:hover { background: var(--bg-hover); }
.tg-sr-top { display: flex; justify-content: space-between; } .tg-sr-top small { color: var(--muted); }
.tg-item.disabled { opacity: .5; }
.tg-shared-item { position: relative; padding: 0; aspect-ratio: 1; overflow: hidden; border-radius: 4px; }
.tg-shared-item img, .tg-shared-item video { width: 100%; height: 100%; object-fit: cover; }
#msg-banners { position: fixed; top: calc(12px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 115; display: flex; flex-direction: column; gap: 8px; width: min(420px, calc(100vw - 24px)); }
.msg-banner { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 14px; background: var(--bg-elev); box-shadow: var(--shadow); border: 1px solid var(--border); text-align: left; animation: remIn .35s var(--ease-out); transition: opacity .25s, transform .25s; }
.msg-banner.out { opacity: 0; transform: translateY(-12px); }
.mb-text { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: 14px; }
.mb-text span { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- mobile ---------- */
@media (max-width: 760px) {
  .sidebar { padding-top: calc(10px + env(safe-area-inset-top)); }
  .sb-collapse { display: none; }
  .page-view { padding: 20px 20px 40vh 30px; }
  .page-view.full { padding-left: 30px; padding-right: 20px; }
  .page-cover { height: 150px; }
  .cover-tools, .page-tools { opacity: 1; }
  .page-icon { font-size: 56px; }
  .page-title { font-size: 32px; }
  .add-btn { display: none; }
  .home { padding: 14px 12px 110px; }
  .home-hero { padding: 20px 18px 16px; border-radius: 18px; }
  .home-hero h1 { font-size: 23px; }
  .home-grid { grid-template-columns: 1fr; gap: 12px; }
  .hc-notes { grid-template-columns: 1fr 1fr; gap: 10px; }
  .ha-btn { padding: 7px 11px; font-size: 13px; }
  .tabbar { height: calc(62px + var(--safe-b)); align-items: flex-start; padding-top: 4px; background: color-mix(in srgb, var(--bg-elev) 88%, transparent); }
  .tab { gap: 2px; color: var(--faint); }
  .tab.active { color: var(--accent); }
  .tab-icon { position: relative; }
  .tab-label { font-size: 10.5px; font-weight: 500; }
  .tab-badge:empty { display: none; }
  .tab-badge { position: absolute; top: -4px; right: -10px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: #ef4444; color: #fff; font-size: 10.5px; font-weight: 700; display: grid; place-items: center; }
  .tab-new { flex: 0 0 72px; }
  .tab-plus { width: 54px; height: 54px; margin-top: -18px; border-radius: 18px; display: grid; place-items: center; color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: 0 8px 20px color-mix(in srgb, var(--accent) 45%, transparent); transition: transform .2s var(--ease-out); }
  .tab-new:active .tab-plus { transform: scale(.92); }
  .content-area { padding-bottom: calc(62px + var(--safe-b)); }
  .fab-add { display: none; }
  .mobile-bar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; gap: 2px; padding: 6px 6px calc(6px + var(--safe-b)); background: var(--bg-elev); border-top: 1px solid var(--border); box-shadow: 0 -4px 16px rgba(0, 0, 0, .06); overflow-x: auto; scrollbar-width: none; transform: translateY(0); opacity: 0; pointer-events: none; transition: opacity .15s; }
  .mobile-bar.show { opacity: 1; pointer-events: auto; }
  .mb-btn { flex: none; width: 42px; height: 40px; border-radius: 10px; display: grid; place-items: center; color: var(--text); }
  .mb-btn:active { background: var(--accent-soft); color: var(--accent); }
  body:has(.mobile-bar.show) .tabbar { visibility: hidden; }
  .mg-stage { padding: 4px; }
  .mg-nav { display: none; }
}
