/* 1. CSS variables - TWALK Glass */
:root {
  --bg-main: #F7FAFB;
  --bg-soft: #EEF5F7;
  --surface: #FFFFFF;
  --glass-bg: rgba(255, 255, 255, 0.78);
  --glass-bg-strong: rgba(255, 255, 255, 0.96);
  --glass-border: rgba(205, 221, 225, 0.78);
  --text-main: #0E1E2F;
  --text-muted: #647584;
  --text-soft: #97A6B1;
  --brand-primary: #006C7C;
  --brand-primary-dark: #005466;
  --brand-primary-soft: #E0F2F5;
  --brand-accent: #35A7B5;
  --sent-bubble: #08788A;
  --sent-text: #FFFFFF;
  --received-bubble: #FFFFFF;
  --danger: #C65050;
  --warning: #B97821;
  --success: #228C67;
  --shadow-soft: 0 22px 55px rgba(14, 42, 56, 0.13);
  --shadow-small: 0 8px 22px rgba(14, 42, 56, 0.09);
  --radius-xl: 30px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --focus: 0 0 0 4px rgba(0, 108, 124, 0.18);
}

/* 2. Reset/base styles */
* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg-main); }
body {
  min-height: 100vh;
  margin: 0;
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.45;
  background:
    radial-gradient(circle at 9% 14%, rgba(116, 181, 205, .26) 0 58px, transparent 60px),
    radial-gradient(circle at 90% 3%, rgba(116, 181, 205, .24) 0 96px, transparent 98px),
    radial-gradient(circle at 5% 88%, rgba(116, 181, 205, .18) 0 120px, transparent 122px),
    linear-gradient(135deg, #FFFFFF 0%, #F7FAFB 42%, #EEF5F7 100%);
  background-attachment: fixed;
}
a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .62; cursor: wait; }
img, video { max-width: 100%; }
:focus-visible { outline: none; box-shadow: var(--focus); }

/* 3. Layout shell */
.app-shell { min-height: 100vh; position: relative; }
.screen {
  width: min(1080px, calc(100% - 24px));
  margin: 0 auto;
  padding: 18px 0 94px;
}
.screen.narrow { width: min(660px, calc(100% - 24px)); }
.screen.admin { width: min(1180px, calc(100% - 24px)); }
.topbar, .top-bar {
  position: sticky;
  top: 0;
  z-index: 40;
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  color: #fff;
  background: linear-gradient(135deg, var(--brand-primary-dark), var(--brand-primary));
  box-shadow: 0 10px 28px rgba(0, 84, 102, .20);
}
.brand, .wordmark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  font-size: 19px;
  font-weight: 800;
  letter-spacing: .08em;
}
.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: var(--brand-primary);
  background: rgba(255,255,255,.95);
  font-size: 12px;
  letter-spacing: 0;
}
.brand-mark::before { content: "TW"; }
.topbar nav {
  position: fixed;
  left: 10px;
  right: 10px;
  bottom: max(10px, env(safe-area-inset-bottom));
  z-index: 60;
  min-height: 58px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 7px;
  color: var(--text-muted);
  background: rgba(255,255,255,.92);
  border: 1px solid var(--glass-border);
  border-radius: 22px;
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
}
.topbar nav a {
  min-height: 44px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 700;
}
.topbar nav a:hover { color: var(--brand-primary); background: var(--brand-primary-soft); }

/* 4. Typography */
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(27px, 7vw, 40px); line-height: 1.1; letter-spacing: 0; }
h2 { margin-bottom: 12px; font-size: 19px; line-height: 1.2; }
h3 { margin-bottom: 8px; font-size: 16px; }
small, .muted { color: var(--text-muted); }
.eyebrow { color: var(--brand-primary); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .11em; }

/* 5. Buttons */
button, .button {
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 11px 16px;
  color: var(--text-main);
  background: #FFFFFF;
  box-shadow: 0 4px 12px rgba(14,42,56,.045);
  transition: transform 120ms ease, opacity 160ms ease, background 160ms ease, box-shadow 160ms ease;
}
button:hover, .button:hover { transform: translateY(-1px); box-shadow: var(--shadow-small); }
button:active, .button:active { transform: translateY(0) scale(.99); }
.primary, .button.primary { color: #fff; background: linear-gradient(135deg, var(--brand-primary), #00869B); border-color: transparent; }
.danger, .button.danger { color: var(--danger); background: rgba(198,80,80,.10); border-color: rgba(198,80,80,.20); }
.ghost { color: var(--brand-primary); background: rgba(255,255,255,.66); }
.icon-button, .attach { width: 46px; height: 46px; flex: 0 0 46px; border-radius: 50%; padding: 0; font-weight: 800; }

/* 6. Forms */
form { margin: 0; }
.stack { display: grid; gap: 14px; }
.compact { gap: 10px; }
label { display: grid; gap: 7px; color: var(--text-muted); font-size: 14px; font-weight: 700; }
input, textarea, select {
  width: 100%;
  min-height: 48px;
  border: 1px solid rgba(212,225,229,.9);
  border-radius: 14px;
  padding: 12px 14px;
  color: var(--text-main);
  background: rgba(255,255,255,.94);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.9), 0 3px 10px rgba(14,42,56,.03);
}
textarea { resize: vertical; }
select[multiple] { min-height: 120px; }
input::placeholder, textarea::placeholder { color: var(--text-soft); }
.search-input { margin: 12px 0 0; }
.search-input input {
  min-height: 48px;
  border-radius: 999px;
  padding-left: 18px;
  background: #fff;
  box-shadow: var(--shadow-small);
}
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; align-items: end; }

