/* =====================================================================
   Magalbyte Inbox — estilos
   Identidad: azul Magalbyte (#0047AB), tinta #131C2E, acento dorado.
   Fondo blanco, neutros, bordes suaves. Sin fuentes externas (CSP).
   ===================================================================== */
:root {
  --brand: #0047AB;
  --brand-600: #003d94;
  --brand-50: #f2f6fd;
  --brand-100: #e5edfa;
  --gold: #D9A400;
  --ink: #131c2e;
  --ink-2: #3d4a63;
  --muted: #6b7890;
  --line: #e6e9f0;
  --line-2: #eef1f6;
  --bg: #ffffff;
  --bg-soft: #f7f8fb;
  --green: #1f7a4c; --green-bg: #e7f5ee;
  --amber: #a86b0c; --amber-bg: #fdf3e1;
  --red: #b3403a;   --red-bg: #fcecea;
  --violet: #5b4bb7; --violet-bg: #efedfb;
  --gray-bg: #eef0f5;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(19, 28, 46, .06), 0 6px 20px rgba(19, 28, 46, .06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 14px/1.45 var(--font); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
svg.ic { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Botones y formularios ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: #fff; cursor: pointer; font-weight: 500; white-space: nowrap; transition: background .12s, border-color .12s; }
.btn:hover { background: var(--bg-soft); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-600); }
.btn.danger { color: var(--red); border-color: #f0cfcc; }
.btn.danger:hover { background: var(--red-bg); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--line-2); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn.icon { width: 34px; padding: 0; }
.btn.icon.sm { width: 28px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > label { font-size: 12px; font-weight: 600; color: var(--ink-2); }
.input, select.input, textarea.input { width: 100%; height: 36px; padding: 0 11px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff; outline: none; }
textarea.input { height: auto; min-height: 80px; padding: 9px 11px; resize: vertical; }
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-100); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.help { font-size: 12px; color: var(--muted); }
.form-error { color: var(--red); font-size: 13px; min-height: 18px; }

/* ---------- Chips / estados ---------- */
.chip { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 500; background: var(--gray-bg); color: var(--ink-2); white-space: nowrap; }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.st-pending { background: var(--amber-bg); color: var(--amber); }
.st-open { background: var(--brand-50); color: var(--brand); }
.st-in_progress { background: var(--violet-bg); color: var(--violet); }
.st-resolved { background: var(--green-bg); color: var(--green); }
.st-closed { background: var(--gray-bg); color: var(--muted); }
.tag { display: inline-flex; align-items: center; gap: 5px; height: 20px; padding: 0 7px; border-radius: 5px; font-size: 11.5px; font-weight: 500; background: var(--line-2); color: var(--ink-2); }
.tag i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }
.badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--brand); color: #fff; font-size: 11px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; }
.sim { background: #fff4d6; color: #7a5a00; border: 1px dashed #e0b84a; }

/* ---------- Avatar ---------- */
.avatar { width: 38px; height: 38px; border-radius: 50%; flex: none; display: grid; place-items: center; font-weight: 600; font-size: 13px; color: #fff; background: var(--brand); overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.sm { width: 30px; height: 30px; font-size: 11px; }
.avatar.lg { width: 56px; height: 56px; font-size: 18px; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: 220px 1fr; height: 100vh; }
.sidebar { border-right: 1px solid var(--line); background: var(--bg-soft); display: flex; flex-direction: column; min-height: 0; }
.brand { display: flex; align-items: center; gap: 10px; padding: 16px 16px 12px; font-weight: 700; letter-spacing: -.01em; }
.brand img { width: 28px; height: 28px; }
.brand small { display: block; font-weight: 500; font-size: 11px; color: var(--muted); letter-spacing: 0; }
.org-switch { margin: 0 12px 10px; }
.org-switch select { height: 32px; font-size: 13px; }
.org-name { margin: 0 16px 10px; font-size: 12.5px; color: var(--ink-2); font-weight: 600; }
.nav { display: flex; flex-direction: column; gap: 2px; padding: 4px 8px; flex: 1; overflow: auto; }
.nav a { display: flex; align-items: center; gap: 10px; height: 36px; padding: 0 10px; border-radius: var(--radius-sm); color: var(--ink-2); font-weight: 500; }
.nav a:hover { background: var(--line-2); text-decoration: none; }
.nav a.active { background: #fff; color: var(--brand); box-shadow: 0 0 0 1px var(--line); }
.nav a .badge { margin-left: auto; }
.nav .sep { height: 1px; background: var(--line); margin: 8px 4px; }
.profile { border-top: 1px solid var(--line); padding: 12px; display: flex; align-items: center; gap: 10px; }
.profile .who { min-width: 0; flex: 1; }
.profile .who b { display: block; font-size: 13px; }
.main { min-width: 0; min-height: 0; overflow: auto; }
.page { padding: 24px 28px; max-width: 1200px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.page-head h1 { font-size: 20px; margin: 0; letter-spacing: -.01em; flex: 1; }

/* ---------- Tarjetas / tablas ---------- */
.card { border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.card-pad { padding: 16px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; background: #fff; }
.kpi .label { font-size: 12px; color: var(--muted); font-weight: 500; }
.kpi .value { font-size: 24px; font-weight: 650; margin-top: 4px; letter-spacing: -.02em; }
.kpi .sub { font-size: 12px; color: var(--muted); }
.section-title { font-size: 13px; font-weight: 650; color: var(--ink-2); margin: 22px 0 10px; text-transform: uppercase; letter-spacing: .04em; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--bg-soft); }
.tbl td { padding: 11px 14px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: var(--bg-soft); }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty svg.ic { width: 32px; height: 32px; stroke-width: 1.4; margin-bottom: 8px; color: #b6bfd0; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar .input { width: auto; }
.search { position: relative; }
.search svg.ic { position: absolute; left: 10px; top: 9px; color: var(--muted); width: 16px; height: 16px; }
.search .input { padding-left: 32px; }

/* ---------- Inbox ---------- */
.inbox { display: grid; grid-template-columns: 340px 1fr; height: 100vh; min-height: 0; }
.inbox.with-details { grid-template-columns: 340px 1fr 300px; }
.conv-col { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.conv-col .head { padding: 14px 14px 10px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.conv-col .head h2 { margin: 0; font-size: 16px; }
.filters { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.filters select { height: 30px; font-size: 12.5px; padding: 0 6px; }
.seg { display: flex; background: var(--line-2); border-radius: 8px; padding: 2px; }
.seg button { flex: 1; border: 0; background: transparent; height: 26px; border-radius: 6px; font-size: 12.5px; cursor: pointer; color: var(--ink-2); }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); font-weight: 600; }
.conv-list { overflow: auto; flex: 1; }
.conv { display: flex; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line-2); cursor: pointer; position: relative; }
.conv:hover { background: var(--bg-soft); }
.conv.active { background: var(--brand-50); }
.conv.active::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--brand); }
.conv .top { display: flex; align-items: baseline; gap: 6px; }
.conv .name { font-weight: 600; flex: 1; min-width: 0; }
.conv.unread .name, .conv.unread .preview { font-weight: 650; color: var(--ink); }
.conv .time { font-size: 11.5px; color: var(--muted); flex: none; }
.conv .preview { color: var(--muted); font-size: 13px; margin-top: 2px; display: flex; gap: 6px; align-items: center; }
.conv .meta { display: flex; gap: 6px; margin-top: 6px; align-items: center; flex-wrap: wrap; }
.conv .assignee { font-size: 11.5px; color: var(--muted); display: inline-flex; align-items: center; gap: 3px; }
.conv .assignee svg.ic { width: 13px; height: 13px; }
.load-more { padding: 12px; text-align: center; }

.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg-soft); }
.chat-head { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: #fff; min-height: 62px; }
.chat-head .who { min-width: 0; flex: 1; }
.chat-head .who b { display: block; }
.chat-actions { display: flex; gap: 6px; align-items: center; }
.messages { flex: 1; overflow: auto; padding: 18px 22px; display: flex; flex-direction: column; gap: 6px; }
.day { align-self: center; font-size: 11.5px; color: var(--muted); background: #fff; border: 1px solid var(--line); padding: 2px 10px; border-radius: 999px; margin: 10px 0 4px; }
.msg { max-width: min(560px, 78%); padding: 8px 11px 6px; border-radius: 12px; background: #fff; border: 1px solid var(--line); align-self: flex-start; white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.out { align-self: flex-end; background: var(--brand-50); border-color: #d3e0f6; }
.msg.out.ext { background: #f3f4f7; border-style: dashed; }
.msg.failed { border-color: #efc2be; background: var(--red-bg); }
.msg .foot { display: flex; gap: 6px; justify-content: flex-end; align-items: center; font-size: 11px; color: var(--muted); margin-top: 3px; white-space: nowrap; }
.msg .who { font-size: 11px; color: var(--muted); font-weight: 600; margin-bottom: 2px; }
.msg .err { font-size: 12px; color: var(--red); margin-top: 4px; white-space: normal; }
.msg .media { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.msg .media img { max-width: 260px; max-height: 260px; border-radius: 8px; display: block; }
.ticks { font-weight: 700; letter-spacing: -2px; }
.ticks.read { color: var(--brand); }
.composer { border-top: 1px solid var(--line); background: #fff; padding: 10px 14px; }
.composer form { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { flex: 1; min-height: 40px; max-height: 160px; resize: none; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; outline: none; }
.composer textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-100); }
.composer .notice { font-size: 12.5px; color: var(--amber); background: var(--amber-bg); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; }
.composer .hint { font-size: 11.5px; color: var(--muted); margin-top: 5px; }
.chat-empty { flex: 1; display: grid; place-items: center; color: var(--muted); text-align: center; }

.details { border-left: 1px solid var(--line); overflow: auto; background: #fff; }
.details .blk { padding: 14px 16px; border-bottom: 1px solid var(--line-2); }
.details h4 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.kv { display: grid; grid-template-columns: 82px 1fr; gap: 6px 10px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.hist { font-size: 12.5px; color: var(--ink-2); display: flex; flex-direction: column; gap: 6px; }
.hist .t { color: var(--muted); font-size: 11.5px; }

/* ---------- Modal / toasts ---------- */
.overlay { position: fixed; inset: 0; background: rgba(19, 28, 46, .35); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 12px; width: min(480px, 100%); max-height: calc(100vh - 32px); overflow: auto; box-shadow: var(--shadow); }
.modal .mh { padding: 16px 18px 6px; display: flex; align-items: center; }
.modal .mh h3 { margin: 0; font-size: 16px; flex: 1; }
.modal .mb { padding: 10px 18px; }
.modal .mf { padding: 12px 18px 16px; display: flex; justify-content: flex-end; gap: 8px; }
.checklist { display: flex; flex-direction: column; gap: 4px; max-height: 300px; overflow: auto; }
.checklist label { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.checklist label:hover { background: var(--bg-soft); }
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); font-size: 13px; max-width: 360px; }
.toast.err { background: var(--red); }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(180deg, var(--brand-50), #fff 60%); padding: 16px; }
.login .card { width: min(380px, 100%); padding: 28px; box-shadow: var(--shadow); }
.login h1 { font-size: 20px; margin: 10px 0 4px; }

/* ---------- Banners ---------- */
.banner { border-radius: var(--radius); padding: 12px 14px; font-size: 13px; display: flex; gap: 10px; align-items: flex-start; margin-bottom: 16px; }
.banner.warn { background: var(--amber-bg); color: #6d4706; }
.banner.info { background: var(--brand-50); color: var(--brand-600); }
.banner.ok { background: var(--green-bg); color: var(--green); }
.banner.err { background: var(--red-bg); color: var(--red); }

/* ---------- Responsive (tablet) ---------- */
@media (max-width: 1280px) {
  .inbox.with-details { grid-template-columns: 300px 1fr; }
  .inbox.with-details .details { position: fixed; right: 0; top: 0; bottom: 0; width: 320px; box-shadow: var(--shadow); z-index: 20; }
}
@media (max-width: 1024px) {
  .shell { grid-template-columns: 64px 1fr; }
  .brand span, .nav a span, .profile .who, .org-switch, .org-name { display: none; }
  .nav a { justify-content: center; padding: 0; }
  .nav a .badge { position: absolute; margin: -18px 0 0 22px; }
  .nav a { position: relative; }
  .inbox, .inbox.with-details { grid-template-columns: 280px 1fr; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .sidebar { order: 2; flex-direction: row; border-right: 0; border-top: 1px solid var(--line); }
  .brand, .profile { display: none; }
  .nav { flex-direction: row; justify-content: space-around; padding: 4px; }
  .inbox, .inbox.with-details { grid-template-columns: 1fr; height: calc(100vh - 56px); }
  .inbox.show-chat .conv-col { display: none; }
  .inbox:not(.show-chat) .chat { display: none; }
  .page { padding: 16px; }
  .grid2 { grid-template-columns: 1fr; }
}
