/* ===== Relay design system ===== */
:root {
  --bg: #f2f4f1; --surf: #ffffff; --surf2: #fafbf9;
  --ink: #14181a; --ink2: #4d5654; --muted: #8a938f;
  --line: #e2e6e1; --accent: #0f6b4d; --accent2: #e6f1ea;
  --warn: #a85a1c; --warnsoft: #fbeee2; --dang: #a32f2f; --dangsoft: #fbe9e7;
  --thread: #eeeee6; --out: #daf1e0;
  --shadow: 0 1px 2px rgba(20,24,26,.05), 0 8px 24px rgba(20,24,26,.05);
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  --radius: 14px;
  /* legacy aliases so existing markup keeps working */
  --panel: var(--surf); --panel-2: var(--surf2); --text: var(--ink); --text-soft: var(--muted);
  --border: var(--line); --brand: var(--accent); --brand-dark: var(--accent); --teal: var(--surf);
  --danger: var(--dang); --amber: var(--warn); --chat-bg: var(--thread);
  --bubble-out: var(--out); --bubble-in: var(--surf);
}
:root[data-theme="dark"] {
  --bg: #0e1110; --surf: #161a19; --surf2: #1b201e;
  --ink: #e8ece9; --ink2: #b3bdb8; --muted: #7d8884;
  --line: #252b29; --accent: #34c48a; --accent2: #14302a;
  --warn: #d9a06a; --warnsoft: #2b2117; --dang: #e08a80; --dangsoft: #2e1c1a;
  --thread: #121615; --out: #183a2c;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.32);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--ink); font-size: 13.5px; -webkit-font-smoothing: antialiased;
}
/* app-style: hidden scrollbars, scroll still works */
* { scrollbar-width: none; -ms-overflow-style: none; }
::-webkit-scrollbar { width: 0; height: 0; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }
.mono, .stat-value, .thread-last small, .meta { font-family: var(--mono); }

#app { display: grid; grid-template-columns: 224px 1fr; height: 100vh; }

