:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --accent: #c2432d;
  --accent-dark: #a93625;
  --accent-soft: #fbeae5;
  --ink: #20232a;
  --muted: #747b88;
  --line: #e3e6eb;
  --panel: #ffffff;
  --canvas: #f4f5f7;
  --success: #18864b;
  --success-soft: #e5f7ec;
  --warning: #b54708;
}

* { box-sizing: border-box; }
html, body, #app { width: 100%; min-height: 100%; margin: 0; }
body { background: #eef0f3; color: var(--ink); }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }

#app {
  min-height: 100dvh;
  display: flex;
  justify-content: center;
}

.app-shell {
  width: min(100%, 620px);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  box-shadow: 0 0 45px rgba(25, 31, 43, 0.08);
}

.loading-screen, .login-screen {
  width: 100%;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 22px;
  background: #fff8f5;
}

.loading-screen { flex-direction: column; gap: 22px; }
.login-card {
  width: min(100%, 420px);
  padding: 38px 28px;
  text-align: center;
  border: 1px solid #f0ddd6;
  border-radius: 28px;
  background: var(--panel);
  box-shadow: 0 20px 60px rgba(87, 42, 28, 0.1);
}
.login-logo { width: 72px; height: 72px; border-radius: 22px; }
.login-title { margin: 18px 0 0; font-size: 30px; line-height: 1.1; letter-spacing: -0.8px; }
.tagline { margin: 7px 0 32px; color: var(--muted); font-size: 13px; }
.field-label { display: block; margin: 0 0 8px; text-align: left; font-size: 12px; font-weight: 800; }
.password-input, .search-input, .message-input {
  width: 100%;
  border: 1px solid var(--line);
  outline: none;
  color: var(--ink);
  background: #f7f8fa;
}
.password-input { height: 50px; padding: 0 15px; border-radius: 14px; font-size: 16px; }
.password-input:focus, .search-input:focus, .message-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(194, 67, 45, 0.1); }
.primary-button {
  width: 100%;
  height: 50px;
  margin-top: 16px;
  border: 0;
  border-radius: 14px;
  color: white;
  background: var(--accent);
  font-weight: 800;
}
.primary-button:disabled { opacity: 0.5; cursor: default; }
.login-note { margin: 14px 0 0; color: var(--muted); font-size: 11px; }
.form-error { min-height: 18px; margin: 9px 0 -4px; text-align: left; color: #b42318; font-size: 12px; }

.spinner { width: 24px; height: 24px; border: 3px solid #f0d4cc; border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.brand-row {
  display: flex;
  align-items: center;
  padding: calc(10px + env(safe-area-inset-top)) 20px 14px;
}
.brand-icon { width: 42px; height: 42px; border-radius: 13px; }
.brand-copy { flex: 1; min-width: 0; margin-left: 12px; }
.brand-title { margin: 0; font-size: 21px; letter-spacing: -0.5px; }
.brand-tagline { margin: 2px 0 0; color: var(--muted); font-size: 11px; }
.icon-button {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  color: var(--ink);
  background: transparent;
  font-size: 22px;
}
.icon-button:active { background: var(--accent-soft); }

.search-wrap { position: relative; margin: 0 20px; }
.search-symbol { position: absolute; left: 13px; top: 8px; z-index: 1; color: var(--muted); font-size: 21px; }
.search-input { height: 44px; padding: 0 13px 0 39px; border: 0; border-radius: 14px; font-size: 14px; }

.filters { display: flex; gap: 7px; overflow-x: auto; padding: 14px 20px 12px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filter-button {
  min-height: 32px;
  flex: 0 0 auto;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 18px;
  color: var(--ink);
  background: var(--panel);
  font-size: 12px;
  font-weight: 700;
}
.filter-button.active { border-color: #1f2937; color: white; background: #1f2937; }
.filter-count { margin-left: 5px; opacity: 0.72; font-size: 11px; }

.section-row { display: flex; align-items: center; min-height: 42px; padding: 5px 20px 5px 21px; }
.section-title { margin: 0; color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: 0.9px; text-transform: uppercase; }
.live-pill { display: flex; align-items: center; gap: 5px; margin-left: auto; padding: 5px 8px; border-radius: 10px; color: var(--success); background: var(--success-soft); font-size: 9px; font-weight: 900; text-transform: uppercase; }
.live-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.live-pill.offline { color: var(--warning); background: #fff1e8; }
.refresh-button { width: 31px; height: 31px; margin-left: 9px; border: 0; border-radius: 10px; color: var(--accent); background: var(--accent-soft); font-size: 18px; }

.conversation-list { flex: 1; padding: 0 10px 8px; }
.conversation-row {
  width: 100%;
  display: flex;
  align-items: center;
  padding: 11px 10px;
  border: 0;
  border-radius: 17px;
  text-align: left;
  color: inherit;
  background: transparent;
}
.conversation-row:active { background: var(--accent-soft); }
.avatar-wrap { position: relative; width: 48px; height: 48px; flex: 0 0 auto; }
.avatar { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 50%; color: white; font-size: 13px; font-weight: 800; }
.channel-dot { position: absolute; right: -1px; bottom: -1px; width: 14px; height: 14px; border: 2px solid white; border-radius: 50%; }
.conversation-copy { flex: 1; min-width: 0; margin-left: 12px; }
.conversation-top, .conversation-bottom { display: flex; align-items: center; }
.conversation-name { flex: 1; overflow: hidden; margin: 0; font-size: 15px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.conversation-time { margin-left: 8px; color: var(--muted); font-size: 10px; }
.conversation-bottom { margin-top: 5px; }
.conversation-preview { flex: 1; overflow: hidden; color: var(--muted); font-size: 12.5px; text-overflow: ellipsis; white-space: nowrap; }
.unread { min-width: 19px; height: 19px; display: grid; place-items: center; margin-left: 8px; padding: 0 5px; border-radius: 10px; color: white; background: var(--accent); font-size: 10px; font-weight: 800; }
.empty-state { display: grid; place-items: center; min-height: 250px; padding: 30px; text-align: center; }
.empty-state h2 { margin: 10px 0 0; font-size: 16px; }
.empty-state p { margin: 6px 0 0; color: var(--muted); font-size: 12px; }

.profile-footer { padding: 8px 16px calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.profile-button { width: 100%; display: flex; align-items: center; padding: 6px; border: 0; border-radius: 13px; text-align: left; color: inherit; background: transparent; }
.profile-avatar { width: 39px; height: 39px; display: grid; place-items: center; border-radius: 50%; color: white; background: #1f2937; font-size: 11px; font-weight: 800; }
.profile-copy { flex: 1; margin-left: 10px; }
.profile-name { display: block; font-size: 13px; font-weight: 700; }
.profile-meta { display: block; margin-top: 2px; color: var(--muted); font-size: 10px; }
.chevron { color: var(--muted); font-size: 24px; }

.chat-shell { background: var(--canvas); }
.chat-header { min-height: 72px; display: flex; align-items: center; padding: calc(9px + env(safe-area-inset-top)) 12px 10px; border-bottom: 1px solid var(--line); background: white; }
.back-button { width: 36px; height: 42px; border: 0; color: var(--ink); background: transparent; font-size: 37px; font-weight: 300; line-height: 1; }
.chat-avatar { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; color: white; font-size: 12px; font-weight: 800; }
.chat-title { flex: 1; min-width: 0; margin-left: 11px; }
.chat-name { overflow: hidden; margin: 0; font-size: 16px; text-overflow: ellipsis; white-space: nowrap; }
.chat-subtitle { display: flex; align-items: center; gap: 6px; margin-top: 4px; color: var(--muted); font-size: 10px; }
.channel-chip { padding: 3px 7px; border-radius: 7px; font-weight: 800; }
.message-list { flex: 1; overflow-y: auto; padding: 20px 14px 10px; }
.day-label { width: max-content; margin: 0 auto 12px; padding: 5px 10px; border-radius: 8px; color: var(--muted); background: #e9ecf1; font-size: 10px; font-weight: 700; }
.message-row { display: flex; justify-content: flex-start; margin: 5px 0; }
.message-row.mine { justify-content: flex-end; }
.message-bubble { max-width: 82%; padding: 10px 13px 7px; border-radius: 17px 17px 17px 5px; background: white; box-shadow: 0 2px 6px rgba(20, 29, 46, 0.05); }
.message-row.mine .message-bubble { border-radius: 17px 17px 5px 17px; color: white; background: var(--accent-dark); }
.message-text { margin: 0; font-size: 14px; line-height: 20px; white-space: pre-wrap; overflow-wrap: anywhere; }
.image-button { display: block; margin: 0 0 6px; padding: 0; border: 0; border-radius: 12px; overflow: hidden; background: #e7eaf0; }
.message-image { display: block; width: min(260px, 64vw); height: 190px; object-fit: cover; }
.attachment-card { min-width: 160px; margin-bottom: 5px; padding: 10px; border-radius: 11px; background: rgba(255, 255, 255, 0.16); font-size: 12px; font-weight: 700; text-transform: capitalize; }
.reaction-row { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.reaction-chip { min-width: 27px; height: 24px; display: grid; place-items: center; padding: 0 6px; border: 1px solid var(--line); border-radius: 12px; background: white; font-size: 14px; }
.reaction-chip.mine { border-color: #8fdbff; background: #e8f7ff; }
.react-button { display: block; margin: 3px 0 0 auto; padding: 2px 5px; border: 0; color: #9299a6; background: transparent; font-size: 11px; font-weight: 800; }
.message-meta { display: flex; align-items: center; justify-content: flex-end; gap: 5px; margin-top: 4px; color: #9299a6; font-size: 9px; }
.message-row.mine .message-meta { color: #f2cac1; }
.message-status { letter-spacing: -2px; }
.message-status.read { color: #8fdbff; }
.message-status.failed { color: #ffd0c7; letter-spacing: 0; font-size: 12px; }
.retry-button { display: block; margin: 5px 0 0 auto; padding: 0; border: 0; color: #ffd0c7; background: transparent; font-size: 11px; font-weight: 700; }
.composer-outer { padding: 3px 9px calc(8px + env(safe-area-inset-bottom)); background: var(--canvas); }
.composer { display: flex; align-items: flex-end; gap: 7px; min-height: 55px; padding: 8px; border: 1px solid var(--line); border-radius: 18px; background: white; box-shadow: 0 7px 18px rgba(20, 29, 46, 0.06); }
.attach-button { width: 38px; height: 38px; flex: 0 0 auto; border: 0; border-radius: 12px; color: var(--muted); background: transparent; font-size: 22px; }
.message-input { min-height: 38px; max-height: 104px; resize: none; flex: 1; padding: 8px 5px; border: 0; background: white; font-size: 14px; line-height: 19px; }
.send-button { width: 39px; height: 39px; flex: 0 0 auto; border: 0; border-radius: 13px; color: white; background: var(--accent); font-size: 17px; }
.send-button:disabled { opacity: 0.38; cursor: default; }

.modal-backdrop { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center; background: rgba(12, 17, 28, 0.53); }
.modal-sheet { width: min(100%, 620px); max-height: 84dvh; overflow-y: auto; padding: 10px 20px calc(18px + env(safe-area-inset-bottom)); border-radius: 28px 28px 0 0; background: white; }
.modal-handle { width: 38px; height: 5px; margin: 0 auto 14px; border-radius: 3px; background: #d7dbe3; }
.modal-heading { display: flex; align-items: flex-start; }
.eyebrow { margin: 0; color: var(--accent); font-size: 10px; font-weight: 900; letter-spacing: 1.2px; }
.modal-title { margin: 3px 0 0; font-size: 24px; letter-spacing: -0.5px; }
.modal-copy { margin: 10px 0 18px; color: var(--muted); font-size: 13px; line-height: 19px; }
.connection-card { min-height: 66px; margin-top: 9px; padding: 11px; border: 1px solid var(--line); border-radius: 16px; }
.connection-heading { display: flex; align-items: center; }
.connection-icon { width: 43px; height: 43px; display: grid; place-items: center; border-radius: 13px; color: white; font-size: 12px; font-weight: 900; }
.connection-copy { flex: 1; min-width: 0; margin-left: 11px; }
.connection-name { display: block; font-size: 13px; font-weight: 700; }
.connection-meta { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; }
.status-pill { margin-left: 8px; padding: 5px 8px; border-radius: 12px; color: var(--success); background: var(--success-soft); font-size: 9px; font-weight: 900; text-transform: uppercase; }
.capability-copy { margin: 9px 0 0; color: var(--muted); font-size: 10px; }
.test-button { margin-top: 9px; padding: 8px 11px; border: 0; border-radius: 10px; color: var(--accent-dark); background: var(--accent-soft); font-size: 10px; font-weight: 800; }
.test-button:disabled { opacity: 0.45; cursor: default; }
.security-note { margin-top: 17px; padding: 13px; border-radius: 15px; background: #f2f4f7; }
.security-note strong { display: block; font-size: 12px; }
.security-note p { margin: 4px 0 0; color: var(--muted); font-size: 10px; line-height: 15px; }
.signout-button { width: 100%; margin-top: 14px; padding: 12px; border: 0; border-radius: 13px; color: var(--accent-dark); background: var(--accent-soft); font-size: 12px; font-weight: 800; }
.legal-links a { color: var(--accent-dark); font-weight: 800; }
.new-chat-form { margin-top: 18px; }
.new-chat-form .field-label { margin-top: 14px; }
.modal-input { width: 100%; min-height: 48px; display: block; margin-top: 7px; padding: 0 13px; border: 1px solid var(--line); border-radius: 14px; color: var(--ink); background: white; font: inherit; }
.modal-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(194, 67, 45, 0.1); }
.modal-help { color: var(--muted); font-size: 11px; line-height: 16px; }

@media (min-width: 621px) {
  .app-shell { min-height: calc(100dvh - 36px); max-height: calc(100dvh - 36px); margin: 18px 0; border-radius: 24px; overflow: hidden; }
  .chat-header { padding-top: 10px; }
  .profile-footer, .composer-outer { padding-bottom: 8px; }
  .modal-sheet { margin-bottom: 18px; border-radius: 28px; }
}
