/* App shell (design C / V3 left side): folder rail | sidebar (head with hamburger + search pill, flat conversation rows) | chat. Drawer. */
.boot { position: fixed; inset: 0; display: grid; place-items: center; color: var(--accent-text); background: var(--bg); z-index: 1000; transition: opacity 200ms; }
.boot.gone { opacity: 0; pointer-events: none; }

.app {
  height: 100dvh; display: grid; background: var(--bg); position: relative;
  grid-template-columns: var(--rail-w) var(--list-w) minmax(0, 1fr); grid-template-rows: 64px minmax(0, 1fr);
  grid-template-areas: "rail head chat" "rail list chat";
}

/* ---------- rail (desktop): folders on top, language / theme / profile at the bottom */
.rail { grid-area: rail; background: var(--rail); box-shadow: inset -1px 0 0 var(--sep); display: flex; flex-direction: column; align-items: center; padding: 12px 0; gap: 6px; min-height: 0; min-width: 0; z-index: 2; }
.brand { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-bottom: 6px; }
.logo { width: 36px; height: 36px; border-radius: 12px; background: var(--own); color: #fff; display: grid; place-items: center; flex: none; }
.brand-name { display: none; }
.rail-folders { display: contents; }
.chips { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.chip {
  position: relative; width: 62px; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 8px 0 7px; border-radius: 14px;
  color: var(--t2); font-size: 12px; line-height: 17px; font-weight: 500; transition: background-color 160ms, color 160ms, transform 100ms var(--ease);
}
.chip:hover { background: var(--hover-strong); color: var(--t1); }
.chip:active { transform: scale(.96); }
.chip .chip-ic { display: grid; }
.chip .n { position: absolute; top: 2px; right: 6px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--badge); color: #fff; font-size: 12px; font-weight: 600; display: grid; place-items: center; line-height: 1; font-variant-numeric: tabular-nums; }
.chip .n:empty { display: none; }
.chip .n.soft { background: var(--hover-strong); color: var(--t2); }
.chip[aria-selected="true"] { background: var(--sel); color: var(--t1); }
.chip[aria-selected="true"] .n { background: var(--own); color: #fff; }
.rail-foot { margin-top: auto; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.rail-btn { width: 62px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 7px 0 6px; border-radius: 14px; color: var(--t2); font-size: 12px; line-height: 17px; font-weight: 500; transition: background-color 140ms, color 140ms, transform 100ms var(--ease); }
.rail-btn:hover { background: var(--hover-strong); color: var(--t1); }
.rail-btn:active { transform: scale(.96); }
.rail-btn .ico { display: grid; }
.avbtn { border-radius: 50%; width: 44px; height: 44px; flex: none; display: grid; place-items: center; margin-top: 4px; }
.avbtn .av { --s: 40px; }
.avbtn:hover .av { filter: brightness(1.08); }
.avbtn:active { transform: scale(.96); }
.mock-badge { font-size: 12px; font-weight: 600; letter-spacing: 0; color: var(--t3); border: 1px dashed var(--t3); padding: 0 4px; border-radius: 4px; pointer-events: none; white-space: nowrap; }

/* ---------- sidebar head: hamburger + search pill */
.sb-head { grid-area: head; background: var(--panel); border-right: 1px solid var(--sep); border-bottom: 1px solid var(--sep); display: flex; align-items: center; gap: 8px; padding: 8px 12px 7px; position: relative; z-index: 30; min-width: 0; }
.sb-head > .ibtn { width: 40px; height: 40px; }
.search { position: static; flex: 1; min-width: 0; }
.search-field { display: flex; align-items: center; gap: 10px; height: 40px; padding: 0 12px; border-radius: 20px; background: var(--input); border: 1px solid var(--field-line); color: var(--t3); transition: box-shadow 140ms; }
.search-field:focus-within { outline: 2px solid var(--ring); outline-offset: 2px; }
.search-field input { flex: 1; min-width: 0; height: 100%; border: 0; background: transparent; outline: none; color: var(--t1); font-size: 14.5px; }
.search-field input::placeholder { color: var(--t3); }
.kbd { font-size: 12px; font-weight: 600; letter-spacing: .02em; padding: 3px 7px; border-radius: 6px; background: var(--line); color: var(--t2); white-space: nowrap; }
.search-field .kbd { display: none; }
.search-results { position: absolute; left: 10px; top: calc(100% - 4px); width: min(380px, calc(100vw - 20px)); background: var(--popover); -webkit-backdrop-filter: blur(24px); backdrop-filter: blur(24px); border-radius: 16px; box-shadow: var(--shadow-pop); padding: 6px; max-height: min(480px, 70vh); overflow-y: auto; z-index: 60; transform-origin: 20% 0; animation: pop-in 140ms var(--ease) both; overscroll-behavior: contain; }
.sr-label { padding: 8px 10px 4px; font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--t3); }
.sr-item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 8px 10px; border-radius: var(--r-12); text-align: left; transition: background-color 120ms; }
.sr-item:hover, .sr-item[aria-selected="true"] { background: var(--hover-strong); }
.sr-item .sr-main { min-width: 0; flex: 1; }
.sr-item .sr-name { font-weight: 600; font-size: 14px; display: flex; gap: 8px; align-items: center; }
.sr-item .sr-sub { font-size: 12.5px; color: var(--t3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sr-note { padding: 18px 14px; text-align: center; color: var(--t2); font-size: 13.5px; }
.sr-note small { display: block; color: var(--t3); margin-top: 4px; font-size: 12.5px; }
.sr-skel { display: flex; align-items: center; gap: 12px; padding: 8px 10px; }
.sr-skel .av { background: var(--line); }

/* ---------- conversation list: flat rows */
.list-pane { grid-area: list; background: var(--panel); border-right: 1px solid var(--sep); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.conv-list { flex: 1; min-height: 0; overflow-y: auto; padding: 4px; display: flex; flex-direction: column; gap: 0; position: relative; scrollbar-gutter: stable; overscroll-behavior: contain; }
.conn-banner { display: flex; align-items: center; gap: 8px; margin: 4px 8px 6px; padding: 8px 12px; border-radius: var(--r-12); background: var(--warn-bg); color: var(--warn); font-size: 13px; font-weight: 500; animation: fade-in 180ms both; }

.conv {
  --ring-bg: var(--panel);
  position: relative; display: grid; grid-template-columns: 54px minmax(0, 1fr) auto; column-gap: 12px; align-items: center; width: 100%; text-align: left; flex: none;
  padding: 9px 10px; min-height: 72px; border-radius: 10px; border: 0; background: transparent;
  transition: background-color 240ms var(--ease), transform 140ms ease-out;
}
.conv:hover { background: var(--hover); --ring-bg: var(--bg); }
.conv:active { transform: scale(.99); }
.conv.active, .conv.active:hover { background: var(--sel); color: var(--sel-text); --ring-bg: var(--bg); }
.conv .c-main { min-width: 0; display: grid; gap: 3px; }
.conv .c-top { display: flex; flex-wrap: wrap; align-content: flex-start; align-items: center; gap: 0 6px; min-width: 0; height: 22px; overflow: hidden; }   /* the flag is always shown; the Demo tag wraps out of the (clipped) row first */
.conv .c-name { font-size: 15.5px; line-height: 22px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; max-width: calc(100% - 30px); flex: 0 1 auto; }   /* 30px stay free for the flag: the flag is always shown, the Demo tag is the first to wrap out */
.conv .c-prev { font-size: 14px; color: var(--t2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 6px; min-width: 0; }
.conv .c-prev .pv { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.conv .c-prev .i { color: var(--t3); }
.conv .c-prev .draft { color: var(--danger); font-weight: 500; flex: none; }
.conv .c-prev.typing { color: var(--accent-text); font-weight: 500; }
.conv .c-prev .pending { font-style: italic; color: var(--t3); }
.conv .c-meta { min-width: 52px; display: grid; justify-items: end; align-content: space-between; gap: 6px; align-self: stretch; padding: 4px 0 3px; }
.conv .c-time { font-size: 12.5px; color: var(--t3); font-variant-numeric: tabular-nums; white-space: nowrap; display: flex; align-items: center; gap: 4px; }
.conv.unread .c-time { color: var(--accent-text); }
.conv .c-meta .badges { display: flex; align-items: center; gap: 6px; min-height: 22px; color: var(--t3); }
.badge { min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px; background: var(--badge); color: #fff; font-size: 12px; font-weight: 600; display: inline-grid; place-items: center; font-variant-numeric: tabular-nums; }
.conv.muted .badge { background: var(--t3); color: var(--panel); }
.conv .c-tick { display: inline-flex; }
.conv .c-time .tk { color: var(--t3); display: inline-flex; }
.conv .c-time .tk.read { color: var(--accent-text); }
.conv .tag { height: 17px; padding: 0 4px; font-size: 12px; }
/* selected row: solid accent, everything on it reads in the light-on-blue colours */
.conv.active .c-prev, .conv.active .c-time, .conv.active .c-time .tk, .conv.active .c-meta .badges, .conv.active .c-prev .i, .conv.active .c-prev .pending { color: var(--sel-sub); }
.conv.active .c-prev.typing, .conv.active .c-time .tk.read { color: var(--accent-text); }



.list-empty { margin: 24px 8px; padding: 28px 20px; border: 1px dashed var(--line); border-radius: var(--r-16); text-align: center; color: var(--t2); display: grid; gap: 8px; justify-items: center; }
.list-empty h3 { font-size: 15px; font-weight: 600; color: var(--t1); }
.list-empty p { font-size: 13.5px; max-width: 26ch; }
.list-empty .eico { width: 48px; height: 48px; border-radius: 16px; background: var(--accent-bg); color: var(--accent-text); display: grid; place-items: center; margin-bottom: 4px; }
.conv-skel { height: 72px; border-radius: 10px; padding: 9px 10px; display: flex; gap: 12px; align-items: center; flex: none; }

/* ---------- drawer */
.scrim { position: fixed; inset: 0; background: var(--scrim); opacity: 0; visibility: hidden; transition: opacity 280ms var(--ease-drawer), visibility 0s linear 280ms; z-index: 200; }
.scrim.open { opacity: 1; visibility: visible; transition: opacity 280ms var(--ease-drawer), visibility 0s; }
.drawer { position: fixed; z-index: 210; top: 0; bottom: 0; left: 0; width: min(320px, 86vw); background: var(--panel); border-right: 1px solid var(--sep); transform: translateX(-102%); visibility: hidden; transition: transform 200ms var(--ease-drawer), visibility 0s linear 200ms; display: flex; flex-direction: column; box-shadow: var(--shadow-pop); padding-top: env(safe-area-inset-top); padding-left: env(safe-area-inset-left); }
.drawer.open { transform: none; visibility: visible; transition: transform 280ms var(--ease-drawer), visibility 0s; }
.dr-head { padding: 24px 20px 16px; display: grid; gap: 12px; border-bottom: 1px solid var(--line); }
.dr-head .row { display: flex; justify-content: space-between; align-items: flex-start; }
.dr-profile { display: grid; gap: 2px; text-align: left; border-radius: 12px; }
.dr-profile .nm { font-size: 17px; font-weight: 600; margin-top: 8px; }
.dr-profile .un { font-size: 13.5px; color: var(--t2); display: flex; gap: 8px; align-items: center; }
.dr-nav { padding: 8px; display: grid; gap: 2px; flex: 1; align-content: start; overflow-y: auto; }
.dr-item { display: flex; align-items: center; gap: 16px; height: 48px; padding: 0 12px; border-radius: var(--r-12); font-size: 14.5px; font-weight: 500; text-align: left; width: 100%; transition: background-color 140ms; }
.dr-item:hover { background: var(--hover-strong); }
.dr-item .i { color: var(--t2); }
.dr-item .grow { flex: 1; }
.dr-item .kbd { margin-left: auto; }
.dr-foot { padding: 14px 20px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); color: var(--t3); font-size: 12px; display: grid; gap: 2px; }

/* ---------- responsive: one pane below 900px; folders become a horizontal strip under the head */
@media (max-width: 1100px) { :root { --list-w: 300px; } }
@media (max-width: 899px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr); grid-template-areas: "head" "rail" "list"; }
  .sb-head { border-right: 0; padding: calc(8px + env(safe-area-inset-top)) 12px 6px; }
  .rail { flex-direction: row; align-items: center; padding: 0 12px 8px; gap: 0; background: var(--panel); }
  .rail-foot, .brand .logo { display: none; }
  .brand { margin: 0 8px 0 0; }   /* only the "Demo data" badge of mock mode shows here */
  .rail-folders { display: block; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
  .rail-folders::-webkit-scrollbar { display: none; }
  .chips { flex-direction: row; align-items: center; gap: 8px; }
  .chip { width: auto; flex-direction: row; gap: 6px; height: 36px; padding: 0 14px; border-radius: var(--r-pill); font-size: 14px; font-weight: 600; background: transparent; border: 1px solid var(--line); }
  .chip .chip-ic { display: none; }
  .chip .n { position: static; background: transparent; color: var(--t3); font-size: 12px; font-weight: 600; min-width: 0; padding: 0; height: auto; }
  .chip[aria-selected="true"] { border-color: var(--field-line); }
  .chip[aria-selected="true"] .n { background: transparent; color: var(--t2); }
  .list-pane { border-right: 0; }
  .search-results { left: 8px; right: 8px; width: auto; }
  .sb-head, .rail, .list-pane { transition: transform 280ms cubic-bezier(.32, .72, 0, 1), opacity 280ms cubic-bezier(.32, .72, 0, 1); }
  .app[data-view="chat"] .sb-head, .app[data-view="chat"] .rail, .app[data-view="chat"] .list-pane { transform: translateX(-24%); opacity: .6; }
}
html[data-motion="reduce"] .drawer { transform: none !important; opacity: 0; transition: opacity .12s, visibility 0s linear .12s !important; }
html[data-motion="reduce"] .drawer.open { opacity: 1; transition: opacity .12s, visibility 0s !important; }
html[data-motion="reduce"] .sb-head, html[data-motion="reduce"] .rail, html[data-motion="reduce"] .list-pane { transform: none !important; }
html[data-motion="reduce"] .conv, html[data-motion="reduce"] .conv:active, html[data-motion="reduce"] .chip:active { transform: none; }

/* demo contacts and the empty-list card */
.tag.demo { color: var(--accent-text); border-color: color-mix(in srgb, var(--accent-text) 45%, var(--line)); }
.conv.active .tag.demo { color: var(--accent-text); }
.list-empty.demo-card { margin: 16px 12px; border-style: solid; gap: 10px; }
.list-empty.demo-card p { max-width: 30ch; }
.demo-acts { display: grid; gap: 8px; width: 100%; margin-top: 6px; }
.demo-acts .btn { width: 100%; }

.conv .c-top .flag { margin-left: 2px; order: 2; flex: none; }
.conv .c-top .tag.demo { order: 3; }   /* tight row: name keeps room for the flag, the Demo tag wraps out first */
.sr-name .flag { margin-left: 2px; }
.rail-btn .flag.lg { margin-bottom: 1px; }
