/* Backoffice de Topes: mismo lenguaje que la app (Spectrum 2, acento
   petróleo #1A6688, superficies con borde y sin sombra). */

:root {
  --bg: #f8f8f8;
  --surface: #ffffff;
  --surface-2: #fafafa;
  --border: #e6e6e6;
  --border-strong: #c5c5c5;
  --text: #131313;
  --text-2: #505050;
  --text-3: #717171;
  --accent: #1a6688;
  --accent-pressed: #134f6c;
  --accent-surface: #e8f4f6;
  --on-accent-surface: #0b3446;
  --positive: #12805c;
  --positive-surface: #ebf7f1;
  --notice: #b65300;
  --notice-surface: #fff6e8;
  --negative: #a31219;
  --negative-surface: #fff2f2;
  --brand: linear-gradient(180deg, #0b2638, #17496b);
  --radius: 8px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #0e1b24;
    --surface: #13242f;
    --surface-2: #172b38;
    --border: #233847;
    --border-strong: #35505f;
    --text: #edf3f6;
    --text-2: #b8c7cf;
    --text-3: #8aa0ab;
    --accent: #5aa9cf;
    --accent-pressed: #86cde4;
    --accent-surface: #173a4c;
    --on-accent-surface: #cfeaf4;
    --positive: #5fd3a4;
    --positive-surface: #123528;
    --notice: #f2b866;
    --notice-surface: #3a2a12;
    --negative: #ff8a8f;
    --negative-surface: #3a1719;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 'Source Sans 3', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.mono { font-family: 'Source Code Pro', ui-monospace, SFMono-Regular, Menlo, monospace; font-variant-numeric: tabular-nums; }

/* --- Barra superior -------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  background: var(--brand);
  color: #fff;
}
.topbar img { width: 30px; height: 30px; }
.topbar .title { font-weight: 800; font-size: 18px; letter-spacing: -.2px; }
.topbar .title span { font-weight: 400; opacity: .7; margin-left: 6px; }
.topbar .spacer { flex: 1; }
.topbar .who { opacity: .8; font-size: 14px; }
.topbar button {
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.25);
  color: #fff;
  border-radius: 16px;
  padding: 4px 14px;
  cursor: pointer;
}

/* --- Navegación ------------------------------------------------------------ */
.tabs {
  display: flex;
  gap: 4px;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.tabs a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 12px 14px 10px;
  color: var(--text-2);
  text-decoration: none;
  font-weight: 600;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tabs a:hover { color: var(--text); }
.tabs a[aria-current='page'] { color: var(--accent); border-bottom-color: var(--accent); }
.badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--notice);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

main { max-width: 1280px; margin: 0 auto; padding: 24px; }

/* --- Métricas ------------------------------------------------------------ */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 12px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.kpi .label { color: var(--text-2); font-size: 13px; font-weight: 600; }
.kpi .value { font-size: 28px; font-weight: 800; letter-spacing: -.5px; margin-top: 2px; }
.kpi .sub { color: var(--text-3); font-size: 13px; }
.kpi.accent { border-left: 4px solid var(--accent); }
.kpi.positive .value { color: var(--positive); }
.kpi.notice .value { color: var(--notice); }
.kpi.online .value { color: var(--positive); }

/* Punto de "en línea" (app abierta en los últimos 5 minutos). */
.online-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--positive);
  box-shadow: 0 0 0 3px var(--positive-surface);
  margin-right: 8px;
  vertical-align: 1px;
}
.pill.online { background: var(--positive-surface); color: var(--positive); margin-left: 6px; }
.pill.online .online-dot { box-shadow: none; margin-right: 6px; }

.chart {
  margin-top: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.chart h3 { margin: 0 0 8px; font-size: 14px; color: var(--text-2); }
.chart svg { width: 100%; height: 90px; display: block; }
.chart rect { fill: var(--accent); }
.chart .empty { color: var(--text-3); font-size: 14px; }

/* --- Lista ------------------------------------------------------------------ */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 24px 0 12px;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  border-radius: 16px;
  padding: 4px 12px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
}
.chip[aria-pressed='true'] { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip .n { opacity: .7; font-weight: 400; margin-left: 4px; }
.toolbar .spacer { flex: 1; }
.toolbar input, .toolbar select {
  height: 34px;
  border: 1px solid var(--border-strong);
  border-radius: 17px;
  background: var(--surface);
  padding: 0 14px;
}
.toolbar input { width: 240px; }
.btn {
  height: 34px;
  border-radius: 17px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  padding: 0 16px;
  cursor: pointer;
  font-weight: 600;
}
.btn.secondary { background: var(--surface); color: var(--accent); }

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; min-width: 900px; }
th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-3);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
.person .name { font-weight: 600; }
.person .email { color: var(--text-3); font-size: 13px; }
.muted { color: var(--text-3); }
.empty-row td { text-align: center; color: var(--text-3); padding: 32px; cursor: default; }

