:root {
  color-scheme: light;
  --ink: #241719;
  --muted: #7d686a;
  --line: #ead9d9;
  --paper: #fff8f7;
  --panel: #ffffff;
  --accent: #d83a3f;
  --accent-dark: #ae252b;
  --soft: #fff0ef;
  --danger: #a9272d;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--paper); overflow: hidden; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
.shell { height: 100vh; height: 100dvh; min-height: 100vh; display: grid; grid-template-rows: auto minmax(0, 1fr); overflow: hidden; padding-top: env(safe-area-inset-top, 0px); }
.topbar { position: relative; display: flex; align-items: center; justify-content: flex-end; gap: 16px; padding: 16px 24px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand, .auth-brand { font-weight: 800; }
.brand { position: absolute; left: 50%; transform: translateX(-50%); text-align: center; white-space: nowrap; }
.subtle { color: var(--muted); font-size: 13px; }
.top-actions, .search, .code-row, .auth-tabs, .admin-nav { display: flex; gap: 8px; align-items: center; }
.button { border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 9px 13px; border-radius: 999px; }
.button.primary { color: #fff; border-color: var(--accent); background: var(--accent); }
.button.primary:hover { background: var(--accent-dark); }
.button.danger { color: var(--danger); }
.button:disabled { cursor: not-allowed; opacity: .5; }
.text-button { border: 0; padding: 0; background: transparent; color: var(--accent); cursor: pointer; }
.admin-entry { display: block; margin: 18px auto 0; }
.wide { width: 100%; }
.workspace { display: grid; min-height: 0; height: 100%; overflow: hidden; }
.admin-layout { grid-template-columns: 330px minmax(0, 1fr); }
.admin-layout.sidebar-collapsed { grid-template-columns: minmax(0, 1fr); }
.admin-layout.sidebar-collapsed .sidebar { display: none; }
.sidebar { border-right: 1px solid var(--line); background: #fff5f4; overflow: auto; }
.sidebar-head, .conversation-head { padding: 18px 20px; border-bottom: 1px solid var(--line); background: var(--panel); }
.sidebar-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.sidebar-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.admin-nav { padding: 10px 12px 0; }
.admin-nav button { border: 0; background: transparent; color: var(--muted); padding: 8px 10px; border-bottom: 2px solid transparent; }
.admin-nav button.active { color: var(--accent); border-color: var(--accent); }
.notification-badge { display: inline-grid; min-width: 18px; height: 18px; padding: 0 5px; place-items: center; border-radius: 999px; background: var(--accent); color: #fff; font-size: 11px; line-height: 1; vertical-align: middle; }
.hide { display: none !important; }
.session-list { padding: 8px; }
.session-item { width: 100%; text-align: left; display: block; border: 0; border-bottom: 1px solid #f0dddd; padding: 14px 12px; background: transparent; color: inherit; }
.session-item.active { background: var(--soft); }
.session-row { display: flex; justify-content: space-between; gap: 8px; }
.session-preview { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 6px; font-size: 13px; }
.unread { color: var(--accent); font-weight: 700; }
.conversation { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; min-width: 0; min-height: 0; height: 100%; overflow: hidden; }
.conversation-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.messages { display: flex; flex-direction: column; min-height: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; padding: 22px max(20px, calc((100vw - 960px) / 2)); }
.message { display: flex; justify-content: flex-start; margin: 10px 0; }
.message.mine { justify-content: flex-end; }
.bubble { width: fit-content; max-width: min(76%, 620px); min-width: 0; padding: 10px 12px; border-radius: 14px; background: #fff; border: 1px solid var(--line); overflow-wrap: anywhere; word-break: break-word; white-space: normal; line-height: 1.55; }
.mine .bubble { background: var(--accent); border-color: var(--accent); color: #fff; }
.message-meta { margin-top: 5px; font-size: 11px; color: var(--muted); overflow-wrap: anywhere; }
.mine .message-meta { color: #ffe1df; }
.bubble img { display: block; max-width: 300px; max-height: 240px; margin-top: 7px; cursor: zoom-in; }
.bubble video { display: block; width: min(360px, 100%); max-height: 280px; margin-top: 7px; border-radius: 10px; }
.quoted-message { display: grid; gap: 2px; margin-bottom: 8px; padding: 7px 9px; border-left: 3px solid var(--accent); border-radius: 6px; background: var(--soft); color: var(--muted); font-size: 12px; }
.quoted-message strong { overflow-wrap: anywhere; word-break: break-word; white-space: normal; color: var(--ink); font-weight: 600; }
.mine .quoted-message { border-left-color: #fff; background: rgba(255, 255, 255, .16); color: #ffe1df; }
.mine .quoted-message strong { color: #fff; }
.message[data-message-id] { touch-action: pan-y; user-select: none; }
.composer { display: flex; flex-wrap: wrap; flex-shrink: 0; gap: 8px; align-items: flex-end; padding: 14px 20px; background: var(--panel); border-top: 1px solid var(--line); position: relative; z-index: 1; }
.quote-preview { flex-basis: 100%; display: flex; justify-content: space-between; align-items: center; gap: 12px; min-width: 0; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--soft); color: var(--muted); font-size: 13px; }
.quote-preview > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quote-clear { flex: 0 0 auto; border: 0; background: transparent; color: var(--accent); cursor: pointer; padding: 0; }
.composer textarea { resize: vertical; min-height: 42px; max-height: 150px; flex: 1; border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
.empty { display: grid; place-items: center; height: 100%; color: var(--muted); padding: 30px; text-align: center; }
.status { font-size: 12px; color: var(--muted); }
.status.online { color: var(--accent); }
.status.error, .notice { color: var(--danger); }
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(135deg, #fff8f7 0%, #ffeceb 100%); }
.auth-panel { width: min(430px, 100%); background: var(--panel); border: 1px solid var(--line); padding: 30px; border-radius: 18px; box-shadow: 0 18px 60px rgba(174, 37, 43, .1); }
.auth-brand { color: var(--accent); margin-bottom: 12px; text-align: center; }
.auth-panel h1 { margin: 0 0 8px; font-size: 26px; text-align: center; }
.auth-panel > .subtle { text-align: center; }
.auth-tabs { margin: 24px 0 18px; border-bottom: 1px solid var(--line); }
.auth-tabs button { border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); padding: 9px 13px; }
.auth-tabs button.active { color: var(--accent); border-color: var(--accent); }
.field { display: grid; gap: 6px; margin: 16px 0; }
.field input, .code-row input, .search input { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 11px; background: #fff; }
.auth-panel .field input, .auth-panel .code-row input { text-align: center; }
.code-row input { flex: 1; min-width: 0; }
.demo-code { min-height: 20px; color: var(--accent); font-size: 13px; }
.notice { min-height: 20px; font-size: 13px; }
.invite-box { display: flex; gap: 8px; padding: 12px; border: 1px solid var(--line); background: var(--panel); margin: 14px 20px 0; border-radius: 12px; }
.invite-box input { flex: 1; min-width: 0; border: 0; color: var(--muted); background: transparent; }
.search input { width: 220px; padding: 8px 10px; }
.user-pill { color: var(--accent); font-weight: 700; }
.announcement-admin { padding: 24px; overflow: auto; }
.page-heading { display: flex; justify-content: space-between; gap: 16px; align-items: center; border-bottom: 1px solid var(--line); padding-bottom: 18px; }
.page-heading h2 { margin: 0 0 5px; }
.announcement-list { max-width: 900px; }
.announcement-item { display: flex; justify-content: space-between; gap: 20px; padding: 18px 0; border-bottom: 1px solid var(--line); }
.announcement-item p { color: var(--muted); white-space: pre-wrap; }
.announcement-actions, .page-heading-actions { display: flex; gap: 8px; align-items: center; }
.empty-instructions { align-self: center; width: min(760px, 100%); height: auto; min-height: 0; margin: 24px auto; padding: 24px; border: 1px solid var(--line); border-radius: 14px; background: #fff; line-height: 1.8; }
.empty-instructions p { margin: 0 0 12px; }
.copy-contact { border: 0; padding: 0; color: var(--accent); background: transparent; cursor: pointer; text-decoration: underline; }
.copy-status { color: var(--accent); font-size: 13px; margin-left: 8px; }
.contact-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.announcement-editor-form { max-width: 760px; margin: 0 0 24px; padding: 20px; border: 1px solid var(--line); border-radius: 14px; background: #fff; }
.announcement-editor-form h3 { margin: 0 0 8px; }
.announcement-editor-form textarea { width: 100%; resize: vertical; border: 1px solid var(--line); border-radius: 10px; padding: 11px; line-height: 1.6; }
.announcement-editor-form select { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 11px; background: #fff; }
.announcement-editor-actions { display: flex; gap: 8px; justify-content: flex-end; }
@media (max-width: 720px) {
  .topbar { flex-direction: column; justify-content: center; gap: 10px; padding: 13px 15px; }
  .brand { position: static; transform: none; }
  .top-actions { width: 100%; justify-content: flex-end; flex-wrap: wrap; }
  .admin-layout { grid-template-columns: 1fr; grid-template-rows: 245px minmax(0, 1fr); }
  .admin-layout.sidebar-collapsed, .admin-layout.conversation-open, .admin-layout.admin-page-open { grid-template-rows: minmax(0, 1fr); }
  .admin-layout.sidebar-collapsed .sidebar, .admin-layout.conversation-open .sidebar, .admin-layout.admin-page-open .sidebar { display: none; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .messages { padding: 16px 12px; }
  .message { width: 100%; }
  .bubble { width: fit-content; max-width: 92%; }
  .conversation-head { padding: 13px 14px; align-items: stretch; flex-direction: column; gap: 10px; }
  .conversation-title { display: flex; align-items: center; gap: 8px; min-width: 0; }
  .conversation-title > div { min-width: 0; }
  .search { width: 100%; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .search input { flex: 1 1 120px; width: auto; min-width: 110px; }
  .search .button { flex: 0 0 auto; }
  .search .notification-badge { flex: 0 0 auto; }
  .composer { padding: 12px; }
  .composer textarea { min-width: 0; width: 100%; flex-basis: calc(100% - 90px); }
  .announcement-admin { padding: 16px 14px; }
  .announcement-item, .page-heading { align-items: flex-start; flex-direction: column; }
  .page-heading-actions { width: 100%; justify-content: flex-start; }
  .page-back { position: fixed; right: max(16px, env(safe-area-inset-right, 0px)); bottom: max(16px, env(safe-area-inset-bottom, 0px)); z-index: 10; box-shadow: 0 6px 18px rgba(36, 23, 25, .16); }
  .conversation .conversation-head .page-back { bottom: calc(max(16px, env(safe-area-inset-bottom, 0px)) + 78px); }
  .empty-instructions { width: 100%; margin: 12px auto; padding: 16px; overflow-wrap: anywhere; word-break: break-word; }
}
