/* =============================================================================
   UPLABS AI — Design tokens (portado desde frontend-saas-uplabs-v3/src/styles/globals.css)
   =============================================================================
   Proyecto SIN build system (HTML/JS estático, sin Tailwind) — por eso estos tokens
   se exponen como variables CSS puras (mismos valores HSL que el SaaS) más un set
   mínimo de clases utilitarias que replican los primitives (Button/Card/Badge/Input)
   del SaaS, para que este softphone use el MISMO lenguaje visual sin necesitar React
   ni un pipeline de build.

   Cómo usar:
     <link rel="stylesheet" href="design/tokens.css">
   (después de linkear las fuentes, ver design/README.md)

   NO edites los valores de color/tipografía acá directamente si lo que quieres es
   cambiar el tema global — esos valores viven en el SaaS
   (`frontend-saas-uplabs-v3/src/styles/globals.css`) y este archivo es un espejo.
   Si el SaaS cambia esos valores, hay que volver a copiarlos acá.
   ============================================================================= */

:root {
    /* shadcn tokens — modo claro (HSL sin la función hsl(), igual que el SaaS) */
    --background: 0 0% 100%;
    --foreground: 222.2 84% 4.9%;
    --card: 0 0% 100%;
    --card-foreground: 222.2 84% 4.9%;
    --popover: 0 0% 100%;
    --popover-foreground: 222.2 84% 4.9%;
    --primary: 217 91% 60%;
    --primary-foreground: 0 0% 100%;
    --secondary: 210 40% 96.1%;
    --secondary-foreground: 222.2 47.4% 11.2%;
    --muted: 210 40% 96.1%;
    --muted-foreground: 215.4 16.3% 46.9%;
    --accent: 210 40% 96.1%;
    --accent-foreground: 222.2 47.4% 11.2%;
    --destructive: 0 72% 48%;
    --destructive-foreground: 210 40% 98%;
    --border: 214.3 31.8% 91.4%;
    --input: 214.3 31.8% 91.4%;
    --ring: 217 91% 60%;
    --radius: 0.5rem;

    --layout-bg: 220 14% 94%;

    /* Status semánticos */
    --status-active: 142 70% 36%;
    --status-inactive: 215 16% 45%;
    --status-pending: 38 90% 40%;
    --status-error: 0 72% 48%;

    /* Tipografía — nombres por rol (Sora = uplabs, Inter = uplabs-body) */
    --font-uplabs: "Sora", system-ui, sans-serif;
    --font-uplabs-body: "Inter", system-ui, sans-serif;

    /* Escala tipográfica UPLABS AI Brand Manual v1.0 (portada de tailwind.config.ts del SaaS,
       fontSize.display/h1/h2/h3/body/body-sm/caption) — ver clases .text-* más abajo. */
    --text-display-size: 1.875rem; /* 30px */
    --text-h1-size: 1.5rem;        /* 24px */
    --text-h2-size: 1.25rem;       /* 20px */
    --text-h3-size: 0.875rem;      /* 14px */
    --text-body-size: 0.875rem;    /* 14px */
    --text-body-sm-size: 0.75rem;  /* 12px */
    --text-caption-size: 0.7rem;   /* 11.2px */

    /* Paleta de marca UPLABS */
    --uplabs-dark: #05000e;
    --uplabs-charcoal: #1a1a1c;
    --uplabs-blue: #3b82f6;
}

/* Modo oscuro — activar agregando la clase `dark` al <html> o <body>
   (o cambiar el selector a `@media (prefers-color-scheme: dark)` si se prefiere
   que siga el tema del sistema en vez de un toggle manual). */
.dark {
    --background: 222 13% 13%;
    --foreground: 210 17% 93%;
    --card: 222 13% 15%;
    --card-foreground: 210 17% 93%;
    --popover: 222 13% 15%;
    --popover-foreground: 210 17% 93%;
    --primary: 217 91% 60%;
    --primary-foreground: 0 0% 100%;
    --secondary: 222 10% 20%;
    --secondary-foreground: 210 17% 93%;
    --muted: 222 10% 20%;
    --muted-foreground: 215 12% 55%;
    --accent: 222 10% 20%;
    --accent-foreground: 210 17% 93%;
    --destructive: 0 68% 52%;
    --destructive-foreground: 210 40% 98%;
    --border: 222 10% 20%;
    --input: 222 10% 20%;
    --ring: 217 91% 60%;

    --status-active: 142 70% 50%;
    --status-inactive: 215 16% 62%;
    --status-pending: 38 90% 55%;
    --status-error: 0 75% 62%;

    --layout-bg: 222 15% 8%;
}

