:root {
  --ink: #17312d;
  --muted: #687a76;
  --canvas: #e8efed;
  --paper: #ffffff;
  --paper-soft: #f6f9f8;
  --line: #c8d7d3;
  --line-strong: #9aafa9;
  --forest: #153d36;
  --forest-soft: #e2efea;
  --blue: #2f6fb3;
  --blue-soft: #e4f0ff;
  --coral: #d9664c;
  --gold: #efbd61;
  --danger: #b74152;
  --shadow: 0 20px 60px rgba(28, 57, 51, 0.18);
  --radius: 8px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
html { -webkit-tap-highlight-color: transparent; }
body { min-width: 320px; overflow: hidden; background: var(--canvas); color: var(--ink); font-family: Inter, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, Arial, sans-serif; font-size: 16px; user-select: none; -webkit-user-select: none; }
button, input, select, textarea { font: inherit; }
button, a, [role="button"] { touch-action: manipulation; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; }
input, textarea, select, option, .person-frame, .person-frame *, .info-block, .info-block * { user-select: text; -webkit-user-select: text; }
img, video, audio, svg, .media-tile, .filmstrip-item, .viewer-media, .chat-media-tile, .chat-video-circle, .chat-video-circle *, .chat-audio-play, .chat-audio-file-play, .video-play-toggle { user-select: none; -webkit-user-select: none; -webkit-user-drag: none; }
button { border: 0; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.42; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid rgba(47, 111, 179, 0.36); outline-offset: 2px; }

.app-shell { display: flex; flex-direction: column; height: 100%; }
.topbar { min-height: 92px; display: grid; grid-template-columns: minmax(250px,310px) minmax(300px,680px) minmax(560px,1fr); align-items: center; flex: 0 0 auto; gap: 22px; padding: 14px 28px; background: var(--forest); color: #f8fffc; box-shadow: 0 5px 20px rgba(17,53,47,.24); z-index: 10; }
.brand { display: inline-flex; align-items: center; gap: 13px; padding: 0; background: transparent; color: inherit; text-align: left; }
.brand-mark { width: 58px; height: 58px; display: grid; place-items: center; flex: 0 0 auto; overflow: hidden; border: 2px solid rgba(255,255,255,.58); border-radius: 50%; background: #fff; }
.brand-mark img { width: 100%; height: 100%; object-fit: cover; transform: scale(1.14); }
.brand strong { display: block; font-size: 20px; line-height: 1.1; }
.brand small { display: block; margin-top: 4px; color: #c8ded8; font-size: 14px; line-height: 1.15; }
.search-wrap { position: relative; justify-self: center; width: min(100%,680px); }
#searchInput { width: 100%; height: 52px; border: 1px solid rgba(255,255,255,.34); border-radius: var(--radius); padding: 0 18px; background: rgba(255,255,255,.1); color: #fff; font-size: 16px; }
#searchInput::placeholder { color: #c9dcd6; }
#searchInput:focus { border-color: var(--gold); background: rgba(255,255,255,.15); }
.search-results { position: absolute; top: calc(100% + 9px); right: 0; left: 0; max-height: 420px; overflow: auto; padding: 8px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); color: var(--ink); box-shadow: var(--shadow); z-index: 30; }
.search-result { display: grid; grid-template-columns: 50px 1fr; gap: 12px; width: 100%; padding: 10px; border-radius: 6px; background: transparent; color: inherit; text-align: left; }
.search-result:hover, .search-result:focus { background: var(--blue-soft); outline: none; }
.search-result img, .search-result .avatar-fallback { width: 50px; height: 62px; border-radius: 5px; object-fit: cover; }
.search-result strong { display: block; font-size: 16px; line-height: 1.25; }
.search-result small { display: block; margin-top: 4px; color: var(--muted); font-size: 14px; }
.search-result mark { padding: 0; background: transparent; color: var(--blue); font-weight: 800; text-decoration: underline; }
.top-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 10px; }
.top-actions button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.top-actions button svg { width: 19px; height: 19px; flex: 0 0 auto; }
.desktop-nav-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mobile-nav-label, .mobile-tools-toggle, .mobile-hint { display: none; }
.map-view-button.active, .chat-view-button.active { border-color: var(--gold); background: var(--gold); color: #362509; }
.primary-button, .ghost-button, .secondary-button, .danger-button { min-height: 46px; padding: 0 18px; border-radius: 7px; font-weight: 700; transition: transform 150ms ease, box-shadow 150ms ease, background 150ms ease; }
.primary-button { background: var(--gold); color: #362509; box-shadow: 0 7px 16px rgba(0,0,0,.12); }
.primary-button:hover { background: #ffd17e; }
.secondary-button { border: 1px solid var(--line-strong); background: var(--paper); color: var(--ink); }
.secondary-button:hover { border-color: var(--blue); color: var(--blue); background: var(--blue-soft); }
.ghost-button { border: 1px solid rgba(255,255,255,.38); background: rgba(255,255,255,.08); color: #fff; }
.ghost-button:hover { background: rgba(255,255,255,.17); }
.danger-button { background: var(--danger); color: #fff; }
.primary-button:hover, .ghost-button:hover, .secondary-button:hover, .danger-button:hover { transform: translateY(-1px); }

.workspace { min-height: 0; flex: 1; display: grid; grid-template-columns: auto 1fr; background-color: var(--canvas); background-image: linear-gradient(rgba(32,83,73,.065) 1px, transparent 1px), linear-gradient(90deg, rgba(32,83,73,.065) 1px, transparent 1px); background-size: 36px 36px; }
.admin-panel { width: 340px; padding: 24px 20px; background: var(--paper); border-right: 1px solid var(--line); box-shadow: 12px 0 28px rgba(25,61,54,.08); z-index: 3; }
.admin-panel[hidden] + .tree-stage { grid-column: 1 / -1; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 22px; font-size: 21px; font-weight: 800; }
.panel-heading small { padding: 5px 10px; border-radius: 99px; background: var(--forest-soft); color: var(--forest); font-size: 13px; font-weight: 800; }
.field-label { display: block; margin: 0 0 7px; color: #4c635e; font-size: 14px; font-weight: 800; }
.admin-panel select, .admin-panel input { width: 100%; }
select, input, textarea { border: 1px solid var(--line-strong); border-radius: 6px; background: #fff; color: var(--ink); }
select, input { min-height: 46px; padding: 0 12px; }
textarea { min-height: 120px; padding: 12px; resize: vertical; line-height: 1.45; }
.tool-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.tool-grid button, .compact-button { min-height: 48px; border: 1px solid var(--line-strong); border-radius: 7px; background: var(--paper); color: var(--ink); font-weight: 700; }
.tool-grid button:hover, .compact-button:hover { border-color: var(--blue); color: var(--blue); background: var(--blue-soft); }
.tool-grid .danger { border-color: #d7909b; color: #9a2f42; }
.hint { margin-top: 20px; padding: 14px; border-left: 4px solid var(--gold); border-radius: 0 6px 6px 0; background: #fff8e8; color: #5b625a; font-size: 14px; line-height: 1.5; }

.tree-stage { position: relative; min-width: 0; min-height: 0; }
.tree-viewport { position: absolute; inset: 0; overflow: hidden; cursor: grab; user-select: none; touch-action: none; }
.tree-viewport.dragging { cursor: grabbing; }
.tree-canvas { position: absolute; top: 0; left: 0; width: 3000px; height: 2100px; transform-origin: 0 0; }
.relation-layer, .person-layer { position: absolute; inset: 0; }
.relation-layer { pointer-events: none; overflow: visible; }
.relation-path { fill: none; stroke: #537c72; stroke-width: 4; stroke-linecap: round; }
.relation-path.relation-partner { stroke: #ad5265; }
.relation-path.relation-friend { stroke: #3f6f9f; stroke-dasharray: 12 8; }
.relation-path.relation-guardian { stroke: #8a6a2f; }
.relation-path.relation-custom { stroke: #65737a; stroke-dasharray: 5 7; }
.relation-endpoint { fill: #fff; stroke: #537c72; stroke-width: 4; }
.relation-endpoint.relation-partner { stroke: #ad5265; }
.relation-endpoint.relation-friend { stroke: #3f6f9f; }
.relation-endpoint.relation-guardian { stroke: #8a6a2f; }
.relation-endpoint.relation-custom { stroke: #65737a; }
.relation-badge { pointer-events: none; }
.relation-badge rect { fill: #fffefb; stroke: #8ba79f; stroke-width: 1.5; }
.relation-badge text { fill: #21473f; font-size: 16px; font-weight: 900; }
.relation-badge.relation-partner rect { fill: #fff4f6; stroke: #cf8190; }
.relation-badge.relation-partner text { fill: #823547; }
.relation-badge.relation-friend rect { fill: #f1f7fd; stroke: #7ea2c7; }
.relation-badge.relation-friend text { fill: #315f8d; }
.relation-badge.relation-guardian rect { fill: #fff8e9; stroke: #b89a5b; }
.relation-badge.relation-guardian text { fill: #73541d; }
.relation-badge.relation-custom rect { fill: #f5f7f8; stroke: #9aa7ad; }
.relation-badge.relation-custom text { fill: #4d5d64; }
.person-card { position: absolute; width: 220px; display: grid; justify-items: center; color: var(--ink); transform: translate(-50%, -50%); transition: filter 180ms ease; }
.person-card:focus { outline: none; }
.person-card:hover { filter: drop-shadow(0 10px 12px rgba(24,65,57,.17)); }
.person-card.selected { filter: drop-shadow(0 0 .9rem rgba(47,111,179,.52)); }
.person-card.is-dragging { z-index: 5; cursor: grabbing; filter: drop-shadow(0 16px 22px rgba(24,65,57,.3)); }
.person-photo { width: 158px; aspect-ratio: 3 / 4; border: 4px solid var(--paper); border-bottom: 0; border-radius: 8px 8px 0 0; background: #d7e2df; box-shadow: 0 10px 20px rgba(24,65,57,.16); object-fit: cover; }
.avatar-fallback, .person-photo.avatar-fallback { display: grid; place-items: center; background: #2b5a51; color: #fff; font-weight: 800; font-size: 21px; }
.person-frame { width: 220px; height: 103px; display: grid; place-items: center; padding: 11px 14px; border: 2px solid #477269; border-radius: 6px; background: #fffdf7; box-shadow: 0 10px 22px rgba(24,65,57,.14); text-align: center; }
.person-frame strong { display: -webkit-box; max-width: 100%; overflow: hidden; font-size: 16px; line-height: 1.2; overflow-wrap: anywhere; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.person-frame small { display: block; margin-top: 6px; color: #5b706a; font-size: 13px; line-height: 1.25; }
.card-plus { position: absolute; z-index: 2; display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--blue); color: #fff; font-size: 22px; line-height: 1; box-shadow: 0 5px 13px rgba(24,65,57,.24); opacity: 0; transition: opacity 160ms ease, transform 160ms ease; }
.person-card:hover .card-plus, .person-card.selected .card-plus { opacity: 1; }
.card-plus.parent { bottom: -16px; left: 50%; transform: translateX(-50%) scale(.88); }
.card-plus.partner { top: 50%; right: -16px; transform: translateY(-50%) scale(.88); }
.person-card:hover .card-plus.parent, .person-card.selected .card-plus.parent { transform: translateX(-50%) scale(1); }
.person-card:hover .card-plus.partner, .person-card.selected .card-plus.partner { transform: translateY(-50%) scale(1); }
.zoom-rail { position: absolute; right: 24px; bottom: 24px; display: grid; grid-template-columns: 46px 170px 46px; gap: 10px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: rgba(255,255,255,.94); box-shadow: var(--shadow); z-index: 4; }
.zoom-rail button { width: 46px; height: 42px; border-radius: 6px; background: var(--forest); color: #fff; font-size: 25px; line-height: 1; }
.zoom-rail input { width: 170px; min-height: auto; padding: 0; }

.map-workspace { position: relative; min-height: 0; flex: 1; display: grid; grid-template-columns: 380px minmax(0,1fr); background: #dfe9e6; }
.map-workspace.map-menu-collapsed { grid-template-columns: minmax(0,1fr); }
.map-sidebar { min-width: 0; overflow: auto; padding: 24px 20px; border-right: 1px solid var(--line); background: var(--paper); box-shadow: 12px 0 28px rgba(25,61,54,.1); z-index: 3; }
.map-sidebar-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.map-sidebar-heading h1 { margin: 3px 0 0; font-size: 25px; line-height: 1.15; }
.map-sidebar-actions { display: flex; align-items: center; gap: 8px; }
.map-sidebar-close, .map-sidebar-toggle { display: grid; place-items: center; border: 1px solid var(--line); border-radius: 6px; background: #f2f7f5; color: var(--forest); }
.map-sidebar-close { width: 42px; height: 42px; flex: 0 0 auto; }
.map-sidebar-close:hover, .map-sidebar-toggle:hover { border-color: var(--blue); background: var(--blue-soft); color: var(--blue); }
.map-sidebar-close svg, .map-sidebar-toggle svg { width: 22px; height: 22px; stroke-width: 2.5; }
.map-sidebar-toggle { position: absolute; top: 18px; left: 18px; z-index: 520; width: 48px; height: 48px; background: rgba(255,255,255,.96); box-shadow: 0 8px 24px rgba(24,65,57,.18); backdrop-filter: blur(8px); }
.map-kicker { color: var(--muted); font-size: 13px; font-weight: 900; text-transform: uppercase; }
.map-count { display: grid; min-width: 42px; height: 42px; place-items: center; padding: 0 10px; border-radius: 50%; background: var(--forest-soft); color: var(--forest); font-size: 16px; font-weight: 900; }
.map-search { display: grid; gap: 7px; color: #38514b; font-size: 14px; font-weight: 800; }
.map-search input { width: 100%; }
.map-filters { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin: 16px 0 12px; }
.map-filters label { min-height: 48px; display: flex; align-items: center; gap: 8px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--paper-soft); color: #38514b; cursor: pointer; font-size: 13px; font-weight: 800; }
.map-filters input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.map-filters label:has(input:not(:checked)) { opacity: .48; }
.map-filter-dot, .map-legend i { width: 13px; height: 13px; flex: 0 0 auto; border-radius: 50%; box-shadow: 0 0 0 3px rgba(255,255,255,.9), 0 0 0 4px currentColor; }
.map-filter-dot.birth, .map-legend i.birth { background: var(--blue); color: var(--blue); }
.map-filter-dot.burial, .map-legend i.burial { background: var(--coral); color: var(--coral); }
.map-fit-button { width: 100%; }
.map-geocode-status { margin: 14px 0 0; padding: 11px 12px; border-left: 4px solid var(--gold); background: #fff8e8; color: #5b625a; font-size: 13px; line-height: 1.4; }
.map-location-list { display: grid; gap: 10px; margin-top: 18px; padding-bottom: 16px; }
.map-location-item { width: 100%; display: grid; grid-template-columns: 48px minmax(0,1fr); gap: 11px; align-items: center; padding: 11px; border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--ink); text-align: left; }
.map-location-item:hover, .map-location-item.active { border-color: var(--blue); background: var(--blue-soft); box-shadow: 0 6px 16px rgba(47,111,179,.12); }
.map-location-avatar { width: 48px; height: 58px; border-radius: 5px; object-fit: cover; }
.map-location-avatar.avatar-fallback { display: grid; place-items: center; color: #fff; font-size: 14px; }
.map-location-copy { min-width: 0; }
.map-location-copy strong, .map-location-copy small, .map-location-copy em { display: block; overflow-wrap: anywhere; }
.map-location-copy strong { font-size: 15px; line-height: 1.25; }
.map-location-copy small { margin-top: 4px; color: var(--muted); font-size: 13px; font-weight: 700; }
.map-location-copy em { margin-top: 3px; color: #47625c; font-size: 12px; font-style: normal; line-height: 1.3; }
.family-map-stage { position: relative; min-width: 0; min-height: 0; overflow: hidden; background: #bfd0cb; }
.family-map { position: absolute; inset: 0; z-index: 1; }
.map-unavailable { position: absolute; inset: 0; z-index: 4; display: grid; place-content: center; gap: 8px; padding: 28px; background: #dfe9e6; color: var(--ink); text-align: center; }
.map-unavailable strong { font-size: 22px; }
.map-unavailable span { color: var(--muted); }
.map-legend { position: absolute; right: 18px; top: 18px; z-index: 500; display: flex; gap: 16px; padding: 11px 14px; border: 1px solid rgba(106,136,128,.36); border-radius: 7px; background: rgba(255,255,255,.94); box-shadow: 0 8px 24px rgba(24,65,57,.16); color: #294740; font-size: 13px; font-weight: 800; backdrop-filter: blur(8px); }
.map-legend span { display: flex; align-items: center; gap: 8px; }
.maplibregl-map { background: #ccdbd7; font-family: inherit; }
.maplibregl-ctrl-bottom-left { max-width: calc(100% - 86px); }
.maplibregl-ctrl-attrib { padding: 1px 3px !important; background: rgba(255,255,255,.68) !important; color: #61736f !important; font-size: 7px !important; line-height: 1.15 !important; opacity: .68; }
.maplibregl-ctrl-attrib:hover { opacity: 1; }
.maplibregl-ctrl-attrib a { color: #356f91; }
.maplibregl-ctrl-attrib-button { width: 20px !important; height: 20px !important; opacity: .58; }
.maplibregl-ctrl-attrib-button:hover, .maplibregl-ctrl-attrib.maplibregl-compact-show .maplibregl-ctrl-attrib-button { opacity: 1; }
.maplibregl-ctrl-attrib.maplibregl-compact:not(:hover):not(:focus-within) { width: 20px; max-width: 20px; height: 20px; overflow: hidden; padding: 0 !important; font-size: 0 !important; line-height: 0 !important; white-space: nowrap; }
.maplibregl-ctrl-group { overflow: hidden; border: 1px solid #92aaa4; border-radius: 5px; box-shadow: 0 4px 14px rgba(24,65,57,.16); }
.maplibregl-ctrl-group button { width: 42px; height: 42px; background-color: #fff; }
.maplibregl-ctrl-group button:hover { background-color: #edf5f2; }
.maplibregl-popup-content { padding: 13px; border-radius: 7px; font-family: inherit; box-shadow: 0 10px 30px rgba(20,55,49,.2); }
.maplibregl-popup-close-button { width: 30px; height: 30px; color: var(--muted); font-size: 22px; }
.family-map-marker-wrap { width: 34px; height: 42px; cursor: pointer; }
.family-map-pin { position: relative; width: 34px; height: 42px; display: grid; place-items: center; border: 3px solid #fff; border-radius: 50% 50% 50% 8px; transform: rotate(-45deg); background: var(--blue); box-shadow: 0 7px 18px rgba(17,53,47,.35); color: #fff; }
.family-map-pin.burial { background: var(--coral); }
.family-map-pin.mixed { background: linear-gradient(135deg,var(--blue) 0 49%,var(--coral) 51% 100%); }
.family-map-pin span { transform: rotate(45deg); color: #fff; font-size: 12px; font-weight: 900; }
.family-popup { min-width: 250px; max-width: 330px; display: grid; gap: 10px; }
.family-popup-event { display: grid; grid-template-columns: 42px minmax(0,1fr); gap: 10px; padding-bottom: 10px; border-bottom: 1px solid #e3ece9; }
.family-popup-event:last-of-type { border-bottom: 0; }
.family-popup-avatar { width: 42px; height: 51px; border-radius: 4px; object-fit: cover; }
.family-popup-avatar.avatar-fallback { display: grid; place-items: center; color: #fff; font-size: 13px; }
.family-popup-copy { min-width: 0; }
.family-popup-copy strong, .family-popup-copy span, .family-popup-copy small { display: block; overflow-wrap: anywhere; }
.family-popup-copy strong { color: var(--ink); font-size: 14px; line-height: 1.25; }
.family-popup-copy span { margin-top: 3px; color: #43605a; font-size: 13px; font-weight: 800; }
.family-popup-copy small { margin-top: 3px; color: var(--muted); font-size: 12px; line-height: 1.3; }
.family-popup-copy .family-popup-approximate { color: #9a6322; font-weight: 800; }
.family-popup-open { min-height: 38px; padding: 0 12px; border-radius: 5px; background: var(--forest); color: #fff; font-size: 13px; font-weight: 800; }

.place-field { position: relative; }
.place-input-wrap { position: relative; }
.place-input-wrap > input { width: 100%; padding-right: 42px; }
.place-input-status { position: absolute; top: 50%; right: 12px; width: 18px; height: 18px; transform: translateY(-50%); display: grid; place-items: center; color: #78908a; font-size: 15px; }
.place-input-status.resolved { color: var(--forest); }
.place-input-status.loading { border: 2px solid #bed0ca; border-top-color: var(--blue); border-radius: 50%; font-size: 0; animation: place-spin .8s linear infinite; }
.place-suggestions { position: absolute; top: calc(100% + 7px); right: 0; left: 0; z-index: 20; max-height: 270px; overflow: auto; padding: 6px; border: 1px solid var(--line); border-radius: 7px; background: #fff; box-shadow: 0 14px 34px rgba(24,65,57,.18); }
.place-suggestion { width: 100%; display: grid; gap: 3px; padding: 10px 11px; border-radius: 5px; background: transparent; color: var(--ink); text-align: left; }
.place-suggestion:hover, .place-suggestion:focus, .place-suggestion.active { background: var(--blue-soft); outline: none; }
.place-suggestion strong { font-size: 14px; line-height: 1.25; }
.place-suggestion small { color: var(--muted); font-size: 12px; font-weight: 600; line-height: 1.3; }
.place-helper { color: var(--muted); font-size: 12px; font-weight: 500; line-height: 1.35; }
@keyframes place-spin { to { transform: translateY(-50%) rotate(360deg); } }

.modal-root { position: fixed; inset: 0; z-index: 1000; pointer-events: none; }
.modal-root.active { pointer-events: auto; }
.modal-open .map-sidebar,
.modal-open .map-sidebar-toggle,
.modal-open .map-legend,
.modal-open .maplibregl-control-container { visibility: hidden; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(14,38,34,.56); backdrop-filter: blur(3px); }
.modal-window { position: absolute; top: 50%; left: 50%; width: min(980px, calc(100vw - 36px)); max-height: calc(100vh - 40px); overflow: auto; transform: translate(-50%, -50%); border-radius: 8px; background: var(--paper); box-shadow: var(--shadow); }
.modal-window.narrow { width: min(510px, calc(100vw - 32px)); }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 22px 26px; border-bottom: 1px solid var(--line); }
.modal-kicker { margin: 0 0 4px; color: var(--muted); font-size: 14px; font-weight: 800; letter-spacing: 0; text-transform: uppercase; }
.modal-title { margin: 0; font-size: 26px; line-height: 1.2; }
.modal-close { width: 42px; height: 42px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 50%; background: var(--paper-soft); color: var(--ink); font-size: 27px; line-height: 1; }
.modal-close:hover { background: #e6efec; }
.modal-body { padding: 26px; }
.auth-tabs, .editor-tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.tab-button { min-height: 46px; padding: 0 16px; border: 1px solid var(--line); border-radius: 6px; background: var(--paper-soft); color: #50645f; font-weight: 800; white-space: nowrap; }
.tab-button.active { border-color: var(--forest); background: var(--forest); color: #fff; }
.tab-count { display: inline-grid; min-width: 23px; height: 23px; place-items: center; margin-left: 5px; padding: 0 6px; border-radius: 99px; background: rgba(255,255,255,.18); font-size: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 16px; }
.form-grid.two { grid-template-columns: repeat(2,1fr); }
.form-grid.one { grid-template-columns: 1fr; }
.form-row { display: grid; gap: 7px; color: #38514b; font-size: 14px; font-weight: 800; }
.form-row > span { display: block; }
.form-row input, .form-row select, .form-row textarea { width: 100%; min-width: 0; }
.form-row.full { grid-column: 1 / -1; }
.form-row small { color: var(--muted); font-weight: 500; line-height: 1.4; }
.checkbox-row, .life-mode-control { display: flex; align-items: center; gap: 10px; min-height: 46px; }
.checkbox-row input, .life-mode-control input { width: 20px; height: 20px; min-height: auto; padding: 0; accent-color: var(--forest); }
.modal-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.muted-copy { color: var(--muted); font-size: 14px; line-height: 1.5; }
.access-key-form { display: grid; gap: 16px; }
.auth-key-copy { margin: 0; color: var(--muted); line-height: 1.5; }
.auth-consents { display: grid; gap: 10px; padding: 13px; border: 1px solid var(--line); border-radius: 7px; background: #f5faf8; }
.auth-consent-row { display: grid; grid-template-columns: 20px minmax(0,1fr); align-items: start; gap: 10px; color: #38514b; font-size: 13px; font-weight: 700; line-height: 1.4; }
.auth-consent-row input { width: 20px; height: 20px; min-height: 0; margin: 0; padding: 0; accent-color: var(--forest); }
.access-key-input { font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace; font-size: 22px; font-weight: 800; letter-spacing: 3px; text-align: center; text-transform: uppercase; }
.auth-key-submit { width: 100%; }

.person-modal { width: min(1040px, calc(100vw - 36px)); }
.person-view { display: grid; grid-template-columns: 250px minmax(0,1fr); gap: 28px; }
.person-main-photo { width: 100%; aspect-ratio: 3 / 4; border-radius: 7px; background: #d7e2df; box-shadow: 0 14px 30px rgba(24,65,57,.18); object-fit: cover; }
.main-media-trigger { display: block; width: 100%; padding: 0; background: transparent; border-radius: 7px; overflow: hidden; }
.main-media-trigger:hover .person-main-photo { transform: scale(1.015); }
.main-media-trigger .person-main-photo { transition: transform 180ms ease; }
.person-facts { display: grid; gap: 0; }
.fact-line { display: grid; grid-template-columns: minmax(138px,170px) 1fr; gap: 12px; align-items: baseline; padding: 11px 0; border-bottom: 1px solid #e5eeeb; }
.fact-line span:first-child { color: var(--muted); font-size: 14px; font-weight: 700; }
.fact-line strong { overflow-wrap: anywhere; line-height: 1.35; }
.info-block { margin-top: 18px; padding: 16px; border-left: 4px solid var(--gold); border-radius: 0 6px 6px 0; background: #fff9ea; line-height: 1.55; white-space: pre-wrap; }
.media-section { margin-top: 16px; }
.media-section-heading { display: flex; align-items: center; justify-content: space-between; margin: 0 0 8px; color: var(--muted); font-size: 14px; font-weight: 800; }
.media-section-heading small { display: grid; place-items: center; min-width: 24px; height: 24px; padding: 0 6px; border-radius: 99px; background: var(--forest-soft); color: var(--forest); font-size: 13px; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill,minmax(108px,1fr)); gap: 10px; }
.media-tile { position: relative; min-height: 100px; display: grid; place-items: center; overflow: hidden; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: var(--paper-soft); color: var(--forest); }
.media-tile:hover { border-color: var(--blue); box-shadow: 0 5px 14px rgba(47,111,179,.16); }
.media-tile img, .media-tile video { width: 100%; height: 100%; object-fit: cover; }
.media-video-tile span, .media-tile > span { position: absolute; right: 6px; bottom: 6px; padding: 3px 7px; border-radius: 4px; background: rgba(21,61,54,.82); color: #fff; font-size: 12px; font-weight: 800; }

.editor-window { width: min(1020px, calc(100vw - 36px)); overflow-x: hidden; }
.editor-header { padding-bottom: 18px; }
.editor-tabs { margin: 0; padding: 14px 26px; border-bottom: 1px solid var(--line); background: var(--paper-soft); }
.editor-form { display: flex; min-height: 520px; flex-direction: column; }
.editor-panel { min-width: 0; flex: 1; padding: 26px; }
.editor-panel[hidden] { display: none; }
.editor-personal-layout { display: grid; grid-template-columns: 210px minmax(0,1fr); gap: 30px; }
.editor-photo-area { display: grid; align-content: start; gap: 10px; color: var(--muted); font-size: 13px; line-height: 1.4; }
.editor-photo-preview { width: 190px; aspect-ratio: 3 / 4; border-radius: 7px; background: #d7e2df; object-fit: cover; }
.editor-photo-preview.avatar-fallback { display: grid; place-items: center; color: #fff; font-size: 30px; }
.editor-fields-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 16px; }
.editor-fields-grid.wide { max-width: 720px; }
.relation-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 0 0 22px; padding: 16px; border: 1px solid #c8dcd5; border-radius: 7px; background: #f5fbf8; }
.life-mode-control { grid-column: 1 / -1; padding: 10px 12px; border: 1px solid #d9e5e1; border-radius: 6px; background: #fbfdfc; color: #38514b; font-size: 14px; font-weight: 800; }
.file-control { position: relative; min-height: 46px; display: inline-flex; align-items: center; justify-content: center; padding: 0 15px; border: 1px dashed #6c9187; border-radius: 6px; background: #f5fbf8; color: var(--forest); cursor: pointer; font-size: 14px; font-weight: 800; }
.file-control:hover { border-color: var(--blue); color: var(--blue); background: var(--blue-soft); }
.file-control input { position: absolute; width: 1px; height: 1px; min-height: 0; opacity: 0; pointer-events: none; }
.biography-input { min-height: 210px; }
.editor-existing-media { margin-top: 22px; padding-top: 20px; border-top: 1px solid var(--line); }
.editor-existing-media > p { margin: 0 0 10px; color: var(--muted); font-size: 14px; font-weight: 800; }
.relation-editor-panel { display: grid; align-content: start; gap: 20px; }
.relation-editor-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.relation-editor-heading h3 { margin: 0; font-size: 22px; }
.relation-editor-heading > span { display: grid; min-width: 34px; height: 34px; place-items: center; padding: 0 9px; border-radius: 99px; background: var(--forest-soft); color: var(--forest); font-weight: 900; }
.relation-add-panel { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 18px; align-items: end; padding: 18px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.relation-add-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 14px; }
.relation-add-grid .full { grid-column: 1 / -1; }
.relation-add-button { min-height: 48px; padding: 0 20px; }
.relation-editor-list { display: grid; gap: 12px; }
.relation-editor-row { display: grid; grid-template-columns: 190px minmax(0,1fr); gap: 18px; padding: 16px; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
.relation-person-summary { display: flex; gap: 12px; align-items: center; align-self: start; }
.relation-person-summary > div { min-width: 0; display: grid; gap: 5px; }
.relation-person-summary strong { overflow-wrap: anywhere; line-height: 1.25; }
.relation-person-summary span { color: var(--muted); font-size: 13px; font-weight: 800; }
.relation-person-avatar { width: 54px; height: 68px; flex: 0 0 auto; border: 2px solid var(--paper); border-radius: 5px; background: #d7e2df; object-fit: cover; box-shadow: 0 5px 12px rgba(24,65,57,.14); }
.relation-person-avatar.avatar-fallback { display: grid; place-items: center; color: #fff; font-size: 15px; }
.relation-row-fields { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px; }
.relation-row-fields .full { grid-column: 1 / -1; }
.relation-row-actions { grid-column: 2; display: flex; justify-content: flex-end; gap: 9px; }
.relation-row-actions button { min-height: 42px; }
.relation-inline-confirm { grid-column: 1 / -1; display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 14px; align-items: center; padding: 13px 14px; border-left: 4px solid var(--danger); border-radius: 0 6px 6px 0; background: #fff0f2; color: #7e2b3a; }
.relation-inline-confirm[hidden] { display: none; }
.relation-inline-confirm > div { display: flex; gap: 8px; }
.relation-inline-confirm button { min-height: 40px; }
.relation-editor-empty { margin: auto 0; }
.editor-footer { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 18px 26px; border-top: 1px solid var(--line); background: var(--paper-soft); color: var(--muted); font-size: 14px; }
.editor-footer .modal-actions { margin: 0; }

.relation-menu { display: grid; gap: 9px; padding: 18px; }
.relation-menu button { min-height: 66px; display: grid; gap: 2px; padding: 10px 15px; border: 1px solid var(--line); border-radius: 7px; background: var(--paper); color: var(--ink); text-align: left; }
.relation-menu button:hover { border-color: var(--blue); background: var(--blue-soft); }
.relation-menu strong { font-size: 16px; }
.relation-menu small { color: var(--muted); font-size: 13px; font-weight: 500; }
.relation-menu .relation-cancel { min-height: 46px; display: block; color: #536b64; text-align: center; }
.profile-window { width: min(820px, calc(100vw - 36px)); }
.profile-layout { display: grid; grid-template-columns: 210px minmax(0,1fr); gap: 30px; }
.profile-avatar-panel { display: grid; justify-items: start; align-content: start; gap: 11px; }
.profile-avatar { width: 142px; height: 142px; border-radius: 50%; background: #d7e2df; object-fit: cover; }
.profile-avatar-panel > small { color: var(--muted); font-size: 13px; line-height: 1.35; }
.avatar-change-button { min-height: 46px; display: inline-flex; align-items: center; justify-content: center; padding: 0 16px; border: 1px solid var(--line-strong); border-radius: 7px; background: var(--paper); color: var(--ink); cursor: pointer; font-size: 14px; font-weight: 800; }
.avatar-change-button:hover { border-color: var(--blue); background: var(--blue-soft); color: var(--blue); }
.visually-hidden-input { position: absolute; width: 1px; height: 1px; min-height: 0; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.profile-details { display: grid; align-content: start; gap: 14px; }
.profile-save-nickname { justify-self: start; }
.profile-preference { display: grid; gap: 9px; padding-top: 13px; border-top: 1px solid var(--line); }
.profile-push-row { display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: center; gap: 14px; }
.profile-push-row > span { display: grid; gap: 3px; }
.profile-push-row strong { font-size: 14px; }
.profile-push-row small { color: var(--muted); font-size: 12px; line-height: 1.35; }
.profile-push-row button { min-height: 40px; white-space: nowrap; }
.profile-push-actions { display: flex; flex-wrap: wrap; justify-content: end; gap: 8px; }
.profile-color-row { display: grid; grid-template-columns: 46px minmax(0,1fr); align-items: center; gap: 11px; }
.profile-color-input { width: 46px; height: 42px; min-height: 42px; padding: 3px; border-radius: 6px; cursor: pointer; }
.profile-nickname-preview { min-width: 0; overflow: hidden; font-size: 17px; font-weight: 900; text-overflow: ellipsis; white-space: nowrap; }
.profile-color-swatches { display: flex; flex-wrap: wrap; gap: 7px; }
.profile-color-swatch { --swatch: #287466; width: 30px; height: 30px; padding: 0; border: 3px solid #fff; border-radius: 50%; background: var(--swatch); box-shadow: 0 0 0 1px #a8bcb6; }
.profile-color-swatch:hover { box-shadow: 0 0 0 2px #7ca298; }
.profile-color-swatch.active { box-shadow: 0 0 0 3px var(--gold); }
.profile-quick-reaction { position: relative; }
.profile-quick-reaction-button { width: 100%; min-height: 58px; display: grid; grid-template-columns: 38px minmax(0,1fr) 24px; align-items: center; gap: 11px; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 7px; background: var(--paper); color: var(--ink); text-align: left; }
.profile-quick-reaction-button:hover, .profile-quick-reaction-button[aria-expanded="true"] { border-color: #79a99d; background: #f0f8f5; }
.profile-quick-reaction-button > span:nth-child(2) { min-width: 0; display: grid; gap: 2px; }
.profile-quick-reaction-button strong, .profile-quick-reaction-button small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-quick-reaction-button small { color: var(--muted); font-size: 12px; }
.profile-quick-reaction-button svg { width: 20px; height: 20px; color: var(--muted); }
.profile-quick-reaction-emoji { width: 34px; height: 34px; display: block; }
.profile-quick-reaction-button .chat-inline-flag { width: 34px; height: 25px; margin: 0; vertical-align: 0; }
.profile-reaction-picker { max-height: 300px; overflow: auto; border: 1px solid var(--line); border-radius: 7px; background: #fff; box-shadow: 0 10px 24px rgba(24,65,57,.12); }
.profile-reaction-tabs { position: sticky; top: 0; z-index: 1; display: flex; gap: 5px; overflow-x: auto; padding: 8px; border-bottom: 1px solid var(--line); background: #fff; }
.profile-reaction-tabs button { min-width: fit-content; height: 32px; padding: 0 9px; border-radius: 5px; background: #edf4f2; color: var(--forest); font-size: 11px; font-weight: 800; }
.profile-reaction-tabs button.active { background: var(--forest); color: #fff; }
.profile-reaction-grid { display: grid; grid-template-columns: repeat(8,1fr); gap: 3px; padding: 8px; }
.profile-reaction-grid button { width: 36px; height: 36px; display: grid; place-items: center; justify-self: center; padding: 0; border-radius: 5px; background: transparent; }
.profile-reaction-grid button:hover, .profile-reaction-grid button.selected { background: #d9eefb; }
.profile-reaction-emoji { width: 27px; height: 27px; }
.profile-reaction-grid button.historical img { width: 30px; height: 22px; border-radius: 2px; object-fit: cover; }
.profile-reaction-grid button.historical img[src*="-telegram"] { background: transparent; object-fit: contain; box-shadow: none; }
.owner-user-management { margin-top: 28px; padding-top: 24px; border-top: 1px solid var(--line); }
.owner-user-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.owner-user-heading h3 { margin: 0; font-size: 19px; }
.owner-user-heading > span { display: grid; min-width: 28px; height: 28px; place-items: center; padding: 0 8px; border-radius: 99px; background: var(--forest-soft); color: var(--forest); font-size: 13px; font-weight: 800; }
.owner-user-search { display: block; margin-top: 15px; }
.owner-user-search input { width: 100%; }
.visually-hidden-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
.user-list { display: grid; gap: 10px; margin-top: 12px; }
.user-row { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 16px; align-items: center; padding: 14px; border: 1px solid var(--line); border-radius: 7px; }
.user-name-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.user-row-actions { display: flex; align-items: center; gap: 10px; }
.role-segments { display: inline-grid; grid-template-columns: 44px 44px; overflow: hidden; border: 1px solid var(--line-strong); border-radius: 7px; background: var(--paper-soft); }
.role-letter { width: 44px; height: 42px; display: grid; place-items: center; border-right: 1px solid var(--line-strong); background: transparent; color: var(--muted); font-size: 16px; font-weight: 900; }
.role-letter:last-child { border-right: 0; }
.role-letter:hover { background: var(--blue-soft); color: var(--blue); }
.role-letter.active { background: var(--forest); color: #fff; }
.role-letter.owner { border: 0; border-radius: 7px; background: var(--gold); color: #3d2a0a; }
.user-delete-button { min-height: 42px; padding: 0 12px; border: 1px solid #d7909b; border-radius: 7px; background: #fff; color: #9a2f42; font-size: 14px; font-weight: 800; }
.user-delete-button:hover { background: #fff0f2; }
.empty-state { padding: 20px; border: 1px dashed var(--line-strong); border-radius: 6px; color: var(--muted); text-align: center; }

.access-lock-screen { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 24px; background: #edf4f1; color: var(--forest); text-align: center; }
.access-lock-screen[hidden] { display: none; }
.access-lock-panel { width: min(480px,100%); display: grid; justify-items: stretch; gap: 16px; padding: 34px; border: 1px solid var(--line); border-radius: 8px; background: #fff; box-shadow: var(--shadow); }
.access-lock-mark { width: 72px; height: 72px; display: grid; place-items: center; justify-self: center; overflow: hidden; border: 2px solid var(--line); border-radius: 50%; background: #fff; }
.access-lock-mark img { width: 100%; height: 100%; object-fit: cover; transform: scale(1.14); }
.access-lock-panel h1 { margin: 0; font-size: 28px; line-height: 1.25; }
.access-lock-panel p { margin: 0; color: var(--muted); line-height: 1.5; }
.access-lock-panel .form-row { text-align: left; }
.access-lock-error { padding: 10px; border-radius: 6px; background: #fff0f2; color: #9a2f42 !important; font-weight: 800; }

.keys-window { width: min(900px, calc(100vw - 36px)); }
.keys-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.keys-toolbar > div { display: flex; align-items: baseline; gap: 8px; color: var(--muted); }
.keys-toolbar strong { color: var(--forest); font-size: 24px; }
.keys-list { display: grid; gap: 10px; }
.access-key-row { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 16px; align-items: center; padding: 14px 16px; border: 1px solid var(--line); border-radius: 7px; background: var(--paper-soft); }
.access-key-main { min-width: 0; display: grid; gap: 5px; }
.access-key-main code { width: fit-content; color: var(--forest); font-size: 18px; font-weight: 900; letter-spacing: 2px; user-select: text; -webkit-user-select: text; }
.access-key-main span { overflow: hidden; color: var(--muted); font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.access-key-actions { display: flex; gap: 8px; }
.key-icon-button { min-height: 42px; padding: 0 13px; border: 1px solid var(--line-strong); border-radius: 6px; background: #fff; color: var(--ink); font-size: 14px; font-weight: 800; }
.key-icon-button.copy:hover { border-color: var(--blue); background: var(--blue-soft); color: var(--blue); }
.key-icon-button.delete { border-color: #d7909b; color: #9a2f42; }
.key-icon-button.delete:hover:not(:disabled) { background: #fff0f2; }
.confirm-window { overflow: hidden; }
.confirm-close { position: absolute; top: 16px; right: 16px; z-index: 1; }
.confirm-body { display: grid; justify-items: center; gap: 12px; padding: 34px 30px 28px; text-align: center; }
.confirm-symbol { width: 58px; height: 58px; display: grid; place-items: center; border-radius: 50%; background: #fff0f2; color: var(--danger); font-size: 30px; font-weight: 900; }
.confirm-body .modal-kicker { margin-top: 2px; color: #9a2f42; }
.confirm-description { max-width: 410px; margin: 0; color: var(--muted); line-height: 1.55; }
.confirm-key-code { padding: 8px 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--paper-soft); color: var(--forest); font-size: 17px; font-weight: 900; letter-spacing: 2px; user-select: text; -webkit-user-select: text; }
.confirm-subject { max-width: 100%; padding: 9px 14px; border: 1px solid var(--line); border-radius: 6px; background: var(--paper-soft); color: var(--forest); font-size: 17px; overflow-wrap: anywhere; }
.copy-dialog-window { overflow: hidden; }
.copy-dialog-symbol { width: 58px; height: 58px; display: grid; place-items: center; border-radius: 50%; background: #e5f3ef; color: var(--forest); font-size: 28px; font-weight: 900; }
.copy-dialog-value { width: 100%; min-height: 48px; padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: 6px; background: #fff; color: var(--ink); font: 700 15px/1.3 ui-monospace, SFMono-Regular, Consolas, monospace; user-select: text; -webkit-user-select: text; }
.copy-dialog-value:focus { outline: 3px solid rgba(42, 119, 106, 0.2); border-color: var(--forest); }
.confirm-actions { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px; }
.confirm-actions button { min-height: 48px; }

.chat-workspace { min-height: 0; flex: 1; position: relative; overflow: hidden; background-color: #dfeae7; background-image: radial-gradient(circle at center, rgba(48,105,92,.12) 1px, transparent 1.5px); background-size: 28px 28px; }
.chat-shell { position: relative; width: 100%; height: 100%; min-height: 0; display: grid; grid-template-rows: auto auto auto minmax(0,1fr) auto auto auto auto; overflow: hidden; background: #f7faf9; }
.chat-pinned-bar { grid-row: 1; }
.chat-typing-bar { grid-row: 2; }
.chat-selection-bar { grid-row: 3; }
.chat-messages { grid-row: 4; }
.chat-upload-status { grid-row: 5; }
.chat-composer-reference { grid-row: 6; }
.chat-pending-attachments { grid-row: 7; }
.chat-composer { grid-row: 8; }
.chat-header { min-height: 78px; display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 14px 22px; border-bottom: 1px solid var(--line); background: #fff; }
.chat-header h1 { margin: 2px 0 0; font-size: 24px; letter-spacing: 0; }
.chat-kicker { color: #5f7771; font-size: 12px; font-weight: 900; text-transform: uppercase; }
.chat-message-count { padding: 7px 11px; border-radius: 99px; background: var(--forest-soft); color: var(--forest); font-size: 13px; font-weight: 800; }
.chat-pinned-bar { min-height: 58px; display: grid; grid-template-columns: 42px minmax(0,1fr) 42px; align-items: stretch; border-bottom: 1px solid var(--line); background: #eff7f4; }
.chat-pinned-arrow { background: transparent; color: var(--forest); font-size: 28px; }
.chat-pinned-arrow:hover { background: #dceee8; }
.chat-pinned-current { min-width: 0; display: grid; align-content: center; gap: 2px; padding: 8px 12px; border-left: 3px solid var(--gold); background: transparent; color: var(--ink); text-align: left; }
.chat-pinned-current span { color: #357065; font-size: 12px; font-weight: 900; }
.chat-pinned-current strong { overflow: hidden; font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.chat-typing-bar { min-width: 0; min-height: 34px; display: flex; align-items: center; gap: 5px; overflow: hidden; padding: 6px 16px; border-bottom: 1px solid #c8d9d4; background: #f4faf8; color: #287466; font-size: 13px; font-weight: 800; }
.chat-typing-bar[hidden] { display: none; }
.chat-typing-bar > span:first-child { min-width: 0; white-space: nowrap; }
.chat-typing-dots { display: inline-flex; flex: 0 0 auto; align-items: end; gap: 3px; height: 13px; }
.chat-typing-dots i { width: 4px; height: 4px; border-radius: 50%; background: currentColor; animation: chat-typing-dot 1.15s infinite ease-in-out; }
.chat-typing-dots i:nth-child(2) { animation-delay: 140ms; }
.chat-typing-dots i:nth-child(3) { animation-delay: 280ms; }
@keyframes chat-typing-dot { 0%, 60%, 100% { transform: translateY(0); opacity: .4; } 30% { transform: translateY(-4px); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .chat-typing-dots i { animation: none; opacity: .75; } }
.chat-selection-bar { min-height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 8px 16px; border-bottom: 1px solid #9cb9b1; background: #e3f2ee; }
.chat-selection-bar > div { display: flex; gap: 8px; }
.chat-selection-bar button { min-height: 40px; }
.chat-messages { min-height: 0; overflow: auto; padding: 24px clamp(14px,4vw,52px) 30px; scroll-behavior: smooth; user-select: none; -webkit-user-select: none; }
.chat-empty { min-height: 100%; display: grid; place-items: center; color: var(--muted); text-align: center; }
.chat-empty > div { max-width: 390px; display: grid; gap: 8px; padding: 30px; }
.chat-empty strong { color: var(--forest); font-size: 22px; }
.chat-date-separator { position: sticky; top: 4px; z-index: 4; display: flex; justify-content: center; margin: 18px 0 12px; pointer-events: none; }
.chat-date-separator:first-child { margin-top: 0; }
.chat-date-separator span { padding: 7px 13px; border: 1px solid rgba(111,145,136,.28); border-radius: 99px; background: rgba(235,244,241,.94); color: #4d6b64; box-shadow: 0 3px 10px rgba(24,65,57,.08); backdrop-filter: blur(8px); font-size: 12px; font-weight: 900; }
.chat-message { position: relative; display: grid; grid-template-columns: 46px minmax(0,1fr); align-items: end; gap: 10px; margin: 15px 0; scroll-margin: 110px; }
.chat-message.own { grid-template-columns: minmax(0,1fr) 46px; }
.chat-message.selected { margin: 0 -10px; padding: 12px 10px; border-radius: 8px; background: #dceafb; box-shadow: inset 3px 0 0 rgba(47,111,179,.78); }
.chat-message.selected-joined-before { border-top-left-radius: 0; border-top-right-radius: 0; }
.chat-message.selected-joined-after { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.chat-message.highlight .chat-bubble { animation: chat-highlight 1.4s ease; }
@keyframes chat-highlight { 0%,100% { box-shadow: none; } 30%,70% { box-shadow: 0 0 0 4px rgba(239,189,97,.65); } }
.chat-quote-source-highlight { padding: 1px 2px; border-radius: 3px; background: transparent; color: inherit; animation: chat-quote-source-highlight 10s ease forwards; }
@keyframes chat-quote-source-highlight {
  0%, 68% { background: #ffe09a; box-shadow: 0 0 0 3px rgba(239,189,97,.38), 0 0 18px rgba(239,189,97,.58); }
  100% { background: transparent; box-shadow: 0 0 0 0 rgba(239,189,97,0), 0 0 0 rgba(239,189,97,0); }
}
.chat-avatar { width: 46px; height: 46px; display: grid; place-items: center; overflow: hidden; border: 2px solid #fff; border-radius: 50%; background: var(--forest); color: #fff; box-shadow: 0 4px 12px rgba(21,61,54,.18); font-size: 14px; font-weight: 900; }
.chat-avatar img { width: 100%; height: 100%; object-fit: cover; }
.chat-message.own .chat-avatar { grid-column: 2; }
.chat-message.own .chat-bubble { grid-column: 1; grid-row: 1; justify-self: end; border-bottom-right-radius: 2px; background: #dcf1e8; }
.chat-bubble { min-width: 150px; max-width: min(680px,82%); display: grid; gap: 7px; justify-self: start; padding: 10px 12px 8px; border: 1px solid #c7d7d2; border-radius: 8px 8px 8px 2px; background: #fff; box-shadow: 0 5px 14px rgba(28,57,51,.08); }
.chat-message-author { color: #287466; font-size: 12px; font-weight: 900; }
.chat-reply-preview { min-width: 0; display: grid; gap: 2px; padding: 5px 8px; border-left: 3px solid var(--blue); border-radius: 0 5px 5px 0; background: rgba(47,111,179,.08); color: var(--ink); text-align: left; }
.chat-reply-preview:hover { background: rgba(47,111,179,.14); }
.chat-reply-preview.quoted { border-left-color: var(--gold); background: rgba(239,189,97,.12); }
.chat-reply-preview.deleted { border-left-color: #9aa9a5; color: var(--muted); }
.chat-reply-preview strong, .chat-reply-preview span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-reply-preview strong { color: #246a8f; font-size: 12px; }
.chat-reply-preview.quoted strong { color: #87600f; }
.chat-reply-preview span { font-size: 13px; }
.chat-message-text { margin: 0; color: #1d3531; line-height: 1.42; overflow-wrap: anywhere; white-space: pre-wrap; user-select: text; -webkit-user-select: text; }
.chat-telegram-emoji { object-fit: contain; pointer-events: none; user-select: none; -webkit-user-select: none; -webkit-user-drag: none; }
.chat-inline-emoji { width: 23px; height: 23px; display: inline-block; margin: 0 1px; vertical-align: -5px; }
.chat-inline-flag { width: 27px; height: 20px; display: inline-block; margin: 0 2px; border-radius: 2px; object-fit: cover; vertical-align: -4px; box-shadow: 0 0 0 1px rgba(20,60,52,.14); }
.chat-inline-flag[src*="-telegram"] { background: transparent; object-fit: contain; box-shadow: none; }
.chat-reactions { display: flex; flex-wrap: wrap; gap: 4px; }
.chat-reaction { min-width: 44px; height: 31px; display: inline-flex; align-items: center; justify-content: center; gap: 5px; padding: 2px 8px; border: 1px solid #bfd2cd; border-radius: 16px; background: #edf4f2; color: #47635c; font-size: 12px; font-weight: 900; }
.chat-reaction:hover { border-color: #71a7c7; background: #e2f0f8; }
.chat-reaction.chosen { border-color: #3f9ad0; background: #d9eefb; color: #177bb5; }
.chat-reaction-emoji { width: 20px; height: 20px; }
.chat-reaction .chat-inline-flag { width: 24px; height: 17px; margin: 0; vertical-align: 0; }
.chat-message-meta { display: flex; justify-content: flex-end; gap: 5px; color: #71847f; font-size: 11px; font-variant-numeric: tabular-nums; }
.chat-receipt { min-width: 15px; display: inline-flex; align-items: center; color: #7e918c; font-size: 14px; font-weight: 900; line-height: 1; user-select: none; -webkit-user-select: none; }
.chat-receipt.read { color: #168dd0; }
.chat-receipt i { font-style: normal; }
.chat-receipt i + i { margin-left: -6px; transform: translate(1px,-1px); }
.chat-message-attachments { display: grid; gap: 8px; }
.chat-media-tile { position: relative; width: min(430px,100%); max-height: 390px; display: block; overflow: hidden; padding: 0; border-radius: 7px; background: #183f38; }
.chat-media-tile img, .chat-media-tile video { width: 100%; max-height: 390px; display: block; object-fit: contain; }
.chat-media-tile > span { position: absolute; right: 8px; bottom: 8px; padding: 5px 8px; border-radius: 5px; background: rgba(7,29,25,.78); color: #fff; font-size: 12px; font-weight: 800; }
.chat-video-circle-row { display: flex; align-items: flex-end; gap: 10px; }
.chat-video-circle { --circle-size: 246px; position: relative; width: var(--circle-size); height: var(--circle-size); flex: 0 0 var(--circle-size); display: grid; place-items: center; overflow: visible; border-radius: 50%; cursor: pointer; transition: width 220ms ease, height 220ms ease, flex-basis 220ms ease, filter 180ms ease; }
.chat-video-circle.expanded { --circle-size: 340px; }
.chat-video-circle:hover { filter: brightness(1.04); }
.chat-video-circle video { position: absolute; inset: 8px; width: calc(100% - 16px); height: calc(100% - 16px); border-radius: 50%; background: #0b201d; object-fit: cover; pointer-events: none; box-shadow: 0 8px 24px rgba(20,59,52,.24); }
.chat-circle-ring { position: absolute; inset: 0; z-index: 3; width: 100%; height: 100%; overflow: visible; transform: rotate(-90deg); pointer-events: none; touch-action: none; }
.chat-circle-track, .chat-circle-progress { fill: none; stroke-width: 2.4; }
.chat-circle-track { stroke: rgba(21,61,54,.2); }
.chat-circle-progress { stroke: var(--blue); stroke-linecap: round; stroke-dasharray: 100; stroke-dashoffset: 100; transition: stroke-dashoffset 120ms linear; }
.chat-circle-hit { fill: none; stroke: transparent; stroke-width: 9; pointer-events: stroke; cursor: grab; }
.chat-circle-hit:active { cursor: grabbing; }
.chat-circle-time { min-width: 58px; margin-bottom: 15px; padding: 4px 7px; border-radius: 5px; background: #e8f2ef; color: #4b6d65; font-size: 12px; font-variant-numeric: tabular-nums; font-weight: 800; text-align: center; white-space: nowrap; }
.chat-audio { min-width: min(380px,72vw); display: grid; grid-template-columns: 44px minmax(110px,1fr) auto; align-items: center; gap: 10px; }
.chat-audio-play { width: 44px; height: 44px; display: grid; place-items: center; padding: 0; border-radius: 50%; background: var(--forest); color: #fff; }
.chat-audio-play svg { width: 21px; height: 21px; pointer-events: none; stroke-width: 3; }
.chat-audio input { width: 100%; min-height: auto; padding: 0; accent-color: var(--forest); }
.chat-audio-time { min-width: 70px; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; text-align: right; }
.chat-audio-file { width: min(460px,76vw); min-width: 310px; display: grid; grid-template-columns: 52px minmax(0,1fr) 40px; align-items: center; gap: 10px; padding: 10px; border: 1px solid #b9cec8; border-radius: 7px; background: #edf6f3; }
.chat-audio-file-play { width: 52px; height: 52px; display: grid; place-items: center; padding: 0; border-radius: 50%; background: var(--blue); color: #fff; box-shadow: 0 5px 13px rgba(47,111,179,.22); }
.chat-audio-file-play svg { width: 24px; height: 24px; pointer-events: none; stroke-width: 3; }
.chat-audio-file-copy { min-width: 0; display: grid; gap: 5px; }
.chat-audio-file-copy strong { overflow: hidden; color: var(--ink); font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.chat-audio-file-copy small { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chat-audio-file-copy small b { color: var(--blue); letter-spacing: .02em; }
.chat-audio-file-copy input { width: 100%; min-height: auto; padding: 0; accent-color: var(--blue); }
.chat-audio-file-copy .chat-audio-time { margin-left: auto; }
.chat-audio-file-download { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; background: #dcebe7; color: var(--forest); }
.chat-audio-file-download:hover { background: #cadfd9; }
.chat-audio-file-download svg { width: 19px; height: 19px; }
.chat-file { width: 100%; display: grid; grid-template-columns: 48px minmax(0,1fr) auto; align-items: center; gap: 10px; padding: 10px; border: 1px solid var(--line); border-radius: 7px; background: #f7faf9; color: var(--ink); text-align: left; text-decoration: none; }
.chat-file:hover { border-color: #8ab4a9; background: #edf6f3; }
.chat-file-icon { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 7px; background: var(--forest); color: #fff; font-size: 12px; font-weight: 900; }
.chat-file-text { min-width: 0; display: grid; gap: 3px; }
.chat-file-text strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-file-text small { color: var(--muted); }
.chat-file-download { color: var(--blue); font-size: 13px; font-weight: 900; }
.chat-upload-status { padding: 8px 18px; border-top: 1px solid var(--line); background: #fff9e9; color: #6a501c; font-size: 13px; font-weight: 800; }
.chat-composer-reference { min-width: 0; display: grid; grid-template-columns: 3px minmax(0,1fr) 38px; align-items: center; gap: 10px; padding: 8px 15px; border-top: 1px solid var(--line); background: #f7fbfa; }
.chat-reference-line { align-self: stretch; border-radius: 3px; background: var(--blue); }
.chat-reference-copy { min-width: 0; display: grid; gap: 2px; }
.chat-reference-copy strong, .chat-reference-copy span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-reference-copy strong { color: var(--blue); font-size: 12px; }
.chat-reference-copy span { color: var(--ink); font-size: 13px; }
.chat-composer-reference button { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; background: transparent; color: var(--muted); font-size: 23px; }
.chat-composer-reference button:hover { background: #e7f0ed; color: var(--ink); }
.chat-composer-reference .chat-reference-copy { width: 100%; height: auto; justify-items: start; padding: 5px 7px; border-radius: 5px; color: var(--ink); font-size: inherit; text-align: left; }
.chat-quote-picker { position: absolute; right: 16px; bottom: 82px; left: 16px; z-index: 32; width: min(620px,calc(100% - 32px)); margin: 0 auto; overflow: hidden; border: 1px solid #8faca4; border-radius: 8px; background: #fff; box-shadow: 0 18px 52px rgba(19,55,49,.3); }
.chat-quote-picker[hidden] { display: none; }
.chat-quote-picker header, .chat-quote-picker footer { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 11px 13px; background: #eff7f4; }
.chat-quote-picker header { border-bottom: 1px solid var(--line); }
.chat-quote-picker footer { border-top: 1px solid var(--line); }
.chat-quote-picker header > div { min-width: 0; display: grid; gap: 2px; }
.chat-quote-picker header strong { color: var(--forest); font-size: 15px; }
.chat-quote-picker header span, .chat-quote-picker footer span { color: var(--muted); font-size: 12px; font-weight: 700; }
.chat-quote-picker header button { width: 34px; height: 34px; flex: 0 0 34px; border-radius: 50%; background: transparent; color: var(--muted); font-size: 23px; }
.chat-quote-picker textarea { width: 100%; min-height: 110px; max-height: 240px; display: block; resize: vertical; padding: 13px; border: 0; border-radius: 0; background: #fff; color: var(--ink); font: inherit; line-height: 1.5; }
.chat-quote-picker textarea:focus { outline: 3px solid rgba(47,111,179,.24); outline-offset: -3px; }
.chat-quote-picker footer .primary-button { min-height: 40px; }
.chat-pending-attachments { display: flex; gap: 8px; overflow-x: auto; padding: 9px 14px; border-top: 1px solid var(--line); background: #f1f7f5; }
.chat-pending-item { min-width: 190px; max-width: 280px; display: grid; grid-template-columns: 42px minmax(0,1fr) 34px; align-items: center; gap: 9px; padding: 7px; border: 1px solid #bfd2cc; border-radius: 7px; background: #fff; }
.chat-pending-preview { width: 42px; height: 42px; display: grid; place-items: center; overflow: hidden; border-radius: 6px; background: var(--forest); color: #fff; font-size: 11px; font-weight: 900; }
.chat-pending-preview img, .chat-pending-preview video { width: 100%; height: 100%; object-fit: cover; }
.chat-pending-copy { min-width: 0; display: grid; gap: 2px; }
.chat-pending-copy strong { overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.chat-pending-copy small { color: var(--muted); font-size: 11px; }
.chat-pending-remove { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%; background: #f6e9eb; color: var(--danger); font-size: 20px; }
.chat-composer { position: relative; display: grid; grid-template-columns: 48px 48px minmax(0,1fr) 48px 48px 52px; align-items: end; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--line); background: #fff; }
.chat-input { width: 100%; min-height: 48px; max-height: 160px; overflow-y: auto; padding: 12px 14px; border: 1px solid var(--line-strong); border-radius: 8px; background: #fff; color: var(--ink); line-height: 1.4; white-space: pre-wrap; overflow-wrap: anywhere; user-select: text; -webkit-user-select: text; }
.chat-input:focus-visible { outline: 3px solid rgba(47,111,179,.36); outline-offset: 2px; }
.chat-input:empty::before { color: var(--muted); content: attr(data-placeholder); pointer-events: none; }
.chat-input-flag { width: 30px; height: 22px; display: inline-block; margin: 0 2px; border-radius: 2px; background: #eef4f2; object-fit: cover; vertical-align: -5px; box-shadow: 0 0 0 1px rgba(20,60,52,.16); user-select: none; -webkit-user-select: none; }
.chat-input-flag[src*="-telegram"] { background: transparent; object-fit: contain; box-shadow: none; }
.chat-input-emoji { width: 27px; height: 27px; display: inline-block; margin: 0 1px; vertical-align: -7px; }
.chat-icon-button, .chat-send-button { width: 48px; height: 48px; display: grid; place-items: center; padding: 0; border-radius: 50%; background: #edf4f2; color: var(--forest); font-size: 25px; font-weight: 800; }
.chat-icon-button:hover { background: #dcece7; }
.chat-send-button { width: 52px; height: 52px; background: var(--forest); color: #fff; font-size: 22px; }
.chat-send-button:hover { background: #236356; }
.chat-view-button { position: relative; }
.chat-unread-badge { position: absolute; top: -8px; right: -7px; min-width: 23px; height: 23px; display: grid; place-items: center; padding: 0 6px; border: 2px solid var(--forest); border-radius: 99px; background: #dc3545; color: #fff; font-size: 12px; font-weight: 900; line-height: 1; }
.topbar .chat-view-button:hover .chat-unread-badge { border-color: currentColor; }
.chat-emoji-wrap { position: static; }
.chat-emoji-picker { position: absolute; right: 0; bottom: 77px; left: 0; z-index: 12; max-height: min(430px,55vh); overflow: auto; padding: 0 18px 16px; border-top: 1px solid var(--line); background: #fff; box-shadow: 0 -18px 38px rgba(24,65,57,.14); }
.chat-emoji-tabs { position: sticky; top: 0; z-index: 1; display: flex; gap: 6px; overflow-x: auto; padding: 12px 0 10px; background: #fff; }
.chat-emoji-tabs button { min-width: fit-content; height: 36px; padding: 0 12px; border-radius: 6px; background: #edf4f2; color: var(--forest); font-size: 13px; font-weight: 800; }
.chat-emoji-tabs button.active { background: var(--forest); color: #fff; }
.chat-emoji-grid { display: grid; grid-template-columns: repeat(auto-fill,minmax(42px,1fr)); gap: 3px; }
.chat-emoji-grid button { width: 42px; height: 42px; justify-self: center; padding: 0; border-radius: 5px; background: transparent; font-family: "Segoe UI Emoji", "Noto Color Emoji", sans-serif; font-size: 24px; }
.chat-emoji-grid button:hover { background: var(--forest-soft); }
.chat-emoji-image { width: 30px; height: 30px; display: block; margin: auto; }
.chat-emoji-grid.flags { grid-template-columns: repeat(auto-fill,minmax(58px,1fr)); gap: 8px; }
.chat-emoji-grid.flags button { width: 58px; height: 46px; display: grid; place-items: center; }
.chat-emoji-grid.flags img.chat-telegram-emoji { width: 34px; height: 34px; }
.chat-emoji-grid.flags button.historical img { width: 44px; height: 33px; border-radius: 3px; object-fit: cover; box-shadow: 0 0 0 1px rgba(20,60,52,.16); }
.chat-emoji-grid.flags button.historical img[src*="-telegram"] { background: transparent; object-fit: contain; box-shadow: none; }
.chat-icon-button svg, .chat-send-button svg { width: 23px; height: 23px; stroke-width: 2.2; }
.chat-icon-button i, .chat-send-button i { display: grid; place-items: center; font-style: normal; font-size: 21px; }
.chat-context-menu { position: fixed; z-index: 90; min-width: 220px; overflow: hidden; padding: 6px; border: 1px solid var(--line); border-radius: 7px; background: #fff; box-shadow: var(--shadow); }
.chat-context-menu button { width: 100%; min-height: 40px; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 0 11px; border-radius: 5px; background: transparent; color: var(--ink); text-align: left; }
.chat-context-menu button:hover { background: var(--forest-soft); }
.chat-context-menu button.danger { color: var(--danger); }
.chat-context-menu span { color: var(--muted); font-size: 12px; }
.chat-quick-reactions { display: grid; grid-template-columns: repeat(7,36px); align-items: center; gap: 2px; margin: 0 0 5px; padding: 3px; border-bottom: 1px solid var(--line); }
.chat-context-menu .chat-quick-reactions button { width: 36px; min-height: 36px; justify-content: center; padding: 0; border-radius: 50%; }
.chat-context-menu .chat-quick-reactions button.more { background: #edf4f2; color: var(--forest); }
.chat-quick-reaction-emoji { width: 27px; height: 27px; }
.chat-reaction-picker { position: fixed; z-index: 95; width: min(390px,calc(100vw - 16px)); max-height: min(440px,70vh); overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: #fff; box-shadow: var(--shadow); }
.chat-reaction-picker header { min-height: 48px; display: flex; align-items: center; justify-content: space-between; padding: 7px 10px 7px 14px; border-bottom: 1px solid var(--line); }
.chat-reaction-picker header button { width: 34px; height: 34px; border-radius: 50%; background: transparent; color: var(--muted); font-size: 24px; }
.chat-reaction-picker header button:hover { background: var(--forest-soft); color: var(--forest); }
.chat-reaction-picker-grid { max-height: min(382px,calc(70vh - 50px)); display: grid; grid-template-columns: repeat(8,1fr); gap: 3px; overflow-y: auto; padding: 9px; }
.chat-reaction-picker-grid button { width: 40px; height: 40px; display: grid; place-items: center; justify-self: center; padding: 0; border-radius: 6px; background: transparent; }
.chat-reaction-picker-grid button:hover, .chat-reaction-picker-grid button.chosen { background: #d9eefb; }
.chat-reaction-picker-emoji { width: 29px; height: 29px; }
.chat-reaction-picker-grid button.historical img { width: 32px; height: 23px; border-radius: 2px; object-fit: cover; }
.chat-reaction-picker-grid button.historical img[src*="-telegram"] { background: transparent; object-fit: contain; box-shadow: none; }
.chat-recorder { position: fixed; right: 24px; bottom: 24px; z-index: 95; width: min(540px,calc(100vw - 32px)); display: grid; grid-template-columns: auto minmax(0,1fr) auto auto; align-items: center; gap: 13px; padding: 14px; border: 1px solid #86a79e; border-radius: 8px; background: #fff; box-shadow: var(--shadow); }
.chat-recorder video { width: 120px; height: 120px; grid-column: 1 / -1; justify-self: center; border-radius: 50%; background: #102d29; object-fit: cover; }
.chat-recording-pulse { width: 18px; height: 18px; border-radius: 50%; background: #d94756; box-shadow: 0 0 0 7px rgba(217,71,86,.14); animation: chat-recording 1.2s infinite; }
@keyframes chat-recording { 50% { box-shadow: 0 0 0 12px rgba(217,71,86,0); } }
.chat-recorder > div:nth-of-type(2) { display: grid; gap: 2px; }
.chat-recorder span { color: var(--muted); font-variant-numeric: tabular-nums; }

.media-viewer-window { position: absolute; top: 50%; left: 50%; width: min(1160px, calc(100vw - 28px)); max-height: calc(100vh - 28px); display: grid; grid-template-rows: auto minmax(0,1fr) auto; overflow: hidden; transform: translate(-50%, -50%); border-radius: 8px; background: #102d29; color: #f8fffc; box-shadow: var(--shadow); }
.media-viewer-header { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 16px 20px; border-bottom: 1px solid rgba(255,255,255,.16); }
.media-viewer-header .modal-kicker { color: #a9c7be; }
.media-viewer-actions { display: flex; align-items: center; gap: 14px; color: #c7ddd6; font-size: 14px; }
.media-zoom-value { min-width: 48px; color: #f6d58d; font-weight: 800; text-align: center; }
.media-header-button {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 50%;
  background: rgba(255,255,255,.1);
  color: #fff;
}
.media-header-button:hover { background: rgba(255,255,255,.2); }
.media-header-button svg { width: 20px; height: 20px; }
.media-viewer-actions .modal-close { background: rgba(255,255,255,.1); color: #fff; }
.media-viewer-content { min-height: 0; display: grid; grid-template-columns: 64px minmax(0,1fr) 64px; align-items: center; gap: 12px; padding: 16px; }
.media-stage { position: relative; min-width: 0; min-height: 360px; height: min(64vh,660px); display: flex; align-items: center; justify-content: center; overflow: hidden; border-radius: 6px; background: #09201d; }
.viewer-media { max-width: 100%; max-height: 100%; width: auto; height: auto; object-fit: contain; transform: scale(var(--media-zoom, 1)); transition: transform 160ms ease; }
#viewerVideo::-webkit-media-controls, .chat-video-circle video::-webkit-media-controls, .chat-media-tile video::-webkit-media-controls { display: none !important; }
#viewerVideo { cursor: pointer; }
.viewer-video-controls { position: absolute; right: 14px; bottom: 14px; left: 14px; display: grid; gap: 9px; padding: 10px; border: 1px solid rgba(255,255,255,.18); border-radius: 7px; background: rgba(7,25,22,.82); backdrop-filter: blur(8px); }
.video-progress-row { display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: center; gap: 10px; }
.video-progress { width: 100%; min-height: auto; padding: 0; accent-color: var(--gold); }
.video-time { min-width: 92px; color: #d8e9e4; font-size: 12px; font-variant-numeric: tabular-nums; text-align: right; }
.video-command-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.video-control-button { min-height: 40px; padding: 0 12px; border: 1px solid rgba(255,255,255,.26); border-radius: 5px; background: rgba(255,255,255,.1); color: #fff; font-size: 14px; font-weight: 800; }
.video-control-button:hover { background: rgba(255,255,255,.2); }
.video-control-button.video-play-toggle { width: 44px; min-width: 44px; height: 44px; padding: 0; display: grid; place-items: center; }
.video-play-toggle svg { width: 22px; height: 22px; pointer-events: none; stroke-width: 3; }
.video-volume-control { display: flex; align-items: center; gap: 8px; margin-left: auto; color: #ecf8f4; font-size: 13px; font-weight: 800; }
.video-volume-control input { width: 92px; min-height: auto; flex: 0 0 92px; padding: 0; accent-color: var(--gold); }
#mediaStage:fullscreen { width: 100vw; height: 100vh; border-radius: 0; background: #061a17; }
#mediaStage:fullscreen .viewer-media { max-width: 100vw; max-height: 100vh; }
.media-nav { width: 52px; height: 60px; border-radius: 6px; background: rgba(255,255,255,.12); color: #fff; font-size: 46px; line-height: 1; }
.media-nav:hover:not(:disabled) { background: rgba(255,255,255,.23); }
.media-filmstrip { display: flex; gap: 8px; min-height: 90px; overflow-x: auto; padding: 12px 16px; border-top: 1px solid rgba(255,255,255,.16); background: #0c2521; }
.filmstrip-item { position: relative; width: 78px; height: 64px; flex: 0 0 auto; overflow: hidden; padding: 0; border: 2px solid transparent; border-radius: 5px; background: #173a34; }
.filmstrip-item.active { border-color: var(--gold); }
.filmstrip-item img, .filmstrip-item video { width: 100%; height: 100%; object-fit: cover; }
.filmstrip-item span { position: absolute; right: 3px; bottom: 3px; padding: 2px 4px; border-radius: 3px; background: rgba(0,0,0,.65); color: #fff; font-size: 10px; }
.toast { position: fixed; bottom: 26px; left: 50%; z-index: 1100; max-width: min(560px, calc(100vw - 32px)); padding: 14px 18px; transform: translateX(-50%); border-radius: 7px; background: var(--forest); color: #fff; box-shadow: var(--shadow); font-weight: 700; }
*::-webkit-scrollbar { width: 12px; height: 12px; }
*::-webkit-scrollbar-track { background: #dbe7e3; }
*::-webkit-scrollbar-thumb { border: 3px solid #dbe7e3; border-radius: 99px; background: #78978e; }
*::-webkit-scrollbar-thumb:hover { background: #52786d; }

@media (max-width: 980px) {
  body { overflow: auto; }
  .app-shell { min-height: 100%; height: auto; }
  body[data-view="chat"] { overflow: hidden; }
  body[data-view="chat"] .app-shell { height: 100dvh; min-height: 0; }
  body[data-view="chat"] .chat-workspace { height: auto; min-height: 0; flex: 1 1 auto; }
  .topbar { grid-template-columns: 1fr auto; min-height: auto; gap: 14px; padding: 14px 18px; }
  .search-wrap { grid-column: 1 / -1; grid-row: 2; width: 100%; }
  .workspace { min-height: calc(100vh - 160px); grid-template-columns: 1fr; }
  .map-workspace { min-height: calc(100vh - 160px); grid-template-columns: 320px minmax(0,1fr); }
  .chat-workspace { height: calc(100vh - 160px); min-height: 620px; }
  .admin-panel { width: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .tree-stage { min-height: 72vh; }
  .editor-personal-layout, .person-view { grid-template-columns: 1fr; }
  .profile-layout { grid-template-columns: 1fr; }
  .editor-photo-area { grid-template-columns: 190px 1fr; align-items: center; }
  .editor-photo-area small { grid-column: 2; }
}
@media (max-width: 680px) {
  .topbar { grid-template-columns: 1fr; padding: 12px; }
  body[data-view="chat"] .search-wrap { display: none; }
  .top-actions { display: grid; grid-template-columns: 1fr 1fr; justify-content: stretch; }
  .top-actions button { width: 100%; min-width: 0; min-height: 48px; overflow: visible; padding: 6px 9px; line-height: 1.2; white-space: normal; }
  .brand strong { font-size: 18px; }
  .workspace { min-height: calc(100vh - 190px); }
  .map-workspace { min-height: calc(100vh - 190px); grid-template-columns: 1fr; grid-template-rows: auto minmax(500px,68vh); }
  .chat-workspace { height: calc(100vh - 190px); min-height: 590px; }
  .chat-header { min-height: 66px; padding: 10px 13px; }
  .chat-header h1 { font-size: 20px; }
  .chat-message-count { padding: 6px 8px; font-size: 11px; }
  .chat-messages { padding: 15px 9px 22px; }
  .chat-message { grid-template-columns: 38px minmax(0,1fr); gap: 7px; }
  .chat-message.own { grid-template-columns: minmax(0,1fr) 38px; }
  .chat-avatar { width: 38px; height: 38px; font-size: 12px; }
  .chat-bubble { max-width: 91%; }
  .chat-composer { grid-template-columns: 38px 38px minmax(0,1fr) 38px 38px 42px; gap: 4px; padding: 8px 6px; }
  .chat-icon-button { width: 42px; height: 42px; font-size: 22px; }
  .chat-composer .chat-icon-button { width: 38px; height: 42px; }
  .chat-send-button { width: 42px; height: 46px; }
  .chat-emoji-picker { bottom: 70px; max-height: 48vh; padding-right: 8px; padding-left: 8px; }
  .chat-emoji-grid { grid-template-columns: repeat(6,1fr); }
  .chat-video-circle { --circle-size: min(230px,calc(100vw - 128px)); }
  .chat-video-circle.expanded { --circle-size: min(270px,calc(100vw - 128px)); }
  .chat-video-circle-row { width: fit-content; max-width: 100%; display: flex; align-items: flex-end; gap: 6px; }
  .chat-circle-time { min-width: 56px; margin: 0 0 14px; padding-right: 4px; padding-left: 4px; }
  .chat-quote-picker { right: 8px; bottom: 72px; left: 8px; width: calc(100% - 16px); }
  .chat-quote-picker footer { align-items: stretch; flex-direction: column; }
  .chat-selection-bar { align-items: stretch; flex-direction: column; }
  .chat-selection-bar > div { display: grid; grid-template-columns: repeat(3,1fr); }
  .profile-reaction-grid { grid-template-columns: repeat(6,1fr); }
  .chat-audio { min-width: min(300px,70vw); grid-template-columns: 40px minmax(80px,1fr); }
  .chat-audio-time { grid-column: 2; text-align: left; }
  .chat-audio-file { width: min(310px,78vw); min-width: 0; grid-template-columns: 46px minmax(0,1fr) 36px; gap: 7px; padding: 8px; }
  .chat-audio-file-play { width: 46px; height: 46px; }
  .chat-audio-file-copy small { align-items: flex-start; flex-wrap: wrap; gap: 3px 6px; }
  .chat-audio-file-copy .chat-audio-time { margin-left: 0; }
  .chat-audio-file-download { width: 36px; height: 36px; }
  .chat-file { grid-template-columns: 42px minmax(0,1fr); }
  .chat-file-download { display: none; }
  .chat-recorder { right: 10px; bottom: 10px; grid-template-columns: auto minmax(0,1fr); }
  .chat-recorder .secondary-button, .chat-recorder .primary-button { width: 100%; }
  .map-sidebar { max-height: 44vh; padding: 18px 14px; border-right: 0; border-bottom: 1px solid var(--line); }
  .map-filters { grid-template-columns: 1fr; }
  .map-legend { right: 10px; top: 10px; gap: 10px; padding: 9px 10px; }
  .admin-panel { padding: 18px 14px; }
  .tool-grid { grid-template-columns: 1fr 1fr; }
  .panel-heading { margin-bottom: 16px; }
  .zoom-rail { right: 10px; bottom: 10px; grid-template-columns: 42px 122px 42px; gap: 7px; padding: 8px; }
  .zoom-rail button { width: 42px; height: 40px; }
  .zoom-rail input { width: 122px; }
  .modal-window, .modal-window.narrow, .editor-window, .person-modal { width: calc(100vw - 20px); max-height: calc(100vh - 20px); }
  .modal-header, .modal-body { padding: 18px; }
  .modal-title { font-size: 22px; }
  .auth-tabs, .editor-tabs { overflow-x: auto; padding-left: 18px; padding-right: 18px; }
  .auth-tabs { padding: 0; }
  .editor-panel { padding: 18px; }
  .editor-fields-grid, .relation-fields, .form-grid.two { grid-template-columns: 1fr; }
  .relation-add-panel, .relation-editor-row { grid-template-columns: 1fr; }
  .relation-add-grid, .relation-row-fields { grid-template-columns: 1fr; }
  .relation-add-grid .full, .relation-row-fields .full { grid-column: auto; }
  .relation-add-button { width: 100%; }
  .relation-row-actions { grid-column: 1; justify-content: stretch; }
  .relation-row-actions button { flex: 1; }
  .relation-inline-confirm { grid-template-columns: 1fr; }
  .relation-inline-confirm > div button { flex: 1; }
  .editor-photo-area { grid-template-columns: 1fr; }
  .editor-photo-area small { grid-column: auto; }
  .editor-photo-preview { width: 160px; }
  .editor-footer { align-items: flex-start; flex-direction: column; padding: 16px 18px; }
  .editor-footer .modal-actions { width: 100%; }
  .editor-footer .modal-actions button { flex: 1; }
  .person-view { gap: 20px; }
  .person-main-photo { max-width: 250px; }
  .fact-line { grid-template-columns: 1fr; gap: 3px; }
  .media-viewer-window { width: calc(100vw - 12px); max-height: calc(100vh - 12px); }
  .media-viewer-content { grid-template-columns: 40px minmax(0,1fr) 40px; gap: 6px; padding: 8px; }
  .media-stage { min-height: 260px; height: 55vh; }
  .media-nav { width: 38px; height: 52px; font-size: 36px; }
  .media-viewer-header { padding: 12px; }
  .media-viewer-header strong { font-size: 14px; }
  .media-viewer-actions { gap: 8px; }
  .media-zoom-value { min-width: 40px; }
  .viewer-video-controls { right: 8px; bottom: 8px; left: 8px; gap: 8px; padding: 8px; }
  .video-control-button { min-height: 36px; padding: 0 9px; font-size: 13px; }
  .video-command-row { flex-wrap: wrap; gap: 8px; }
  .video-volume-control { margin-left: 0; }
  .video-volume-control input { width: 78px; flex-basis: 78px; }
  .user-row { grid-template-columns: 1fr; }
  .user-row-actions { justify-content: space-between; }
  .keys-toolbar { align-items: stretch; flex-direction: column; }
  .access-key-row { grid-template-columns: 1fr; }
  .access-key-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .access-lock-panel { padding: 24px 18px; }
  .confirm-body { padding: 30px 18px 20px; }
  .confirm-actions { grid-template-columns: 1fr; }
}

/* Mobile application layout */
@media (max-width: 980px) {
  html, body { height: 100%; min-height: 100%; }
  body { overflow: hidden; }
  .app-shell, body[data-view="chat"] .app-shell { height: 100dvh; min-height: 0; }
  .topbar { grid-template-columns: minmax(190px,1fr) auto; gap: 10px; padding: 10px 14px; }
  .brand-mark { width: 50px; height: 50px; }
  .top-actions { flex-wrap: nowrap; gap: 8px; }
  .top-actions button { width: 46px; min-width: 46px; height: 46px; padding: 0; }
  .top-actions button svg { width: 22px; height: 22px; }
  .top-actions .desktop-nav-label, .top-actions .mobile-nav-label { display: none; }
  .workspace { position: relative; display: block; height: auto; min-height: 0; flex: 1 1 auto; }
  .tree-stage { position: absolute; inset: 0; min-height: 0; }
  .admin-panel {
    position: absolute;
    top: 14px;
    left: 14px;
    z-index: 8;
    width: min(340px, calc(100% - 28px));
    max-height: calc(100% - 28px);
    overflow: auto;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
  }
  .mobile-tools-toggle {
    width: 100%;
    min-height: 52px;
    display: grid;
    grid-template-columns: 24px minmax(0,1fr) 22px;
    align-items: center;
    gap: 11px;
    padding: 8px 12px;
    border-radius: 6px;
    background: #fff;
    color: var(--forest);
    text-align: left;
  }
  .mobile-tools-toggle > span { min-width: 0; display: grid; gap: 2px; }
  .mobile-tools-toggle strong { font-size: 15px; }
  .mobile-tools-toggle small { overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
  .mobile-tools-toggle svg { width: 21px; height: 21px; }
  .admin-panel.mobile-collapsed { padding: 0; overflow: hidden; }
  .admin-panel.mobile-collapsed > :not(.mobile-tools-toggle) { display: none; }
  .admin-panel:not(.mobile-collapsed) .mobile-tools-toggle {
    width: calc(100% + 24px);
    margin: -12px -12px 14px;
    border-bottom: 1px solid var(--line);
    border-radius: 7px 7px 0 0;
  }
  .map-workspace { height: auto; min-height: 0; flex: 1 1 auto; grid-template-columns: minmax(280px,320px) minmax(0,1fr); }
  .chat-workspace, body[data-view="chat"] .chat-workspace { height: auto; min-height: 0; flex: 1 1 auto; }
}

@media (max-width: 680px) {
  body { overflow: hidden; }
  .app-shell, body[data-view="chat"] .app-shell {
    height: 100dvh;
    min-height: 0;
    padding-bottom: calc(64px + env(safe-area-inset-bottom));
  }
  .topbar {
    min-height: 0;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    gap: 8px;
    padding: 8px 10px;
  }
  .brand { min-width: 0; gap: 9px; }
  .brand-mark { width: 44px; height: 44px; }
  .brand strong { font-size: 17px; }
  .brand small { margin-top: 2px; font-size: 12px; }
  .search-wrap { grid-column: 1; grid-row: 2; }
  #searchInput { height: 42px; min-height: 42px; padding: 0 13px; font-size: 14px; }
  body[data-view="chat"] .search-wrap, body[data-view="map"] .search-wrap { display: none; }

  .top-actions {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 45;
    height: calc(64px + env(safe-area-inset-bottom));
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0,1fr);
    gap: 0;
    padding: 0 4px env(safe-area-inset-bottom);
    border-top: 1px solid var(--line);
    background: rgba(255,255,255,.98);
    box-shadow: 0 -8px 26px rgba(20,55,49,.13);
  }
  .top-actions button, .top-actions #authButton {
    width: 100%;
    min-width: 0;
    min-height: 64px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    overflow: visible;
    padding: 6px 2px;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: #526963;
    box-shadow: none;
    line-height: 1;
    white-space: nowrap;
  }
  .top-actions button:hover, .top-actions #authButton:hover { transform: none; background: #eef5f3; }
  .top-actions button svg { width: 22px; height: 22px; }
  .top-actions .desktop-nav-label { display: none; }
  .top-actions .mobile-nav-label { display: block; font-size: 10px; font-weight: 800; line-height: 1.1; }
  .top-actions .active { background: #e5f1ed; color: var(--forest); box-shadow: inset 0 3px 0 var(--forest); }
  .top-actions #authButton { color: #9a6322; }
  .chat-unread-badge { top: 4px; right: 8px; border-color: #fff; }

  .workspace, .map-workspace, .chat-workspace, body[data-view="chat"] .chat-workspace { height: auto; min-height: 0; flex: 1 1 auto; }
  .workspace { position: relative; display: block; }
  .tree-stage { position: absolute; inset: 0; min-height: 0; }
  .admin-panel { top: 8px; right: 8px; left: 8px; width: auto; max-height: calc(100% - 16px); padding: 12px; }
  .mobile-tools-toggle { min-height: 48px; }
  .admin-panel:not(.mobile-collapsed) .mobile-tools-toggle { margin: -12px -12px 12px; }
  .mobile-hint { display: block; }
  .desktop-hint { display: none; }
  .hint { margin-top: 12px; padding: 10px; font-size: 12px; }
  .zoom-rail { right: 8px; bottom: 8px; grid-template-columns: 40px minmax(90px,120px) 40px; gap: 5px; padding: 6px; }
  .zoom-rail button { width: 40px; height: 40px; }
  .zoom-rail input { width: 100%; }

  .map-workspace { position: relative; display: block; }
  .family-map-stage { position: absolute; inset: 0; }
  .map-sidebar {
    position: absolute;
    right: 8px;
    bottom: 8px;
    left: 8px;
    z-index: 510;
    max-height: min(48%,360px);
    overflow: auto;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255,255,255,.97);
    box-shadow: var(--shadow);
  }
  .map-sidebar-heading { margin-bottom: 10px; }
  .map-sidebar-heading h1 { font-size: 20px; }
  .map-kicker { font-size: 10px; }
  .map-count { min-width: 34px; height: 34px; font-size: 13px; }
  .map-search { gap: 5px; font-size: 12px; }
  .map-search input { min-height: 42px; }
  .map-filters { grid-template-columns: 1fr 1fr; gap: 6px; margin: 9px 0; }
  .map-filters label { min-height: 40px; padding: 6px; font-size: 11px; }
  .map-fit-button { min-height: 40px; }
  .map-location-list { display: flex; gap: 8px; overflow-x: auto; margin-top: 10px; padding: 0 0 4px; scroll-snap-type: x mandatory; }
  .map-location-item { min-width: min(275px,78vw); grid-template-columns: 38px minmax(0,1fr); padding: 8px; scroll-snap-align: start; }
  .map-location-avatar { width: 38px; height: 46px; }
  .map-location-copy strong { font-size: 13px; }
  .map-location-copy small, .map-location-copy em { font-size: 11px; }
  .map-legend { top: 8px; right: 8px; gap: 8px; padding: 7px 9px; font-size: 10px; }

  .chat-messages { padding: 12px 7px 18px; }
  .chat-message { grid-template-columns: 34px minmax(0,1fr); gap: 6px; margin: 10px 0; }
  .chat-message.own { grid-template-columns: minmax(0,1fr) 34px; }
  .chat-avatar { width: 34px; height: 34px; font-size: 10px; }
  .chat-bubble { min-width: 0; max-width: 94%; padding: 8px 9px 7px; }
  .chat-pinned-bar { min-height: 50px; grid-template-columns: 36px minmax(0,1fr) 36px; }
  .chat-pinned-current { padding: 6px 8px; }
  .chat-pinned-current strong { font-size: 12px; }
  .chat-context-menu, .chat-reaction-picker {
    right: 8px !important;
    bottom: calc(72px + env(safe-area-inset-bottom));
    left: 8px !important;
    top: auto !important;
    width: auto;
    min-width: 0;
  }
  .chat-reaction-picker-grid { grid-template-columns: repeat(7,1fr); }
  .chat-recorder { right: 8px; bottom: calc(72px + env(safe-area-inset-bottom)); left: 8px; width: auto; }
  .toast { bottom: calc(76px + env(safe-area-inset-bottom)); }

  .modal-window, .modal-window.narrow, .editor-window, .person-modal, .profile-window {
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100vw;
    max-height: calc(100dvh - 8px);
    transform: none;
    border-radius: 8px 8px 0 0;
  }
  .modal-header { position: sticky; top: 0; z-index: 5; padding: 13px 14px; background: #fff; }
  .modal-title { font-size: 20px; }
  .modal-kicker { font-size: 11px; }
  .modal-close { width: 40px; height: 40px; }
  .modal-body { padding: 14px; }
  .person-view { grid-template-columns: 1fr; gap: 14px; }
  .person-main-photo { max-width: 210px; margin: 0 auto; }
  .fact-line { grid-template-columns: 1fr; gap: 3px; padding: 8px 0; }
  .editor-window { height: calc(100dvh - 8px); display: flex; flex-direction: column; overflow: hidden; }
  .editor-header { flex: 0 0 auto; }
  .editor-tabs { flex: 0 0 auto; margin: 0; overflow-x: auto; padding: 8px 12px; }
  .editor-form { min-height: 0; flex: 1 1 auto; overflow: hidden; }
  .editor-panel { min-height: 0; overflow: auto; padding: 14px; }
  .editor-footer { flex: 0 0 auto; position: relative; padding: 10px 12px; }
  .editor-footer > span { display: none; }
  .editor-footer .modal-actions { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0; }
  .editor-footer .modal-actions button { min-height: 44px; }
  .form-grid, .form-grid.two, .editor-fields-grid, .relation-fields { grid-template-columns: 1fr; }
  .profile-avatar-panel { justify-items: center; }
  .profile-avatar { width: 116px; height: 116px; }
  .profile-save-nickname { width: 100%; justify-self: stretch; }
  .profile-push-row { grid-template-columns: 1fr; }
  .profile-push-row button { width: 100%; }
  .profile-push-actions { display: grid; grid-template-columns: 1fr; }
  .access-key-main code { max-width: 100%; overflow-wrap: anywhere; font-size: 15px; letter-spacing: 1px; }
  .access-key-main span { white-space: normal; }
}

@media (max-width: 420px) {
  .brand small { display: none; }
  .topbar { padding: 7px 8px; }
  .mobile-nav-label { font-size: 9px; }
  .chat-composer {
    grid-template-columns: repeat(5,1fr);
    grid-template-areas: "input input input input input" "attach emoji voice circle send";
    gap: 6px;
    padding: 7px 8px;
  }
  .chat-input { grid-area: input; min-height: 42px; max-height: 110px; padding: 9px 11px; }
  #chatAttachButton { grid-area: attach; }
  #chatEmojiButton { grid-area: emoji; }
  #chatVoiceButton { grid-area: voice; }
  #chatCircleButton { grid-area: circle; }
  #chatSendButton { grid-area: send; }
  .chat-composer .chat-icon-button, .chat-send-button { width: 42px; height: 42px; justify-self: center; }
  .chat-emoji-picker { bottom: 104px; }
  .chat-quote-picker { bottom: 108px; }
  .map-filters { grid-template-columns: 1fr; }
}

@media (max-width: 900px) and (max-height: 560px) {
  .topbar { grid-template-columns: auto minmax(160px,1fr) auto; grid-template-rows: auto; gap: 10px; padding: 6px 10px; }
  .search-wrap { grid-column: 2; grid-row: 1; }
  .top-actions { grid-column: 3; grid-row: 1; }
  body[data-view="chat"] .topbar, body[data-view="map"] .topbar { grid-template-columns: 1fr; }
  .brand-mark { width: 40px; height: 40px; }
  .brand small { display: none; }
  .map-sidebar { max-height: 72%; }
}

/* Touch-friendly map panel and media viewer */
.media-stage { touch-action: none; }
.viewer-media {
  transform: translate3d(var(--media-pan-x,0),var(--media-pan-y,0),0) scale(var(--media-zoom,1));
  transform-origin: center;
  transition: transform 120ms ease;
  will-change: transform;
}
#viewerVideo { width: 100%; height: 100%; object-fit: contain; }
.video-center-toggle {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 4;
  width: 68px;
  height: 68px;
  display: grid;
  place-items: center;
  padding: 0;
  transform: translate(-50%,-50%);
  border: 1px solid rgba(255,255,255,.58);
  border-radius: 50%;
  background: rgba(8,35,31,.76);
  color: #fff;
  box-shadow: 0 9px 28px rgba(0,0,0,.28);
  backdrop-filter: blur(8px);
  transition: opacity 150ms ease, transform 150ms ease;
}
.video-center-toggle svg { width: 31px; height: 31px; margin-left: 3px; fill: currentColor; stroke-width: 1.7; }
.media-stage.video-playing .video-center-toggle { opacity: 0; pointer-events: none; transform: translate(-50%,-50%) scale(.9); }
.viewer-video-controls {
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 3;
  gap: 7px;
  padding: 44px 16px 14px;
  border: 0;
  border-radius: 0;
  background: linear-gradient(transparent,rgba(3,20,18,.86));
  backdrop-filter: none;
}
.video-progress {
  width: 100%;
  height: 18px;
  min-height: 18px;
  margin: 0;
  padding: 0;
  accent-color: #58aef4;
  cursor: pointer;
  touch-action: pan-x;
}
.video-command-row { min-height: 38px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.video-time { min-width: 0; color: #fff; font-size: 13px; font-weight: 800; text-align: left; text-shadow: 0 1px 3px rgba(0,0,0,.75); }
.video-control-actions { display: flex; align-items: center; gap: 7px; }
.video-control-button {
  width: 40px;
  min-width: 40px;
  height: 40px;
  min-height: 40px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(255,255,255,.32);
  border-radius: 50%;
  background: rgba(7,31,28,.68);
  color: #fff;
}
.video-control-button svg { width: 20px; height: 20px; }
#mediaStage:fullscreen, #mediaStage:-webkit-full-screen { width: 100vw; height: 100dvh; border-radius: 0; background: #031612; }
#mediaStage:fullscreen .viewer-media, #mediaStage:-webkit-full-screen .viewer-media { max-width: 100vw; max-height: 100dvh; }

@media (max-width: 980px) {
  .map-sidebar-actions { gap: 6px; }
  .map-sidebar-close { width: 36px; height: 36px; }
  .map-sidebar-toggle { top: 8px; left: 8px; width: 46px; height: 46px; }
  .map-workspace.map-menu-collapsed .family-map-stage { inset: 0; }

  .media-viewer-window {
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100vw;
    height: 100dvh;
    max-height: none;
    grid-template-rows: minmax(0,1fr);
    transform: none;
    border-radius: 0;
    background: #031612;
  }
  .media-viewer-header {
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    z-index: 8;
    min-height: 64px;
    padding: calc(8px + env(safe-area-inset-top)) 10px 8px;
    border: 0;
    background: linear-gradient(rgba(2,21,18,.9),transparent);
    pointer-events: none;
  }
  .media-viewer-header > div:first-child { min-width: 0; }
  .media-viewer-header .modal-kicker,
  .media-viewer-header strong { display: block; max-width: 54vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .media-viewer-header .modal-kicker { font-size: 10px; }
  .media-viewer-header strong { font-size: 12px; }
  .media-viewer-actions { gap: 7px; font-size: 11px; pointer-events: auto; }
  .media-zoom-value { min-width: 34px; }
  .media-viewer-actions .modal-close { width: 42px; height: 42px; }
  .media-viewer-content { position: relative; display: block; height: 100%; padding: 0; }
  .media-stage { width: 100%; height: 100%; min-height: 0; border-radius: 0; }
  .viewer-media { max-width: 100%; max-height: 100%; transition: none; }
  .media-nav {
    position: absolute;
    top: 50%;
    z-index: 7;
    width: 38px;
    height: 58px;
    transform: translateY(-50%);
    border: 0;
    background: rgba(5,31,27,.42);
    font-size: 34px;
    backdrop-filter: blur(5px);
  }
  .media-nav.prev { left: 5px; }
  .media-nav.next { right: 5px; }
  .media-nav:disabled { visibility: hidden; }
  .media-filmstrip { display: none; }
  .video-center-toggle { width: 64px; height: 64px; }
  .viewer-video-controls { padding: 44px 12px calc(12px + env(safe-area-inset-bottom)); }
  .video-command-row { min-height: 34px; }
  .video-control-button { width: 42px; min-width: 42px; height: 42px; min-height: 42px; }
}

@media (max-width: 900px) and (max-height: 560px) and (orientation: landscape) {
  .media-viewer-header { min-height: 48px; padding: 5px 8px; }
  .media-viewer-header > div:first-child { display: none; }
  .media-viewer-actions { margin-left: auto; }
  .viewer-video-controls { padding: 28px max(14px,env(safe-area-inset-right)) max(7px,env(safe-area-inset-bottom)) max(14px,env(safe-area-inset-left)); }
  .video-center-toggle { width: 58px; height: 58px; }
  .video-center-toggle svg { width: 27px; height: 27px; }
  .video-control-button { width: 38px; min-width: 38px; height: 38px; min-height: 38px; }
}

/* Phones in landscape can report a tablet-like CSS width. */
@media (max-width: 1200px) and (max-height: 620px) and (orientation: landscape) {
  .app-shell, body[data-view="chat"] .app-shell {
    height: 100dvh;
    min-height: 0;
    padding-bottom: 0;
  }
  .topbar {
    min-height: 54px;
    height: 54px;
    grid-template-columns: minmax(170px,1fr) minmax(190px,420px) auto;
    grid-template-rows: 54px;
    gap: 8px;
    padding: 4px 10px;
  }
  body[data-view="chat"] .topbar,
  body[data-view="map"] .topbar { grid-template-columns: minmax(170px,1fr) auto; }
  body[data-view="chat"] .search-wrap,
  body[data-view="map"] .search-wrap { display: none; }
  .brand { min-width: 0; gap: 8px; }
  .brand-mark { width: 38px; height: 38px; }
  .brand strong { font-size: 17px; white-space: nowrap; }
  .brand small { display: none; }
  .search-wrap { grid-column: 2; grid-row: 1; }
  #searchInput { height: 40px; min-height: 40px; padding: 0 11px; font-size: 13px; }
  .top-actions {
    position: static;
    grid-column: 3;
    grid-row: 1;
    width: auto;
    height: auto;
    display: flex;
    gap: 6px;
    padding: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
  }
  body[data-view="chat"] .top-actions,
  body[data-view="map"] .top-actions { grid-column: 2; }
  .top-actions button,
  .top-actions #authButton {
    width: 42px;
    min-width: 42px;
    min-height: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 1px solid rgba(255,255,255,.28);
    border-radius: 6px;
    background: rgba(255,255,255,.05);
    color: #fff;
    box-shadow: none;
  }
  .top-actions .desktop-nav-label,
  .top-actions .mobile-nav-label { display: none; }
  .top-actions .active { background: var(--gold); color: #153d36; box-shadow: none; }
  .top-actions #authButton { color: #fff; }

  .workspace, .map-workspace, .chat-workspace, body[data-view="chat"] .chat-workspace {
    height: auto;
    min-height: 0;
    flex: 1 1 auto;
  }
  .chat-pinned-bar { min-height: 42px; grid-template-columns: 36px minmax(0,1fr) 36px; }
  .chat-pinned-current { gap: 0; padding: 4px 9px; }
  .chat-pinned-current span { font-size: 10px; }
  .chat-pinned-current strong { font-size: 12px; }
  .chat-typing-bar { min-height: 28px; padding: 3px 10px; font-size: 11px; }
  .chat-messages { padding: 8px 14px 10px; }
  .chat-message { margin: 7px 0; }
  .chat-composer {
    grid-template-columns: 40px 40px minmax(0,1fr) 40px 40px 44px;
    gap: 5px;
    padding: 5px 8px;
  }
  .chat-input { min-height: 40px; max-height: 76px; padding: 8px 11px; }
  .chat-composer .chat-icon-button { width: 40px; height: 40px; }
  .chat-send-button { width: 44px; height: 44px; }
  .chat-emoji-picker { bottom: 56px; max-height: calc(100dvh - 112px); }
  .chat-recorder { right: 8px; bottom: 8px; left: auto; width: min(500px,calc(100vw - 16px)); }
  .chat-recorder video { width: min(120px,28vh); height: min(120px,28vh); }
  .chat-video-circle { --circle-size: min(190px,calc(100dvh - 165px)); }
  .chat-video-circle.expanded { --circle-size: min(230px,calc(100dvh - 150px)); }

  .modal-window,
  .modal-window.narrow,
  .editor-window,
  .person-modal,
  .profile-window,
  .keys-window {
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100vw;
    height: 100dvh;
    max-height: none;
    transform: none;
    border-radius: 0;
  }
  .modal-header { position: sticky; top: 0; z-index: 5; min-height: 50px; padding: 6px 12px; background: #fff; }
  .modal-title { font-size: 19px; }
  .modal-kicker { margin-bottom: 1px; font-size: 9px; }
  .modal-close { width: 38px; height: 38px; }
  .modal-body { padding: 10px 12px; }
  .profile-layout { grid-template-columns: 160px minmax(0,1fr); gap: 16px; }
  .profile-avatar { width: 86px; height: 86px; }
  .profile-avatar-panel small { font-size: 10px; text-align: center; }
}

/* Message metadata stays inside its bubble even for wide media attachments. */
.chat-bubble,
.chat-message-attachments { min-width: 0; max-width: 100%; }
.chat-message-meta {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  padding-inline: 2px;
  line-height: 1;
  white-space: nowrap;
}
.chat-receipt { flex: 0 0 auto; }
.chat-video-circle-row {
  width: fit-content;
  max-width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0,1fr);
  justify-items: start;
  align-items: start;
  gap: 0;
}
.chat-video-circle { max-width: 100%; }
.chat-circle-time {
  max-width: 100%;
  justify-self: end;
  margin: 4px 4px 0 0;
  padding: 3px 6px;
}

/* Recorder: a focused, touch-friendly capture surface instead of a file picker. */
body.recording-open { overflow: hidden; }
.chat-recorder {
  position: fixed;
  inset: 0;
  z-index: 1300;
  width: 100vw;
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0,1fr);
  grid-template-rows: minmax(0,1fr) auto auto;
  justify-items: center;
  align-items: center;
  gap: 22px;
  padding: max(24px,env(safe-area-inset-top)) 20px max(28px,env(safe-area-inset-bottom));
  border: 0;
  border-radius: 0;
  background: rgba(3,29,25,.97);
  color: #fff;
  box-shadow: none;
  backdrop-filter: blur(16px);
}
.chat-recorder-visual {
  position: relative;
  width: min(64vw,340px);
  max-height: 100%;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  align-self: end;
}
.chat-recorder video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  grid-column: auto;
  justify-self: auto;
  border: 5px solid rgba(161,215,201,.72);
  border-radius: 50%;
  background: #071b18;
  object-fit: cover;
  transform: scaleX(-1);
  box-shadow: 0 18px 56px rgba(0,0,0,.42), 0 0 0 1px rgba(255,255,255,.12);
}
.chat-recorder-audio {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 50%;
  background: radial-gradient(circle at 50% 35%,#28695d 0,#154a41 46%,#0a312b 100%);
  box-shadow: 0 18px 56px rgba(0,0,0,.36), inset 0 0 0 12px rgba(255,255,255,.035);
}
.chat-recorder-audio > svg { width: 70px; height: 70px; color: #fff; stroke-width: 1.7; }
.chat-recorder-circle-placeholder {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  align-content: center;
  gap: 12px;
  border: 5px solid rgba(161,215,201,.72);
  border-radius: 50%;
  background: radial-gradient(circle at 50% 35%,rgba(62,111,101,.92) 0,#163f38 48%,#071b18 100%);
  color: #fff;
  box-shadow: 0 18px 56px rgba(0,0,0,.42), 0 0 0 1px rgba(255,255,255,.12);
}
.chat-recorder-circle-placeholder svg { width: 72px; height: 72px; stroke-width: 1.5; }
.chat-recorder-circle-placeholder span { color: #c8dbd6; font-size: 13px; font-weight: 800; }
.chat-recorder.circle-mode .chat-recorder-audio { display: none; }
.chat-recorder.circle-mode .chat-recorder-circle-placeholder { display: grid; }
.chat-recorder.circle-mode.has-preview .chat-recorder-circle-placeholder { display: none; }
.chat-recorder.voice-mode .chat-recorder-circle-placeholder { display: none; }
.chat-recorder.voice-mode video { display: none !important; }
.chat-recorder.is-preparing .chat-recorder-action.finish {
  opacity: .55;
  pointer-events: none;
}
.chat-recording-pulse {
  position: absolute;
  top: 7%;
  right: 7%;
  z-index: 3;
  width: 18px;
  height: 18px;
  border: 3px solid rgba(255,255,255,.92);
  border-radius: 50%;
  background: #e64a58;
  box-shadow: 0 0 0 7px rgba(230,74,88,.2);
  animation: chat-recording 1.2s infinite;
}
.chat-recorder-wave {
  position: absolute;
  bottom: 24%;
  left: 50%;
  display: flex;
  align-items: center;
  gap: 6px;
  transform: translateX(-50%);
}
.chat-recorder-wave b {
  width: 5px;
  height: 24px;
  border-radius: 4px;
  background: #f2c96f;
  animation: recorder-wave .9s ease-in-out infinite alternate;
}
.chat-recorder-wave b:nth-child(2), .chat-recorder-wave b:nth-child(4) { height: 39px; animation-delay: -.3s; }
.chat-recorder-wave b:nth-child(3) { height: 52px; animation-delay: -.55s; }
@keyframes recorder-wave { to { transform: scaleY(.38); opacity: .62; } }
.chat-recorder-copy {
  display: grid;
  justify-items: center;
  gap: 5px;
  color: #fff;
  text-align: center;
}
.chat-recorder-copy strong { color: #fff; font-size: clamp(20px,5vw,28px); }
.chat-recorder #chatRecorderTime {
  color: #f4d17f;
  font-size: clamp(34px,9vw,48px);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
}
.chat-recorder-copy small { max-width: 330px; color: #b9d0ca; font-size: 13px; line-height: 1.4; }
.chat-recorder-actions { display: flex; align-items: start; justify-content: center; gap: 34px; }
.chat-recorder-action {
  width: 92px;
  min-height: 88px;
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 7px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  -webkit-tap-highlight-color: transparent;
}
.chat-recorder-action svg {
  width: 58px;
  height: 58px;
  padding: 16px;
  border-radius: 50%;
  color: #fff;
  stroke-width: 2.3;
  box-sizing: border-box;
}
.chat-recorder-action.cancel svg { background: rgba(217,71,86,.92); }
.chat-recorder-action.finish svg { background: #f0bd58; color: #123c35; }
.chat-recorder-action:active svg { transform: scale(.94); }

@media (max-width: 640px) {
  .chat-bubble { max-width: 94%; }
  .chat-audio,
  .chat-audio-file { width: 100%; min-width: 0; max-width: 100%; }
  .chat-video-circle-row { display: grid; gap: 0; }
  .chat-circle-time { min-width: 0; margin: 4px 4px 0 0; padding: 3px 6px; }
  .chat-recorder {
    right: auto;
    bottom: auto;
    left: auto;
    width: 100vw;
    padding-inline: 16px;
  }
  .chat-recorder-visual { width: min(76vw,330px); }
}

@media (max-width: 1200px) and (max-height: 620px) and (orientation: landscape) {
  .chat-recorder {
    right: auto;
    bottom: auto;
    left: auto;
    width: 100vw;
    grid-template-columns: minmax(180px,1fr) minmax(220px,1fr);
    grid-template-rows: minmax(0,1fr) auto;
    gap: 12px 26px;
    padding: max(12px,env(safe-area-inset-top)) max(22px,env(safe-area-inset-right)) max(12px,env(safe-area-inset-bottom)) max(22px,env(safe-area-inset-left));
  }
  .chat-recorder-visual {
    width: min(66vh,290px);
    grid-row: 1 / 3;
    align-self: center;
  }
  .chat-recorder video { width: 100%; height: 100%; }
  .chat-recorder-copy { align-self: end; }
  .chat-recorder-copy strong { font-size: 20px; }
  .chat-recorder #chatRecorderTime { font-size: 36px; }
  .chat-recorder-copy small { font-size: 11px; }
  .chat-recorder-actions { align-self: start; }
  .chat-recorder-action { min-height: 76px; }
  .chat-recorder-action svg { width: 50px; height: 50px; padding: 13px; }
}
