/* Estilos propios de la web de QA de llamadas (componentes). Tailwind (CDN fijado) aporta las utilidades.
   Las capas se declaran aquí, antes de que Tailwind inyecte las suyas, para que las utilidades
   (p. ej. `px-2`) sigan ganando a los componentes. Color de marca: #1F4E78 (plantilla de auditoría). */
@layer theme, base, components, utilities;

:root {
  --brand-50: #eff5fa;
  --brand-100: #dbe8f3;
  --brand-200: #b8d1e8;
  --brand-600: #255d8f;
  --brand-700: #1f4e78;
  --brand-800: #1a4163;
  --brand-900: #14324d;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --surface: #ffffff;
  --canvas: #f4f6f9;
  --ok: #047857;
  --ok-bg: #ecfdf5;
  --warn: #b45309;
  --warn-bg: #fffbeb;
  --bad: #b91c1c;
  --bad-bg: #fef2f2;
  --player-h: 0px;
}

@layer base {
  html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
  }
  body {
    background: var(--canvas);
    color: var(--ink);
    font-family: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
  }
  /* Tailwind 4 pone el borde por defecto en currentColor: aquí, gris suave en toda la app */
  html *,
  html ::before,
  html ::after {
    border-color: var(--line);
  }
  :focus-visible {
    outline: 2px solid var(--brand-600);
    outline-offset: 2px;
  }
  [id] {
    scroll-margin-top: calc(var(--player-h) + 16px);
  }
}

