/* ============================================================
   Panel-Dashboard · Real Flow AI · v2.1
   Universal core · triage · filters · search · pagination
   Self-contained · brand tokens inline
   ============================================================ */

:root {
  --bg-primary: #0d1117;
  --bg-panel: #161b22;
  --bg-subtle: #1c2128;
  --bg-elevated: #1B2838;
  --bg-deep: #060E1A;
  --border: #30363d;
  --border-soft: #21262d;
  --border-strong: #484f58;
  --text: #e6edf3;
  --text-muted: #7d8590;
  --text-dim: #484f58;
  --orange: #f97316;
  --orange-bright: #fb923c;
  --orange-bg: #2d1408;
  --amber: #e3b341;
  --amber-bg: #2d2208;
  --green: #3fb950;
  --green-bg: #0e2a14;
  --green-bright: #56d364;
  --coral: #da3633;
  --coral-bright: #ff7b7b;
  --coral-bg: #3d0e0e;
  --cyan: #4DB8C7;
  --purple: #a78bfa;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --radius: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-pill: 9999px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-primary);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--cyan); text-decoration: none; }
a:hover { color: var(--orange-bright); }

button { font-family: inherit; }

.dashboard {
  max-width: 1240px;
  margin: 0 auto;
}

/* ===== TOPBAR ===== */
.topbar {
  background: var(--bg-panel);
  border-bottom: 0.5px solid var(--border);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-3);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.av {
  width: 28px; height: 28px;
  border-radius: 6px;
  background: var(--orange);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px;
  font-weight: 500;
  color: white;
}

.bn {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
}

.bs {
  font-size: 13px;
  color: var(--text-muted);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.live {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--green);
}

.ld {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ===== KPIs ===== */
.kpis {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  padding: 16px;
}
.kpis-4 { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 900px) {
  .kpis, .kpis-4 { grid-template-columns: repeat(2, 1fr); }
}

.kpi {
  background: var(--bg-panel);
  border: 0.5px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}

.kv {
  font-size: 32px;
  font-weight: 600;
  color: var(--text);
  font-feature-settings: "tnum";
  line-height: 1.1;
}

.kv.o { color: var(--orange); }
.kv.y { color: var(--amber); }
.kv.g { color: var(--green); }
.kv.r { color: var(--coral-bright); }
.kv.p { color: var(--purple); }

.kl {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ===== BODY ===== */
.body { padding: 0 16px 16px; }

/* ===== CONTRACT BAR ===== */
.contract-bar {
  background: var(--bg-panel);
  border: 0.5px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.contract-label {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}

.progress-track {
  flex: 1;
  height: 12px;
  background: var(--bg-deep);
  border-radius: var(--radius-pill);
  overflow: hidden;
  position: relative;
  min-width: 200px;
}

.progress-fill {
  height: 100%;
  background: var(--green);
  border-radius: var(--radius-pill);
  transition: width 400ms ease, background-color 400ms ease;
}

.progress-fill.warn { background: var(--amber); }
.progress-fill.crit { background: var(--coral); }

.progress-marker {
  position: absolute;
  top: -4px;
  width: 2px;
  height: 20px;
  background: var(--text-muted);
  left: 50%;
}

.pct-value {
  font-size: 18px;
  font-weight: 700;
  font-feature-settings: "tnum";
  min-width: 50px;
  text-align: right;
  color: var(--text);
}

/* ===== TRIAGE ===== */
.triage {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

@media (max-width: 768px) {
  .triage { grid-template-columns: 1fr; }
}

.tbox {
  border-radius: 8px;
  padding: 10px 12px;
  border: 0.5px solid;
}

.tbox.crit { background: #1a0e0e; border-color: var(--coral); }
.tbox.mod  { background: #16140e; border-color: var(--amber); }
.tbox.low  { background: #0e1a10; border-color: var(--green); }

.tnum {
  font-size: 32px;
  font-weight: 600;
  font-feature-settings: "tnum";
  line-height: 1.1;
}

.tnum.r { color: var(--coral-bright); }
.tnum.y { color: var(--amber); }
.tnum.g { color: var(--green); }

.tlabel {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

.tbadge {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 8px;
  margin-top: 6px;
  display: inline-block;
}

.tb-r { background: var(--coral-bg); color: var(--coral-bright); }
.tb-y { background: var(--amber-bg); color: var(--amber); }
.tb-g { background: var(--green-bg); color: var(--green); }

/* ===== TOOLBAR ===== */
.toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.tl-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-right: 2px;
}

.bc {
  background: var(--coral);
  color: white;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 8px;
  font-weight: 500;
}

.divider {
  width: 0.5px;
  height: 16px;
  background: var(--border);
  margin: 0 2px;
}

.filter-btns, .date-btns {
  display: flex;
  gap: 3px;
}

.fb, .db {
  padding: 6px 12px;
  border-radius: 5px;
  font-size: 13px;
  border: 0.5px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 120ms ease;
}

.fb:hover, .db:hover { color: var(--text); }

.fb.on {
  background: var(--orange);
  color: white;
  border-color: var(--orange);
}

.db.on {
  background: var(--bg-panel);
  color: var(--text);
  border-color: var(--text-muted);
}

.date-group { display: flex; align-items: center; gap: 6px; }
.date-label { font-size: 13px; color: var(--text-dim); }

.spacer { flex: 1; }

.search {
  background: var(--bg-panel);
  border: 0.5px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 14px;
  color: var(--text);
  outline: none;
  width: 220px;
  font-family: inherit;
}

.search:focus { border-color: var(--orange); }

/* ===== TABLA PENDIENTES ===== */
.table-wrap {
  background: var(--bg-panel);
  border: 0.5px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: var(--space-5);
}

.thead {
  display: grid;
  grid-template-columns: 20px 200px 1fr 150px 80px 100px 100px;
  gap: 0;
  background: var(--bg-primary);
  border-bottom: 0.5px solid var(--border);
  padding: 10px 14px;
  align-items: center;
}

.th {
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.row {
  display: grid;
  grid-template-columns: 20px 200px 1fr 150px 80px 100px 100px;
  gap: 0;
  padding: 12px 14px;
  align-items: center;
  border-bottom: 0.5px solid var(--border-soft);
  transition: background 120ms ease;
}

.row:last-child { border-bottom: none; }
.row:hover { background: var(--bg-subtle); }
.row.crit { border-left: 3px solid var(--coral); }
.row.mod  { border-left: 3px solid var(--amber); }
.row.low  { border-left: 3px solid var(--green); }

.dot {
  width: 7px; height: 7px;
  border-radius: 50%;
}

.dr { background: var(--coral); }
.dy { background: var(--amber); }
.dg { background: var(--green); }

.cell-client {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.cname {
  font-size: 15px;
  color: var(--text);
  font-weight: 600;
}

.cnum {
  font-size: 13px;
  color: var(--text-dim);
  font-family: ui-monospace, "SF Mono", monospace;
}

.cmsg {
  font-size: 14px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-style: italic;
  padding-right: 8px;
}

.tag {
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 8px;
  display: inline-block;
  font-weight: 500;
}

.tag-r { background: var(--coral-bg); color: var(--coral-bright); }
.tag-y { background: var(--amber-bg); color: var(--amber); }
.tag-g { background: var(--green-bg); color: var(--green); }

.ago {
  font-size: 13px;
  color: var(--text-dim);
  font-family: ui-monospace, monospace;
}

.actions {
  display: flex;
  gap: 4px;
  align-items: center;
}

.btn-sm {
  padding: 6px 12px;
  border-radius: 5px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  white-space: nowrap;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  transition: all 120ms ease;
}

.btn-o {
  background: var(--orange);
  color: white;
}
.btn-o:hover {
  background: var(--orange-bright);
  color: white;
}

.btn-g {
  background: var(--bg-elevated);
  color: var(--text-muted);
}
.btn-g:hover {
  color: var(--green);
}

/* ===== SECTION ===== */
.section { margin-bottom: var(--space-5); }

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: var(--space-3);
}

.section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.section-title .count {
  background: var(--bg-elevated);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
}

.see-all { font-size: 12px; color: var(--text-muted); }

/* ===== CONV LIST ===== */
.conv-list {
  display: grid;
  gap: 1px;
  background: var(--border);
  border: 0.5px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.conv-item {
  background: var(--bg-panel);
  padding: 12px 16px;
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: var(--space-4);
  align-items: center;
  cursor: pointer;
  transition: background 120ms ease;
}

/* Pending row (incluye dot, tag, ts, btn) */
.conv-item.conv-pending {
  grid-template-columns: 12px 1fr auto auto auto;
}
.conv-item .dot-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
}
.conv-item .name .cnum {
  font-weight: 400;
  color: var(--text-dim);
  font-family: ui-monospace, monospace;
  margin-left: 6px;
  font-size: 12px;
}

.see-more {
  text-align: center;
  padding: 12px;
  font-size: 12px;
  color: var(--text-dim);
  font-style: italic;
}

.conv-item:hover { background: var(--bg-subtle); }

.conv-item .name {
  font-weight: 500;
  color: var(--text);
  font-size: 13px;
}

.conv-item .preview {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 600px;
}

.conv-item .status-tag {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-weight: 500;
}

.conv-item .status-tag.active   { background: var(--green-bg); color: var(--green); }
.conv-item .status-tag.handoff  { background: var(--coral-bg); color: var(--coral-bright); }
.conv-item .status-tag.closed   { background: var(--bg-elevated); color: var(--text-dim); }

.conv-item .ts {
  font-size: 11px;
  color: var(--text-dim);
  font-family: ui-monospace, monospace;
}

/* ===== EMPTY ===== */
.empty, .loading {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-muted);
  font-size: 13px;
}

.empty .emoji {
  font-size: 28px;
  display: block;
  margin-bottom: 8px;
  opacity: 0.7;
}

/* ===== CONVERSATION DETAIL ===== */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 13px;
  margin: 14px 16px 0;
}
.back-link:hover { color: var(--text); }

.conv-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 0.5px solid var(--border);
  flex-wrap: wrap;
  gap: var(--space-3);
}

.conv-header h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.conv-header small {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
  margin-top: 2px;
}

.status-badge {
  font-size: 11px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-weight: 500;
}

.status-badge.ok      { background: var(--green-bg); color: var(--green); }
.status-badge.warn    { background: var(--amber-bg); color: var(--amber); }
.status-badge.crit    { background: var(--coral-bg); color: var(--coral-bright); }
.status-badge.neutral { background: var(--bg-elevated); color: var(--text-muted); }

.message-thread {
  background: var(--bg-panel);
  border: 0.5px solid var(--border);
  border-radius: 8px;
  padding: var(--space-4);
  display: grid;
  gap: var(--space-3);
  max-height: 70vh;
  overflow-y: auto;
}

.msg {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  max-width: 80%;
  font-size: 13px;
  line-height: 1.5;
}

.msg.user {
  background: var(--bg-elevated);
  align-self: flex-start;
  justify-self: start;
  border-bottom-left-radius: 2px;
}

.msg.assistant {
  background: var(--orange-bg);
  border: 0.5px solid var(--orange);
  align-self: flex-end;
  justify-self: end;
  border-bottom-right-radius: 2px;
}

.msg.human {
  background: var(--green-bg);
  border: 0.5px solid var(--green);
  align-self: flex-end;
  justify-self: end;
  border-bottom-right-radius: 2px;
}

.msg .role {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 4px;
  font-weight: 600;
}

.msg .ts {
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 4px;
  font-family: ui-monospace, monospace;
}

/* ===== ESCALATION CARDS (re-uso en conversation.html) ===== */
.escalations {
  display: grid;
  gap: var(--space-3);
}

.esc-card {
  background: linear-gradient(180deg, var(--coral-bg), var(--bg-panel));
  border: 0.5px solid var(--coral);
  border-left: 3px solid var(--coral);
  border-radius: 8px;
  padding: var(--space-3) var(--space-4);
}

.esc-card.handled {
  background: var(--bg-panel);
  border-color: var(--border);
  border-left-color: var(--green);
}

.esc-card .name {
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
}

.esc-card .meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

.esc-card .reason {
  display: inline-block;
  background: var(--coral-bg);
  color: var(--coral-bright);
  padding: 2px 6px;
  border-radius: var(--radius);
  font-size: 10px;
  margin-right: 6px;
  font-weight: 500;
}

.esc-card .quote {
  margin: 8px 0 4px 0;
  padding: 6px 10px;
  background: var(--bg-deep);
  border-left: 2px solid var(--coral);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 12px;
  font-style: italic;
  color: var(--text);
}

.section-title.urgent .count {
  background: var(--coral-bg);
  color: var(--coral-bright);
}
