/* v2: top bar + WhatsApp page + Mail page (loaded after app.css) */
:root { --wa-in: #ffffff; --wa-out: #d9fdd3; --wa-bg: #efeae2; --wa-accent: #1baf7a; --tick-read: #2a78d6; --topbar: #0f1b2d; }
:root[data-theme="dark"] { --wa-in: #202c33; --wa-out: #005c4b; --wa-bg: #0b141a; --tick-read: #53bdeb; --topbar: #070b12; }
body { min-height: 100vh; }
.topbar { position: sticky; top: 0; z-index: 50; display: flex; align-items: center; gap: 14px; padding: 8px 18px;
  background: var(--topbar); color: #fff; flex-wrap: wrap; }
.topbar .brand { display: flex; align-items: center; gap: 10px; color: #fff; padding: 0; }
.topbar .brand:hover { text-decoration: none; }
.topbar .brand .logo { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(135deg, #2a78d6, #1baf7a); box-shadow: none; }
.topbar .brand .logo .icon { stroke: #fff; }
.topbar .brand b { display: block; font-size: 14px; }
.topbar .brand small { display: block; font-size: 10px; color: #8fa2bd; text-transform: uppercase; letter-spacing: .08em; }
.tabs { display: flex; gap: 4px; background: rgba(255,255,255,.06); padding: 4px; border-radius: 12px; }
.tab { display: flex; align-items: center; gap: 7px; padding: 7px 14px; border-radius: 9px; color: #c9d4e3; font-weight: 550; }
.tab:hover { color: #fff; background: rgba(255,255,255,.08); text-decoration: none; }
.tab.on { background: #fff; color: #0f1b2d; }
.tab .count { background: #d03b3b; color: #fff; font-size: 11px; font-weight: 700; border-radius: 999px; padding: 0 7px; line-height: 18px; }
.tab .count.green { background: #0ca30c; }
.tab .count.blue { background: #2a78d6; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.topbar .btn.ghost { color: #c9d4e3; border-color: #2a3b55; }
.clock-form { display: flex; align-items: center; gap: 6px; color: #8fa2bd; margin: 0; }
.clock-form input { background: #0b1422; color: #fff; border: 1px solid #2a3b55; padding: 4px 8px; color-scheme: dark; font-size: 12.5px; }
.clock-form .btn { padding: 4px 10px; }
.user-pill { display: flex; align-items: center; gap: 7px; font-size: 13px; color: #c9d4e3; }
.user-pill .avatar { width: 26px; height: 26px; font-size: 12px; }
.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; }
.menu summary::-webkit-details-marker { display: none; }
.menu-pop { position: absolute; right: 0; top: 38px; background: var(--surface); color: var(--ink); border: 1px solid var(--ring);
  border-radius: 12px; box-shadow: var(--shadow); padding: 6px; min-width: 190px; display: flex; flex-direction: column; z-index: 60; }
.menu-pop a, .menu-pop button { padding: 8px 10px; border-radius: 8px; color: var(--ink); display: flex; gap: 8px; align-items: center;
  background: none; border: 0; font: inherit; cursor: pointer; text-align: left; }
.menu-pop a:hover, .menu-pop button:hover { background: var(--surface-2); text-decoration: none; }
.pw-warning { background: var(--warning-soft); color: var(--warning-ink); padding: 6px 18px; font-size: 12.5px; display: flex; gap: 6px; align-items: center; }
.pw-warning code { font-weight: 700; }
.main { max-width: 1500px; margin: 0 auto; }
.main.full { padding: 0; max-width: none; }
.main.full .flash { margin: 10px 14px 0; }
.tiny { font-size: 11.5px; }
.ok-text { color: var(--good-ink); }
.btn.sm, .sm.btn { font-size: 12px !important; padding: 4px 9px !important; }
.topbar .btn.ghost { background: transparent; }
.topbar .btn.ghost .icon { stroke: #c9d4e3; }
@media (min-width: 1201px) { body.has-warning .wa, body.has-warning .mailx { height: calc(100vh - 84px); } }
.btn.round { border-radius: 50%; width: 42px; height: 42px; padding: 0; justify-content: center; flex: none; }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; flex: none;
  background: linear-gradient(135deg, #6250d6, #2a78d6); }
.avatar.team { background: linear-gradient(135deg, #1baf7a, #0c7a52); }
.avatar.lg { width: 42px; height: 42px; }
.enq-chip { display: inline-flex; align-items: center; background: var(--accent-soft); color: var(--accent-ink); border-radius: 6px;
  padding: 1px 7px; font-size: 12px; font-weight: 650; white-space: nowrap; }
:root[data-theme="dark"] .enq-chip { color: #cde2fb; }
.enq-chip.sm { font-size: 11px; padding: 0 6px; }
.tag { display: inline-flex; font-size: 11px; font-weight: 650; padding: 1px 7px; border-radius: 6px; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.tag.ok { background: var(--good-soft); color: var(--good-ink); }
.tag.bad { background: var(--critical-soft); color: var(--critical-ink); }
.tag.warn { background: var(--warning-soft); color: var(--warning-ink); }
.tag.t-rfq { color: var(--s1); }
.tag.t-airline-quote { color: #6250d6; }
.tag.t-offer { color: var(--s2); }
.tag.t-customer-reply { color: var(--s3); }

/* ---------------------------------------------------------------- WhatsApp */
.wa { display: grid; grid-template-columns: 340px minmax(0, 1fr) 360px; height: calc(100vh - 52px); }
.wa-list, .wa-ai { background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.wa-ai { border-right: 0; border-left: 1px solid var(--line); overflow-y: auto; display: block; }
.wa-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 14px; background: var(--surface-2); position: relative; }
.wa-search { padding: 8px 12px 4px; }
.wa-search input { width: 100%; border-radius: 10px; background: var(--surface-2); border: 0; padding: 8px 12px; }
.wa-filters { display: flex; gap: 6px; flex-wrap: wrap; padding: 6px 12px 8px; border-bottom: 1px solid var(--line); }
.chip-f { font-size: 12.5px; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); }
.chip-f.on { background: color-mix(in srgb, var(--wa-accent) 22%, transparent); color: var(--good-ink); font-weight: 650; }
.chip-f:hover { text-decoration: none; }
.wa-rows { overflow-y: auto; flex: 1; }
.wa-sep { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 10px 14px 4px; }
.wa-row { display: flex; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); color: var(--ink); }
.wa-row:hover { background: var(--surface-2); text-decoration: none; }
.wa-row.on { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--wa-accent); }
.wa-row-main { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.wa-row-top { display: flex; justify-content: space-between; gap: 6px; }
.wa-row-top b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wa-row-prev { font-size: 13px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wa-row.unread .wa-row-prev { color: var(--ink); font-weight: 600; }
.wa-row-tags { display: flex; gap: 5px; align-items: center; flex-wrap: wrap; }
.unread-dot { margin-left: auto; background: var(--wa-accent); color: #fff; font-size: 11px; font-weight: 700; border-radius: 999px; padding: 0 7px; line-height: 18px; }
.wa-chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; background-color: var(--wa-bg);
  background-image: radial-gradient(rgba(0,0,0,.035) 1px, transparent 1px); background-size: 18px 18px; }
.wa-chathead { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--surface-2); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.chips-row { display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto; }
.wa-msgs { flex: 1; overflow-y: auto; padding: 16px 6%; display: flex; flex-direction: column; gap: 4px; }
.day-sep { text-align: center; margin: 10px 0; }
.day-sep span { background: var(--surface); color: var(--ink-2); font-size: 12px; padding: 4px 12px; border-radius: 8px; box-shadow: 0 1px 1px rgba(0,0,0,.08); }
.bubble-row { display: flex; }
.bubble-row.out { justify-content: flex-end; }
.bubble { max-width: min(620px, 78%); padding: 6px 9px 4px; border-radius: 9px; box-shadow: 0 1px 1px rgba(0,0,0,.1); font-size: 14px; position: relative; }
.bubble.in { background: var(--wa-in); border-top-left-radius: 2px; }
.bubble.out { background: var(--wa-out); border-top-right-radius: 2px; }
.bubble.k-card { border-left: 3px solid var(--wa-accent); }
.bubble.k-card .btext { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }
.bubble-row:target .bubble { outline: 3px solid var(--warning); }
.btext { white-space: pre-wrap; word-break: break-word; }
.fwd-label { font-size: 11.5px; font-style: italic; color: var(--muted); margin-bottom: 2px; }
.bmeta { display: flex; justify-content: flex-end; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); margin-top: 2px; }
.tick { letter-spacing: -3px; font-weight: 700; padding-right: 3px; }
.tick.read { color: var(--tick-read); }
.wa-compose { display: flex; gap: 8px; align-items: flex-end; padding: 10px 14px; background: var(--surface-2); flex-wrap: wrap; }
.wa-compose textarea { flex: 1; resize: none; border-radius: 10px; padding: 10px 12px; max-height: 160px; min-width: 0; }
.wa-compose .tiny { flex-basis: 100%; }
.wa-empty { margin: auto; text-align: center; padding: 30px; }
.wa-empty h2 { font-size: 22px; margin: 10px 0 6px; }
.logo.big { width: 70px; height: 70px; border-radius: 20px; display: grid; place-items: center; margin: 0 auto;
  background: linear-gradient(135deg, #2a78d6, #1baf7a); }
.logo.big .icon { width: 34px; height: 34px; stroke: #fff; }
details.sim, details.fwd { position: relative; }
details.sim > summary, details.fwd > summary { list-style: none; cursor: pointer; }
details.sim > summary::-webkit-details-marker, details.fwd > summary::-webkit-details-marker { display: none; }
.sim-form, .pop { position: absolute; z-index: 40; right: 0; top: 40px; width: 320px; background: var(--surface); border: 1px solid var(--ring);
  border-radius: 12px; box-shadow: var(--shadow); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.wa-head .sim-form { right: auto; left: 0; }
.mx-folders .sim-form { left: 0; right: auto; top: auto; bottom: 46px; width: 300px; }
.ai-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; background: var(--surface-2); position: sticky; top: 0; z-index: 2; }
.switch-form { margin: 0 0 0 auto; }
.switch { border: 0; border-radius: 999px; padding: 4px 12px; font-weight: 700; font-size: 12px; font-family: inherit; cursor: pointer;
  background: var(--critical-soft); color: var(--critical-ink); }
.switch.on { background: var(--good-soft); color: var(--good-ink); }
.ai-msg { margin: 10px 14px 0; padding: 9px 11px; border-radius: 10px; font-size: 13px; background: var(--good-soft); color: var(--good-ink); }
.compose .ai-msg { margin: 0; }
.ai-msg.bad { background: var(--critical-soft); color: var(--critical-ink); }
.ai-sec { padding: 10px 14px; border-bottom: 1px solid var(--line); }
.ai-sec h3 { font-size: 13.5px; margin-bottom: 8px; display: flex; gap: 6px; align-items: center; }
.ai-form { display: flex; flex-direction: column; gap: 6px; }
.ai-form textarea { resize: vertical; font-size: 13px; }
.ai-form .btn { align-self: flex-start; }
.rule { border: 1px solid var(--ring); border-radius: 10px; padding: 8px 10px; margin-bottom: 8px; background: var(--surface); }
.rule.active { border-left: 3px solid var(--good); }
.rule.broken { border-left: 3px solid var(--critical); }
.rule-top { display: flex; gap: 6px; align-items: center; }
.rule-acts { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 6px; }
.rule-acts form { margin: 0; display: inline-flex; gap: 6px; align-items: center; }
.rule-acts details > summary { list-style: none; cursor: pointer; }
.preview { background: color-mix(in srgb, var(--warning) 12%, transparent); }
.prev-item { margin: 6px 0; padding: 6px 8px; border-radius: 8px; background: var(--surface); }
.missed { padding: 8px 0; border-top: 1px dashed var(--line); }
.missed:first-of-type { border-top: 0; }
.missed select { font-size: 12px; padding: 3px 6px; }
.log { padding: 6px 0; border-top: 1px dashed var(--line); }
.log.blocked { background: color-mix(in srgb, var(--critical) 7%, transparent); }
.logpre { white-space: pre-wrap; font-size: 11px; margin: 4px 0; background: var(--surface-2); padding: 6px; border-radius: 6px; }

/* ---------------------------------------------------------------- Mail */
.mailx { display: grid; grid-template-columns: 230px 380px minmax(0, 1fr); height: calc(100vh - 52px); }
.mx-folders { background: var(--surface-2); padding: 12px; display: flex; flex-direction: column; gap: 10px; overflow-y: auto; position: relative; }
.mb-select select { width: 100%; }
.folders { display: flex; flex-direction: column; gap: 1px; }
.folders a { display: flex; gap: 8px; align-items: center; padding: 7px 10px; border-radius: 8px; color: var(--ink); font-size: 13.5px; }
.folders a:hover { background: var(--surface); text-decoration: none; }
.folders a.on { background: var(--surface); font-weight: 650; box-shadow: inset 3px 0 0 var(--accent); }
.folders .cnt { margin-left: auto; font-size: 12px; font-weight: 700; color: var(--accent); }
.fsep { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 10px 10px 2px; }
.mx-list { border-right: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; min-height: 0; overflow-y: auto; }
.mx-search { display: flex; gap: 6px; flex-wrap: wrap; padding: 10px; border-bottom: 1px solid var(--line); }
.mx-search input[name=q] { flex: 1 1 100%; }
.mx-search select, .mx-search input { font-size: 12.5px; padding: 5px 8px; }
.mx-row { display: flex; flex-direction: column; gap: 2px; padding: 10px 14px; border-bottom: 1px solid var(--line); color: var(--ink); }
.mx-row:hover { background: var(--surface-2); text-decoration: none; }
.mx-row.on { background: color-mix(in srgb, var(--accent) 10%, transparent); box-shadow: inset 3px 0 0 var(--accent); }
.mx-row.unread b, .mx-row.unread .mx-subj { font-weight: 750; }
.mx-row.unread { box-shadow: inset 3px 0 0 var(--accent); }
.mx-top { display: flex; justify-content: space-between; gap: 6px; }
.mx-top b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.mx-subj { font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mx-prev { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mx-read { overflow-y: auto; padding: 18px 24px; background: var(--page); display: flex; flex-direction: column; gap: 12px; }
.mx-thread-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.mx-thread-head h2 { font-size: 19px; flex: 1; min-width: 200px; }
.ai-summary { background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 12%, transparent), transparent); border-radius: 10px; padding: 10px 12px; font-size: 13.5px; }
.mx-mail { background: var(--surface); border: 1px solid var(--ring); border-radius: 12px; padding: 14px 16px; }
.mx-mail:target { outline: 3px solid var(--warning); }
.mx-mail-head { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 10px; }
.mx-body { font-size: 14px; line-height: 1.55; }
mark { background: #fff1a8; color: #0b0b0b; border-radius: 3px; padding: 0 2px; }
.compose { display: flex; flex-direction: column; gap: 8px; max-width: 820px; }
.compose label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--ink-2); }
.compose input, .compose select, .compose textarea { font-size: 14px; }

@media (max-width: 1200px) {
  .wa { grid-template-columns: 300px minmax(0, 1fr); height: auto; }
  .wa-ai { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); }
  .wa-list, .wa-chat { height: 75vh; }
  .mailx { grid-template-columns: 210px 320px minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .wa, .mailx { grid-template-columns: minmax(0, 1fr); height: auto; }
  .wa-list { height: 50vh; } .wa-chat { height: 75vh; }
  .mx-list { max-height: 55vh; }
  .topbar { gap: 8px; } .tab { padding: 6px 9px; } .clock-form input { width: 150px; }
}