/* ── Base ─────────────────────────────────────────────────────────────────── */

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    background: hsl(var(--background));
    color: hsl(var(--foreground));
    font-family: var(--font-uplabs);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

p,
span,
label,
li,
td,
th,
input,
textarea,
select,
button {
    font-family: var(--font-uplabs-body);
}

h1,
h2,
h3,
h4 {
    font-family: var(--font-uplabs);
    margin: 0;
}

/* Scrollbar delgada (igual criterio que el SaaS) */
* {
    scrollbar-width: thin;
    scrollbar-color: hsl(var(--muted-foreground) / 0.25) transparent;
}
*::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
*::-webkit-scrollbar-thumb {
    background-color: hsl(var(--muted-foreground) / 0.2);
    border-radius: 9999px;
}

/* ── Layout de página (equivalente simplificado al "island layout" del SaaS) ── */

/* `min-height` (no `height` fija) a propósito: esta pantalla vive dentro de un iframe/widget
   cuyo tamaño lo decide quien lo embebe (ver FloatingCallWidget.tsx del SaaS: hoy 420px x
   70vh, pero puede cambiar a algo más bajo y ancho). Con `min-height` el contenido corto
   queda centrado verticalmente igual que antes, pero si algún estado necesita más alto que
   el disponible, el documento crece y es el iframe/navegador el que scrollea de forma
   normal — NO uses `overflow: auto` acá: eso encierra un scroll anidado dentro de la propia
   página en vez de dejar que el contenedor real (iframe o ventana) lo maneje. */
.page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: clamp(0.75rem, 4vh, 2.5rem) 1rem;
    background: hsl(var(--layout-bg));
    overflow: auto;
}

/* ── Card (equivalente a shared/primitives/card.tsx) ─────────────────────────
   Card: rounded-xl border border-border bg-card text-card-foreground shadow-sm
   CardContent default: p-6 (acá compactado, ver DESIGN.md "Compact CRM panels").
   max-width subido de 26rem a 34rem: más horizontal, con espacio para que la barra de
   llamada (nombre + estado + timer + colgar) entre en una sola fila en vez de apilarse. */

.card {
    width: 100%;
    max-width: 34rem;
    background: hsl(var(--card));
    color: hsl(var(--card-foreground));
    border: 1px solid hsl(var(--border));
    border-radius: 0.75rem; /* rounded-xl */
    box-shadow:
        0 1px 2px 0 rgb(0 0 0 / 0.05); /* shadow-sm */
    padding: 1.25rem 1.5rem;
}

.card-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.875rem;
}

/* "Icon box" — mismo patrón que StatCard.tsx en el SaaS: fondo tintado al 10%, ícono en
   color primary sólido, sin degradado. Antes duplicado idéntico en index.html y
   marcador/index.html (ahí solo queda `.logo { width/height }` si el tamaño difiere). */
.icon-box {
    width: 40px; height: 40px;
    border-radius: 0.5rem;
    background: hsl(var(--primary) / .1);
    display: flex; align-items: center; justify-content: center;
    color: hsl(var(--primary));
    flex: none;
}
.icon-box .icon { width: 20px; height: 20px; }

/* Identificador de llamada (Call-ID SIP) en fuente monoespaciada — antes duplicado
   idéntico en index.html y marcador/index.html. */
.call-id {
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    color: hsl(var(--primary)); font-weight: 600;
    background: hsl(var(--primary) / .12); padding: 2px 7px; border-radius: 6px;
}

/* Barra de llamada horizontal — nombre a la izquierda, estado/timer al medio, acción a la
   derecha, siempre en una sola fila (pensado para un widget más ancho y bajo que alto, no
   una tarjeta vertical). Reemplaza el layout apilado anterior (nombre, timer y estado cada
   uno en su propia línea).
   Nota sobre flex-wrap: usar `wrap` acá es una trampa — con multi-línea, el navegador decide
   qué entra en cada línea según el tamaño NATURAL (sin encoger) de cada ítem, no según cuánto
   podría encoger con flex-shrink. Con el nombre siendo el único ítem que puede achicarse (los
   demás son de ancho fijo), `wrap` termina mandando el botón entero a una segunda línea en vez
   de dejar que el nombre se trunque con "…" — que es lo que realmente queremos. Por eso NO hay
   `flex-wrap` acá (default `nowrap`): `.call-who` usa `flex-basis: 0%` para que se lleve todo
   el espacio sobrante y el nombre largo trunque ahí, dejando timer/botón siempre visibles. */
