:root {
  --bg: #f7f5f3;
  --panel: #ffffff;
  --panel-alt: #f7f8fa;
  --line: #e5e7e9;
  --text: #111b21;
  --muted: #667781;
  --green: #00a884;
  --green-deep: #008069;
  --bubble-out: #d9fdd3;
  --bubble-in: #ffffff;
  --hover: #f5f6f6;
  --selected: #f0f2f5;
  --shadow: 0 1px 2px rgba(11,20,26,.13);
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { font-family: "Segoe UI", Helvetica, Arial, sans-serif; background: var(--bg); color: var(--text); }
button, input { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }

.app-shell { display: grid; grid-template-columns: 64px 390px minmax(430px, 1fr); height: 100dvh; max-width: 1800px; margin: 0 auto; background: var(--panel); box-shadow: 0 0 20px rgba(0,0,0,.08); }
.rail { display: flex; flex-direction: column; justify-content: space-between; align-items: center; padding: 10px 0 12px; background: var(--panel-alt); border-right: 1px solid var(--line); }
.rail-top, .rail-bottom { display: grid; gap: 7px; justify-items: center; }
.rail-button, .icon-button { position: relative; display: grid; place-items: center; width: 42px; height: 42px; padding: 0; border: 0; border-radius: 50%; background: transparent; cursor: pointer; }
.rail-button:hover, .icon-button:hover { background: rgba(11,20,26,.07); }
.rail-button.active { background: #d9fdd3; color: #005c4b; }
.rail-button b { position: absolute; top: 4px; right: 1px; min-width: 17px; height: 17px; padding: 0 4px; border: 2px solid var(--panel-alt); border-radius: 10px; color: #fff; background: var(--green); font-size: 10px; line-height: 13px; }
.icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.avatar { display: grid; place-items: center; flex: 0 0 auto; border: 0; border-radius: 50%; color: #fff; background: linear-gradient(145deg,#a67cdd,#6746aa); font-weight: 600; cursor: pointer; }
.avatar-self { width: 32px; height: 32px; font-size: 12px; }

.sidebar { display: grid; grid-template-rows: 64px auto auto auto minmax(0,1fr) auto; min-width: 0; border-right: 1px solid var(--line); background: var(--panel); }
.ios-status, .mobile-menu, .mobile-camera, .mobile-tabs { display: none; }
.sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 0 18px 0 20px; }
.sidebar-header h1 { margin: 0; font-size: 22px; letter-spacing: -.3px; }
.header-actions { display: flex; gap: 4px; }
.search-wrap { position: relative; margin: 0 12px 7px; }
.search-wrap > .icon { position: absolute; z-index: 1; top: 8px; left: 13px; width: 18px; color: var(--muted); }
.search-wrap input { width: 100%; height: 35px; padding: 0 18px 0 54px; border: 0; border-radius: 8px; outline: 0; color: var(--text); background: var(--panel-alt); font-size: 13px; }
.search-wrap input:focus { box-shadow: inset 0 -2px var(--green); }
.filter-row { display: flex; gap: 8px; padding: 2px 12px 8px; overflow-x: auto; scrollbar-width: none; }
.filter { height: 32px; padding: 0 13px; border: 1px solid var(--line); border-radius: 17px; color: var(--muted); background: var(--panel); cursor: pointer; font-size: 14px; }
.filter:hover { background: var(--hover); }
.filter.active { border-color: #d9fdd3; color: #008069; background: #e7fce9; }
.archive-row { display: grid; grid-template-columns: 62px 1fr auto; align-items: center; height: 50px; padding: 0 27px 0 0; border: 0; background: var(--panel); text-align: left; cursor: pointer; }
.archive-row .icon { justify-self: center; width: 19px; color: var(--green-deep); }
.archive-row strong { font-size: 15px; font-weight: 500; }
.archive-row small { color: var(--green-deep); font-size: 12px; }
.chat-list { overflow-y: auto; scrollbar-color: #c7cdd0 transparent; scrollbar-width: thin; }
.chat-row { display: grid; grid-template-columns: 62px minmax(0,1fr); min-height: 72px; padding: 0; border: 0; background: var(--panel); text-align: left; cursor: pointer; width: 100%; }
.chat-row:hover { background: var(--hover); }
.chat-row.active { background: var(--selected); }
.chat-avatar { align-self: center; justify-self: center; width: 49px; height: 49px; font-size: 15px; }
.chat-avatar { background-position: center; background-size: cover; }
.chat-avatar > span { display: none; }
.chat-copy { display: grid; grid-template-columns: minmax(0,1fr) auto; align-content: center; column-gap: 8px; border-top: 1px solid var(--line); padding: 10px 13px 10px 0; min-width: 0; }
.chat-row:first-child .chat-copy { border-top-color: transparent; }
.chat-copy strong, .chat-copy p { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.chat-copy strong { font-size: 16px; font-weight: 500; }
.chat-copy time { color: var(--muted); font-size: 11px; }
.chat-copy p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.chat-copy .unread-time { color: var(--green); }
.unread-badge { align-self: end; justify-self: end; display: grid; place-items: center; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; color: #fff; background: var(--green); font-size: 11px; }
.encrypted-note { padding: 12px 20px 18px; text-align: center; color: #8696a0; font-size: 11px; }
.encrypted-note .icon { width: 11px; height: 11px; vertical-align: -2px; }
.encrypted-note em { color: var(--green-deep); font-style: normal; }

.conversation { position: relative; display: grid; grid-template-rows: 64px minmax(0,1fr) 62px; min-width: 0; background: #efeae2; overflow: hidden; }
.conversation::before { content: ""; position: absolute; inset: 64px 0 62px; opacity: .42; pointer-events: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='320' height='320' viewBox='0 0 320 320'%3E%3Cg fill='none' stroke='%23c7beb2' stroke-width='1' opacity='.6'%3E%3Cpath d='M28 31l8 8m-4-12v16M88 66c8-10 23 2 14 12-7 7-14 11-14 11s-7-4-14-11c-9-10 6-22 14-12zM196 22l17 6-7 18-17-6zM267 65c10 0 18 8 18 18s-8 18-18 18-18-8-18-18 8-18 18-18zM46 178c14-19 31-19 46 0M49 181h39M142 118l23 23m-23 0l23-23M250 172l20 7-8 21-20-8zM169 249c8-10 23 2 14 12-7 7-14 11-14 11s-7-4-14-11c-9-10 6-22 14-12zM58 267l10 10m-5-15v20M278 279c-8 12-26 12-34 0'/%3E%3C/g%3E%3C/svg%3E"); }
.conversation-header { position: relative; z-index: 2; display: flex; align-items: center; padding: 0 12px 0 16px; background: var(--panel-alt); border-bottom: 1px solid var(--line); }
.mobile-back { display: none; }
.contact-info { display: flex; align-items: center; gap: 12px; min-width: 0; padding: 0; border: 0; background: transparent; text-align: left; cursor: pointer; }
.avatar-contact { width: 40px; height: 40px; font-size: 13px; }
.contact-info > span:last-child { display: grid; min-width: 0; }
.contact-info strong { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 15px; font-weight: 500; }
.contact-info small { margin-top: 2px; color: var(--muted); font-size: 12px; }
.conversation-actions { display: flex; align-items: center; gap: 3px; margin-left: auto; }
.call-button { display: flex; align-items: center; gap: 7px; height: 34px; padding: 0 9px; border: 1px solid var(--line); border-radius: 18px; color: var(--muted); background: transparent; cursor: pointer; }
.call-button:hover { background: rgba(11,20,26,.07); }
.call-button .icon:first-child { width: 19px; }
.call-button .icon:last-child { width: 13px; }
.call-divider { width: 1px; height: 18px; background: var(--line); }
.messages { position: relative; z-index: 1; display: flex; flex-direction: column; gap: 3px; overflow-y: auto; padding: 22px clamp(5%, 8vw, 110px) 18px; scrollbar-width: thin; }
.date-pill, .encryption-pill { align-self: center; max-width: 590px; margin-bottom: 9px; padding: 7px 11px; border-radius: 7px; background: #fff; box-shadow: var(--shadow); color: #54656f; font-size: 11.5px; text-align: center; }
.encryption-pill { color: #5e5a4b; background: #ffeecd; }
.encryption-pill .icon { width: 11px; height: 11px; vertical-align: -2px; }
.message { position: relative; align-self: flex-start; max-width: min(65%, 570px); padding: 7px 58px 7px 9px; border-radius: 8px; background: var(--bubble-in); box-shadow: var(--shadow); font-size: 14px; line-height: 19px; }
.message.out { align-self: flex-end; background: var(--bubble-out); }
.message .meta { position: absolute; right: 7px; bottom: 3px; display: flex; align-items: center; gap: 3px; color: #667781; font-size: 10px; line-height: 12px; }
.message .ticks { color: #53bdeb; font-size: 13px; letter-spacing: -4px; margin-right: 3px; }
.message.tail-in::before, .message.tail-out::before { content: ""; position: absolute; top: 0; width: 0; height: 0; border: 8px solid transparent; }
.message.tail-in::before { left: -8px; border-top-color: var(--bubble-in); }
.message.tail-out::before { right: -8px; border-top-color: var(--bubble-out); }
.attachment-menu { position: absolute; z-index: 10; bottom: 69px; left: 12px; display: grid; width: 210px; padding: 8px; border-radius: 10px; background: var(--panel); box-shadow: 0 3px 18px rgba(11,20,26,.22); }
.attachment-menu button { display: flex; align-items: center; gap: 13px; height: 47px; padding: 0 8px; border: 0; border-radius: 7px; background: transparent; cursor: pointer; }
.attachment-menu button:hover { background: var(--hover); }
.attach-icon { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; color: #fff; }
.attach-icon .icon { width: 18px; }
.attach-icon.document { background: #7f66ff; }.attach-icon.photos { background: #007bfc; }.attach-icon.camera { background: #ff2e74; }.attach-icon.contact { background: #009de2; }.attach-icon.poll { background: #ff8b37; }
.composer { position: relative; z-index: 2; display: grid; grid-template-columns: 42px 42px minmax(0,1fr) 42px; align-items: center; gap: 1px; padding: 9px 13px; background: var(--panel-alt); }
.composer input { height: 42px; padding: 0 14px; border: 0; border-radius: 9px; outline: 0; color: var(--text); background: var(--panel); }
.composer .icon-button { color: var(--muted); }

.details-panel { display: grid; grid-template-rows: 64px auto auto auto 1fr; position: relative; z-index: 5; min-width: 330px; background: var(--panel-alt); border-left: 1px solid var(--line); overflow-y: auto; }
.details-panel > header { display: flex; align-items: center; gap: 18px; padding: 0 12px; background: var(--panel); font-size: 15px; }
.details-profile { padding: 28px 20px 25px; text-align: center; background: var(--panel); border-top: 1px solid var(--line); }
.avatar-large { width: 150px; height: 150px; margin: 0 auto; font-size: 38px; }
.details-profile h2 { margin: 18px 0 5px; font-size: 21px; font-weight: 400; }
.details-profile p { margin: 0; color: var(--muted); }
.details-card { margin-top: 10px; padding: 15px 28px; background: var(--panel); box-shadow: 0 1px 2px rgba(11,20,26,.08); }
.details-card small { color: var(--muted); }.details-card p { margin: 12px 0 2px; font-size: 14px; }
.media-preview > div { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; }
.media-preview strong { display: flex; align-items: center; font-weight: 400; }.media-preview strong .icon { width: 16px; }
.media-preview section { display: grid; grid-template-columns: repeat(3,1fr); gap: 4px; margin-top: 14px; }.media-preview i { aspect-ratio: 1; border-radius: 4px; background: linear-gradient(135deg,#6aa69a,#d5bd7c); }
.media-preview i:nth-child(2) { background: linear-gradient(135deg,#526f91,#ddb27d); }.media-preview i:nth-child(3) { background: linear-gradient(135deg,#c8807c,#664d78); }
.detail-actions { display: grid; padding: 8px 0; }.detail-actions button { display: flex; align-items: center; gap: 22px; min-height: 48px; padding: 0 28px; border: 0; background: transparent; cursor: pointer; text-align: left; }.detail-actions button:hover { background: var(--hover); }.detail-actions .danger { color: #ea0038; }
.toast { position: fixed; z-index: 99; left: 50%; bottom: 82px; translate: -50% 20px; padding: 10px 16px; border-radius: 7px; color: #fff; background: #111b21; opacity: 0; pointer-events: none; transition: .2s ease; font-size: 13px; }.toast.show { translate: -50% 0; opacity: 1; }

body.dark { --bg:#111b21; --panel:#111b21; --panel-alt:#202c33; --line:#2a3942; --text:#e9edef; --muted:#8696a0; --bubble-out:#005c4b; --bubble-in:#202c33; --hover:#202c33; --selected:#2a3942; --shadow:0 1px 2px rgba(0,0,0,.34); }
body.dark .rail-button.active { background:#005c4b; color:#e9edef; }.dark .filter.active { background:#0a332c; border-color:#0a332c; color:#00a884; }.dark .conversation { background:#0b141a; }.dark .conversation::before { opacity:.14; }.dark .date-pill { background:#182229; }.dark .encryption-pill { color:#ffd279; background:#182229; }.dark .encrypted-note em { color:#00a884; }

@media (max-width: 1050px) {
  .app-shell { grid-template-columns: 56px 340px minmax(400px,1fr); }
  .messages { padding-left: 5%; padding-right: 5%; }
}
@media (max-width: 720px) {
  .app-shell { display: block; width: 100%; }
  .rail { display: none; }
  .sidebar, .conversation { width: 100%; height: 100dvh; border: 0; }
  .sidebar { grid-template-rows: 54px 44px 95px 43.5px minmax(0,1fr) 83px; background: #fff; }
  .ios-status { grid-row: 1; }
  .sidebar-header { grid-row: 2; }
  .filter-row { grid-row: 3; }
  .archive-row { grid-row: 4; }
  .chat-list { grid-row: 5; }
  .mobile-tabs { grid-row: 6; }
  .ios-status { display: flex; align-items: center; justify-content: space-between; padding: 16px 31px 11px 41px; color: #050505; font-size: 17px; letter-spacing: -.6px; }
  .ios-status span { font-size: 9px; font-weight: 700; }
  .sidebar-header { padding: 0 13px 0 14px; }
  .sidebar-header h1 { position: absolute; top: 51px; left: 16px; z-index: 2; font-size: 33px; font-weight: 700; letter-spacing: -1.33px; }
  .sidebar-header .header-actions { margin-left: auto; }
  .sidebar-header .header-actions > .icon-button:last-child { display: none; }
  .mobile-menu { display: none; }
  .mobile-camera { display: grid; }
  #newChat { color: #fff; background: #24d366; width: 28px; height: 28px; }
  #newChat .icon, .mobile-camera .icon { width: 16px; height: 16px; }
  .search-wrap { display: none; }
  .search-wrap input { height: 33px; border-radius: 9px; padding-left: 29px; background: #f3f3f5; font-size: 12px; }
  .search-wrap > .icon { left: 8px; top: 8px; width: 15px; }
  .filter-row { align-items: end; gap: 8px; padding: 0 16px 8px; }
  .filter { height: 34px; padding: 0 14px; border: 0; background: #f4f4f4; font-size: 14px; font-weight: 600; }
  .filter.active { color: #15603e; background: #d0fecf; }
  .archive-row { height: 43.5px; grid-template-columns: 72px 1fr auto; padding: 0 15px 0 0; }
  .archive-row strong { font-size: 16px; font-weight: 600; }.archive-row .icon { width: 18px; color: #767779; }
  .chat-row { grid-template-columns: 84px minmax(0,1fr); min-height: 77.33px; }
  .chat-avatar { width: 56px; height: 56px; font-size: 13px; }
  .chat-copy { padding: 10px 15px 10px 0; }
  .chat-copy strong { font-size: 16px; font-weight: 600; letter-spacing: -.32px; }.chat-copy p { margin-top: 1.5px; font-size: 14px; line-height: 19px; }.chat-copy time { font-size: 14px; line-height: 19px; }
  .unread-badge { min-width: 17px; height: 17px; font-size: 9px; }
  .mobile-tabs { display: grid; grid-template-columns: repeat(5,1fr); align-items: start; padding: 4px 23px 0; border-top: .33px solid rgba(0,0,0,.3); background: rgba(244,244,244,.88); backdrop-filter: blur(25px); }
  .mobile-tabs button { position: relative; display: grid; justify-items: center; gap: 0; padding: 0; border: 0; color: #767779; background: transparent; }
  .mobile-tabs .icon { width: 32px; height: 32px; }.mobile-tabs small { font-size: 10px; }.mobile-tabs button.active { color: #0a0a0a; font-weight: 600; }
  .tab-badge { position: absolute; top: -2px; left: calc(50% + 7px); display: grid; place-items: center; min-width: 14px; height: 14px; padding: 0 3px; border-radius: 8px; color: #fff; background: #22c55e; font-size: 8px; }
  .conversation { position: fixed; inset: 0; z-index: 20; grid-template-rows: 98px minmax(0,1fr) 77px; transform: translateX(100%); transition: transform .23s ease; }
  .app-shell.chat-open .conversation { transform: translateX(0); }
  .mobile-back { display: grid; margin-left: -9px; }
  .conversation-header { padding: 54px 8px 0; background: rgba(255,255,255,.92); backdrop-filter: blur(22px); }
  .conversation-header::before { content:var(--mobile-clock, ''); position:absolute; left:41px; top:18px; font-size:17px; font-weight:700; letter-spacing:-.6px; }
  .conversation-header::after { content:'▮▮▮  WiFi  100%'; position:absolute; right:31px; top:20px; font-size:9px; font-weight:700; }
  .conversation-actions .icon-button[aria-label="Search in conversation"] { display: none; }
  .call-button { border: 0; padding: 0 5px; }
  .call-divider, .call-button .icon:last-child { display: none; }
  .messages { padding: 12px 16px 14px; }
  .message { max-width: 78%; font-size: 16px; line-height: 21px; }
  .composer { grid-template-columns: 40px minmax(0,1fr) 40px; gap: 4px; padding: 8px; }
  .composer #emojiButton { position: absolute; left: 52px; z-index: 2; }
  .composer input { padding-left: 48px; }
  .encrypted-note { display: none; }
  .details-panel { position: fixed; inset: 0; z-index: 30; min-width: 0; }
}

@media (min-width: 721px) and (min-height: 760px) {
  body::before { content:""; position:fixed; inset:0 0 auto; height:118px; background:#00a884; z-index:-1; }
  .app-shell { height:calc(100dvh - 38px); margin-top:19px; }
}
