/* ==========================================================================
   Startia PBX — Sistema de diseño del portal
   ========================================================================== */
:root {
  --bg: #f3f5fa;
  --panel: #ffffff;
  --panel-2: #f8f9fd;
  --ink: #16192b;
  --ink-2: #3d4258;
  --muted: #7a8199;
  --line: #e6e9f2;
  --line-2: #d8dcea;
  --accent: #3b5bfd;
  --accent-2: #2743d6;
  --accent-soft: #eef1ff;
  --accent-ink: #ffffff;
  --ok: #0e9f5c;  --ok-soft: #e3f8ee;
  --bad: #dd3b46; --bad-soft: #fdeaec;
  --warn: #d78100; --warn-soft: #fdf3df;
  --info: #3b5bfd; --info-soft: #e9edff;
  --sidebar-bg: #0e1120;
  --sidebar-ink: #9aa2bd;
  --sidebar-active: #1c2340;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(22, 25, 43, .05), 0 8px 24px -12px rgba(22, 25, 43, .12);
  --shadow-lg: 0 24px 64px -16px rgba(22, 25, 43, .25);
  --font: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-font-smoothing: antialiased; }
body { margin: 0; background: var(--bg); color: var(--ink);
  font: 400 14.5px/1.5 var(--font); }
h1 { font-size: 22px; font-weight: 700; letter-spacing: -.02em; margin: 0; }
h2 { font-size: 16.5px; font-weight: 650; letter-spacing: -.01em; margin: 0 0 4px; }
h3 { font-size: 14.5px; font-weight: 600; margin: 0 0 8px; }
.muted { color: var(--muted); }
.error { color: var(--bad); font-size: 13.5px; }
a { color: var(--accent); }

/* ------------------------------------------------------------- controles */
button, .btn {
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  border: 1px solid var(--line-2); background: var(--panel); color: var(--ink-2);
  border-radius: 10px; padding: 7px 14px; cursor: pointer;
  font: 500 13.5px/1.2 var(--font);
  transition: background .15s, border-color .15s, box-shadow .15s, transform .05s;
}
button:hover, .btn:hover { background: var(--panel-2); border-color: #c9cfe2; }
button:active, .btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: var(--accent-ink);
  border-color: var(--accent); box-shadow: 0 6px 16px -8px rgba(59, 91, 253, .7); }
.btn.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn.danger { color: var(--bad); border-color: #f0c8cb; background: #fff; }
.btn.danger:hover { background: var(--bad-soft); }
.btn.small { padding: 4px 10px; font-size: 12.5px; border-radius: 8px; gap: 5px; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--accent-soft); color: var(--accent); }
.btn svg { width: 15px; height: 15px; flex: none; }

input, select, textarea {
  width: 100%; padding: 8.5px 12px; border: 1px solid var(--line-2);
  border-radius: 10px; font: 400 14px/1.4 var(--font);
  background: #fff; color: var(--ink); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59, 91, 253, .14);
}
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent);
  margin: 0; flex: none; cursor: pointer; }
label { display: block; margin-bottom: 10px; font: 550 12px/1.3 var(--font);
  color: var(--ink-2); letter-spacing: .01em; }
label input, label select, label textarea { margin-top: 5px; font-weight: 400; }

/* filas de checkbox: caja alineada a la izquierda, texto al lado, ayuda debajo */
.check-row { display: flex; align-items: flex-start; gap: 10px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; cursor: pointer; margin-bottom: 0; align-self: start;
  transition: border-color .15s, background .15s; }
.check-row:hover { border-color: var(--line-2); }
.check-row input[type="checkbox"] { margin-top: 1px; }
.check-row .check-text { font: 550 13px/1.35 var(--font); color: var(--ink); }
.check-row .help { margin-top: 2px; font-weight: 400; }
.check-row:has(input:checked) { border-color: rgba(59, 91, 253, .4);
  background: var(--accent-soft); }

/* constructor de listas (opciones IVR, reglas de horario, fechas...) */
.builder { border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel-2); padding: 10px 12px; }
.builder-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px;
  flex-wrap: wrap; }