.call-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}
.call-who {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
    flex: 1 1 0%;
}
.call-who .peer {
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0; /* sin esto, un nombre largo no trunca — se desborda en vez de cortarse */
}
.call-mid {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    flex: 0 1 auto;
    min-width: 0;
    white-space: nowrap;
    font-size: 0.8125rem;
    color: hsl(var(--muted-foreground));
    font-weight: 600;
}
.call-mid .timer { font-variant-numeric: tabular-nums; }
.call-row .btn {
    flex: 0 0 auto;
    width: auto;
    height: 2.25rem;
    padding: 0 0.875rem;
    margin: 0;
}

/* Estado de conexión/llamada — antes duplicado idéntico en index.html y marcador/index.html.
   Estilizado por ID (no por clase) a propósito: `updateStatus()` en webrtc-shared.js hace
   `status.className = className` (reemplazo completo, no `classList.add`), así que una clase
   base tipo `.call-status` en el HTML se perdería en cada cambio de estado. El margen
   (único valor que difiere entre las dos páginas) se define localmente en cada una. */
#status {
    padding: 11px 14px;
    border-radius: 10px;
    text-align: center;
    font-weight: 600;
    font-size: 13.5px;
    font-family: var(--font-uplabs-body);
    border: 1px solid transparent;
    transition: all .25s ease;
}
#status.disconnected { background: hsl(var(--status-error) / .12);   color: hsl(var(--status-error));   border-color: hsl(var(--status-error) / .3); }
#status.connected    { background: hsl(var(--status-active) / .12); color: hsl(var(--status-active));   border-color: hsl(var(--status-active) / .3); }
#status.calling      { background: hsl(var(--status-pending) / .12);color: hsl(var(--status-pending)); border-color: hsl(var(--status-pending) / .3); }
#status .icon { vertical-align: -3px; margin-right: 6px; width: 16px; height: 16px; }

/* Calcado de CardTitle real (shared/primitives/card.tsx): text-2xl font-semibold leading-none
   tracking-tight — antes tenía un tamaño/peso inventado (18px/700) que no correspondía. */
.card-title {
    font-size: 1.5rem;
    font-weight: 600;
    line-height: 1;
    letter-spacing: -0.025em;
    color: hsl(var(--foreground));
}

/* Calcado de CardDescription real: text-sm text-muted-foreground. */
.card-subtitle {
    font-size: 0.875rem;
    color: hsl(var(--muted-foreground));
    margin-top: 0.125rem;
}

/* ── Button (equivalente a shared/primitives/button.tsx) ─────────────────────
   Variantes/tamaños calcados 1:1 de buttonVariants (cva) del SaaS. */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    white-space: nowrap;
    border-radius: 0.375rem; /* rounded-md */
    font-size: 0.875rem;
    font-weight: 500;
    font-family: var(--font-uplabs-body);
    border: none;
    cursor: pointer;
    transition: opacity 0.15s, background-color 0.15s, color 0.15s;
    height: 2.5rem; /* size=default */
    padding: 0 1rem;
}
.btn:disabled {
    pointer-events: none;
    opacity: 0.5;
}
.btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px hsl(var(--ring));
}

.btn-default {
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
}
.btn-default:hover {
    opacity: 0.9;
}

.btn-secondary {
    background: hsl(var(--secondary));
    color: hsl(var(--secondary-foreground));
}
.btn-secondary:hover {
    opacity: 0.9;
}

.btn-outline {
    background: hsl(var(--background));
    color: hsl(var(--foreground));
    border: 1px solid hsl(var(--border));
}
.btn-outline:hover {
    background: hsl(var(--accent));
    color: hsl(var(--accent-foreground));
}

.btn-destructive {
    background: hsl(var(--destructive));
    color: hsl(var(--destructive-foreground));
}
.btn-destructive:hover {
    opacity: 0.9;
}

