/* xCorrosion OS — tema claro.
   Panel para una asociación técnica: sobrio, legible, sin efectismos. */

:root {
  --bg:          #F6F7F9;
  --surface:     #FFFFFF;
  --surface-alt: #FAFBFC;
  --border:      #E3E7EC;
  --border-soft: #EEF1F4;

  --text:        #14202E;
  --text-muted:  #64748B;
  --text-faint:  #94A3B8;

  --accent:      #0B6E99;
  --accent-dark: #075976;
  --accent-soft: #E7F1F7;

  --ok:          #0F7B54;
  --ok-soft:     #E6F5EF;
  --warn:        #B45309;
  --warn-soft:   #FDF3E3;
  --danger:      #C62828;
  --danger-soft: #FCEBEA;

  --radius:      10px;
  --radius-sm:   7px;
  --shadow:      0 1px 2px rgba(20, 32, 46, .05), 0 1px 3px rgba(20, 32, 46, .04);
  --shadow-lg:   0 4px 16px rgba(20, 32, 46, .08);

  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
          "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; padding: 0; height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Estructura ──────────────────────────────────────────────────────────── */
.shell { display: grid; grid-template-columns: 216px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
}
.brand { padding: 0 8px 18px; border-bottom: 1px solid var(--border-soft); margin-bottom: 14px; }
.brand-name { font-size: 16px; font-weight: 700; letter-spacing: -.01em; color: var(--text); }
.brand-sub  { font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .08em; margin-top: 3px; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-weight: 500; font-size: 13.5px;
}
.nav a:hover { background: var(--surface-alt); color: var(--text); text-decoration: none; }
.nav a.on { background: var(--accent-soft); color: var(--accent-dark); font-weight: 600; }
.nav .count {
  background: var(--accent); color: #fff; font-size: 11px; font-weight: 600;
  min-width: 19px; height: 19px; padding: 0 5px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
}

.main { padding: 22px 26px 60px; min-width: 0; }
.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-title { font-size: 20px; font-weight: 700; letter-spacing: -.015em; margin: 0; }
.page-sub { color: var(--text-muted); font-size: 13px; margin: 3px 0 0; }

/* ── Tarjetas ────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-pad { padding: 16px 18px; }
.card-head {
  padding: 13px 18px; border-bottom: 1px solid var(--border-soft);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.card-title { font-size: 14px; font-weight: 650; margin: 0; }

.grid { display: grid; gap: 14px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }

.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat-label { font-size: 11.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.stat-value { font-size: 25px; font-weight: 700; letter-spacing: -.02em; margin-top: 5px; font-variant-numeric: tabular-nums; }
.stat-hint { font-size: 12px; color: var(--text-faint); margin-top: 2px; }

/* ── Tablas ──────────────────────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th {
  text-align: left; font-size: 11.5px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .05em;
  padding: 9px 14px; border-bottom: 1px solid var(--border); background: var(--surface-alt);
  white-space: nowrap;
}
td { padding: 10px 14px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-alt); }
.num { font-variant-numeric: tabular-nums; text-align: right; }
.mono { font-family: var(--mono); font-size: 12.5px; }

/* ── Controles ───────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-size: 13px; font-weight: 550; font-family: inherit;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-alt); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-danger { color: var(--danger); border-color: #F3C9C7; background: var(--danger-soft); }
.btn-danger:hover { background: #F8DEDC; }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

input[type=text], input[type=search], input[type=email], input[type=number],
input[type=password], select, textarea {
  width: 100%; padding: 7px 10px; font-size: 13.5px; font-family: inherit;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: vertical; min-height: 80px; line-height: 1.55; }
label { font-size: 12.5px; font-weight: 600; color: var(--text-muted); display: block; margin-bottom: 4px; }
.field { margin-bottom: 13px; }
.hint { font-size: 12px; color: var(--text-faint); margin-top: 4px; }
.row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 130px; }
.row > .shrink { flex: 0 0 auto; min-width: 0; }

/* ── Chips y avisos ──────────────────────────────────────────────────────── */
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 20px; font-size: 11.5px; font-weight: 600;
  background: var(--surface-alt); color: var(--text-muted); border: 1px solid var(--border);
  white-space: nowrap;
}
.chip-ok     { background: var(--ok-soft);     color: var(--ok);     border-color: #C9E7DB; }
.chip-warn   { background: var(--warn-soft);   color: var(--warn);   border-color: #F3DFBE; }
.chip-danger { background: var(--danger-soft); color: var(--danger); border-color: #F3C9C7; }
.chip-accent { background: var(--accent-soft); color: var(--accent-dark); border-color: #C5DEEB; }

.alert { padding: 11px 14px; border-radius: var(--radius-sm); font-size: 13.5px; margin-bottom: 16px; border: 1px solid; }
.alert-ok   { background: var(--ok-soft);     border-color: #C9E7DB; color: #0B5C3F; }
.alert-err  { background: var(--danger-soft); border-color: #F3C9C7; color: #9B2220; }
.alert-warn { background: var(--warn-soft);   border-color: #F3DFBE; color: #8A4308; }

.empty { padding: 44px 20px; text-align: center; color: var(--text-faint); }
.empty-title { font-weight: 600; color: var(--text-muted); margin-bottom: 4px; }

/* ── Inbox ───────────────────────────────────────────────────────────────── */
.inbox { display: grid; grid-template-columns: 320px 1fr; gap: 14px; height: calc(100vh - 118px); min-height: 460px; }

.conv-list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; overflow: hidden; box-shadow: var(--shadow); }
.conv-filters { padding: 11px; border-bottom: 1px solid var(--border-soft); display: flex; flex-direction: column; gap: 8px; }
.conv-tabs { display: flex; gap: 5px; flex-wrap: wrap; }
.conv-scroll { overflow-y: auto; flex: 1; }

.conv-item { display: block; padding: 11px 13px; border-bottom: 1px solid var(--border-soft); color: inherit; }
.conv-item:hover { background: var(--surface-alt); text-decoration: none; }
.conv-item.on { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.conv-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.conv-name { font-weight: 620; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 11px; color: var(--text-faint); white-space: nowrap; }
.conv-company { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-preview { font-size: 12.5px; color: var(--text-faint); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-meta { display: flex; gap: 5px; margin-top: 6px; align-items: center; flex-wrap: wrap; }
.dot-unread { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex: 0 0 auto; }

.thread { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; overflow: hidden; box-shadow: var(--shadow); }
.thread-head { padding: 12px 16px; border-bottom: 1px solid var(--border-soft); display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
/* Ojo: NO usar justify-content:flex-end aqui. En un flex column con scroll,
   el contenido que desborda por ARRIBA queda inalcanzable: el navegador no
   genera area de scroll hacia el y no se puede leer el inicio del chat.
   El mismo efecto (mensajes pegados abajo cuando hay pocos) se logra con
   margin-top:auto en el primer hijo, y ese si deja subir. */
.thread-body { flex: 1; min-height: 0; overflow-y: auto; padding: 16px 18px; background: var(--surface-alt); display: flex; flex-direction: column; gap: 7px; }
.thread-body > *:first-child { margin-top: auto; }
.thread-body > * { flex: 0 0 auto; }

.msg {
  max-width: 62%; min-width: 0; width: fit-content;
  padding: 7px 10px 5px; border-radius: 12px;
  font-size: 13.5px; line-height: 1.45;
  box-shadow: 0 1px 1px rgba(20,32,46,.06);
}
.msg-body { display: block; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-in  { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 3px; }
.msg-out { align-self: flex-end; background: var(--accent-soft); border: 1px solid #C5DEEB; border-bottom-right-radius: 3px; }
.msg-tpl { align-self: flex-end; background: #FBF7EC; border: 1px solid #EADFC4; border-bottom-right-radius: 3px; }
.msg-foot {
  display: flex; align-items: center; justify-content: flex-end;
  gap: 5px; margin-top: 2px; font-size: 10.5px; color: var(--text-faint);
  line-height: 1;
}
.msg-in .msg-foot { justify-content: flex-start; }
.msg-time { font-variant-numeric: tabular-nums; white-space: nowrap; }
.msg-status { white-space: nowrap; }
.msg-status.is-read { color: var(--accent); font-weight: 600; }
.msg-status.is-failed { color: var(--danger); font-weight: 600; }
.msg-tag {
  background: rgba(20,32,46,.06); border-radius: 4px;
  padding: 1px 5px; font-size: 9.5px; text-transform: uppercase;
  letter-spacing: .04em; font-weight: 600;
}
.msg-error { display: block; margin-top: 3px; font-size: 11.5px; color: var(--danger); }
.msg-day { align-self: center; font-size: 11px; color: var(--text-faint); background: var(--surface); border: 1px solid var(--border); padding: 2px 10px; border-radius: 20px; margin: 6px 0; }

.composer { border-top: 1px solid var(--border-soft); padding: 11px 14px; background: var(--surface); }
.composer form { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 40px; max-height: 130px; }
.composer-locked { padding: 13px 16px; background: var(--warn-soft); border-top: 1px solid #F3DFBE; color: #8A4308; font-size: 13px; }

/* ── Barra de progreso ───────────────────────────────────────────────────── */
.bar { height: 7px; background: var(--border-soft); border-radius: 4px; overflow: hidden; display: flex; }
.bar span { display: block; height: 100%; }
.bar .s-sent { background: var(--accent); }
.bar .s-delivered { background: #5BA7C9; }
.bar .s-read { background: var(--ok); }
.bar .s-failed { background: var(--danger); }

.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-muted); margin-top: 8px; }
.legend i { width: 9px; height: 9px; border-radius: 2px; display: inline-block; margin-right: 5px; }

.denied { max-width: 440px; margin: 16vh auto; text-align: center; }

@media (max-width: 1000px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--border); }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .inbox { grid-template-columns: 1fr; height: auto; }
  .grid-4, .grid-3, .grid-2 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 560px) {
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .main { padding: 16px 14px 40px; }
  .msg { max-width: 86%; }
}

/* ── Auto-actualización ──────────────────────────────────────────────────── */
.live-dot {
  display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  background: var(--ok); margin-right: 6px; vertical-align: middle;
  animation: live-pulse 2.4s ease-in-out infinite;
}
@keyframes live-pulse { 0%,100% { opacity: 1 } 50% { opacity: .25 } }
.msg-new { animation: msg-in-anim .28s ease-out; }
@keyframes msg-in-anim { from { opacity: 0; transform: translateY(6px) } to { opacity: 1; transform: none } }