.builder-row > select, .builder-row > input { width: auto; flex: 1; min-width: 90px; }
.builder-row .fixed { flex: 0 0 auto; width: 76px; }
.builder-row .grow2 { flex: 2; }
.builder-days { display: flex; gap: 4px; flex-wrap: wrap; }
.builder-days label { display: flex; align-items: center; gap: 3px; margin: 0;
  font-size: 11.5px; padding: 3px 7px; border: 1px solid var(--line-2);
  border-radius: 7px; background: #fff; cursor: pointer; }
.builder-days label:has(input:checked) { background: var(--accent);
  color: #fff; border-color: var(--accent); }
.builder-days input { display: none; }

/* ------------------------------------------------------------------ login */
.login-body { display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  background:
    radial-gradient(900px 500px at 85% -10%, rgba(59, 91, 253, .18), transparent 60%),
    radial-gradient(700px 500px at -10% 110%, rgba(14, 159, 92, .10), transparent 55%),
    var(--bg); }
.login-card { background: var(--panel); border: 1px solid var(--line);
  border-radius: 20px; padding: 40px 38px 32px; width: 392px;
  box-shadow: var(--shadow-lg); }
.brand { text-align: center; margin-bottom: 26px; }
.brand h1 { margin: 14px 0 3px; font-size: 21px; }
.brand p { margin: 0; }
.brand-logo { width: 54px; height: 54px; margin: 0 auto; border-radius: 16px;
  background: linear-gradient(135deg, #4d6bff, #2743d6);
  color: #fff; font-size: 26px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 10px 24px -8px rgba(59, 91, 253, .55); }
.login-card button { width: 100%; margin-top: 10px; padding: 11px; font-size: 14.5px; }

/* ------------------------------------------------------------------ layout */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 232px; background: var(--sidebar-bg); color: var(--sidebar-ink);
  padding: 20px 12px; flex-shrink: 0; display: flex; flex-direction: column; }
.brand-mini { color: #fff; font-weight: 700; font-size: 15.5px;
  padding: 4px 12px 18px; display: flex; align-items: center; gap: 10px;
  letter-spacing: -.01em; }
.brand-mini .dot { width: 30px; height: 30px; border-radius: 9px; flex: none;
  background: linear-gradient(135deg, #4d6bff, #2743d6);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 15px; font-weight: 800; }
.sidebar a { display: flex; align-items: center; gap: 10px; color: var(--sidebar-ink);
  text-decoration: none; padding: 8.5px 12px; border-radius: 9px;
  margin-bottom: 2px; font: 500 13.5px/1.2 var(--font);
  transition: background .12s, color .12s; }
.sidebar a svg { width: 16px; height: 16px; flex: none; opacity: .75; }
.sidebar a.active, .sidebar a:hover { background: var(--sidebar-active); color: #fff; }
.sidebar a.active svg { opacity: 1; }
.sidebar .spacer { flex: 1; }
.sidebar .last-login { color: #5b6280; font-size: 11px; line-height: 1.5;
  padding: 10px 12px 4px; border-top: 1px solid #1c2340; margin-top: 8px; }
.agent-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  margin-right: 6px; vertical-align: middle; }
.agent-dot.free { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.agent-dot.busy { background: var(--bad); }
.agent-dot.ringing { background: var(--warn); animation: blink 1s infinite; }
.agent-dot.offline { background: #c3c8d8; }
.agent-dot.pausedd { background: var(--warn); }
@keyframes blink { 50% { opacity: .35; } }
.main { flex: 1; padding: 26px 34px 60px; max-width: 1240px; min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 20px; gap: 14px; }
.who { font-size: 13px; color: var(--muted); background: var(--panel);
  border: 1px solid var(--line); padding: 6px 14px; border-radius: 999px; }

/* ------------------------------------------------------------------ cards */
.card { background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px 22px; margin-bottom: 18px;
  box-shadow: var(--shadow); }
.section-head { display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 14px; gap: 12px; flex-wrap: wrap; }
.section-head .sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: 1fr 1fr; }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols-5 { grid-template-columns: repeat(5, 1fr); }
.stat { background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px 18px 15px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 2px; }
.stat .num { font-size: 27px; font-weight: 750; letter-spacing: -.03em;
  color: var(--ink); }
.stat .num.accent { color: var(--accent); }
.stat .lbl { color: var(--muted); font-size: 12.5px; font-weight: 550; }
.stat .ico { width: 34px; height: 34px; border-radius: 10px;
  background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center; margin-bottom: 9px; }
.stat .ico svg { width: 17px; height: 17px; }

/* ------------------------------------------------------------------ tablas */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.8px; }
th { text-align: left; color: var(--muted); font-weight: 600; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .06em; padding: 8px 12px;
  border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10.5px 12px; border-bottom: 1px solid var(--line);
  vertical-align: middle; }
tbody tr { transition: background .1s; }
tbody tr:hover { background: var(--panel-2); }
tr:last-child td { border-bottom: none; }
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2.5px 10px;
  border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.info { background: var(--info-soft); color: var(--info); }
.pill.plain::before { display: none; }
.actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
code.kv { background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 7px; padding: 2px 8px; font-size: 12.5px;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }

/* ------------------------------------------------------------------ forms */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr));
  gap: 8px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid .help { color: var(--muted); font-size: 11.5px; font-weight: 400;
  margin-top: 3px; }
.hidden { display: none !important; }

dialog { border: none; border-radius: 18px; padding: 0;
  width: min(720px, 94vw); box-shadow: var(--shadow-lg); }
dialog::backdrop { background: rgba(14, 17, 32, .55); backdrop-filter: blur(2px); }
.dlg-head { padding: 18px 24px 14px; border-bottom: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: center; }
.dlg-body { padding: 20px 24px; max-height: 62vh; overflow-y: auto; }
.dlg-foot { padding: 14px 24px; border-top: 1px solid var(--line);
  display: flex; gap: 10px; justify-content: flex-end; background: var(--panel-2);
  border-radius: 0 0 18px 18px; }

/* ------------------------------------------------------------------ toasts */
#toast { position: fixed; bottom: 20px; right: 20px; z-index: 99;
  display: flex; flex-direction: column; align-items: flex-end; }
.toast-item { background: #16192b; color: #fff; padding: 11px 18px;
  border-radius: 12px; margin-top: 8px; font-size: 13.5px; max-width: 380px;
  box-shadow: var(--shadow-lg); display: flex; gap: 9px; align-items: center;
  animation: toast-in .18s ease-out; }
.toast-item.err { background: var(--bad); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ------------------------------------------------------------------ teléfono */
.phone-wrap { max-width: 430px; margin: 26px auto; padding: 0 14px; }
.phone-card { background: var(--panel); border: 1px solid var(--line);
  border-radius: 22px; padding: 24px; box-shadow: var(--shadow-lg); }
.phone-head { display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 14px; }
.phone-head h2 { margin: 0; font-size: 16px; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--warn);
  display: inline-block; margin-right: 7px; }
.status-dot.on { background: var(--ok); box-shadow: 0 0 0 4px var(--ok-soft); }
.status-dot.off { background: var(--bad); }
.phone-status { font-size: 13px; color: var(--muted); min-height: 20px;
  display: flex; align-items: center; }
.phone-display { font-size: 28px; text-align: center; padding: 18px 14px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 14px; min-height: 70px; letter-spacing: 2px; margin: 14px 0;
  font-weight: 600; overflow: hidden; }
.dialpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  margin: 14px 0 16px; }
.dialpad button { font-size: 21px; padding: 15px; border-radius: 14px;
  font-weight: 550; }
.call-buttons { display: flex; gap: 10px; }
.call-buttons button { flex: 1; padding: 14px; font-size: 15px;
  border-radius: 14px; font-weight: 650; }
.btn.call { background: var(--ok); color: #fff; border-color: var(--ok);
  box-shadow: 0 8px 20px -8px rgba(14, 159, 92, .6); }
.btn.call:hover { background: #0b8a4f; }
.btn.hang { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn.hang:hover { background: #c22f3a; }
.btn.hang:disabled, .btn.call:disabled { opacity: .45; cursor: not-allowed;
  box-shadow: none; }
.incoming-banner { background: linear-gradient(135deg, #eef1ff, #e5ebff);
  border: 1px solid #c9d4ff; padding: 18px; border-radius: 16px;
  margin-bottom: 14px; text-align: center;
  animation: pulse-ring 1.2s ease-in-out infinite; }
@keyframes pulse-ring {
  0%, 100% { box-shadow: 0 0 0 0 rgba(59, 91, 253, .25); }
  50% { box-shadow: 0 0 0 9px rgba(59, 91, 253, 0); } }
.vm-row { display: flex; align-items: center; gap: 10px; padding: 9px 0;
  border-bottom: 1px solid var(--line); font-size: 13.5px; }
.vm-row:last-child { border-bottom: none; }
audio { height: 34px; }

/* ------------------------------------------------------------------ responsive */
@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; flex-wrap: wrap; padding: 10px;
    align-items: center; }
  .sidebar .brand-mini { padding: 4px 10px; }
  .sidebar .spacer { display: none; }
  .main { padding: 18px 14px 50px; }
  .grid.cols-4, .grid.cols-5 { grid-template-columns: 1fr 1fr; }
}
