:root {
  --primary: #0a7cb8;
  --primary-dark: #07608e;
  --primary-soft: #e3f2fa;
  --navy: #3f5688;
  --ink: #2b2f36;
  --muted: #6b7480;
  --line: #e3e8ee;
  --bg: #f2f5f9;
  --card: #fff;
  --ok: #0a6c3a; --ok-bg: #d8f3e4;
  --warn: #7a5b00; --warn-bg: #fff1c2;
  --bad: #b42318; --bad-bg: #fde2e0;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 4px 14px rgba(20, 30, 50, .05);
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, 'Segoe UI', sans-serif; color: var(--ink); background: var(--bg); min-height: 100vh; display: flex; flex-direction: column; }
a { color: var(--primary); }
[hidden] { display: none !important; }
.ico { vertical-align: -3px; flex: none; }
button .ico, .btn .ico, nav a .ico, h1 .ico, h2 .ico { margin-right: 6px; }

/* ---- Encabezado ---- */
header { background: var(--card); border-bottom: 1px solid var(--line); box-shadow: 0 1px 0 rgba(20, 30, 50, .03); position: sticky; top: 0; z-index: 10; }
.header-inner { max-width: 1040px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--ink); }
.brand img { height: 38px; width: auto; display: block; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; padding-left: 14px; position: relative; }
.brand-text::before { content: ''; position: absolute; left: 0; top: 2px; bottom: 2px; width: 3px; border-radius: 3px; background: linear-gradient(180deg, #0098db, #3f5688); }
.brand-text b { font-size: 16px; font-weight: 700; letter-spacing: -.01em; color: var(--navy); }
.brand-text small { font-size: 12px; font-weight: 500; color: var(--muted); letter-spacing: .02em; margin-top: 2px; }
nav { display: flex; gap: 2px; align-items: center; flex-wrap: wrap; }
nav a { color: var(--ink); text-decoration: none; padding: 7px 10px; border-radius: 8px; font-size: 14px; white-space: nowrap; }
nav a:hover { background: var(--bg); }
nav a.active { background: var(--primary-soft); color: var(--primary-dark); font-weight: 600; }
nav button { margin-left: 4px; padding: 6px 10px; font-size: 13px; }
nav[hidden] { display: none; }

main { width: 100%; max-width: 1040px; margin: 24px auto; padding: 0 16px; flex: 1; }
h1 { font-size: 22px; margin: 0 0 12px; color: var(--ink); display: flex; align-items: center; }
h2 { font-size: 16px; margin: 0 0 8px; display: flex; align-items: center; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow); }
.center { text-align: center; }
.muted { color: var(--muted); font-size: 13px; }
.error { color: var(--bad); }
code { background: var(--bg); padding: 1px 6px; border-radius: 4px; font-size: 13px; }

/* ---- Tablas ---- */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 8px; border-bottom: 2px solid var(--line); }
td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); }
tbody tr:hover { background: #f8fafc; }
td .row { margin: 0; }

/* ---- Formularios ---- */
textarea, input[type=text], input[type=password], select { width: 100%; padding: 9px 11px; border: 1px solid #c8d0da; border-radius: 8px; font: inherit; background: #fff; color: var(--ink); }
textarea:focus, input:focus, select:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
textarea { resize: vertical; }
textarea.prompt { min-height: 320px; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
button { display: inline-flex; align-items: center; justify-content: center; padding: 8px 15px; border: 0; border-radius: 8px; background: var(--primary); color: #fff; font: inherit; font-weight: 500; cursor: pointer; transition: background .12s; }
button:hover:not(:disabled) { background: var(--primary-dark); }
button.secondary { background: #e8edf3; color: var(--ink); }
button.secondary:hover:not(:disabled) { background: #dbe2eb; }
button.danger { background: var(--bad); }
button.danger:hover:not(:disabled) { background: #8f1c12; }
button:disabled { opacity: .5; cursor: default; }
.btn { display: inline-flex; align-items: center; padding: 8px 15px; border-radius: 8px; background: #e8edf3; color: var(--ink); text-decoration: none; font-weight: 500; }
.btn:hover { background: #dbe2eb; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.row > input { flex: 1; }
.row > input[type=text] { min-width: 220px; }
label.muted { display: block; margin-top: 8px; }

/* ---- Switch ---- */
.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: #b8c1ca; border-radius: 24px; cursor: pointer; transition: .15s; }
.slider::before { content: ''; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; box-shadow: 0 1px 2px rgba(0, 0, 0, .25); }
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(18px); }
.switch input:focus-visible + .slider { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---- Pestañas ---- */
.tabs { display: flex; gap: 4px; margin-bottom: 12px; flex-wrap: wrap; }
.tabs button { background: #e8edf3; color: var(--ink); }
.tabs button.active { background: var(--primary); color: #fff; }

/* ---- Badges ---- */
.badge { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 12px; font-weight: 500; background: #e8edf3; color: #46505c; }
.badge.opp { background: var(--ok-bg); color: var(--ok); }
.badge.kw { background: var(--warn-bg); color: var(--warn); }
.badge.err { background: var(--bad-bg); color: var(--bad); }

/* ---- Mensajes ---- */
.msg { border-bottom: 1px solid var(--line); padding: 4px 0; }
.msg:last-child { border-bottom: 0; }
.msg.open { background: #fafcfe; }
.msg .line { display: flex; gap: 8px; align-items: center; cursor: pointer; padding: 6px 4px; white-space: nowrap; overflow: hidden; border-radius: 6px; }
.msg .line:hover { background: var(--bg); }
.msg .chev { width: 14px; color: var(--muted); flex: none; display: inline-flex; }
.msg .when { font-size: 12px; color: var(--muted); flex: none; }
.msg .who { font-weight: 600; flex: none; max-width: 240px; overflow: hidden; text-overflow: ellipsis; }
.msg .snippet { color: #52606d; overflow: hidden; text-overflow: ellipsis; min-width: 0; display: inline-flex; align-items: center; gap: 4px; }
.msg .badge { flex: none; }
.msg .detail { padding: 6px 4px 10px 22px; }
.msg .meta { font-size: 12px; color: var(--muted); }
.msg .text { white-space: pre-wrap; margin: 6px 0; padding: 10px 12px; background: var(--bg); border-left: 3px solid var(--primary); border-radius: 0 8px 8px 0; }
.data { font-size: 13px; background: var(--primary-soft); border-radius: 8px; padding: 8px 12px; display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 2px 12px; margin: 6px 0; }
.replybox { margin-top: 8px; }

/* ---- Varios ---- */
.avatar { width: 52px; height: 52px; border-radius: 50%; object-fit: cover; background: #dde3e8; flex: none; }
.avatar.ph { background: linear-gradient(135deg, var(--navy), var(--primary)); }
.stats { display: flex; gap: 12px; flex-wrap: wrap; }
.stats div { flex: 1; min-width: 160px; background: var(--bg); border-radius: 10px; padding: 12px 14px; display: grid; grid-template-columns: auto 1fr; column-gap: 12px; align-items: center; }
.stats .ico-box { grid-row: span 2; width: 38px; height: 38px; border-radius: 10px; background: var(--primary-soft); color: var(--primary-dark); display: flex; align-items: center; justify-content: center; }
.stats .ico-box .ico { margin: 0; }
.stats b { font-size: 22px; line-height: 1.1; }
.stats span { font-size: 12px; color: var(--muted); }
.pick { max-height: 260px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; margin-top: 8px; }
.pick label { display: block; padding: 7px 10px; border-bottom: 1px solid #f0f2f4; cursor: pointer; }
.pick label:hover { background: var(--bg); }
.pick[hidden], .pick label[hidden] { display: none; }
.form { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0 12px; align-items: end; }
.form label { display: block; margin: 8px 0 2px; font-size: 13px; color: var(--muted); }
.form button { margin-top: 8px; }

/* ---- Login ---- */
.login { max-width: 400px; margin: 40px auto; padding: 28px; }
.login .logo { display: block; width: 240px; max-width: 100%; margin: 0 auto 18px; }
.login h1 { justify-content: center; }
.login label { display: block; margin: 10px 0 3px; font-size: 13px; color: var(--muted); }
.login button { width: 100%; padding: 10px; }

/* ---- Pie ---- */
footer { border-top: 1px solid var(--line); background: var(--card); color: var(--muted); font-size: 13px; }
.footer-inner { max-width: 1040px; margin: 0 auto; padding: 14px 16px; display: flex; justify-content: space-between; gap: 8px 16px; flex-wrap: wrap; }
footer a { color: var(--muted); }

/* ---- Documento (politica de privacidad) ---- */
.doc { max-width: 780px; margin-left: auto; margin-right: auto; }
.doc h1 { font-size: 26px; }
.doc h2 { font-size: 18px; margin-top: 26px; color: var(--navy); }
.doc p, .doc li { line-height: 1.65; }
.doc ul { padding-left: 22px; }

@media (max-width: 640px) {
  .brand-text { display: none; }
  .msg .who { max-width: 110px; }
  .msg .when { display: none; }
}

.back { display: inline-flex; align-items: center; gap: 2px; padding: 6px 14px 6px 10px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); color: var(--primary-dark); text-decoration: none; font-weight: 500; font-size: 14px; box-shadow: var(--shadow); transition: background .12s, transform .12s; }
.back .ico { margin-right: 2px; transition: transform .12s; }
.back:hover { background: var(--primary-soft); }
.back:hover .ico { transform: translateX(-3px); }
