/* ===== Inbox Raite — PWA mobile-first ===== */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
:root {
  --bg: #f4f6f8; --card: #fff; --line: #e3e8ee; --text: #1a1f26; --mut: #57606a; --mut2: #8b949e;
  --carlos: #2563eb; --yisus: #059669; --accent: #f59e0b; --ai: #7c3aed; --red: #ef4444;
  --safe-top: env(safe-area-inset-top, 0px); --safe-bot: env(safe-area-inset-bottom, 0px);
}
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: -apple-system, 'Segoe UI', Roboto, sans-serif;
  overscroll-behavior-y: contain;
}
.hidden { display: none !important; }
.view { position: fixed; inset: 0; display: flex; flex-direction: column; }
button { font: inherit; border: 0; background: none; cursor: pointer; color: inherit; }

/* ===== login ===== */
#view-login { align-items: center; justify-content: center; background: #101521; color: #e6edf3; }
.login-box { text-align: center; width: min(320px, 86vw); }
.login-logo { font-size: 56px; }
.login-box h1 { font-size: 30px; margin: 8px 0 4px; }
.login-box h1 span { color: var(--accent); }
.login-box p { color: #8b949e; margin-bottom: 22px; }
#pin-input {
  width: 100%; padding: 14px; font-size: 24px; text-align: center; letter-spacing: 8px;
  border-radius: 14px; border: 1px solid #2d3644; background: #1a2230; color: #fff; outline: none;
}
#pin-input:focus { border-color: var(--accent); }
.login-box .btn { margin-top: 14px; width: 100%; }
.login-error { color: var(--red); margin-top: 12px; font-weight: 600; }

