/* ── Variables ──────────────────────────────────────────────── */
:root {
    --sidebar-w:  230px;
    --primary:    #2563eb;
    --primary-d:  #1d4ed8;
    --sidebar-bg: #0f172a;
    --bg:         #f1f5f9;
    --surface:    #ffffff;
    --border:     #e2e8f0;
    --text:       #1e293b;
    --muted:      #64748b;
    --radius:     10px;
    --shadow:     0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.05);
}

/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    min-height: 100%;
}
a { color: inherit; text-decoration: none; }
code {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    background: #f1f5f9;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 12px;
    color: var(--primary);
}

/* ── Layout ─────────────────────────────────────────────────── */
.cb-layout { display: flex; min-height: 100vh; }

/* ── Sidebar ────────────────────────────────────────────────── */
.cb-sidebar {
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    overflow-y: auto;
}
.cb-sidebar__logo {
    padding: 22px 20px 18px;
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid rgba(255,255,255,.06);
    letter-spacing: -.01em;
}
.cb-nav { padding: 10px 0; flex: 1; }
.cb-nav__item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 18px;
    color: #94a3b8;
    font-size: 13.5px;
    font-weight: 500;
    transition: color .15s, background .15s;
    border-left: 3px solid transparent;
    margin: 1px 0;
}
.cb-nav__item:hover { color: #fff; background: rgba(255,255,255,.05); }
.cb-nav__item.active {
    color: #fff;
    background: rgba(37,99,235,.25);
    border-left-color: var(--primary);
}
.cb-nav__item svg { width: 16px; height: 16px; flex-shrink: 0; }
.cb-sidebar__bottom {
    padding: 0 0 12px;
}
.cb-sidebar__sep {
    height: 1px;
    background: rgba(255,255,255,.08);
    margin: 0 0 8px;
}
.cb-sidebar__link {
    display: flex;
    align-items: center;
    gap: 7px;
    color: #64748b;
    font-size: 13px;
    font-weight: 500;
    transition: color .15s;
    padding: 8px 18px;
}
.cb-sidebar__link:hover { color: #94a3b8; }

/* ── Main ───────────────────────────────────────────────────── */
.cb-main { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; }
.cb-topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 14px 32px;
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 12px;
}
.cb-topbar__title { font-size: 16px; font-weight: 700; color: var(--text); }
.cb-content { padding: 28px 32px; flex: 1; width: 100%; }

/* ── Cards ──────────────────────────────────────────────────── */
.cb-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.cb-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow);
    border-top: 3px solid var(--primary);
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.cb-card--green  { border-color: #10b981; }
.cb-card--orange { border-color: #f59e0b; }
.cb-card--purple { border-color: #8b5cf6; }
.cb-card--rose   { border-color: #f43f5e; }
.cb-card--alt    { background: #94a3b8; }
.cb-card--alt .cb-card__lbl { color: #fff; }
.cb-card--alt .cb-card__val { color: #1e293b; }
.cb-card__icon { line-height: 0; margin-bottom: 2px; }
.cb-card__val  { font-size: 30px; font-weight: 800; line-height: 1; }
.cb-card__lbl  {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--muted);
}
.cb-lbl-short { display: none; }
.cb-lbl-full  { display: inline; }

/* ── Panel ──────────────────────────────────────────────────── */
.cb-panel {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 24px;
    border: 1px solid var(--border);
    overflow: hidden;
}
.cb-panel__head {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
.cb-panel__title { font-size: 13.5px; font-weight: 600; }
.cb-panel__body  { padding: 20px; }

/* ── Table ──────────────────────────────────────────────────── */
.cb-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.cb-table th {
    padding: 9px 16px;
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--muted);
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.cb-table td {
    padding: 11px 16px;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
}
.cb-table tr:last-child td { border-bottom: none; }
.cb-table tbody tr:hover { background: #f8fafc; }
.cb-table .muted { color: var(--muted); font-size: 12px; }

/* ── Badge ──────────────────────────────────────────────────── */
.cb-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #eff6ff;
    color: var(--primary);
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 20px;
    white-space: nowrap;
}
.cb-badge--green { background: #d1fae5; color: #059669; }
.cb-badge--gray  { background: #f1f5f9; color: var(--muted); }

/* ── Button ─────────────────────────────────────────────────── */
.cb-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 7px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all .15s;
    border: none;
    white-space: nowrap;
    font-family: inherit;
}
.cb-btn--primary { background: var(--primary); color: #fff; }
.cb-btn--primary:hover { background: var(--primary-d); }
.cb-btn--primary:disabled { background: #93c5fd; cursor: not-allowed; }
.cb-btn--ghost {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
}
.cb-btn--ghost:hover { background: var(--bg); color: var(--text); border-color: #cbd5e1; }
.cb-btn--sm { padding: 5px 10px; font-size: 12px; }

/* ── Search ─────────────────────────────────────────────────── */
.cb-search-form { display: flex; gap: 8px; align-items: center; }
.cb-search-input {
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 6px 12px;
    font-size: 13px;
    font-family: inherit;
    color: var(--text);
    background: var(--bg);
    outline: none;
    transition: border-color .2s;
    width: 220px;
}
.cb-search-input:focus { border-color: var(--primary); background: #fff; }

/* ── Thread ─────────────────────────────────────────────────── */
.cb-thread { display: flex; flex-direction: column; gap: 16px; }
.cb-bubble-wrap {
    display: flex;
    flex-direction: column;
    max-width: 78%;
}
.cb-bubble-wrap.user { align-self: flex-end; align-items: flex-end; }
.cb-bubble-wrap.assistant { align-self: flex-start; align-items: flex-start; }
.cb-bubble__meta {
    font-size: 11px;
    color: var(--muted);
    margin-bottom: 4px;
    font-weight: 500;
}
.cb-bubble {
    padding: 11px 15px;
    border-radius: 14px;
    line-height: 1.6;
    font-size: 13.5px;
    word-break: break-word;
}
.cb-bubble--user {
    background: var(--primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.cb-bubble--assistant {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
    box-shadow: var(--shadow);
}

/* ── Textarea ───────────────────────────────────────────────── */
.cb-textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    font-family: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.65;
    color: var(--text);
    background: #f8fafc;
    resize: vertical;
    min-height: 340px;
    transition: border-color .2s, background .2s;
    outline: none;
}
.cb-textarea:focus { border-color: var(--primary); background: #fff; }

/* ── Pagination ─────────────────────────────────────────────── */
.cb-pagination {
    display: flex;
    gap: 4px;
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    align-items: center;
    flex-wrap: wrap;
}
.cb-page-btn {
    min-width: 32px; height: 32px;
    padding: 0 8px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--muted);
    transition: all .15s;
    text-decoration: none;
}
.cb-page-btn:hover { border-color: var(--primary); color: var(--primary); }
.cb-page-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ── Toast ──────────────────────────────────────────────────── */
.cb-toast {
    position: fixed;
    bottom: 24px; right: 24px;
    background: #1e293b;
    color: #fff;
    padding: 12px 18px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    box-shadow: 0 8px 24px rgba(0,0,0,.2);
    z-index: 9999;
    transform: translateY(12px);
    opacity: 0;
    transition: all .25s ease;
    pointer-events: none;
    max-width: 320px;
}
.cb-toast.show { transform: translateY(0); opacity: 1; }
.cb-toast--success { border-left: 4px solid #10b981; }
.cb-toast--error   { border-left: 4px solid #ef4444; }

/* ── Empty ──────────────────────────────────────────────────── */
.cb-empty { text-align: center; padding: 60px 20px; color: var(--muted); }

/* ── Nav badge ──────────────────────────────────────────────── */
.cb-nav__badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #f59e0b;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 10px;
    margin-left: 4px;
}

/* ── Sidebar widget ─────────────────────────────────────────── */
.cb-sidebar__widget {
    margin: 0 12px 12px;
    background: rgba(251,191,36,.1);
    border: 1px solid rgba(251,191,36,.25);
    border-radius: 8px;
    padding: 12px 14px;
}
.cb-sidebar__widget-title {
    font-size: 11px;
    font-weight: 700;
    color: #fbbf24;
    text-transform: uppercase;
    letter-spacing: .05em;
    margin-bottom: 8px;
}
.cb-sidebar__widget-item {
    display: block;
    font-size: 11.5px;
    color: #94a3b8;
    line-height: 1.5;
    margin-bottom: 5px;
    padding: 4px 0;
    border-bottom: 1px solid rgba(255,255,255,.05);
    transition: color .15s;
}
.cb-sidebar__widget-item:hover { color: #e2e8f0; }
.cb-sidebar__widget-link {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: #fbbf24;
    margin-top: 8px;
    transition: opacity .15s;
}
.cb-sidebar__widget-link:hover { opacity: .8; }

/* ── User detail (click para ver email) ────────────────────── */
.cb-user-detail { display: inline-block; }
.cb-user-detail summary {
    font-weight: 600;
    cursor: pointer;
    list-style: none;
    color: var(--text);
    white-space: nowrap;
}
.cb-user-detail summary::-webkit-details-marker { display: none; }
.cb-user-detail summary::marker { display: none; }
.cb-user-detail summary:hover { color: var(--primary); }
.cb-user-detail .cb-user-email {
    display: block;
    font-size: 11.5px;
    color: var(--muted);
    margin-top: 2px;
    white-space: nowrap;
}

/* ── Tabs ───────────────────────────────────────────────────── */
.cb-tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border); }
.cb-tab {
    padding: 8px 16px;
    font-size: 13.5px;
    font-weight: 500;
    color: var(--muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color .15s, border-color .15s;
    display: flex;
    align-items: center;
}
.cb-tab:hover { color: var(--text); }
.cb-tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* ── Improvement card ───────────────────────────────────────── */
.cb-improvement { border-left: 4px solid #f59e0b; }
.cb-improvement--resolved { border-left-color: #10b981; }

/* ── Hamburger button ───────────────────────────────────────── */
.cb-hamburger {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    cursor: pointer;
    background: none;
    border: none;
    padding: 5px;
    border-radius: 6px;
    transition: background .15s;
}
.cb-hamburger:hover { background: var(--bg); }
.cb-hamburger span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--text);
    border-radius: 2px;
    transition: transform .25s, opacity .25s;
}

/* ── Sidebar overlay (mobile) ───────────────────────────────── */
.cb-sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 99;
    backdrop-filter: blur(1px);
}
.cb-sidebar-overlay.open { display: block; }

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 768px) {
    /* Evitar scroll horizontal a nivel de página */
    html, body { overflow-x: hidden; max-width: 100%; }

    /* Mostrar hamburguesa */
    .cb-hamburger { display: flex; }

    /* Sidebar: oculto por defecto, desliza desde la izquierda */
    .cb-sidebar {
        transform: translateX(-100%);
        transition: transform .25s ease;
        z-index: 200;
        height: 100dvh;       /* toda la pantalla exacta */
        overflow-y: auto;     /* scroll interno si el contenido no cabe */
        overflow-x: hidden;
    }
    .cb-sidebar.open { transform: translateX(0); }

    /* Main ocupa todo el ancho, sin desbordamiento */
    .cb-main { margin-left: 0; overflow-x: hidden; }

    /* Topbar y contenido con menos padding */
    .cb-topbar { padding: 12px 16px; }
    .cb-content { padding: 3px 3px 16px; overflow-x: hidden; }

    /* Cards: 5 columnas → 1 fila */
    .cb-cards { grid-template-columns: repeat(5, 1fr); gap: 4px; }
    .cb-card  { padding: 8px 4px; gap: 4px; border-top-width: 2px; }
    .cb-card__icon { display: none; }
    .cb-card__val  { font-size: 20px; }
    .cb-card__lbl  { font-size: 9px; letter-spacing: 0; }
    /* Etiquetas: versión corta en móvil */
    .cb-lbl-full  { display: none; }
    .cb-lbl-short { display: inline; }

    /* Panel: contiene el overflow */
    .cb-panel { overflow: hidden; }

    /* Tabla actúa como bloque con scroll propio */
    .cb-table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        width: 100%;
    }
    /* Cabeceras pueden romper línea para no forzar ancho */
    .cb-table th { white-space: normal; min-width: 70px; }
    /* Celdas en 1 línea — la tabla scrollea horizontalmente si hace falta */
    .cb-table td { white-space: nowrap; }

    /* Panel head: apila en columna si no cabe */
    .cb-panel__head {
        padding: 12px 16px;
        gap: 8px;
        flex-direction: column;
        align-items: flex-start;
    }
    .cb-search-form { width: 100%; }
    .cb-search-input { flex: 1; width: 100%; min-width: 0; }

    .cb-panel__body  { padding: 14px 16px; }

    /* Paginación más compacta */
    .cb-pagination { padding: 12px 16px; }

    /* Thread: burbujas a ancho casi completo */
    .cb-bubble-wrap { max-width: 92%; }

    /* Mejoras: textarea más corta */
    .cb-textarea { min-height: 180px; }

    /* Ocultar columnas opcionales en tabla */
    .cb-table .cb-hide-mobile { display: none; }
    .cb-hide-mobile { display: none; }

    /* Cabecera "Mensajes" → "Msj" */
    .cb-table .th-msgs { font-size: 0; }
    .cb-table .th-msgs::after { content: "Msj"; font-size: 11px; font-weight: 600; letter-spacing: .05em; }

    /* Preview: una línea, texto alineado a la derecha para ver el final */
    .cb-preview-cell {
        white-space: nowrap;
        overflow: hidden;
        max-width: 160px;
    }

    /* Sidebar: compactar para que todo quepa en una pantalla */
    .cb-sidebar__logo { padding: 16px 20px 14px; }
    .cb-nav { padding: 6px 0; }
    .cb-nav__item { padding: 8px 18px; }
    .cb-sidebar__widget { margin: 0 10px 8px; padding: 10px 12px; }
    .cb-sidebar__widget-item { font-size: 11px; }
    .cb-sidebar__bottom { padding: 0 0 8px; }
}

@media (max-width: 480px) {
    .cb-topbar__title { font-size: 14px; }
}