/* Sidebar */
.sidebar { background: var(--surf); color: var(--ink); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 14px 10px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 16px; }
.brand-logo { width: 30px; height: 30px; background: var(--accent); border-radius: 8px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.brand-logo svg { width: 20px; height: 20px; }
.brand-logo svg path { fill: #fff !important; }
.brand-name { font-weight: 700; font-size: 13.5px; letter-spacing: -.01em; }
.brand-sub { font-size: 11px; color: var(--muted); font-family: var(--mono); }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px;
  color: var(--ink2); text-decoration: none; font-weight: 600; font-size: 13px; transition: .12s;
}
.nav a .ico { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; opacity: .85; }
.nav a .lbl { flex: 1; }
.brand-txt { flex: 1; min-width: 0; }
.nav-collapse { margin-left: auto; background: transparent; border: 0; color: var(--muted); cursor: pointer; width: 28px; height: 28px; border-radius: 7px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.nav-collapse:hover { background: var(--surf2); color: var(--ink); }
.nav-collapse svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: transform .15s; }
#app.nav-collapsed { grid-template-columns: 66px 1fr; }
.nav-collapsed .brand-txt, .nav-collapsed .brand-logo, .nav-collapsed .lbl, .nav-collapsed .sender-badge, .nav-collapsed .ek-logo, .nav-collapsed .navbadge { display: none; }
.nav-collapsed .brand { justify-content: center; padding-bottom: 12px; }
.nav-collapsed .nav-collapse { margin: 0; }
.nav-collapsed .nav-collapse svg { transform: rotate(180deg); }
.nav-collapsed .nav a { justify-content: center; }
.nav-collapsed .sidebar-foot { justify-content: center; }
.nav a:hover { background: var(--surf2); color: var(--ink); }
.nav a.active { background: var(--accent2); color: var(--accent); }
.sidebar-foot { display: flex; align-items: center; gap: 8px; padding-top: 10px; border-top: 1px solid var(--line); }
.ek-logo { width: 26px; height: 26px; background: #fff; border-radius: 6px; padding: 2px; object-fit: contain; flex-shrink: 0; box-shadow: var(--shadow); }
.sender-badge { flex: 1; font-size: 12px; color: var(--ink2); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.theme-toggle { background: var(--surf2); border: 1px solid var(--line); color: var(--ink2); width: 32px; height: 32px; border-radius: 8px; cursor: pointer; font-size: 14px; }

/* Main */
.main { overflow: hidden; display: flex; flex-direction: column; }
.view { flex: 1; min-height: 0; overflow-y: auto; padding: 22px 26px; }
.view.no-pad { padding: 0; overflow: hidden; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 18px; gap: 14px; flex-wrap: wrap; }
.page-head h1 { font-size: 21px; margin: 0; font-weight: 700; letter-spacing: -.02em; }
.page-head p { margin: 3px 0 0; color: var(--muted); font-size: 12.5px; }

/* Cards & grid */
.grid { display: grid; gap: 16px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 12px; }
.card { background: var(--surf); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.card h3 { font-size: 14px; font-weight: 700; }
.stat .stat-label { color: var(--muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; font-weight: 700; }
.stat .stat-value { font-size: 25px; font-weight: 700; margin-top: 6px; letter-spacing: -.03em; }
.stat .stat-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.stat.clickable { cursor: pointer; transition: .12s; }
.stat.clickable:hover { border-color: var(--accent); transform: translateY(-1px); }

/* Buttons & inputs */
button, .btn { font-family: inherit; font-size: 13px; }
.btn { display: inline-flex; align-items: center; gap: 6px; background: var(--accent); color: #fff; border: 0; padding: 10px 18px; border-radius: 10px; cursor: pointer; font-weight: 700; transition: .12s; }
.btn:hover { filter: brightness(1.06); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.secondary { background: var(--surf2); color: var(--ink); border: 1px solid var(--line); font-weight: 600; }
.btn.danger { background: var(--dang); }
.btn.small { padding: 6px 11px; font-size: 12px; border-radius: 8px; }
.btn.ghost { background: var(--surf2); color: var(--accent); border: 1px solid var(--line); font-weight: 600; }
input, select, textarea {
  font-family: inherit; font-size: 13px; width: 100%; padding: 9px 11px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--surf2); color: var(--ink); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 72px; }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 7px; }
.hdr-actions { display: flex; gap: 10px; align-items: center; flex-shrink: 0; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 160px; }

/* Table */
.table-wrap { overflow-x: auto; background: var(--surf); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--line); font-size: 12.5px; }
th { background: var(--surf2); color: var(--muted); font-weight: 700; font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; }
tr:last-child td { border-bottom: 0; }
tr:hover td { background: var(--surf2); }

/* Badges / pills */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 700; }
.badge.green { background: var(--accent2); color: var(--accent); }
.badge.amber { background: var(--warnsoft); color: var(--warn); }
.badge.red { background: var(--dangsoft); color: var(--dang); }
.badge.blue { background: var(--accent2); color: var(--accent); }
.badge.gray { background: var(--surf2); color: var(--muted); border: 1px solid var(--line); }

/* Chat */
.chat { display: grid; grid-template-columns: 312px 1fr; grid-template-rows: minmax(0, 1fr); height: 100%; min-height: 0; }
.chat.has-thread { grid-template-columns: 312px minmax(0, 1fr) 288px; }
.chat-panel { min-height: 0; }
.chat:not(.has-thread) .chat-side { display: none; }
.chat-side { border-left: 1px solid var(--line); background: var(--surf); padding: 16px; overflow-y: auto; }
.win-bar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.win-bar.open { background: var(--accent2); }
.win-bar.closed { background: var(--warnsoft); }
.win-label { font-size: 11px; font-weight: 700; letter-spacing: .08em; }
.win-bar.open .win-label { color: var(--accent); }
.win-bar.closed .win-label { color: var(--warn); }
.win-track { flex: 1; height: 6px; border-radius: 6px; background: rgba(0,0,0,.07); overflow: hidden; max-width: 420px; }
.win-track > div { height: 6px; border-radius: 6px; }
.win-clock { font-size: 19px; font-weight: 700; font-family: var(--mono); letter-spacing: -.02em; }
.win-note { font-size: 11.5px; color: var(--ink2); }
:root[data-theme="dark"] .win-track { background: rgba(255,255,255,.1); }
.thread-list { border-right: 1px solid var(--line); background: var(--surf); overflow-y: auto; }
.thread-list .tl-head { padding: 14px 16px; border-bottom: 1px solid var(--line); font-weight: 700; font-size: 16px; letter-spacing: -.015em; display: flex; justify-content: space-between; align-items: center; }
.thread { display: flex; gap: 10px; padding: 10px 12px; margin: 3px 8px; cursor: pointer; border-radius: 10px; align-items: center; }
.thread:hover, .thread.active { background: var(--surf2); }
.avatar { width: 34px; height: 34px; border-radius: 10px; background: var(--accent2); color: var(--accent); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 11.5px; flex-shrink: 0; }
.thread-main { flex: 1; min-width: 0; }
.thread-name { font-weight: 650; font-size: 13px; display: flex; justify-content: space-between; gap: 6px; }
.thread-name small { color: var(--muted); font-weight: 400; }
.thread-last { color: var(--ink2); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.chat-panel { display: flex; flex-direction: column; height: 100%; background: var(--thread); }
.chat-head { padding: 11px 16px; background: var(--surf); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 11px; }
.chat-head .who { flex: 1; min-width: 0; }
.chat-head .who b { display: block; font-size: 13.5px; }
.chat-head .who small { color: var(--muted); font-family: var(--mono); font-size: 11px; }
.chat-body { flex: 1; min-height: 0; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 9px; }
.day-chip { align-self: center; font-size: 10.5px; font-family: var(--mono); color: var(--muted); background: var(--surf); border: 1px solid var(--line); padding: 3px 12px; border-radius: 20px; margin: 4px 0; box-shadow: var(--shadow); }
.bubble { max-width: 64%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); font-size: 13.5px; line-height: 1.45; word-wrap: break-word; }
/* WhatsApp message bodies are newline-significant. Scoped to the text node, not
   .bubble itself, because the bubble markup carries its own indentation. */
.bubble-text { white-space: pre-wrap; }
.bubble .meta { font-size: 10.5px; color: var(--muted); margin-top: 4px; text-align: right; }
.bubble.out { align-self: flex-end; background: var(--out); }
.bubble.in { align-self: flex-start; background: var(--surf); }
.chat-compose { padding: 12px 16px; background: var(--surf); border-top: 1px solid var(--line); }
.window-note { font-size: 12px; padding: 10px 14px; border-radius: 11px; margin-bottom: 9px; border: 1px solid var(--line); font-weight: 600; }
.window-note.open { background: var(--accent2); color: var(--accent); }
.window-note.closed { background: var(--warnsoft); color: var(--warn); }
.compose-row { display: flex; gap: 9px; align-items: flex-end; }
.compose-row textarea { min-height: 46px; max-height: 120px; border-radius: 11px; }
.compose-row .btn { padding: 11px 20px; border-radius: 11px; }
.chat-empty { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--muted); flex-direction: column; gap: 8px; }
.tick { display: inline-flex; align-items: center; color: var(--muted); }
.tick.read { color: #53bdeb; }
.tickico { height: 11px; width: auto; fill: currentColor; }

/* Media in chat bubbles */
.media-img-wrap { margin: 2px 0 4px; border-radius: 8px; overflow: hidden; }
/* contain, not cover: customers send screenshots, and cropping hides the content.
   Letterbox onto a neutral panel; tap still opens the full image in the modal. */
.chat-img { display: block; max-width: 100%; max-height: 300px; border-radius: 8px; cursor: pointer; transition: transform .15s ease, opacity .15s ease; object-fit: contain; background: rgba(0,0,0,.05); }
.chat-img:hover { opacity: .92; transform: scale(1.01); }
.media-vid-wrap { margin: 2px 0 4px; }
.chat-video { max-width: 100%; max-height: 280px; border-radius: 10px; display: block; background: #000; }

/* Video tile: poster frame + our own play affordance. The native WebView chrome
   is only revealed once playback actually starts. */
.vid-card { position: relative; display: inline-block; max-width: 100%; border-radius: 10px; overflow: hidden; background: #000; line-height: 0; }
.vid-play { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 54px; height: 54px; border-radius: 50%; border: none; cursor: pointer;
  background: rgba(255,255,255,.92); box-shadow: 0 2px 10px rgba(0,0,0,.35);
  display: flex; align-items: center; justify-content: center; padding: 0;
  transition: transform .12s ease, background .12s ease; }
.vid-play:hover { transform: translate(-50%, -50%) scale(1.06); background: #fff; }
.vid-play svg { width: 26px; height: 26px; margin-left: 3px; fill: var(--accent); }
.vid-time { position: absolute; right: 8px; bottom: 8px; font-family: var(--mono); font-size: 11px;
  color: #fff; background: rgba(0,0,0,.6); border-radius: 4px; padding: 1px 6px; line-height: 1.5; }
.vid-card.playing .vid-play, .vid-card.playing .vid-time { display: none; }
/* GIFs loop silently — no play affordance, just a badge like WhatsApp shows */
.vid-card.is-gif .vid-play { display: none; }
.vid-card.is-gif .vid-time { font-weight: 700; letter-spacing: .04em; }
.chat-audio-wrap { display: flex; align-items: center; gap: 8px; margin: 4px 0; min-width: 240px; }
.audio-ico { font-size: 16px; }
.chat-audio { flex: 1; height: 36px; outline: none; }
.chat-doc-card { display: flex; align-items: center; gap: 10px; background: rgba(0,0,0,0.04); border: 1px solid var(--line); border-radius: 9px; padding: 8px 12px; margin: 3px 0; text-decoration: none; color: inherit; transition: background .15s ease; }
.chat-doc-card:hover { background: rgba(0,0,0,0.08); }
.doc-ico { font-size: 24px; line-height: 1; }
.doc-info { flex: 1; min-width: 0; }
.doc-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink); }
.doc-dl { font-size: 11px; color: var(--accent); margin-top: 1px; }
.media-sticker-wrap { margin: 2px 0; }
.chat-sticker { max-width: 130px; max-height: 130px; object-fit: contain; }
.chat-location-card { display: flex; align-items: flex-start; gap: 9px; background: rgba(0,0,0,0.04); border: 1px solid var(--line); border-radius: 9px; padding: 9px 12px; margin: 3px 0; }
.loc-ico { font-size: 20px; }
.loc-name { font-weight: 600; font-size: 13px; color: var(--ink); }
.loc-addr { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.loc-link { display: inline-block; font-size: 11.5px; color: var(--accent); margin-top: 4px; text-decoration: none; font-weight: 600; }
.loc-link:hover { text-decoration: underline; }
.chat-reaction { display: flex; align-items: center; gap: 6px; }
.reaction-emoji { font-size: 18px; line-height: 1; }
.chat-unsupported { display: flex; align-items: flex-start; gap: 8px; background: var(--warnsoft); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 12px; margin: 2px 0; color: var(--ink2); }
.sub-muted { font-size: 10.5px; color: var(--muted); margin-top: 2px; font-weight: normal; }
.media-legacy { display: inline-flex; align-items: center; gap: 6px; background: rgba(0,0,0,0.04); border-radius: 6px; padding: 4px 8px; font-size: 12px; font-weight: 500; color: var(--ink2); }
.media-caption { margin-top: 5px; white-space: pre-wrap; }

/* Params / chips */
.param-row { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; }
.param-row input { flex: 1; }
.chip-list { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--surf2); border: 1px solid var(--line); border-radius: 20px; padding: 4px 10px; font-size: 12px; font-weight: 600; display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
.chip.on { background: var(--accent2); color: var(--accent); border-color: var(--accent2); }

/* Recipient token input */
.field-block { display: block; margin-bottom: 14px; }
.field-lbl { display: block; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 7px; }
.recip-box { position: relative; display: flex; flex-wrap: wrap; align-items: center; gap: 7px; min-height: 46px; padding: 8px 10px; border: 1px solid var(--line); background: var(--surf2); border-radius: 12px; cursor: text; }
.recip-box:focus-within { border-color: var(--accent); }
.recip-chips { display: contents; }
.recip-chip { display: inline-flex; align-items: center; gap: 7px; background: var(--surf); border: 1px solid var(--line); border-radius: 20px; padding: 5px 11px; font-size: 13px; font-weight: 700; color: var(--ink); }
.recip-chip.seg { background: var(--accent2); border-color: var(--accent2); color: var(--accent); }
.recip-chip b { cursor: pointer; font-weight: 700; color: var(--muted); font-size: 15px; line-height: 1; }
.recip-chip.seg b { color: var(--accent); }
.recip-chip b:hover { color: var(--dang); }
.recip-input { flex: 1; min-width: 140px; border: 0 !important; background: transparent; padding: 4px 2px; font-size: 14px; box-shadow: none; outline: none; }
.recip-input:focus { border: 0 !important; }
.recip-menu { position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 40; max-height: 230px; overflow-y: auto; background: var(--surf); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 5px; }
.recip-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 11px; border-radius: 8px; cursor: pointer; font-size: 13px; }
.recip-item:hover { background: var(--accent2); }
.recip-empty { padding: 12px; font-size: 12px; text-align: center; }
.recip-summary { font-size: 12px; color: var(--muted); margin-top: 8px; }

/* Pager */
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 16px 0 4px; }
.pager .btn[disabled] { opacity: .45; cursor: default; }

/* Load-older affordance in chat */
.load-older { text-align: center; margin: 6px auto 12px; padding: 6px 14px; font-size: 12px; font-weight: 650; color: var(--accent); background: var(--surf2); border: 1px solid var(--line); border-radius: 20px; cursor: pointer; width: max-content; }
.load-older:hover { background: var(--accent2); }

/* Misc */
.muted { color: var(--muted); }
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty .big { font-size: 40px; margin-bottom: 8px; }
.spinner { width: 20px; height: 20px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.center { display: flex; align-items: center; justify-content: center; padding: 40px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.bar-chart { display: flex; align-items: flex-end; gap: 10px; height: 160px; padding: 10px 0; overflow-x: auto; }
.bar-chart .bar-col { flex: 0 0 auto; width: 40px; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.bar-chart .bar-pair { display: flex; gap: 3px; align-items: flex-end; height: 120px; }
.bar-chart .bar { width: 14px; background: var(--accent); border-radius: 3px 3px 0 0; }
.bar-chart .bar.in { background: var(--accent2); }
.bar-chart .bar-label { font-size: 10px; color: var(--muted); font-family: var(--mono); }

/* Toast & modal */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--surf); padding: 12px 20px; border-radius: 11px; box-shadow: 0 8px 24px rgba(0,0,0,.25); opacity: 0; pointer-events: none; transition: .25s; z-index: 100; font-size: 13px; font-weight: 600; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--dang); color: #fff; }
.toast.success { background: var(--accent); color: #fff; }
.modal-overlay { position: fixed; inset: 0; background: rgba(20,24,26,.5); display: flex; align-items: center; justify-content: center; z-index: 90; padding: 20px; }
.modal-overlay[hidden] { display: none; }
.modal { background: var(--surf); border-radius: var(--radius); padding: 22px; width: 100%; max-width: 520px; max-height: 88vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3); border: 1px solid var(--line); }
.modal h3 { margin: 0 0 14px; font-size: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* Login (two-panel) */
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.login-brand { background: var(--accent); color: #fff; padding: 46px 56px; display: flex; flex-direction: column; }
.login-logo { display: flex; align-items: center; gap: 11px; font-weight: 800; font-size: 15px; }
.login-logo .sq { width: 30px; height: 30px; background: #fff; border-radius: 8px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.login-hero { margin-top: auto; }
.login-hero h1 { font-size: 44px; line-height: 1.05; font-weight: 800; letter-spacing: -.02em; margin: 0 0 18px; }
.login-hero p { font-size: 15px; line-height: 1.55; opacity: .85; max-width: 460px; margin: 0; }
.login-foot { margin-top: auto; padding-top: 40px; font-family: var(--mono); font-size: 12px; opacity: .82; display: flex; align-items: center; gap: 8px; }
.login-foot .dot, .login-note .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; display: inline-block; flex-shrink: 0; }
.login-form-side { display: flex; align-items: center; justify-content: center; padding: 40px; background: var(--surf); }
.login-form { width: 100%; max-width: 380px; }
.login-form h2 { font-size: 28px; font-weight: 800; margin: 0 0 4px; letter-spacing: -.02em; }
.login-form .sub { color: var(--muted); font-size: 13px; margin: 0 0 26px; }
.login-form label { display: block; font-size: 11px; font-weight: 700; letter-spacing: .06em; color: var(--muted); margin: 0 0 7px; }
.pw-field { position: relative; }
.pw-field input { padding-right: 62px; }
.pw-field .pw-show { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); font-size: 12px; font-weight: 600; color: var(--accent); cursor: pointer; }
.login-note { margin-top: 22px; font-size: 12px; color: var(--muted); background: var(--surf2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; display: flex; align-items: center; gap: 8px; }
.login-note .dot { color: var(--accent); }
@media (max-width: 820px) { .login-wrap { grid-template-columns: 1fr; } .login-brand { display: none; } }

.cc-picker { position: relative; }
.cc-list { position: absolute; top: 100%; left: 0; right: 0; z-index: 5; background: var(--surf); border: 1px solid var(--line); border-radius: 10px; margin-top: 4px; max-height: 105px; overflow-y: auto; box-shadow: var(--shadow); }
.cc-item { padding: 9px 12px; cursor: pointer; font-size: 13px; }
.cc-item:hover { background: var(--surf2); }
.sendtabs { display: flex; gap: 2px; padding: 2px; background: var(--surf2); border: 1px solid var(--line); border-radius: 9px; }
.sendtab { padding: 6px 14px; border-radius: 7px; font-size: 12px; font-weight: 600; color: var(--muted); text-decoration: none; }
.sendtab:hover { text-decoration: none; color: var(--ink); }
.sendtab.on { background: var(--surf); color: var(--ink); box-shadow: var(--shadow); }
.chat-back { display: none; }

/* Tablet: auto-collapse the sidebar and hide the contact rail */
@media (min-width: 821px) and (max-width: 1200px) {
  #app { grid-template-columns: 68px 1fr; }
  .brand-txt, .nav a .lbl, .sender-badge, .ek-logo, .navbadge, .nav-collapse { display: none; }
  .brand { justify-content: center; padding-bottom: 12px; }
  .nav a { justify-content: center; }
  .sidebar-foot { justify-content: center; }
  .chat.has-thread { grid-template-columns: 312px minmax(0, 1fr); }
  .chat-side { display: none; }
}

@media (max-width: 820px) {
  #app { grid-template-columns: 1fr; }
  /* sidebar becomes a fixed, scrollable bottom tab bar */
  .sidebar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 50; flex-direction: row; align-items: stretch;
    height: 62px; padding: 0; border-right: 0; border-top: 1px solid var(--line); box-shadow: 0 -2px 12px rgba(20,24,26,.06); }
  .brand, .sidebar-foot { display: none; }
  .nav { flex-direction: row; gap: 0; height: 100%; align-items: stretch; flex: 1; overflow-x: auto; padding: 0 6px; }
  .nav a { flex: 0 0 auto; flex-direction: column; gap: 3px; padding: 8px 13px; font-size: 9.5px; border-radius: 0; white-space: nowrap; min-width: 62px; justify-content: center; position: relative; }
  .nav a .ico { width: 20px; height: 20px; opacity: .9; }
  .nav a .lbl { flex: none; }
  .nav a.active { background: transparent; color: var(--accent); }
  .nav a.active::after { content: ''; position: absolute; top: 0; left: 14px; right: 14px; height: 2px; background: var(--accent); }
  .nav .navbadge { position: absolute; top: 4px; right: 12px; margin: 0 !important; }
  .view { padding: 16px 16px 80px; overflow-x: hidden; }
  .view.no-pad { padding: 0; overflow: hidden; }
  .page-head h1 { font-size: 19px; }
  /* stack wide two-column grids so nothing overflows */
  [style*="minmax(400px"], [style*="minmax(360px"], [style*="1.5fr) minmax"] { grid-template-columns: 1fr !important; }
  .table-wrap { max-width: 100% !important; }
  table { font-size: 12px; }
  th, td { padding: 9px 10px; }
  /* single-pane chat */
  .chat, .chat.has-thread { grid-template-columns: 1fr; height: calc(100vh - 62px); }
  .chat-side { display: none !important; }
  .win-clock { font-size: 21px; }
  .chat .chat-panel { display: none; }
  .chat.has-thread .thread-list { display: none; }
  .chat.has-thread .chat-panel { display: flex; }
  .chat-body { padding-bottom: 8px; }
  .chat-back { display: inline; font-size: 24px; line-height: 1; color: var(--muted); text-decoration: none; margin-right: 2px; }
  .compose-row .btn { border-radius: 12px; width: auto; min-width: 66px; height: 44px; padding: 0 16px; justify-content: center; }
  .bubble { max-width: 82%; }
  /* segments: stack the two panes vertically */
  .segchat { display: block !important; height: auto !important; }
  .segchat .thread-list { border-right: 0; border-bottom: 1px solid var(--line); }
  .segchat #segDetail { padding: 16px !important; }
}

/* Android app (WebView) only: keep header + bottom tab bar off the phone's status bar
   and gesture bar. Honors the requested 20px/10px minimums, and clears notches/gesture
   bars via safe-area insets when the device reports them. */
@media (max-width: 820px) {
  html.inapp {
    --app-top: max(20px, env(safe-area-inset-top));
    --nav-h: calc(62px + max(10px, env(safe-area-inset-bottom)));
  }
  /* bottom tab bar: grow so icons sit above the gesture bar */
  html.inapp .sidebar { height: 62px; box-sizing: content-box; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  /* top breathing room for every screen's header */
  html.inapp .view:not(.no-pad) { padding-top: var(--app-top); }
  html.inapp .view.no-pad { padding-top: var(--app-top); }
  html.inapp .view { padding-bottom: calc(var(--nav-h) + 18px); }
  /* chat is full-height: fit it between the top pad and the taller nav */
  html.inapp .chat, html.inapp .chat.has-thread { height: calc(100dvh - var(--nav-h) - var(--app-top)); }
}


/* ---- rich inbound message types (contacts, replies, orders, system, raw) ---- */
.chat-contact-card { display: flex; align-items: flex-start; gap: 9px; background: rgba(0,0,0,0.04); border: 1px solid var(--line); border-radius: 9px; padding: 9px 12px; margin: 3px 0; }
.ct-ico { font-size: 17px; line-height: 1; }
.ct-name { font-weight: 600; font-size: 13px; color: var(--ink); }
.ct-num { display: block; font-size: 11.5px; color: var(--accent); text-decoration: none; margin-top: 2px; font-family: var(--mono); }
.ct-num:hover { text-decoration: underline; }

.chat-reply-card { background: var(--accent2); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 8px; padding: 7px 10px; margin: 2px 0; }
.rp-kind { font-size: 10.5px; color: var(--accent); font-weight: 700; letter-spacing: .02em; }
.rp-text { font-size: 13px; color: var(--ink); font-weight: 600; margin-top: 2px; }
.rp-desc { font-size: 11.5px; color: var(--ink2); margin-top: 2px; }
.rp-id { font-size: 10px; color: var(--muted); margin-top: 3px; font-family: var(--mono); word-break: break-all; }
.kv-mini { width: 100%; margin-top: 5px; border-collapse: collapse; font-size: 11.5px; }
.kv-mini td { padding: 2px 4px; border-top: 1px solid var(--line); vertical-align: top; }
.kv-mini td:first-child { color: var(--muted); white-space: nowrap; }

.chat-order-card { background: rgba(0,0,0,0.04); border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; margin: 3px 0; min-width: 210px; }
.od-head { font-size: 12px; font-weight: 700; color: var(--ink); margin-bottom: 5px; }
.od-items { width: 100%; border-collapse: collapse; font-size: 11.5px; color: var(--ink2); }
.od-items td { padding: 3px 2px; border-top: 1px solid var(--line); }
.od-price { text-align: right; white-space: nowrap; color: var(--ink); }
.od-total { display: flex; justify-content: space-between; font-size: 12px; margin-top: 6px; padding-top: 5px; border-top: 1px solid var(--line); color: var(--ink2); }
.od-note { font-size: 11.5px; color: var(--muted); font-style: italic; margin-top: 5px; }

.chat-system { display: inline-flex; align-items: center; gap: 6px; background: rgba(0,0,0,0.04); border-radius: 20px; padding: 4px 11px; font-size: 11.5px; color: var(--ink2); margin: 2px 0; }
.raw-json { font-family: var(--mono); font-size: 10px; color: var(--ink2); background: rgba(0,0,0,.05); border-radius: 5px; padding: 5px 6px; margin: 5px 0 0; max-height: 150px; overflow: auto; white-space: pre-wrap; word-break: break-all; }

/* context that can ride on any bubble */
.quote-strip { display: flex; gap: 6px; align-items: stretch; background: rgba(0,0,0,0.045); border-radius: 6px; padding: 5px 7px; margin-bottom: 4px; }
.q-bar { width: 3px; border-radius: 2px; background: var(--accent); flex-shrink: 0; }
.q-txt { font-size: 11.5px; color: var(--ink2); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.fwd-tag, .ref-tag { font-size: 10.5px; color: var(--muted); margin-bottom: 3px; font-style: italic; }


/* Country selector above the recipient box. Kept outside .recip-box so the chip
   flex layout is untouched; a native <select> also gives the phone's own picker. */
.recip-cc-row { display: flex; align-items: center; gap: 10px; margin-bottom: 7px; }
.recip-cc-row > span { font-size: 11.5px; color: var(--muted); flex: 1; }
.recip-cc { font: inherit; font-size: 12.5px; padding: 5px 8px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surf2); color: var(--ink); max-width: 58%; }
@media (max-width: 560px) {
  .recip-cc-row { flex-direction: column; align-items: stretch; gap: 4px; }
  .recip-cc { max-width: 100%; }
}