/* ===== appbar / tabs ===== */
.appbar { background: var(--card); border-bottom: 1px solid var(--line); padding: calc(10px + var(--safe-top)) 14px 0; flex-shrink: 0; }
.appbar-top { display: flex; justify-content: space-between; align-items: center; }
.logo { font-weight: 800; font-size: 20px; }
.logo span { color: var(--accent); }
.iconbtn { font-size: 22px; padding: 6px 10px; border-radius: 10px; color: var(--mut); text-decoration: none; }
.iconbtn:active { background: var(--bg); }
.tabs { display: flex; gap: 7px; padding: 10px 0; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 7px 14px; border-radius: 17px; font-size: 13px; font-weight: 700;
  background: #eef1f5; color: var(--mut); white-space: nowrap;
}
.tab.active { background: var(--text); color: #fff; }
.tab-carlos.active { background: var(--carlos); }
.tab-yisus.active { background: var(--yisus); }

/* ===== lista ===== */
.list { flex: 1; overflow-y: auto; padding-bottom: var(--safe-bot); }
.empty { text-align: center; color: var(--mut2); padding: 60px 30px; font-size: 15px; line-height: 1.5; }
.convo {
  background: var(--card); padding: 13px 14px; border-bottom: 1px solid #edf0f4;
  display: flex; gap: 11px; align-items: flex-start; width: 100%; text-align: left;
}
.convo:active { background: #f8fafc; }
.convo.unread { background: #fffdf5; }
.avatar {
  width: 46px; height: 46px; border-radius: 50%; flex-shrink: 0; position: relative;
  display: flex; align-items: center; justify-content: center; font-weight: 700; color: #fff; font-size: 16px;
}
.avatar.carlos { background: linear-gradient(135deg, #3b82f6, #1d4ed8); }
.avatar.yisus { background: linear-gradient(135deg, #10b981, #047857); }
.channel {
  position: absolute; bottom: -3px; right: -3px; width: 19px; height: 19px; border-radius: 50%;
  background: #fff; display: flex; align-items: center; justify-content: center; font-size: 11px;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.convo-body { flex: 1; min-width: 0; }
.convo-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.cname { font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ctime { font-size: 11px; color: var(--mut2); font-weight: 600; flex-shrink: 0; }
.ctime.urgent { color: var(--red); }
.brandtag { font-size: 10px; font-weight: 800; letter-spacing: .4px; text-transform: uppercase; margin: 1px 0 3px; }
.brandtag.carlos { color: var(--carlos); }
.brandtag.yisus { color: var(--yisus); }
.cmsg { font-size: 13.5px; color: var(--mut); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.quote-mini { font-size: 11.5px; color: var(--mut2); margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quote-mini b { color: var(--text); }
.convo-right { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; flex-shrink: 0; }
.badge {
  background: var(--red); color: #fff; font-size: 11px; font-weight: 700; min-width: 19px; height: 19px;
  border-radius: 10px; display: flex; align-items: center; justify-content: center; padding: 0 5px;
}
.draft-ready { font-size: 10px; font-weight: 700; color: var(--ai); background: #f3e8ff; padding: 2px 7px; border-radius: 9px; }
.heat { font-size: 13px; }

/* ===== thread ===== */
.thread-head {
  background: var(--card); padding: calc(8px + var(--safe-top)) 10px 8px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 9px; flex-shrink: 0;
}
.thread-head .avatar { width: 38px; height: 38px; font-size: 14px; }
.th-info { flex: 1; min-width: 0; }
.th-name { font-weight: 700; font-size: 15.5px; }
.th-sub { font-size: 11.5px; color: var(--mut2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#back-btn { font-size: 28px; padding: 0 10px; }

.quotecard {
  margin: 10px 12px 4px; border-radius: 14px; padding: 11px 14px; color: #fff; flex-shrink: 0;
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
}
.quotecard.yisus { background: linear-gradient(135deg, #065f46, #059669); }
.qc-top { display: flex; justify-content: space-between; font-size: 11px; opacity: .85; font-weight: 600; }
.qc-route { font-size: 14px; font-weight: 700; margin-top: 4px; }
.qc-bottom { display: flex; justify-content: space-between; margin-top: 5px; font-size: 12.5px; align-items: baseline; }
.qc-price { font-size: 18px; font-weight: 800; }

.msgs { flex: 1; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.bubble { max-width: 82%; padding: 8px 12px; border-radius: 16px; font-size: 14px; line-height: 1.4; word-wrap: break-word; white-space: pre-wrap; }
.bubble.in { background: var(--card); border: 1px solid var(--line); align-self: flex-start; border-bottom-left-radius: 5px; }
.bubble.out { background: #dcfce7; align-self: flex-end; border-bottom-right-radius: 5px; }
.bubble.sys { background: #eef2ff; border: 1px dashed #c7d2fe; align-self: center; font-size: 12.5px; color: #3730a3; max-width: 92%; }
.btime { font-size: 10px; color: var(--mut2); margin-top: 3px; text-align: right; }
.bubble a { color: #1d4ed8; word-break: break-all; }
.msg-img { display: block; max-width: 100%; max-height: 260px; border-radius: 10px; margin: 2px 0; }
.msg-audio { width: 230px; max-width: 100%; margin: 2px 0; display: block; }
.msg-loc {
  display: inline-block; background: #eff6ff; border: 1px solid #bfdbfe; color: #1d4ed8 !important;
  font-weight: 700; font-size: 13px; padding: 7px 12px; border-radius: 12px; text-decoration: none; margin: 2px 0;
  word-break: normal !important;
}

/* ===== draft panel ===== */
.draftpanel {
  background: var(--card); border-top: 2px solid #e9d5ff; padding: 11px 14px calc(14px + var(--safe-bot));
  flex-shrink: 0; box-shadow: 0 -6px 20px rgba(124,58,237,.08); max-height: 55vh; overflow-y: auto;
}
.dp-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 7px; gap: 8px; }
.dp-title { font-size: 12px; font-weight: 800; color: var(--ai); }
.dp-conf { font-size: 10.5px; font-weight: 700; color: var(--yisus); background: #ecfdf5; padding: 2px 8px; border-radius: 9px; white-space: nowrap; }
.dp-strategies { display: flex; gap: 6px; margin-bottom: 8px; overflow-x: auto; scrollbar-width: none; }
.dp-strategies::-webkit-scrollbar { display: none; }
.strat {
  font-size: 11.5px; font-weight: 700; padding: 5px 11px; border-radius: 13px;
  background: #eef1f5; color: var(--mut); white-space: nowrap;
}
.strat.active { background: var(--ai); color: #fff; }
.dp-text {
  background: #faf7ff; border: 1px solid #e9d5ff; border-radius: 12px; padding: 10px 12px;
  font-size: 14px; line-height: 1.45; width: 100%; min-height: 74px; resize: vertical;
  font-family: inherit; color: var(--text); outline: none;
}
.dp-text:focus { border-color: var(--ai); box-shadow: 0 0 0 3px rgba(124,58,237,.12); background: #fff; }
.dp-cat { font-size: 11px; color: var(--mut2); margin-top: 6px; }
.dp-cat b { color: var(--ai); }
.dp-actions { display: flex; gap: 8px; margin-top: 10px; }
.btn { flex: 1; padding: 13px 0; border-radius: 12px; font-size: 14.5px; font-weight: 700; text-align: center; }
.btn:disabled { opacity: .55; }
.btn-primary, .btn.send { background: var(--yisus); color: #fff; box-shadow: 0 3px 10px rgba(5,150,105,.35); }
.btn.send { flex: 1.5; }
.btn.gray { background: #eef1f5; color: var(--text); }
.btn.small { flex: .55; }
.dp-secondary { display: flex; gap: 8px; margin-top: 8px; }
.linkbtn { flex: 1; padding: 9px 0; font-size: 12.5px; font-weight: 600; color: var(--mut); background: none; border-radius: 10px; text-align: center; }
.linkbtn:active { background: var(--bg); }
.dp-generating { display: flex; align-items: center; gap: 9px; color: var(--mut); font-size: 13.5px; padding: 8px 2px; }
.spinner {
  width: 17px; height: 17px; border: 2.5px solid #e9d5ff; border-top-color: var(--ai);
  border-radius: 50%; animation: spin .8s linear infinite; flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== toast ===== */
.toast {
  position: fixed; bottom: calc(24px + var(--safe-bot)); left: 50%; transform: translateX(-50%);
  background: #1a1f26; color: #fff; padding: 11px 20px; border-radius: 13px; font-size: 14px;
  font-weight: 600; z-index: 99; box-shadow: 0 8px 24px rgba(0,0,0,.3); max-width: 86vw; text-align: center;
}
.toast.err { background: var(--red); }

/* ===== pestaña Cotizar ===== */
.qrow {
  background: var(--card); border-bottom: 1px solid var(--line); padding: 12px 14px;
  display: flex; flex-direction: column; gap: 5px;
}
.qrow.carlos { box-shadow: inset 3px 0 0 var(--carlos); }
.qrow.yisus { box-shadow: inset 3px 0 0 var(--yisus); }
.qrow-top { display: flex; align-items: baseline; gap: 8px; }
.qrow-top .ctime { margin-left: auto; }
.qrow-id { font-weight: 800; font-size: 13px; font-family: ui-monospace, monospace; }
.qrow-route { font-size: 14.5px; font-weight: 700; }
.qrow-pax { font-size: 12.5px; color: var(--mut); }
.qrow-actions { display: flex; gap: 8px; margin-top: 6px; align-items: center; }
.qrow-price {
  flex: 1; min-width: 0; padding: 11px 12px; border: 1.5px solid var(--line); border-radius: 12px;
  font-size: 16px; font-weight: 700; background: #fff;
}
.qrow-price:focus { border-color: var(--accent); outline: none; }
.qrow-actions .btn.send { flex: 1.2; padding: 11px 0; }
.qrow-actions .iconbtn { font-size: 19px; }

/* ===== pestaña Ventas ===== */
.salechip {
  font-size: 10px; font-weight: 800; color: #92400e; background: #fef3c7;
  padding: 1px 6px; border-radius: 8px; vertical-align: middle;
}
.salesbar { background: var(--card); border-bottom: 1px solid var(--line); padding: 11px 14px; }
.salesbar-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 13.5px; }
.salesbar .linkbtn { color: var(--ai); font-weight: 700; font-size: 12.5px; }
.salesbar .linkbtn:disabled { color: var(--mut2); }
.insights { margin-top: 8px; }
.insights summary { font-size: 12.5px; font-weight: 700; color: var(--mut); cursor: pointer; }
.insights-md {
  white-space: pre-wrap; font-size: 12px; line-height: 1.5; background: #f8fafc;
  border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-top: 6px;
  max-height: 50vh; overflow-y: auto; font-family: inherit;
}

/* tablet chica / fold a medio abrir: columna centrada */
@media (min-width: 760px) and (max-width: 899px) {
  .view { max-width: 620px; margin: 0 auto; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}

/* Z Fold abierto / desktop: dos paneles (lista fija + conversación) */
@media (min-width: 900px) {
  #view-list { right: auto; width: 400px; border-right: 1px solid var(--line); }
  #view-thread { left: 400px; background: var(--bg); }
  #back-btn { display: none; }
  .convo.selected { background: #eef4ff; box-shadow: inset 3px 0 0 var(--carlos); }
  .convo.selected .cname { color: var(--carlos); }
  .bubble { max-width: 65%; }
  .draftpanel { max-height: 45vh; }
}
