:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --text: #1f2430;
  --muted: #6b7280;
  --border: #e5e7eb;
  --waiting: #f59e0b;
  --agent: #10b981;
  --bot: #6366f1;
  --closed: #9ca3af;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }

.login-body { display: flex; align-items: center; justify-content: center; height: 100vh; }
.login-card {
  background: var(--card); padding: 40px; border-radius: 12px; width: 340px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.08); display: flex; flex-direction: column; gap: 14px;
}
.login-card h1 { margin: 0; font-size: 22px; }
.subtitle { margin: 0 0 8px; color: var(--muted); font-size: 14px; }
.login-card label { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }
.login-card input {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
}
.login-card button {
  margin-top: 8px; padding: 11px; border: none; border-radius: 8px; background: var(--primary);
  color: white; font-weight: 600; cursor: pointer; font-size: 14px;
}
.login-card button:hover { background: var(--primary-dark); }
.error { color: #dc2626; font-size: 13px; min-height: 16px; margin: 0; }

/* ---- Dashboard layout ---- */
.app { display: flex; height: 100vh; }
.sidebar {
  width: 220px; background: #111827; color: #e5e7eb; display: flex; flex-direction: column; padding: 16px 0;
  flex-shrink: 0;
}
.sidebar .brand { padding: 0 20px 16px; font-weight: 700; font-size: 16px; border-bottom: 1px solid #1f2937; margin-bottom: 8px; }
.sidebar .nav-item {
  padding: 12px 20px; cursor: pointer; font-size: 14px; color: #cbd5e1; border-left: 3px solid transparent;
}
.sidebar .nav-item:hover { background: #1f2937; }
.sidebar .nav-item.active { background: #1f2937; color: white; border-left-color: var(--primary); }
.sidebar .spacer { flex: 1; }
.sidebar .user-box { padding: 12px 20px; font-size: 12px; color: #9ca3af; border-top: 1px solid #1f2937; }
.sidebar .logout-btn { margin: 8px 20px 0; padding: 8px; background: #374151; border: none; border-radius: 6px; color: white; cursor: pointer; font-size: 12px; }

.main { flex: 1; overflow-y: auto; padding: 28px 32px; }
.main h2 { margin-top: 0; }
.panel { display: none; }
.panel.active { display: block; }

.stats-row { display: flex; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.stat-card { background: var(--card); padding: 18px 22px; border-radius: 10px; box-shadow: 0 1px 3px rgba(0,0,0,0.06); min-width: 130px; }
.stat-card .num { font-size: 26px; font-weight: 700; }
.stat-card .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* ---- Gráficas de estadísticas ---- */
.chart-card { background: var(--card); border-radius: 10px; box-shadow: 0 1px 3px rgba(0,0,0,0.06); padding: 16px 18px; padding-top:60px; margin-bottom: 20px; overflow-x: auto; }
.chart-legend { margin-top: 8px; display: flex; flex-wrap: wrap; }
.chart-legend .swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; margin-right: 5px; }
.chart-toggle { background: none; border: none; color: var(--primary); font-size: 12px; cursor: pointer; padding: 0; margin-top: 8px; text-decoration: underline; }
.chart-axis-label { font-size: 10px; fill: var(--muted); }
.chart-empty { color: var(--muted); font-size: 13px; padding: 20px 0; }

.chart-gridline { stroke: var(--border); stroke-width: 1; }
.chart-crosshair { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; pointer-events: none; }
.stat-line-dot { transition: r .1s ease; pointer-events: none; }
.stat-line-dot.active { r: 6; }
.stat-line-hit { cursor: crosshair; }
.chart-tooltip {
  position: absolute; pointer-events: none; transform: translate(-50%, -115%);
  background: #111827; color: #fff; padding: 8px 12px; border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.28); white-space: nowrap; z-index: 5;
}
.chart-tooltip .period { font-size: 11px; color: #9ca3af; margin-bottom: 4px; }
.chart-tooltip .row { display: flex; align-items: center; gap: 6px; font-size: 12px; padding: 1px 0; }
.chart-tooltip .row .swatch { width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0; }
.chart-tooltip .row strong { margin-left: auto; padding-left: 14px; font-size: 13px; }

table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: 10px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,0.06);}
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 14px; }
th { background: #fafafa; font-size: 12px; text-transform: uppercase; color: var(--muted); }
tr:last-child td { border-bottom: none; }

.btn { padding: 8px 14px; border: none; border-radius: 7px; background: var(--primary); color: white; cursor: pointer; font-size: 13px; font-weight: 600; }
.btn:hover { background: var(--primary-dark); }
.btn.secondary { background: #e5e7eb; color: var(--text); }
.btn.danger { background: #dc2626; }
.btn.small { padding: 5px 10px; font-size: 12px; }

.form-row { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; align-items: end; }
.form-row label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.form-row input, .form-row textarea, .form-row select { padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; }
.form-row textarea { min-width: 260px; min-height: 38px; font-family: inherit; }
.form-row input[type="color"] { padding: 2px; width: 48px; height: 38px; cursor: pointer; }

.badge { padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; color: white; text-transform: uppercase; }
.badge.waiting { background: var(--waiting); }
.badge.agent { background: var(--agent); }
.badge.bot { background: var(--bot); }
.badge.closed { background: var(--closed); }

.embed-box { background: #111827; color: #a5f3fc; padding: 10px 12px; border-radius: 6px; font-family: monospace; font-size: 12px; word-break: break-all; }

/* ---- Chat view ---- */
.chat-layout { display: flex; height: calc(100vh - 56px); gap: 0; margin: -28px -32px; }
.chat-list { width: 300px; border-right: 1px solid var(--border); background: var(--card); overflow-y: auto; flex-shrink: 0; }
.chat-list-header { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; gap: 8px; }
.chat-list-header select { flex: 1; padding: 6px; border-radius: 6px; border: 1px solid var(--border); }
.chat-item { padding: 12px 16px; border-bottom: 1px solid var(--border); cursor: pointer; }
.chat-item:hover { background: #f9fafb; }
.chat-item.active { background: #eef2ff; }
.chat-item .row1 { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.chat-item .site-name { font-size: 12px; color: var(--muted); }

.chat-window { flex: 1; display: flex; flex-direction: column; background: #f9fafb; }
.chat-window-header { padding: 14px 20px; background: var(--card); border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.chat-messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 60%; padding: 10px 14px; border-radius: 12px; font-size: 14px; line-height: 1.4; }
.msg.visitor { align-self: flex-start; background: white; border: 1px solid var(--border); }
.msg.bot { align-self: flex-start; background: #eef2ff; color: #3730a3; }
.msg.agent { align-self: flex-end; background: var(--primary); color: white; }
.msg a { text-decoration: underline; color: inherit; }
.msg.bot a { color: #3730a3; }
.msg .meta { font-size: 10px; opacity: .6; margin-top: 4px; }
.chat-input-row { padding: 14px 20px; background: var(--card); border-top: 1px solid var(--border); display: flex; gap: 10px; }
.chat-input-row textarea { flex: 1; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border); resize: none; font-family: inherit; font-size: 14px; }
.empty-state { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--muted); font-size: 14px; }