.pill {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 10px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.pill.free { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.pill.trial { background: var(--accent-surface); color: var(--on-accent-surface); }
.pill.active { background: var(--positive-surface); color: var(--positive); }
.pill.cancelled, .pill.paused { background: var(--notice-surface); color: var(--notice); }
.pill.billing_issue, .pill.refunded { background: var(--negative-surface); color: var(--negative); }
.pill.expired { background: var(--surface-2); color: var(--text-3); border: 1px solid var(--border); }
.pill.sandbox { background: var(--notice-surface); color: var(--notice); margin-left: 6px; }
.pill.t-abierto { background: var(--notice-surface); color: var(--notice); }
.pill.t-en_proceso { background: var(--accent-surface); color: var(--on-accent-surface); }
.pill.t-resuelto { background: var(--positive-surface); color: var(--positive); }
.pill.unread-pill { background: var(--accent); color: #fff; margin-left: 8px; height: 20px; font-size: 12px; }
.small { font-size: 13px; }
tr.unread .person .name, tr.unread .excerpt { font-weight: 600; }
.excerpt { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; color: var(--text-3); font-size: 14px; }
.pager button { margin-left: 6px; }

/* --- Ficha ------------------------------------------------------------------- */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); }
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(520px, 100%);
  background: var(--bg);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  animation: slide .2s ease-out;
}
@keyframes slide { from { transform: translateX(24px); opacity: 0; } }
.drawer header {
  position: sticky;
  top: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 20px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.drawer header .who { flex: 1; min-width: 0; }
.drawer header h2 { margin: 0; font-size: 20px; overflow-wrap: anywhere; }
.drawer header .email { color: var(--text-2); overflow-wrap: anywhere; }
.drawer .close { border: 0; background: transparent; font-size: 24px; cursor: pointer; color: var(--text-2); line-height: 1; }
.drawer section { padding: 0 20px; }
.drawer h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .1em; color: var(--text-3); margin: 20px 0 8px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
dl { margin: 0; display: grid; grid-template-columns: 150px 1fr; }
dt, dd { margin: 0; padding: 8px 14px; border-bottom: 1px solid var(--border); }
dt { color: var(--text-2); font-size: 14px; }
dd { overflow-wrap: anywhere; }
dl > :nth-last-child(-n+2) { border-bottom: 0; }
.actions { display: flex; gap: 8px; padding: 16px 20px 0; flex-wrap: wrap; }
.actions a { text-decoration: none; display: inline-flex; align-items: center; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 10px 14px; border-bottom: 1px solid var(--border); display: flex; gap: 10px; }
.timeline li:last-child { border-bottom: 0; }
.timeline .dot { width: 8px; height: 8px; border-radius: 4px; background: var(--accent); margin-top: 7px; flex: none; }
.timeline .dot.abierto { background: var(--notice); }
.timeline .dot.resuelto { background: var(--positive); }
.timeline li.link { cursor: pointer; }
.timeline li.link:hover { background: var(--surface-2); }
.timeline .what { font-weight: 600; }
.timeline .when { color: var(--text-3); font-size: 13px; }
.note { color: var(--text-3); font-size: 13px; padding: 16px 20px 32px; }

/* --- Soporte: ticket ------------------------------------------------------------- */
.drawer.wide { width: min(720px, 100%); }
.segmented { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 17px; overflow: hidden; }
.segmented button { border: 0; background: var(--surface); padding: 0 14px; height: 32px; cursor: pointer; font-weight: 600; font-size: 14px; }
.segmented button + button { border-left: 1px solid var(--border-strong); }
.segmented button[aria-pressed='true'] { background: var(--accent); color: #fff; }
pre.mail {
  margin: 0;
  padding: 12px 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 13px;
  line-height: 1.5;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  max-height: 320px;
  overflow-y: auto;
}
.card > pre.mail:first-child { border-top: 0; }
.thread { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.msg { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; max-width: 92%; }
.msg.agent { align-self: flex-end; background: var(--accent-surface); border-color: transparent; color: var(--on-accent-surface); }
.msg .meta { font-size: 12px; color: var(--text-3); font-weight: 600; margin-bottom: 4px; }
.msg.agent .meta { color: inherit; opacity: .75; }
.msg .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.thumb { display: block; width: 120px; height: 120px; border-radius: 6px; overflow: hidden; border: 1px solid var(--border); background: var(--surface-2); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.file {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  max-width: 100%;
}
.file-type { font-size: 11px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); }
.file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reply textarea, .rules-main textarea, .field input {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  padding: 8px 12px;
  resize: vertical;
}
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 10px; }
.row-actions select, .field.inline input { height: 34px; border: 1px solid var(--border-strong); border-radius: 17px; background: var(--surface); padding: 0 12px; }
.error-text { color: var(--negative); font-size: 14px; min-height: 20px; margin-top: 6px; }
.drawer section > .row-actions { justify-content: flex-start; }

/* --- Reglas de lectura -------------------------------------------------------------- */
.rules-layout { display: grid; grid-template-columns: 320px 1fr; gap: 20px; align-items: start; }
.rules-side { display: flex; flex-direction: column; gap: 8px; }
.rules-main { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.pad { padding: 16px; }
.side-head { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; }
.side-head h3, .rules-main h2 { margin: 0; }
.side-head h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .1em; color: var(--text-3); }
.rules-main h2 { font-size: 18px; }
.btn.small { height: 28px; padding: 0 12px; font-size: 13px; }
.btn.wide { width: 100%; margin-top: 12px; }
.items { list-style: none; margin: 0; padding: 0; }
.items li { display: flex; align-items: center; border-bottom: 1px solid var(--border); }
.items li:last-child { border-bottom: 0; }
.items li.empty { padding: 12px 14px; color: var(--text-3); font-size: 14px; }
.items li.selected { background: var(--accent-surface); }
.item-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 8px 14px;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  overflow-wrap: anywhere;
}
.item-main.static { cursor: default; }
.item-main .pill { margin-left: 6px; height: 20px; font-size: 12px; }
.item-tools { display: flex; gap: 2px; padding-right: 8px; }
.icon { border: 1px solid var(--border); background: var(--surface); border-radius: 6px; width: 26px; height: 26px; cursor: pointer; font-size: 10px; color: var(--text-2); }
.icon:disabled { opacity: .35; cursor: default; }
.publish-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.publish-head .label { color: var(--text-2); font-size: 13px; font-weight: 600; }
.publish-head .value { font-size: 26px; font-weight: 800; }
.editor-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.editor-head select { height: 34px; border: 1px solid var(--border-strong); border-radius: 17px; background: var(--surface); padding: 0 12px; max-width: 100%; }
.field { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin: 10px 0 4px; }
.field input, .field textarea { margin-top: 4px; font-weight: 400; color: var(--text); }
.field input { height: 36px; }
.field.inline { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.field.inline input.narrow { width: 90px; margin: 0; }
textarea.code { font-size: 13px; line-height: 1.5; tab-size: 2; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.hint { color: var(--text-3); font-size: 14px; margin: 0 0 4px; }
.checks { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.check { font-size: 14px; padding: 6px 10px; border-radius: 6px; background: var(--surface-2); overflow-wrap: anywhere; }
.check.ok { background: var(--positive-surface); color: var(--positive); }
.check.warn { background: var(--notice-surface); color: var(--notice); }
.check.error { background: var(--negative-surface); color: var(--negative); }
#tester-results { margin-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.verdict { padding: 10px 14px; border-radius: 8px; }
.verdict.ok { background: var(--positive-surface); color: var(--positive); }
.verdict.none { background: var(--surface-2); border: 1px solid var(--border); }
table.compact { min-width: 640px; }
table.compact td { vertical-align: top; padding: 8px 12px; }
table.compact tbody tr { cursor: default; }
tr.winner { background: var(--positive-surface); }
.yes { color: var(--positive); font-weight: 600; }
.no { color: var(--negative); font-weight: 600; }
details summary { cursor: pointer; color: var(--text-2); font-size: 14px; font-weight: 600; margin-bottom: 6px; }
details pre.mail { border: 1px solid var(--border); border-radius: 6px; }

/* --- Login ------------------------------------------------------------------- */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: var(--brand);
  padding: 16px;
}
.login form {
  width: min(380px, 100%);
  background: var(--surface);
  border-radius: 16px;
  padding: 28px;
}
.login img { width: 56px; height: 56px; display: block; margin: 0 auto 8px; }
.login h1 { text-align: center; margin: 0; font-size: 24px; letter-spacing: -.4px; }
.login p { text-align: center; color: var(--text-3); margin: 2px 0 20px; }
.login label { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin: 12px 0 4px; }
.login input {
  width: 100%;
  height: 44px;
  border: 1px solid var(--border-strong);
  border-radius: 22px;
  padding: 0 16px;
  background: var(--surface);
}
.login input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.login .btn { width: 100%; height: 48px; border-radius: 24px; margin-top: 20px; font-size: 16px; }
.login .error { color: var(--negative); text-align: center; margin-top: 12px; min-height: 20px; font-size: 14px; }

@media (max-width: 720px) {
  main { padding: 16px; }
  .topbar { padding: 12px 16px; }
  .toolbar input { width: 100%; }
  dl { grid-template-columns: 120px 1fr; }
  .tabs { padding: 0 8px; }
  .rules-layout, .grid2 { grid-template-columns: 1fr; }
}
