/* Desktop hierarchy: workspaces / navigation and conversations / active work.
   Mobile keeps its existing single-pane navigation and bottom tabs. */
.workspace-tools { flex-shrink: 0; }
.workspace-list { min-height: 0; }
@media (max-width: 720px) {
  .app-shell .workspace-tools { display: none; }
}
@media (min-width: 721px) {
  body:not(.dark) { --sidebar: #f0f4f0; --rail: #173b2d; --panel: #ffffff; --bg: #f7f9f6; --text: #23392e; --muted: #6d7e73; --line: #dfe6e0; --accent: #28654a; --accent-soft: #dcebdd; --hover: #e5ece5; }
  body.dark { --sidebar: #232c27; --rail: #14251c; --panel: #1b211e; --bg: #171e1a; --text: #e5eee8; --muted: #9eadA3; --line: #354139; --accent: #93d5ad; --accent-soft: #354d3e; --hover: #2c3830; }
  .app-shell { --desk-rail: 64px; --desk-sidebar: 266px; --desk-details: 294px; grid-template-columns: var(--desk-rail) var(--desk-sidebar) minmax(0, 1fr); }
  .app-shell.details-open { grid-template-columns: var(--desk-rail) var(--desk-sidebar) minmax(0, 1fr) var(--desk-details); }
  .app-shell .workspace-rail { padding: 13px 8px 12px; gap: 12px; background: var(--rail); border-right: 1px solid #ffffff08; }
  .app-shell .workspace-logo.workspace-name-mark { width: 34px; height: 34px; min-height: 34px; padding: 0; border-radius: 9px; border: 0; box-shadow: none; margin-bottom: 4px; flex-shrink: 0; }
  .workspace-list { display: flex; flex-direction: column; align-items: center; gap: 11px; width: 100%; padding: 5px 0; overflow-y: auto; overflow-x: hidden; scrollbar-width: none; }
  .workspace-list::-webkit-scrollbar { display: none; }
  .workspace-list button { position: relative; display: grid; place-items: center; width: 42px; height: 42px; min-height: 42px; padding: 0; border-radius: 12px; border: 1px solid #b9d7c126; background: #aecbb725; color: #deeee3; font-size: 15px; font-weight: 720; flex-shrink: 0; transition: background .15s, border-color .15s; }
  .workspace-list button:hover { background: #a0c4a54d; border-color: #cce9d5a6; }
  .workspace-list button.selected, .workspace-list button[aria-current="true"], .workspace-list button[aria-current="page"] { background: #dcefe1; color: #264934; border-color: #c5e6cf; box-shadow: 0 0 0 2px var(--rail), 0 0 0 4px #83a48b; }
  .workspace-list button img { width: 100%; height: 100%; object-fit: cover; border-radius: 10px; }
  .workspace-add-button { display: grid; place-items: center; width: 40px; height: 40px; min-height: 40px; padding: 0; border-radius: 12px; border: 1px dashed #a2b9aa54; background: transparent; color: #b7cebf; flex-shrink: 0; }
  .workspace-add-button:hover { background: #b5d0bf19; border-color: #b7cebf; color: #fff; }
  .workspace-add-button svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; }
  .app-shell .rail-spacer { flex: 1 1 auto; min-height: 10px; }
  .app-shell #profileButton { width: 36px; height: 36px; min-height: 36px; border-radius: 11px; margin: 0; flex-shrink: 0; border: 1px solid #a2b9aa66; box-shadow: none; }
  .app-shell .sidebar { height: 100%; min-height: 0; padding: 0; background: var(--sidebar); border-right: 1px solid var(--line); }
  .app-shell .sidebar-header { height: 64px; min-height: 64px; flex-shrink: 0; padding: 13px 14px 13px 18px; gap: 6px; border-bottom: 0; }
  .sidebar-header > div:first-child { min-width: 0; }
  .app-shell .sidebar-header .eyebrow { display: none; }
  .app-shell .sidebar-header h2 { font-size: 17px; font-weight: 750; letter-spacing: -.035em; margin: 0; line-height: 1.4; }
  .app-shell .sidebar-header-actions { gap: 3px; flex-shrink: 0; }
  .app-shell .sidebar-header .icon-button { height: 28px; width: 28px; min-height: 28px; border: 0 !important; color: var(--muted) !important; border-radius: 6px; }
  .app-shell .sidebar-header .icon-button:hover { background: var(--hover) !important; color: var(--text) !important; }
  .app-shell .workspace-tools { display: flex; align-items: stretch; gap: 2px; padding: 0 10px 13px; border-bottom: 1px solid var(--line); margin-bottom: 13px; }
  .app-shell .workspace-tools .rail-nav-button { display: flex; align-items: center; justify-content: flex-start; gap: 10px; width: 100%; height: 33px; min-height: 33px; padding: 6px 10px; border-radius: 6px; color: var(--muted); border: 0; background: transparent; }
  .app-shell .workspace-tools .rail-nav-button:hover { background: var(--hover); color: var(--text); }
  .app-shell .workspace-tools .rail-nav-button.selected { background: var(--accent-soft); color: var(--text); }
  .app-shell .workspace-tools .rail-nav-button.selected:before { display: none; }
  .app-shell .workspace-tools .rail-nav-button svg { width: 18px; height: 18px; flex: 0 0 18px; stroke-width: 1.6; }
  .app-shell .workspace-tools .rail-label { padding: 0; text-align: left; font-size: 13px; line-height: 1.35; letter-spacing: -.015em; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .app-shell .workspace-tools .rail-nav-button.selected .rail-label { font-weight: 700; }
  .app-shell #homeRailAttentionBadge { inset: auto 9px auto auto; position: absolute; width: auto; height: 16px; min-width: 17px; padding: 0 4px; border: 0; border-radius: 5px; font-size: 9px; line-height: 16px; background: #a75e48; color: #fff; }
  .app-shell .sidebar-home-button, .app-shell .profile-card { display: none; }
  .app-shell .search-wrap { position: relative; flex-shrink: 0; min-height: 32px; margin: 0 12px 14px; padding: 6px 9px; border-radius: 6px; border: 1px solid var(--line); background: color-mix(in srgb, var(--panel) 58%, var(--sidebar)); box-shadow: none; }
  .app-shell .search-wrap input { min-width: 0; font-size: 11px; line-height: 1.5; background: transparent; }
  .app-shell .search-wrap > span { font-size: 19px; color: var(--muted); }
  .app-shell .search-wrap kbd { font-size: 9px; background: transparent; border: 0; color: var(--muted); padding: 0; }
  .app-shell .search-results { position: absolute; inset: calc(100% + 6px) auto auto 0; width: min(460px, calc(100vw - var(--desk-rail) - 32px)); max-height: min(480px, 65vh); z-index: 35; padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); box-shadow: 0 12px 34px #10211822; }
  .app-shell .conversation-heading { padding: 0 17px 5px; min-height: 29px; flex-shrink: 0; }
  .app-shell .conversation-heading h3 { color: var(--muted); font-size: 11px; font-weight: 650; letter-spacing: .01em; }
  .app-shell .conversation-filters { gap: 1px; }
  .app-shell .conversation-filters button { min-height: 24px; padding: 2px 7px; font-size: 10px; border: 0; border-radius: 4px; }
  .app-shell .conversation-filters button.selected { background: color-mix(in srgb, var(--panel) 80%, var(--sidebar)); color: var(--text); border: 0; }
  .app-shell .channel-list { padding: 0 9px 22px; min-height: 0; flex: 1 1 auto; overflow-y: auto; }
  .app-shell .channel-section-title { padding: 14px 9px 7px; font-size: 11px; font-weight: 580; letter-spacing: 0; color: var(--muted); }
  .app-shell .channel-item { margin: 1px 0; border-radius: 5px; }
  .app-shell .channel-item.selected { background: var(--accent-soft); box-shadow: none; }
  .app-shell .channel-main { min-height: 34px; padding: 5px 9px; gap: 9px; border-radius: 5px; }
  .app-shell .channel-item:hover .channel-main { padding-right: 77px; }
  .app-shell .channel-icon { width: 22px; height: 22px; min-width: 22px; border-radius: 5px; font-size: 13px; font-weight: 600; background: transparent; border: 0; color: var(--muted); }
  .app-shell .channel-copy { min-width: 0; }
  .app-shell .channel-copy strong { font-size: 13px; font-weight: 500; line-height: 1.5; }
  .app-shell .channel-item.selected .channel-copy strong { font-weight: 700; color: var(--text); }
  .app-shell .channel-copy > span { display: none; }
  .app-shell .channel-main:has(.unread) .channel-copy strong { color: var(--text); font-weight: 700; }
  .app-shell .unread { min-width: 18px; height: 17px; font-size: 10px; line-height: 17px; border-radius: 5px; margin-left: auto; background: #44785b; color: #fff; }
  .app-shell .channel-pref-actions { right: 5px; padding: 1px; gap: 1px; border-radius: 4px; }
  .app-shell .channel-pref { height: 23px; width: 23px; min-height: 23px; font-size: 11px; border-radius: 4px; }
  .app-shell .archive-zone { margin-top: 10px; border-top-color: var(--line); }
  .app-shell .archive-toggle { font-size: 11px; min-height: 32px; }
  /* The content frame has rounded surfaces, not an overflow clip: composer
     popovers and independent call windows must remain usable outside it. */
  .app-shell .chat-panel { height: auto; min-height: 0; margin: 10px; border: 1px solid var(--line); border-radius: 16px; background: var(--panel); overflow: visible; }
  .app-shell .home-view { min-height: 0; border-radius: inherit; }
  .app-shell .home-header, .app-shell .chat-header { border-top-left-radius: 15px; border-top-right-radius: 15px; }
  .app-shell .home-scroll, .app-shell .composer-wrap { border-bottom-left-radius: 15px; border-bottom-right-radius: 15px; }
  .app-shell .chat-header { height: 64px; min-height: 64px; padding: 0 23px; gap: 20px; background: var(--panel); border-bottom: 1px solid var(--line); }
  .app-shell .chat-title-wrap { gap: 10px; min-width: 0; }
  .app-shell .chat-avatar { width: 30px; height: 30px; min-width: 30px; border-radius: 7px; background: transparent; color: var(--muted); font-size: 21px; }
  .app-shell .chat-title-wrap h1 { font-size: 17px; line-height: 1.4; letter-spacing: -.03em; font-weight: 720; }
  .app-shell .chat-title-wrap p { font-size: 11px; line-height: 1.3; margin: 3px 0 0; }
  .app-shell .header-actions { gap: 4px; flex-shrink: 0; }
  .app-shell .header-actions .action-button { width: 32px; height: 32px; min-height: 32px; border: 0 !important; border-radius: 6px; color: var(--muted) !important; }
  .app-shell .header-actions .action-button:hover, .app-shell .header-actions .action-button.active { color: var(--accent) !important; background: var(--accent-soft); }
  .app-shell .header-actions .action-button svg { width: 18px; height: 18px; }
  .app-shell .messages { padding: 13px 0 16px; scrollbar-gutter: stable; }
  .app-shell .date-divider { margin: 8px 20px 15px; gap: 14px; font-size: 10px; color: var(--muted); font-weight: 600; }
  .app-shell .message-row, .app-shell .message-row.mine { flex-direction: row; gap: 11px; margin: 0; padding: 8px 23px; align-items: flex-start; }
  .app-shell .message-row:hover, .app-shell .message-row:focus-within { background: color-mix(in srgb, var(--sidebar) 45%, var(--panel)); }
  .app-shell .message-row > .avatar { width: 33px; height: 33px; min-width: 33px; border-radius: 7px; font-size: 12px; margin-top: 2px; }
  .app-shell .message-row .message-body { flex: 1; min-width: 0; max-width: 100%; }
  .app-shell .message-row .message-meta { justify-content: flex-start; margin: 0 0 2px; gap: 8px; min-height: 18px; align-items: baseline; }
  .app-shell .message-meta strong { font-size: 13px; font-weight: 720; }
  .app-shell .message-meta time { font-size: 10px; color: var(--muted); }
  .app-shell .message-academic { font-size: 9px; font-weight: 550; color: var(--muted); }
  .app-shell .message-row .bubble, body.dark .app-shell .message-row .bubble { padding: 0; border: 0; border-radius: 0; background: transparent; box-shadow: none; font-size: 14px; line-height: 1.55; }
  .app-shell .message-actions { top: -12px; right: -3px; z-index: 1; border: 1px solid var(--line); box-shadow: 0 2px 6px #10211812; }
  .app-shell .message-actions button { width: 26px; height: 25px; border: 0; }
  .app-shell .message-file { max-width: 400px; min-width: 0; margin-top: 8px; padding: 10px; border-radius: 7px; background: var(--panel); }
  .app-shell .composer-wrap { position: relative; margin: 0; padding: 7px 23px 13px; background: var(--panel); }
  .app-shell .composer-wrap > .format-toolbar-toggle { max-width: none; min-height: 25px; margin: 0 0 5px; padding: 2px 1px; border: 0; background: transparent; color: var(--muted); font-size: 10px; box-shadow: none; }
  .app-shell .composer-wrap > .format-toolbar-toggle svg { width: 15px; height: 15px; }
  .app-shell .composer-wrap > .format-toolbar-toggle small { color: var(--muted); font-size: 9px; }
  .app-shell .composer-wrap > .format-toolbar { max-width: none; width: 100%; }
  .app-shell .composer { width: 100%; max-width: none; border: 1px solid color-mix(in srgb, var(--muted) 35%, var(--line)); border-radius: 8px; padding: 8px 9px; gap: 5px; min-height: 62px; background: var(--panel); box-shadow: none; }
  .app-shell .composer:focus-within { border-color: var(--muted); box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 18%, transparent); }
  .app-shell .composer textarea { min-height: 42px; height: 42px; padding: 11px 7px; font-size: 13px; line-height: 1.5; }
  .app-shell .composer > button { width: 32px; height: 34px; min-height: 34px; align-self: flex-end; margin-bottom: 3px; color: var(--muted); border-radius: 5px; }
  .app-shell .composer > button:hover { background: var(--hover); }
  .app-shell .composer .send-button { background: #326c4c; color: #fff; }
  .app-shell .composer .send-button:hover { background: #43805b; }
  .app-shell .composer-wrap > p { text-align: right; margin: 6px 1px 0; font-size: 9px; color: var(--muted); }
  .app-shell .home-header { height: auto; min-height: 104px; padding: 20px 28px; gap: 20px; }
  .app-shell .home-heading .eyebrow { display: block; font-size: 10px; line-height: 1.5; letter-spacing: .1em; }
  .app-shell .home-heading h1 { font-size: 22px; line-height: 1.35; margin: 5px 0 0; white-space: normal; overflow-wrap: anywhere; letter-spacing: -.025em; }
  .app-shell .home-heading p { font-size: 13px; line-height: 1.55; margin: 5px 0 0; }
  .app-shell .home-profile-button { width: 48px; height: 48px; flex: 0 0 48px; border-radius: 12px; }
  .app-shell .home-scroll { padding: 28px clamp(24px,2.7vw,40px) 36px; }
  .app-shell .home-hero { gap: 24px; }
  .app-shell .home-hero h2 { font-size: clamp(26px,2.3vw,32px); line-height: 1.3; letter-spacing: -.025em; margin-bottom: 9px; }
  .app-shell .home-hero p { font-size: 14px; line-height: 1.6; }
  .app-shell .home-stats { gap: 16px; }
  .app-shell .home-stats button { min-height: 104px; border-radius: 14px; padding: 20px 22px; }
  .app-shell .home-stats strong { font-size: 30px; line-height: 1.15; }
  .app-shell .home-stats span { font-size: 13px; line-height: 1.5; margin-top: 7px; }
  .app-shell .home-content-grid { gap: 18px; margin-top: 22px; }
  .app-shell .home-card, .app-shell .home-tools { border-radius: 14px; padding: 22px; }
  .app-shell .home-tools { margin-top: 22px; }
  .app-shell .home-card-heading { margin-bottom: 18px; }
  .app-shell .home-card-heading h2 { font-size: 18px; line-height: 1.4; }
  .app-shell .home-list-item { min-height: 72px; border-radius: 10px; }
  .app-shell .home-list-item strong { font-size: 14px; line-height: 1.45; }
  .app-shell .home-list-item small { font-size: 12px; line-height: 1.5; }
  .app-shell .tool-card { border-radius: 12px; }
  .app-shell .details-panel { border-left: 1px solid var(--line); background: var(--panel); }
  .app-shell .details-panel > header { height: 64px; min-height: 64px; padding: 0 18px; }
  .app-shell .details-panel > header h3 { font-size: 13px; }
  .app-shell .details-profile { padding: 22px 18px; }
  .app-shell .details-avatar { width: 50px; height: 50px; border-radius: 10px; }
  .app-shell .details-profile h2 { font-size: 16px; }
  .app-shell .details-profile p { font-size: 11px; }
  .app-shell .detail-section { padding: 16px 17px 10px; }
  body.dark .app-shell .workspace-tools .rail-nav-button.selected { background: #3a5141; color: #f0f7f2; }
  body.dark .app-shell .channel-item.selected { background: #3a5141; }
  body.dark .app-shell .channel-icon { background: transparent; border: 0; color: var(--muted); }
  body.dark .app-shell .search-wrap { background: #1b241e; }
  body.dark .app-shell .channel-pref-actions { background: var(--sidebar); }
  body.dark .app-shell .channel-item.selected .channel-pref-actions { background: #3a5141; }
}
@media (min-width: 721px) and (max-width: 1180px) {
  .app-shell, .app-shell.details-open { --desk-sidebar: 242px; grid-template-columns: var(--desk-rail) var(--desk-sidebar) minmax(0, 1fr); }
  .app-shell.details-open .details-panel { position: fixed; inset: 0 0 0 auto; width: 294px; display: flex; z-index: 40; box-shadow: -12px 0 40px #10211825; }
  .app-shell .chat-header { padding-inline: 18px; gap: 12px; }
  .app-shell .message-row, .app-shell .message-row.mine { padding-inline: 18px; }
  .app-shell .composer-wrap { padding-inline: 18px; }
  .app-shell .home-header { padding-inline: 22px; }
  .app-shell .home-scroll { padding: 24px 22px 30px; }
  .app-shell .home-content-grid { grid-template-columns: minmax(0,1fr); }
}
/* Phone headers size to their content; a long name never crowds the avatar.
   The existing single-pane navigation and fixed bottom tabs stay unchanged. */
@media (max-width: 720px) {
  .app-shell .home-header { height: auto; min-height: calc(108px + env(safe-area-inset-top)); padding: calc(18px + env(safe-area-inset-top)) 18px 18px; gap: 14px; align-items: flex-start; }
  .app-shell .home-heading h1 { font-size: 21px; line-height: 1.35; margin: 6px 0 0; white-space: normal; overflow-wrap: anywhere; }
  .app-shell .home-heading .eyebrow { display: block; font-size: 10px; line-height: 1.5; }
  .app-shell .home-heading p { display: block; font-size: 12px; line-height: 1.55; margin: 6px 0 0; }
  .app-shell .home-profile-button { width: 44px; height: 44px; flex: 0 0 44px; margin-top: 2px; border-radius: 12px; }
  .app-shell .home-card, .app-shell .home-tools, .app-shell .home-stats button { border-radius: 14px; }
}
@media (max-width: 720px) and (max-height: 500px) {
  .app-shell .home-header { min-height: 84px; padding: 12px 16px; gap: 12px; }
  .app-shell .home-heading h1 { font-size: 18px; margin-top: 3px; }
  .app-shell .home-heading p { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .workspace-list button { transition: none; }
}

/* Group creation belongs to the group list. Reserve its space so discovery
   by hover or keyboard does not move names or counts. */
.app-shell .channel-group-section { min-width: 0; min-height: 50px; gap: 8px; }
.app-shell .channel-section-tools { display: inline-flex; align-items: center; justify-content: flex-end; gap: 7px; }
.app-shell .channel-section-count { min-width: 12px; text-align: right; }
.app-shell .channel-create-button { display: inline-flex; align-items: center; gap: 4px; min-height: 28px; padding: 3px 6px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font: inherit; font-weight: 600; white-space: nowrap; opacity: 0; pointer-events: none; }
.app-shell .channel-create-button svg { width: 14px; height: 14px; flex: 0 0 14px; }
.app-shell .channel-group-section:hover .channel-create-button,
.app-shell .channel-group-section:focus-within .channel-create-button,
.app-shell .channel-list:has(> .channel-group-item:hover) .channel-create-button,
.app-shell .channel-list:has(> .channel-group-item:focus-within) .channel-create-button { opacity: 1; pointer-events: auto; }
.app-shell .channel-create-button:hover { color: var(--accent); background: var(--accent-soft); }
.app-shell .channel-create-button:focus-visible { color: var(--accent); background: var(--accent-soft); outline: 2px solid var(--accent); outline-offset: 2px; }
@media (hover: none), (pointer: coarse), (max-width: 720px) {
  .app-shell .channel-create-button { opacity: 1; pointer-events: auto; min-height: 36px; }
}