@layer components {
  /* ---------- navegación */
  .nav-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    height: 2.25rem;
    padding: 0 0.75rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: #c9dbeb;
    white-space: nowrap;
    transition: background-color 0.15s, color 0.15s;
  }
  .nav-link:hover {
    color: #fff;
    background: rgb(255 255 255 / 0.08);
  }
  .nav-link[aria-current="page"] {
    color: #fff;
    background: rgb(255 255 255 / 0.14);
    box-shadow: inset 0 -2px 0 #9cc3e6;
  }

  /* ---------- tarjetas */
  .card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 0.75rem;
    box-shadow: 0 1px 2px rgb(15 23 42 / 0.04);
  }
  .card-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem 1rem;
    padding: 0.875rem 1.25rem;
    border-bottom: 1px solid var(--line);
  }
  .card-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--ink);
  }
  .card-body {
    padding: 1.25rem;
  }
  .eyebrow {
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
  }
  .page-title {
    font-size: 1.5rem;
    line-height: 2rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--ink);
  }
  .page-subtitle {
    margin-top: 0.25rem;
    font-size: 0.875rem;
    color: var(--muted);
  }

  /* ---------- botones */
  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    height: 2.25rem;
    padding: 0 0.875rem;
    border-radius: 0.5rem;
    border: 1px solid transparent;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
  }
  .btn:disabled {
    opacity: 0.6;
    cursor: wait;
  }
  .btn-primary {
    background: var(--brand-700);
    color: #fff;
    box-shadow: 0 1px 2px rgb(15 23 42 / 0.15);
  }
  .btn-primary:hover {
    background: var(--brand-800);
  }
  .btn-secondary {
    background: #fff;
    color: #334155;
    border-color: var(--line-strong);
    box-shadow: 0 1px 2px rgb(15 23 42 / 0.05);
  }
  .btn-secondary:hover {
    background: #f8fafc;
    color: var(--ink);
  }
  .btn-ghost {
    background: transparent;
    color: var(--brand-700);
  }
  .btn-ghost:hover {
    background: var(--brand-50);
  }
  .btn-violet {
    background: #6d28d9;
    color: #fff;
  }
  .btn-violet:hover {
    background: #5b21b6;
  }
  .btn-danger {
    background: #b91c1c;
    color: #fff;
  }
  .btn-danger:hover {
    background: #991b1b;
  }
  .btn-sm {
    height: 1.875rem;
    padding: 0 0.625rem;
    font-size: 0.8125rem;
  }

  /* ---------- formularios */
  .field {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    min-width: 0;
    font-size: 0.8125rem;
    font-weight: 500;
    color: #334155;
  }
  .input {
    width: 100%;
    min-width: 0;
    height: 2.25rem;
    padding: 0 0.75rem;
    border: 1px solid var(--line-strong);
    border-radius: 0.5rem;
    background: #fff;
    color: var(--ink);
    font-size: 0.875rem;
    font-weight: 400;
    box-shadow: 0 1px 2px rgb(15 23 42 / 0.04);
    transition: border-color 0.15s, box-shadow 0.15s;
  }
  textarea.input {
    height: auto;
    padding: 0.5rem 0.75rem;
    line-height: 1.45;
    resize: vertical;
  }
  .input:focus {
    outline: none;
    border-color: var(--brand-600);
    box-shadow: 0 0 0 3px rgb(37 93 143 / 0.18);
  }
  .input::placeholder {
    color: #94a3b8;
  }
  .check {
    width: 1rem;
    height: 1rem;
    accent-color: var(--brand-700);
  }

  /* ---------- insignias */
  .badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    height: 1.375rem;
    padding: 0 0.5rem;
    border-radius: 9999px;
    border: 1px solid transparent;
    font-size: 0.75rem;
    font-weight: 500;
    line-height: 1;
    white-space: nowrap;
  }
  .badge-dot::before {
    content: "";
    width: 0.375rem;
    height: 0.375rem;
    border-radius: 9999px;
    background: currentColor;
  }
  .badge-slate { background: #f1f5f9; color: #475569; border-color: #e2e8f0; }
  .badge-green { background: var(--ok-bg); color: var(--ok); border-color: #a7f3d0; }
  .badge-amber { background: var(--warn-bg); color: var(--warn); border-color: #fde68a; }
  .badge-orange { background: #fff7ed; color: #c2410c; border-color: #fed7aa; }
  .badge-red { background: var(--bad-bg); color: var(--bad); border-color: #fecaca; }
  .badge-blue { background: var(--brand-50); color: var(--brand-700); border-color: var(--brand-200); }
  .badge-sky { background: #f0f9ff; color: #0369a1; border-color: #bae6fd; }
  .badge-violet { background: #f5f3ff; color: #6d28d9; border-color: #ddd6fe; }

  /* ---------- tonos de nota (0-100 y 0-5) */
  .tone-ok { color: var(--ok); }
  .tone-warn { color: var(--warn); }
  .tone-bad { color: var(--bad); }
  .tone-mid { color: #334155; }
  .tone-none { color: #94a3b8; }
  .bar { height: 0.5rem; border-radius: 9999px; background: #eef2f6; overflow: hidden; }
  .bar > span { display: block; height: 100%; border-radius: 9999px; background: var(--brand-600); }
  .bar > span.tone-ok { background: #10b981; }
  .bar > span.tone-warn { background: #f59e0b; }
  .bar > span.tone-bad { background: #ef4444; }
  .score-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 3.25rem;
    height: 1.625rem;
    padding: 0 0.5rem;
    border-radius: 0.4rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    font-size: 0.875rem;
  }
  .score-pill.tone-ok { background: var(--ok-bg); }
  .score-pill.tone-warn { background: var(--warn-bg); }
  .score-pill.tone-bad { background: var(--bad-bg); }
  .score-pill.tone-mid { background: #f1f5f9; }
  .score-pill.tone-none { background: #f8fafc; }
  .heat-ok { background: #ecfdf5; color: #065f46; }
  .heat-warn { background: #fffbeb; color: #92400e; }
  .heat-bad { background: #fef2f2; color: #991b1b; }
  .heat-mid { background: #f8fafc; color: #334155; }

  /* ---------- tablas */
  .table {
    width: 100%;
    font-size: 0.875rem;
    border-collapse: separate;
    border-spacing: 0;
  }
  .table thead th {
    position: sticky;
    top: 0;
    background: #f8fafc;
    padding: 0.625rem 0.875rem;
    border-bottom: 1px solid var(--line);
    text-align: left;
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--muted);
    white-space: nowrap;
  }
  .table tbody td {
    padding: 0.7rem 0.875rem;
    border-bottom: 1px solid #eef2f6;
    vertical-align: middle;
  }
  .table tbody tr:last-child td {
    border-bottom: 0;
  }
  .table tbody tr:hover td {
    background: #f8fafc;
  }
  .table tbody tr.is-flagged td:first-child {
    box-shadow: inset 3px 0 0 #f59e0b;
  }
  .table .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
  }

  /* ---------- reproductor y saltos */
  .seek {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    height: 1.5rem;
    padding: 0 0.5rem;
    border-radius: 0.375rem;
    border: 1px solid var(--brand-200);
    background: var(--brand-50);
    color: var(--brand-700);
    font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
    font-size: 0.75rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color 0.15s;
  }
  .seek:hover {
    background: var(--brand-100);
  }
  .seek-red {
    border-color: #fecaca;
    background: #fff;
    color: var(--bad);
  }
  .seek-red:hover {
    background: var(--bad-bg);
  }
  .timeline {
    position: relative;
    height: 1.25rem;
  }
  .timeline::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    height: 4px;
    margin-top: -2px;
    border-radius: 9999px;
    background: #e8eef4;
  }
  .timeline-progress {
    position: absolute;
    left: 0;
    top: 50%;
    height: 4px;
    margin-top: -2px;
    border-radius: 9999px;
    background: var(--brand-200);
    width: 0;
    pointer-events: none;
  }
  .tick {
    position: absolute;
    top: 50%;
    width: 0.75rem;
    height: 0.75rem;
    margin: -0.375rem 0 0 -0.375rem;
    border-radius: 9999px;
    border: 2px solid #fff;
    background: var(--brand-600);
    box-shadow: 0 0 0 1px rgb(15 23 42 / 0.12);
    cursor: pointer;
    transition: transform 0.1s;
  }
  .tick:hover,
  .tick:focus-visible {
    transform: scale(1.35);
    z-index: 2;
  }
  .tick-alert {
    background: #dc2626;
    width: 0.875rem;
    height: 0.875rem;
    margin: -0.4375rem 0 0 -0.4375rem;
    z-index: 1;
  }
  .tick-low {
    background: #f59e0b;
  }
  audio {
    height: 2.5rem;
  }

  /* ---------- citas, transcripción */
  .quote {
    border-left: 3px solid var(--brand-200);
    padding: 0.125rem 0 0.125rem 0.75rem;
    color: #1e293b;
    font-style: italic;
  }
  .utt {
    display: grid;
    grid-template-columns: 3.75rem minmax(0, 1fr);
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    border-radius: 0.5rem;
    transition: background-color 0.2s;
  }
  .utt-agent {
    background: #f6f9fc;
  }
  .utt.is-playing {
    background: #fef9c3;
    box-shadow: inset 3px 0 0 #eab308;
  }
  .utt-time {
    font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
    font-size: 0.75rem;
    color: #94a3b8;
    text-align: left;
    padding-top: 0.15rem;
    cursor: pointer;
    font-variant-numeric: tabular-nums;
  }
  .utt-time:hover {
    color: var(--brand-700);
  }
  .speaker {
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.06em;
  }

  /* ---------- varios */
  .avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 9999px;
    background: var(--brand-100);
    color: var(--brand-800);
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.02em;
  }
  .kpi-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 0.625rem;
    background: var(--brand-50);
    color: var(--brand-700);
  }
  .empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 3rem 1rem;
    text-align: center;
    color: var(--muted);
    font-size: 0.875rem;
  }
  .empty-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 3rem;
    height: 3rem;
    border-radius: 9999px;
    background: #f1f5f9;
    color: #94a3b8;
  }
  .dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 2rem 1rem;
    border: 2px dashed var(--line-strong);
    border-radius: 0.75rem;
    background: #f8fafc;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s, background-color 0.15s;
  }
  .dropzone:hover,
  .dropzone.is-over {
    border-color: var(--brand-600);
    background: var(--brand-50);
  }
  .flash {
    display: flex;
    align-items: flex-start;
    gap: 0.625rem;
    padding: 0.75rem 1rem;
    border-radius: 0.625rem;
    border: 1px solid #a7f3d0;
    background: var(--ok-bg);
    color: #065f46;
    font-size: 0.875rem;
  }
  .htmx-request .htmx-indicator,
  .htmx-request.htmx-indicator {
    opacity: 1;
  }
  .htmx-indicator {
    opacity: 0;
    transition: opacity 0.2s;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}