/* 7. Glass cards */
.glass-panel, .glass-card, .auth-card, .panel, .admin-card, .update-panel {
  background: var(--glass-bg);
  border: 1px solid rgba(255,255,255,.72);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(20px) saturate(150%);
  -webkit-backdrop-filter: blur(20px) saturate(150%);
}
.auth-card, .panel, .admin-card, .update-panel { padding: 20px; }
.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.auth-card {
  width: min(420px, 100%);
  background: rgba(255,255,255,.68);
}
.auth-card h1 {
  color: var(--brand-primary);
  font-size: clamp(40px, 13vw, 54px);
  margin-bottom: 4px;
  text-align: center;
  letter-spacing: .10em;
}
.auth-card > p { color: var(--text-muted); text-align: center; }

/* 8. Navigation/tabs */
.tabs, .admin-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  margin: 12px 0 14px;
  padding: 5px;
  border-radius: 18px;
  background: rgba(229, 238, 241, .96);
}
.admin-nav { grid-template-columns: repeat(auto-fit, minmax(86px, 1fr)); }
.tabs a, .admin-nav a {
  min-height: 42px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  color: var(--text-muted);
  font-weight: 760;
}
.tabs .active, .admin-nav .active { color: var(--brand-primary); background: #fff; box-shadow: 0 4px 12px rgba(14,42,56,.055); }

/* 9. Chat lists */
.list, .chat-list { display: grid; gap: 10px; }
.list-row, .chat-item {
  min-height: 76px;
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 12px;
  border-radius: 18px;
  background: rgba(255,255,255,.94);
  border: 1px solid rgba(216,228,231,.86);
  box-shadow: 0 6px 18px rgba(14,42,56,.045);
  transition: transform 120ms ease, background 160ms ease, box-shadow 160ms ease;
}
.list-row:hover, .chat-item:hover { transform: translateY(-1px); background: #fff; box-shadow: var(--shadow-small); }
.avatar {
  position: relative;
  flex: 0 0 50px;
  width: 50px;
  height: 50px;
  border-radius: 17px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(145deg, #0292A4, #0A6F7E);
  box-shadow: var(--shadow-small);
  font-weight: 800;
}
.avatar.big { width: 92px; height: 92px; border-radius: 30px; margin: 0 auto 12px; font-size: 34px; }
.presence-dot {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #2CD480;
  border: 3px solid #fff;
}
.grow { flex: 1; min-width: 0; }
.grow strong, .grow small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grow strong { font-size: 15px; }
.list-meta { display: grid; justify-items: end; gap: 7px; color: var(--text-soft); font-size: 12px; }

/* 10. Message bubbles */
.chat-screen {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  width: min(820px, 100%);
  margin: 0 auto;
  background:
    radial-gradient(circle at 12% 0%, rgba(116,181,205,.20), transparent 32%),
    linear-gradient(180deg, #F8FBFC 0%, #EEF5F7 100%);
}
.chat-screen::before {
  content: "";
  position: fixed;
  inset: 70px 0 84px;
  pointer-events: none;
  opacity: .38;
  background-image:
    radial-gradient(circle at 18px 18px, rgba(0,108,124,.08) 0 2px, transparent 3px),
    radial-gradient(circle at 54px 44px, rgba(0,108,124,.07) 0 1px, transparent 3px);
  background-size: 82px 82px;
}
.chat-head {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: calc(68px + env(safe-area-inset-top));
  display: flex;
  align-items: center;
  gap: 11px;
  padding: calc(9px + env(safe-area-inset-top)) 14px 9px;
  color: #fff;
  background: linear-gradient(135deg, var(--brand-primary-dark), var(--brand-primary));
  box-shadow: 0 10px 26px rgba(0,84,102,.22);
}
.chat-head > a:first-child {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: rgba(255,255,255,.13);
  font-size: 20px;
  font-weight: 800;
}
.chat-head small { color: rgba(255,255,255,.78); }
.chat-head .info-link { margin-left: auto; color: #fff; font-weight: 760; }
.messages, .message-thread {
  position: relative;
  z-index: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px 12px 104px;
  scroll-behavior: smooth;
}
.bubble, .message-bubble {
  max-width: min(84%, 560px);
  padding: 10px 12px;
  border-radius: 18px;
  overflow-wrap: anywhere;
  animation: messageIn 180ms ease both;
}
.bubble.mine, .message-bubble.sent {
  align-self: flex-end;
  color: var(--sent-text);
  background: linear-gradient(135deg, var(--sent-bubble), #0995A7);
  border-bottom-right-radius: 6px;
  box-shadow: 0 10px 24px rgba(0,108,124,.18);
}
.bubble.theirs, .message-bubble.received {
  align-self: flex-start;
  color: var(--text-main);
  background: var(--received-bubble);
  border: 1px solid rgba(216,228,231,.9);
  border-bottom-left-radius: 6px;
  box-shadow: var(--shadow-small);
}
.bubble p { margin: 3px 0 6px; font-size: 15.5px; white-space: pre-wrap; }
.bubble small, .message-meta { display: block; text-align: right; color: rgba(255,255,255,.78); font-size: 11.5px; }
.bubble.theirs small { color: var(--text-muted); }
.bubble .read { color: #BDF7EF; }
.sender-name { display: block; margin: 0 0 4px; color: var(--brand-primary); font-size: 12.5px; font-weight: 800; }

/* 11. Media cards */
.media-thumb { display: block; width: 100%; max-height: 360px; object-fit: cover; border-radius: 15px; }
.media-player { display: block; width: min(310px, 100%); border-radius: 15px; }
.media-card, .doc-card {
  display: grid;
  gap: 4px;
  padding: 13px;
  border-radius: 15px;
  color: inherit;
  background: rgba(255,255,255,.18);
  border: 1px solid rgba(255,255,255,.30);
}
.theirs .doc-card { background: #F6FAFB; border-color: rgba(0,108,124,.10); }
.doc-card::before { content: "Document"; font-size: 11px; font-weight: 800; opacity: .78; text-transform: uppercase; letter-spacing: .06em; }

/* 12. Group UI */
.group-hero { text-align: center; }
.member-list { display: grid; gap: 8px; }
.sender-summary { color: var(--text-muted); font-size: 12px; }

/* 13. Admin UI */
.admin-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 0;
  border-top: 1px solid rgba(0,108,124,.08);
}
.admin-row:first-child { border-top: 0; }
.admin-row small { display: block; color: var(--text-muted); }
.actions, .member-action { display: flex; flex-wrap: wrap; gap: 7px; justify-content: flex-end; }
.actions button, .member-action button { min-height: 40px; padding: 8px 10px; font-size: 13px; }
.admin-table { width: 100%; border-collapse: collapse; }
.admin-table th, .admin-table td { padding: 12px; border-bottom: 1px solid rgba(0,108,124,.08); text-align: left; }

/* 14. Update portal UI */
.version-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }
.version-card { padding: 16px; border-radius: var(--radius-md); background: rgba(255,255,255,.82); border: 1px solid var(--glass-border); }
.version-card strong { display: block; color: var(--brand-primary); font-size: 20px; }
.warning-note { padding: 12px; border-radius: var(--radius-sm); color: #6D4514; background: rgba(185,126,36,.12); border: 1px solid rgba(185,126,36,.20); }

/* 15. Toasts/alerts/badges */
.alert, .toast {
  margin: 10px 0;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  color: var(--brand-primary);
  background: rgba(224,242,245,.90);
  border: 1px solid rgba(0,108,124,.12);
}
.alert.danger, .toast.danger { color: var(--danger); background: rgba(198,80,80,.10); border-color: rgba(198,80,80,.18); }
.alert.success, .toast.success { color: var(--success); background: rgba(34,140,103,.11); border-color: rgba(34,140,103,.18); }
.toast {
  position: fixed;
  left: 50%;
  bottom: 88px;
  z-index: 80;
  width: min(420px, calc(100% - 28px));
  margin: 0;
  transform: translateX(-50%) translateY(10px);
  opacity: 0;
  pointer-events: none;
  box-shadow: var(--shadow-soft);
  transition: opacity 160ms ease, transform 160ms ease;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.unread, .badge, .status-pill {
  min-width: 25px;
  min-height: 25px;
  display: inline-grid;
  place-items: center;
  padding: 4px 8px;
  border-radius: 999px;
  color: #fff;
  background: var(--brand-primary);
  font-size: 12px;
  font-weight: 800;
}
.unread { animation: badgePulse 900ms ease both; }
.status-pill { color: var(--brand-primary); background: var(--brand-primary-soft); }
.status-pill.approved, .status-pill.active { color: var(--success); background: rgba(34,140,103,.12); }
.status-pill.pending { color: var(--warning); background: rgba(185,126,36,.12); }
.status-pill.blocked, .status-pill.removed, .status-pill.left { color: var(--danger); background: rgba(198,80,80,.12); }

/* 16. Loading/skeleton states */
.skeleton { min-height: 18px; border-radius: 999px; background: linear-gradient(90deg, rgba(255,255,255,.45), rgba(255,255,255,.9), rgba(255,255,255,.45)); background-size: 220% 100%; animation: skeleton 1.2s ease infinite; }
.empty, .empty-state { padding: 34px 18px; color: var(--text-muted); text-align: center; }
.hidden, [hidden] { display: none !important; }

/* 17. Mobile responsiveness */
.composer, .composer-glass {
  position: fixed;
  left: 50%;
  bottom: max(10px, env(safe-area-inset-bottom));
  z-index: 25;
  width: min(790px, calc(100% - 18px));
  display: flex;
  align-items: end;
  gap: 8px;
  padding: 8px;
  border-radius: 23px;
  background: rgba(255,255,255,.96);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-soft);
  transform: translateX(-50%);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
}
.composer textarea { min-height: 46px; max-height: 126px; border-radius: 17px; box-shadow: none; }
.composer button { width: 48px; min-width: 48px; border-radius: 50%; color: white; background: linear-gradient(135deg, var(--brand-primary), #008CA0); font-size: 0; }
.composer button::before { content: ">"; font-size: 18px; }
.attach input { display: none; }
.notify-enable { position: fixed; right: 14px; bottom: 78px; z-index: 45; min-height: 38px; padding: 8px 12px; border-radius: 999px; color: white; background: rgba(14,30,47,.88); }

@media (max-width: 520px) {
  .screen { width: 100%; padding: 12px 10px 92px; }
  .screen > .panel:first-child { border-radius: 0 0 24px 24px; margin: -12px -10px 0; padding: 18px 16px; }
  .auth-card, .panel { padding: 17px; border-radius: 22px; }
  .admin-row { align-items: stretch; flex-direction: column; }
  .actions, .member-action { justify-content: flex-start; }
  .bubble { max-width: 88%; }
}

@media (min-width: 860px) {
  body { padding: 22px; }
  .app-shell {
    width: min(1180px, 100%);
    min-height: calc(100vh - 44px);
    margin: 0 auto;
    display: grid;
    grid-template-columns: 210px 1fr;
    overflow: hidden;
    background: rgba(255,255,255,.78);
    border: 1px solid rgba(210,224,229,.92);
    border-radius: 22px;
    box-shadow: var(--shadow-soft);
  }
  .app-shell::before {
    content: "";
    grid-column: 1 / -1;
    height: 38px;
    background:
      radial-gradient(circle at 18px 19px, #FF5F57 0 4px, transparent 5px),
      radial-gradient(circle at 34px 19px, #FFBD2E 0 4px, transparent 5px),
      radial-gradient(circle at 50px 19px, #28C840 0 4px, transparent 5px),
      linear-gradient(#F7F9FA, #EFF4F5);
    border-bottom: 1px solid rgba(210,224,229,.82);
  }
  .topbar {
    position: relative;
    top: auto;
    grid-row: 2;
    align-self: stretch;
    min-height: auto;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    padding: 18px 14px;
    color: var(--text-main);
    background: rgba(245,249,250,.92);
    box-shadow: none;
    border-right: 1px solid rgba(210,224,229,.82);
    border-bottom: 0;
  }
  .brand { color: var(--brand-primary); margin-bottom: 18px; }
  .brand-mark { color: #fff; background: var(--brand-primary); }
  .topbar nav {
    position: static;
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    min-height: auto;
    padding: 0;
    color: var(--text-muted);
    background: transparent;
    border: 0;
    box-shadow: none;
  }
  .topbar nav a {
    justify-content: flex-start;
    place-items: center start;
    min-height: 44px;
    padding: 0 12px;
    font-size: 14px;
    background: transparent;
  }
  .topbar nav a:hover { background: var(--brand-primary-soft); }
  .screen {
    grid-row: 2;
    width: 100%;
    margin: 0;
    padding: 18px 22px 24px;
    overflow: auto;
  }
  .screen:not(.narrow):not(.admin) {
    display: grid;
    grid-template-columns: minmax(310px, 420px) 1fr;
    align-content: start;
    gap: 16px;
  }
  .screen:not(.narrow):not(.admin) > .panel:first-child,
  .screen:not(.narrow):not(.admin) > .tabs,
  .screen:not(.narrow):not(.admin) > .panel:nth-of-type(2) {
    grid-column: 1;
  }
  .screen:not(.narrow):not(.admin) > .list {
    grid-column: 1;
  }
  .screen:not(.narrow):not(.admin)::after {
    content: "Select a TWALK conversation";
    grid-column: 2;
    grid-row: 1 / span 4;
    min-height: 520px;
    display: grid;
    place-items: center;
    color: var(--text-muted);
    background:
      radial-gradient(circle at 50% 42%, rgba(116,181,205,.18) 0 120px, transparent 122px),
      rgba(255,255,255,.72);
    border: 1px solid rgba(210,224,229,.82);
    border-radius: 22px;
  }
  .chat-screen {
    width: min(960px, 100%);
    min-height: calc(100vh - 44px);
    overflow: hidden;
    border: 1px solid rgba(210,224,229,.92);
    border-radius: 22px;
    box-shadow: var(--shadow-soft);
  }
}

/* 18. Accessibility helpers */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .glass-panel, .glass-card, .auth-card, .panel, .topbar, .chat-head, .composer { background: #FFFFFF; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: .001ms !important;
  }
}
@keyframes messageIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* TWALK Apple UI overhaul - flat premium system */
:root {
  --color-background-primary: #F9F9FB;
  --color-background-secondary: #F2F2F7;
  --color-surface: #FFFFFF;
  --color-surface-elevated: #FFFFFF;
  --color-accent: #0A84FF;
  --color-accent-pressed: #006EDB;
  --color-sent: #0A84FF;
  --color-received: #EFEFF4;
  --color-separator: #E5E5EA;
  --color-text-primary: #1C1C1E;
  --color-text-secondary: #6C6C70;
  --color-text-tertiary: #AEAEB2;
  --color-danger: #FF3B30;
  --color-success: #34C759;
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --radius-ios: 14px;
  --radius-inset: 12px;
  --shadow-ios: 0 10px 30px rgba(60, 60, 67, .08);
  --hairline: .5px solid var(--color-separator);
  --focus: 0 0 0 2px rgba(10,132,255,.26);
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-background-primary: #000000;
    --color-background-secondary: #1C1C1E;
    --color-surface: #1C1C1E;
    --color-surface-elevated: #2C2C2E;
    --color-received: #3A3A3C;
    --color-separator: #38383A;
    --color-text-primary: #F5F5F7;
    --color-text-secondary: #AEAEB2;
    --color-text-tertiary: #6C6C70;
    --shadow-ios: none;
  }
}

html { background: var(--color-background-primary); }
body.twalk-glass, body {
  color: var(--color-text-primary);
  font-family: var(--font-sans);
  letter-spacing: 0;
  background:
    radial-gradient(circle at 12% 12%, rgba(10,132,255,.10), transparent 170px),
    radial-gradient(circle at 88% 0%, rgba(90,200,250,.12), transparent 190px),
    var(--color-background-primary);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--color-accent); }
:focus-visible { outline: none; box-shadow: var(--focus); }

h1 {
  color: var(--color-text-primary);
  font-size: 34px;
  font-weight: 700;
  line-height: 1.12;
  letter-spacing: -.3px;
}
h2 {
  color: var(--color-text-primary);
  font-size: 17px;
  font-weight: 600;
  line-height: 1.2;
}
h3, strong { color: var(--color-text-primary); }
p, small, .muted { color: var(--color-text-secondary); }
.eyebrow {
  color: var(--color-text-tertiary);
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
}

.app-shell {
  background: transparent;
}
.screen {
  width: min(980px, 100%);
  padding: max(18px, env(safe-area-inset-top)) 14px calc(96px + env(safe-area-inset-bottom));
}
.screen.narrow { width: min(680px, 100%); }
.screen.admin { width: min(1220px, 100%); }

.topbar, .top-bar {
  color: var(--color-text-primary);
  background: rgba(249,249,251,.84);
  border-bottom: var(--hairline);
  box-shadow: none;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
.brand, .wordmark {
  color: var(--color-text-primary);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.8px;
}
.brand-mark {
  color: #fff;
  background: var(--color-accent);
  border-radius: 13px;
}
.topbar nav {
  height: calc(64px + env(safe-area-inset-bottom));
  min-height: 64px;
  align-items: start;
  padding: 7px 8px calc(7px + env(safe-area-inset-bottom));
  color: var(--color-text-tertiary);
  background: rgba(255,255,255,.78);
  border: var(--hairline);
  border-radius: 0;
  box-shadow: 0 -8px 22px rgba(60,60,67,.08);
}
.topbar nav a {
  min-height: 44px;
  color: var(--color-text-tertiary);
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
}
.topbar nav a:hover,
.topbar nav a:active {
  color: var(--color-accent);
  background: var(--color-background-secondary);
}

.panel, .glass-panel, .glass-card, .auth-card, .admin-card, .update-panel {
  color: var(--color-text-primary);
  background: var(--color-surface);
  border: var(--hairline);
  border-radius: var(--radius-ios);
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
.panel, .admin-card, .update-panel { padding: 18px; }

.auth-shell {
  align-items: start;
  min-height: 100dvh;
  padding: max(36px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
  background: var(--color-background-primary);
}
.auth-card {
  width: min(390px, 100%);
  margin: 0 auto;
  padding: 18px 0 0;
  border: 0;
  background: transparent;
}
.auth-card .eyebrow { display: none; }
.auth-card h1 {
  margin: 42px 0 8px;
  color: var(--color-text-primary);
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -1px;
  text-align: center;
}
.auth-card > p {
  margin-bottom: 34px;
  color: var(--color-text-secondary);
  font-size: 17px;
  text-align: center;
}
.auth-panel-title {
  margin-bottom: 16px;
}
.auth-panel-title strong {
  display: block;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -.3px;
}
.auth-panel-title small {
  display: block;
  margin-top: 3px;
  font-size: 16px;
}
.auth-link { margin-top: 22px; text-align: center; }

label {
  position: relative;
  gap: 6px;
  color: var(--color-text-secondary);
  font-size: 13px;
  font-weight: 400;
}
input, textarea, select {
  min-height: 52px;
  border: 1px solid transparent;
  border-radius: var(--radius-ios);
  color: var(--color-text-primary);
  background: var(--color-background-secondary);
  box-shadow: none;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--color-accent);
  box-shadow: var(--focus);
}
.search-input input {
  min-height: 42px;
  border: 0;
  border-radius: var(--radius-inset);
  background: var(--color-background-secondary);
  box-shadow: none;
}
.search-input input::placeholder { color: var(--color-text-secondary); }

button, .button {
  min-height: 44px;
  border: 0;
  border-radius: var(--radius-ios);
  color: var(--color-accent);
  background: var(--color-background-secondary);
  box-shadow: none;
  font-weight: 600;
  transition: transform 120ms ease, opacity 160ms ease, background 160ms ease;
}
button:hover, .button:hover { box-shadow: none; transform: none; }
button:active, .button:active { transform: scale(.97); opacity: .78; }
.primary, .button.primary {
  min-height: 52px;
  color: #fff;
  background: var(--color-accent);
}
.primary:active, .button.primary:active { background: var(--color-accent-pressed); }
.danger, .button.danger { color: var(--color-danger); background: rgba(255,59,48,.10); }
.full-button { width: 100%; }

.tabs, .admin-nav {
  gap: 0;
  margin: 10px 0 0;
  padding: 0;
  border-bottom: var(--hairline);
  border-radius: 0;
  background: transparent;
}
.tabs a, .admin-nav a {
  min-height: 44px;
  border-radius: 0;
  color: var(--color-text-secondary);
  font-size: 15px;
  font-weight: 500;
  background: transparent;
}
.tabs .active, .admin-nav .active {
  color: var(--color-accent);
  background: transparent;
  box-shadow: inset 0 -2px 0 var(--color-accent);
}

.list, .chat-list {
  gap: 0;
  overflow: hidden;
  border-radius: var(--radius-ios);
  background: var(--color-surface);
}
.list-row, .chat-item {
  min-height: 72px;
  gap: 12px;
  padding: 10px 14px;
  border: 0;
  border-bottom: var(--hairline);
  border-radius: 0;
  background: var(--color-surface);
  box-shadow: none;
}
.list-row:last-child, .chat-item:last-child { border-bottom: 0; }
.list-row:hover, .chat-item:hover {
  background: var(--color-background-secondary);
  box-shadow: none;
  transform: none;
}
.list-row:active, .chat-item:active {
  background: #EFEFEF;
  transition-duration: 80ms;
}
.avatar {
  flex-basis: 48px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, #5AC8FA, var(--color-accent));
  box-shadow: none;
  font-size: 17px;
  font-weight: 600;
}
.avatar.big {
  width: 104px;
  height: 104px;
  border-radius: 50%;
  font-size: 40px;
}
.presence-dot {
  right: 0;
  bottom: 0;
  width: 12px;
  height: 12px;
  background: var(--color-success);
  border: 2px solid var(--color-surface);
}
.grow strong {
  font-size: 17px;
  font-weight: 600;
}
.grow small {
  margin-top: 2px;
  color: var(--color-text-secondary);
  font-size: 15px;
}
.list-meta small {
  color: var(--color-text-tertiary);
  font-size: 13px;
}
.unread, .badge {
  min-width: 18px;
  min-height: 18px;
  padding: 0 5px;
  background: var(--color-accent);
  font-size: 13px;
  line-height: 18px;
}
.status-pill {
  min-height: 22px;
  color: var(--color-accent);
  background: rgba(10,132,255,.12);
  font-size: 12px;
}
.status-pill.pending { color: #FF9500; background: rgba(255,149,0,.12); }
.status-pill.blocked { color: var(--color-danger); background: rgba(255,59,48,.12); }
.empty, .empty-state {
  color: var(--color-text-secondary);
  background: var(--color-surface);
  border-radius: var(--radius-ios);
}

.chat-screen {
  width: min(760px, 100%);
  min-height: 100dvh;
  background:
    radial-gradient(circle at 20% 0%, rgba(10,132,255,.08), transparent 180px),
    var(--color-background-primary);
}
.chat-head {
  min-height: calc(58px + env(safe-area-inset-top));
  padding: calc(7px + env(safe-area-inset-top)) 12px 7px;
  color: var(--color-text-primary);
  background: rgba(249,249,251,.86);
  border-bottom: var(--hairline);
  box-shadow: none;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
.chat-head > a:first-child {
  color: var(--color-accent);
  background: transparent;
  font-size: 28px;
  font-weight: 400;
}
.chat-head strong {
  display: block;
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
  max-width: 48vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-head small { color: var(--color-text-secondary); }
.chat-head .info-link {
  margin-left: auto;
  color: var(--color-accent);
}
.messages {
  gap: 2px;
  padding: 16px 10px calc(88px + env(safe-area-inset-bottom));
}
.bubble, .message-bubble {
  max-width: min(75vw, 520px);
  padding: 8px 11px 6px;
  border: 0;
  box-shadow: none;
  animation: twalk-message-in 220ms ease-out both;
}
.bubble.mine, .message-bubble.mine, .message-bubble.sent {
  color: #fff;
  background: var(--color-sent);
  border-radius: 20px 20px 6px 20px;
}
.bubble.theirs, .message-bubble.theirs, .message-bubble.received {
  color: var(--color-text-primary);
  background: var(--color-received);
  border-radius: 20px 20px 20px 6px;
}
.bubble p, .message-bubble p {
  margin: 0 0 4px;
  font-size: 17px;
  line-height: 1.35;
}
.bubble small, .message-meta {
  color: rgba(255,255,255,.68);
  font-size: 11px;
  line-height: 1.1;
  text-align: right;
}
.bubble.theirs small, .theirs .message-meta, .received .message-meta {
  color: var(--color-text-tertiary);
}
.sender-name {
  margin: 0 0 3px;
  color: var(--color-accent);
  font-size: 13px;
  font-weight: 600;
}
.message-actions {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 4px;
}
.message-actions button {
  min-height: 28px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: rgba(255,255,255,.18);
  color: inherit;
}
.composer, .composer-glass {
  bottom: 0;
  width: min(760px, 100%);
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  border: 0;
  border-top: var(--hairline);
  border-radius: 0;
  background: rgba(249,249,251,.86);
  box-shadow: none;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
.composer textarea {
  min-height: 42px;
  max-height: 132px;
  border: 0;
  border-radius: 20px;
  background: var(--color-background-secondary);
}
.composer button {
  width: 42px;
  min-width: 42px;
  height: 42px;
  min-height: 42px;
  border-radius: 50%;
  color: #fff;
  background: var(--color-accent);
}
.composer button::before { content: "↑"; font-size: 19px; font-weight: 700; }
.composer-tools {
  display: flex;
  align-items: end;
  gap: 4px;
}
.attach, .icon-button {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  color: var(--color-accent);
  background: transparent;
  font-size: 19px;
}
.camera-button { font-size: 11px; }
.attach input { display: none; }
.notify-enable {
  position: fixed;
  right: 12px;
  bottom: calc(76px + env(safe-area-inset-bottom));
  z-index: 50;
  min-height: 36px;
  border-radius: 18px;
  font-size: 13px;
  color: #fff;
  background: rgba(28,28,30,.86);
}
.hidden { display: none !important; }

.media-thumb {
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 16px;
  background: var(--color-background-secondary);
}
.media-player, video.media-player {
  width: min(300px, 100%);
  border-radius: 16px;
}
.media-card, .doc-card {
  border: 0;
  border-radius: 16px;
  background: rgba(255,255,255,.20);
}
.theirs .media-card, .theirs .doc-card {
  background: var(--color-surface);
}

.alert, .toast {
  border: 0;
  border-radius: var(--radius-ios);
  color: var(--color-text-primary);
  background: var(--color-background-secondary);
}
.alert.danger, .toast.danger {
  color: var(--color-danger);
  background: rgba(255,59,48,.10);
}
.alert.success, .toast.success {
  color: var(--color-success);
  background: rgba(52,199,89,.12);
}
.toast {
  bottom: calc(86px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-ios);
}

.admin-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 0;
  border-bottom: var(--hairline);
}
.admin-row:last-child { border-bottom: 0; }
.admin-row small { display: block; margin-top: 3px; }
.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}
.actions button, .actions select {
  min-height: 36px;
  padding: 6px 10px;
}
.version-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}
.version-card {
  padding: 14px;
  border-radius: var(--radius-ios);
  background: var(--color-background-secondary);
}
.version-card strong {
  display: block;
  margin-top: 4px;
  font-size: 22px;
}

@media (max-width: 520px) {
  body.twalk-glass, body {
    background: var(--color-background-primary);
  }
  .screen {
    width: 100%;
    padding: max(14px, env(safe-area-inset-top)) 0 calc(90px + env(safe-area-inset-bottom));
  }
  .screen > .panel:first-child {
    margin: 0;
    padding: 18px 16px 14px;
    border-width: 0 0 .5px;
    border-radius: 0;
    background: var(--color-background-primary);
  }
  .screen > .panel:first-child h1 { margin-bottom: 4px; }
  .screen > .panel:first-child .eyebrow { display: none; }
  .tabs { margin: 0; padding: 0 16px; }
  .list, .chat-list { border-radius: 0; }
  .panel:not(:first-child), .glass-panel:not(:first-child) {
    margin: 12px 14px;
  }
  .admin-row {
    align-items: stretch;
    flex-direction: column;
  }
  .actions { justify-content: flex-start; }
}

@media (min-width: 860px) {
  body.twalk-glass:not(.twalk-chat-view) {
    padding: 24px;
  }
  .app-shell:not(.chat-mode) {
    width: min(1220px, 100%);
    min-height: calc(100vh - 48px);
    margin: 0 auto;
    display: grid;
    grid-template-columns: 220px 1fr;
    overflow: hidden;
    border: var(--hairline);
    border-radius: 16px;
    background: var(--color-surface);
    box-shadow: var(--shadow-ios);
  }
  .app-shell:not(.chat-mode)::before {
    content: "";
    grid-column: 1 / -1;
    height: 38px;
    background:
      radial-gradient(circle at 18px 19px, #FF5F57 0 4px, transparent 5px),
      radial-gradient(circle at 35px 19px, #FFBD2E 0 4px, transparent 5px),
      radial-gradient(circle at 52px 19px, #28C840 0 4px, transparent 5px),
      var(--color-background-secondary);
    border-bottom: var(--hairline);
  }
  .topbar, .top-bar {
    position: relative;
    grid-row: 2;
    align-self: stretch;
    min-height: auto;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    padding: 18px 14px;
    border-right: var(--hairline);
    border-bottom: 0;
    background: var(--color-surface);
  }
  .brand, .wordmark { margin-bottom: 24px; }
  .topbar nav {
    position: static;
    display: grid;
    grid-template-columns: 1fr;
    height: auto;
    min-height: auto;
    gap: 4px;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }
  .topbar nav a {
    justify-content: start;
    place-items: center start;
    min-height: 40px;
    padding: 0 12px;
    color: var(--color-text-secondary);
    font-size: 15px;
  }
  .topbar nav a:hover {
    color: var(--color-accent);
    background: var(--color-background-secondary);
  }
  .screen {
    grid-row: 2;
    width: 100%;
    margin: 0;
    padding: 24px;
    overflow: auto;
  }
  .screen:not(.narrow):not(.admin) {
    display: grid;
    grid-template-columns: minmax(320px, 420px) 1fr;
    gap: 0;
  }
  .screen:not(.narrow):not(.admin) > .panel:first-child,
  .screen:not(.narrow):not(.admin) > .tabs,
  .screen:not(.narrow):not(.admin) > .panel:nth-of-type(2),
  .screen:not(.narrow):not(.admin) > .list {
    grid-column: 1;
  }
  .screen:not(.narrow):not(.admin)::after {
    content: "Select a conversation";
    grid-column: 2;
    grid-row: 1 / span 4;
    min-height: 640px;
    display: grid;
    place-items: center;
    color: var(--color-text-tertiary);
    border-left: var(--hairline);
    background: var(--color-background-primary);
  }
  .screen.admin {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    align-content: start;
  }
  .screen.admin > .admin-nav,
  .screen.admin > .panel:first-of-type,
  .screen.admin > .alert {
    grid-column: 1 / -1;
  }
  .screen.admin > .panel {
    margin: 0;
  }
  .chat-screen {
    width: min(1020px, calc(100% - 48px));
    min-height: calc(100vh - 48px);
    margin: 24px auto;
    overflow: hidden;
    border: var(--hairline);
    border-radius: 16px;
    box-shadow: var(--shadow-ios);
  }
  .chat-screen::before {
    content: "";
    height: 38px;
    background:
      radial-gradient(circle at 18px 19px, #FF5F57 0 4px, transparent 5px),
      radial-gradient(circle at 35px 19px, #FFBD2E 0 4px, transparent 5px),
      radial-gradient(circle at 52px 19px, #28C840 0 4px, transparent 5px),
      var(--color-background-secondary);
    border-bottom: var(--hairline);
  }
  .composer, .composer-glass {
    width: min(1020px, calc(100% - 48px));
    bottom: 24px;
    border: var(--hairline);
    border-top: var(--hairline);
    border-radius: 0 0 16px 16px;
  }
}

@media (prefers-color-scheme: dark) {
  .topbar nav { background: rgba(28,28,30,.82); }
  .topbar, .top-bar, .chat-head, .composer, .composer-glass { background: rgba(28,28,30,.86); }
  .brand-mark { background: var(--color-accent); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: .001ms !important;
  }
}

@keyframes twalk-message-in {
  from { opacity: 0; transform: translateY(40px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes badgePulse { 0% { transform: scale(.94); } 55% { transform: scale(1.06); } 100% { transform: scale(1); } }
@keyframes skeleton { to { background-position: -220% 0; } }

/* 20. Production app polish */
body {
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
.twalk-glass::before,
.twalk-glass::after {
  content: "";
  position: fixed;
  z-index: -1;
  border-radius: 999px;
  pointer-events: none;
  filter: blur(.2px);
}
.twalk-glass::before {
  width: 170px;
  height: 170px;
  right: 4vw;
  top: -52px;
  background: rgba(116,181,205,.22);
}
.twalk-glass::after {
  width: 220px;
  height: 220px;
  left: -72px;
  bottom: -66px;
  background: rgba(116,181,205,.16);
}
.full-button {
  width: 100%;
}
.auth-shell {
  position: relative;
  overflow: hidden;
}
.auth-card {
  position: relative;
  padding: 26px;
  border-radius: 30px;
  background:
    radial-gradient(circle at 83% 8%, rgba(116,181,205,.32), transparent 34%),
    rgba(255,255,255,.72);
}
.auth-card::before {
  content: "";
  position: absolute;
  inset: 14px;
  z-index: -1;
  border-radius: 34px;
  background: rgba(255,255,255,.44);
  box-shadow: 0 28px 80px rgba(0,84,102,.14);
}
.auth-panel-title {
  display: grid;
  gap: 2px;
  margin: 18px 0 14px;
  padding-top: 2px;
}
.auth-panel-title strong {
  font-size: 17px;
}
.auth-panel-title small {
  font-size: 12px;
}
.auth-link {
  margin: 16px 0 0;
  text-align: center;
  font-size: 13px;
}
.auth-link a,
.muted a {
  color: var(--brand-primary);
  font-weight: 800;
}
.topbar nav {
  grid-template-columns: repeat(auto-fit, minmax(70px, 1fr));
}
.topbar nav a {
  position: relative;
}
.topbar nav a:hover,
.topbar nav a:focus-visible {
  transform: translateY(-1px);
}
.screen > .panel:first-child {
  overflow: hidden;
}
.screen > .panel:first-child h1 {
  margin-bottom: 6px;
}
.list-row,
.chat-item,
.admin-row,
.version-card {
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
}
.list-row:active,
.chat-item:active {
  transform: scale(.992);
}
.avatar {
  color: #fff;
  font-size: 17px;
}
.avatar::after {
  content: "";
  position: absolute;
  inset: 1px;
  border-radius: inherit;
  border: 1px solid rgba(255,255,255,.28);
  pointer-events: none;
}
.badge,
.unread,
.status-pill {
  line-height: 1;
}
.status-pill {
  color: var(--brand-primary);
  border: 1px solid rgba(0,108,124,.08);
}
.admin-nav {
  position: sticky;
  top: 12px;
  z-index: 10;
  box-shadow: var(--shadow-small);
}
.admin-row {
  border-top-color: rgba(0,108,124,.07);
}
.admin-row > div {
  min-width: 0;
}
.actions select {
  width: auto;
  min-width: 94px;
  min-height: 40px;
  padding: 7px 10px;
}
.actions button,
.member-action button {
  border-radius: 999px;
}
.update-panel input[type="file"] {
  padding: 24px;
  border-style: dashed;
  border-radius: 18px;
  background: rgba(255,255,255,.72);
}
.chat-head .avatar {
  flex-basis: 48px;
  width: 48px;
  height: 48px;
}
.chat-head strong,
.chat-head small {
  display: block;
}
.chat-head div {
  min-width: 0;
}
.chat-head strong {
  max-width: 28vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.message-bubble {
  line-height: 1.42;
}
.composer textarea {
  resize: none;
}
.composer-tools .attach {
  font-size: 15px;
}
.camera-button {
  font-size: 11px !important;
  letter-spacing: 0;
}
.empty-state {
  border: 1px dashed rgba(0,108,124,.16);
  border-radius: 22px;
  background: rgba(255,255,255,.58);
}

@media (min-width: 860px) {
  .app-shell {
    width: min(1240px, calc(100vw - 44px));
  }
  .screen:not(.narrow):not(.admin)::after {
    content: "";
    background:
      radial-gradient(circle at 50% 42%, rgba(116,181,205,.18) 0 112px, transparent 114px),
      linear-gradient(180deg, rgba(255,255,255,.82), rgba(248,251,252,.72));
  }
}

@media (max-width: 520px) {
  .auth-shell {
    padding: 18px 14px;
  }
  .auth-card {
    padding: 22px 18px;
  }
  .topbar {
    border-radius: 0 0 22px 22px;
  }
  .list-row,
  .chat-item {
    min-height: 72px;
  }
  .admin-nav {
    top: 8px;
  }
}

/* 19. Webview chat workspace fixes */
body.twalk-chat-view {
  padding: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
}
.app-shell.chat-mode {
  width: min(1220px, calc(100vw - 28px));
  height: min(860px, calc(100vh - 28px));
  min-height: 620px;
  margin: 0 auto;
  display: block;
  overflow: hidden;
  background: rgba(255,255,255,.78);
  border: 1px solid rgba(210,224,229,.92);
  border-radius: 24px;
  box-shadow: var(--shadow-soft);
}
.app-shell.chat-mode::before {
  content: "";
  display: block;
  height: 38px;
  background:
    radial-gradient(circle at 18px 19px, #FF5F57 0 4px, transparent 5px),
    radial-gradient(circle at 34px 19px, #FFBD2E 0 4px, transparent 5px),
    radial-gradient(circle at 50px 19px, #28C840 0 4px, transparent 5px),
    linear-gradient(#F7F9FA, #EFF4F5);
  border-bottom: 1px solid rgba(210,224,229,.82);
}
.app-shell.chat-mode .chat-screen {
  position: relative;
  width: 100%;
  height: calc(100% - 38px);
  min-height: 0;
  margin: 0;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background:
    radial-gradient(circle at 16% 8%, rgba(116,181,205,.18), transparent 26%),
    linear-gradient(180deg, rgba(255,255,255,.82) 0%, rgba(239,246,248,.88) 100%);
}
.app-shell.chat-mode .chat-screen::before {
  position: absolute;
  inset: 0;
}
.app-shell.chat-mode .chat-head {
  border-radius: 0 0 22px 0;
  width: min(420px, 100%);
  min-height: 72px;
}
.app-shell.chat-mode .messages {
  height: 100%;
  min-height: 0;
  padding: 20px clamp(16px, 3vw, 42px) 18px;
}
.composer, .composer-glass {
  position: sticky;
  left: auto;
  right: auto;
  bottom: max(10px, env(safe-area-inset-bottom));
  transform: none;
  width: min(760px, calc(100% - 28px));
  margin: 0 auto max(12px, env(safe-area-inset-bottom));
}
.composer-tools {
  display: flex;
  gap: 6px;
}
.attach.camera-button {
  background: var(--brand-primary-soft);
  color: var(--brand-primary);
}
.attach.camera-button::before {
  content: "";
}
.message-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 6px;
  opacity: .82;
}
.message-actions button {
  min-height: 28px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  background: rgba(255,255,255,.22);
  color: inherit;
  box-shadow: none;
}
.message-bubble.received .message-actions,
.bubble.theirs .message-actions {
  display: none;
}
.message-edited {
  opacity: .75;
  font-style: italic;
}
.message-deleted {
  opacity: .72;
  font-style: italic;
}
.notify-enable {
  right: max(16px, calc((100vw - min(1220px, calc(100vw - 28px))) / 2 + 16px));
}

@media (min-width: 860px) {
  body.twalk-chat-view { padding: 0; }
  .app-shell.chat-mode {
    display: block;
    grid-template-columns: none;
  }
  .app-shell.chat-mode .chat-screen {
    width: 100%;
    min-height: 0;
  }
}

@media (max-width: 720px) {
  body.twalk-chat-view {
    display: block;
    padding: 0;
  }
  .app-shell.chat-mode {
    width: 100%;
    height: 100vh;
    min-height: 100vh;
    border: 0;
    border-radius: 0;
  }
  .app-shell.chat-mode::before {
    display: none;
  }
  .app-shell.chat-mode .chat-screen {
    height: 100vh;
  }
  .app-shell.chat-mode .chat-head {
    width: 100%;
    border-radius: 0 0 22px 22px;
  }
  .app-shell.chat-mode .messages {
    padding: 16px 12px 12px;
  }
  .composer, .composer-glass {
    width: calc(100% - 16px);
    margin-bottom: max(8px, env(safe-area-inset-bottom));
  }
}