.btn-ghost:hover {
    background: hsl(var(--accent));
    color: hsl(var(--accent-foreground));
}

.btn-sm {
    height: 2.25rem;
    padding: 0 0.75rem;
}
.btn-lg {
    height: 2.75rem;
    padding: 0 2rem;
}
.btn-icon {
    height: 2.5rem;
    width: 2.5rem;
    padding: 0;
}

/* ── Input (equivalente a shared/primitives/input.tsx) ────────────────────── */

.input {
    display: block;
    width: 100%;
    height: 2.5rem;
    border-radius: 0.375rem;
    border: 1px solid hsl(var(--input));
    background: hsl(var(--background));
    color: hsl(var(--foreground));
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    font-family: var(--font-uplabs-body);
}
.input::placeholder {
    color: hsl(var(--muted-foreground));
}
.input:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px hsl(var(--ring));
}

.field-label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 500;
    color: hsl(var(--foreground));
    margin-bottom: 0.375rem;
}

/* ── StatusBadge (equivalente a shared/components/StatusBadge.tsx) ───────────
   Pill semántico con punto de color — mismo criterio que el SaaS: active/
   inactive/pending/error, nunca colores hardcodeados fuera de estos 4. */

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    border: 1px solid transparent;
    font-size: 0.75rem;
    font-weight: 500;
    font-family: var(--font-uplabs-body);
}
.status-badge::before {
    content: "";
    width: 0.375rem;
    height: 0.375rem;
    border-radius: 9999px;
    background: currentColor;
    flex: none;
}

.status-badge.active {
    color: hsl(var(--status-active));
    background: hsl(var(--status-active) / 0.1);
    border-color: hsl(var(--status-active) / 0.2);
}
.status-badge.inactive {
    color: hsl(var(--status-inactive));
    background: hsl(var(--status-inactive) / 0.1);
    border-color: hsl(var(--status-inactive) / 0.2);
}
.status-badge.pending {
    color: hsl(var(--status-pending));
    background: hsl(var(--status-pending) / 0.1);
    border-color: hsl(var(--status-pending) / 0.2);
}
.status-badge.error {
    color: hsl(var(--status-error));
    background: hsl(var(--status-error) / 0.1);
    border-color: hsl(var(--status-error) / 0.2);
}

/* ── Icon (envoltorio para SVG estilo lucide, inline — sin dependencia de paquete) ──
   Mismos defaults que lucide-react: viewBox 0 0 24 24, stroke actual, stroke-width 2,
   redondeado en puntas y uniones. Ver design/README.md para la lista de iconos usados. */
.icon {
    width: 1em;
    height: 1em;
    flex: none;
    stroke: currentColor;
}
.icon-spin {
    animation: icon-spin 0.9s linear infinite;
}
@keyframes icon-spin {
    to { transform: rotate(360deg); }
}

/* ── Escala tipográfica de marca (equivalente a theme.fontSize en tailwind.config.ts) ──────
   Igual que el SaaS: display/h1/h2/h3 heredan Sora vía el selector de tag (h1-h4 más abajo);
   aplicar sobre un <h1>-<h4> o agregar font-uplabs a mano si es otro elemento. */
.text-display { font-size: var(--text-display-size); line-height: 1.15; font-weight: 700; letter-spacing: -0.02em; }
.text-h1      { font-size: var(--text-h1-size);       line-height: 1.25; font-weight: 700; letter-spacing: -0.015em; }
.text-h2      { font-size: var(--text-h2-size);       line-height: 1.4;  font-weight: 600; letter-spacing: -0.01em; }
.text-h3      { font-size: var(--text-h3-size);       line-height: 1.4;  font-weight: 500; }
.text-body    { font-size: var(--text-body-size);     line-height: 1.5;  font-weight: 400; }
.text-body-sm { font-size: var(--text-body-sm-size);  line-height: 1.4;  font-weight: 400; }

/* ── Utilidades de texto (subset de la escala tipográfica del SaaS) ──────── */

.text-muted {
    color: hsl(var(--muted-foreground));
}
.text-destructive {
    color: hsl(var(--destructive));
}
.text-caption {
    font-family: var(--font-uplabs-body);
    font-size: var(--text-caption-size);
    line-height: 1.2;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: hsl(var(--muted-foreground));
}
