/* =========================
   DESIGN SYSTEM PRO (STABLE VERSION + FIX PRO)
========================= */

:root {
    --bg: #0b0f19;
    --bg-gradient: radial-gradient(circle at top, rgba(59,130,246,0.18), transparent 70%);

    --card: rgba(17, 24, 39, 0.75);
    --card-strong: rgba(17, 24, 39, 0.9);
    --card-soft: rgba(31, 41, 55, 0.6);

    --text: #e5e7eb;
    --text-muted: rgba(229, 231, 235, 0.7);

    --accent: #3b82f6;
    --accent-dark: #2563eb;

    --border: rgba(255,255,255,0.08);

    --radius: 14px;
    --radius-sm: 10px;
    --radius-lg: 18px;

    --shadow: 0 12px 30px rgba(0,0,0,0.45);
    --shadow-lg: 0 25px 60px rgba(0,0,0,0.55);

    --transition: 0.25s ease;

    --z-header: 50;
    --z-modal: 1000;
    --z-toast: 1100;
    --z-panel: 1200;
}

/* =========================
   LIGHT MODE
========================= */

body.light {
    --bg: #f8fafc;
    --card: rgba(255,255,255,0.9);
    --card-soft: #f1f5f9;

    --text: #0f172a;
    --text-muted: rgba(15, 23, 42, 0.7);

    --accent: #2563eb;
    --border: rgba(0,0,0,0.08);

    --shadow: 0 12px 30px rgba(0,0,0,0.08);
}

/* =========================
   BASE
========================= */

* {
    box-sizing: border-box;
    scroll-behavior: smooth;
}

body {
    margin: 0;
    font-family: system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    transition: var(--transition);
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    background: var(--bg-gradient);
    pointer-events: none;
}

/* =========================
   APP
========================= */

.app {
    max-width: 1200px;
    margin: auto;
    padding: 20px;
}

/* =========================
   HEADER
========================= */

.header {
    position: sticky;
    top: 0;
    z-index: var(--z-header);

    display: flex;
    justify-content: space-between;
    align-items: center;

    padding: 14px 0;
    margin-bottom: 20px;

    background: var(--bg);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(10px);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-sm);
}

.top-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* =========================
   SEARCH
========================= */

#search {
    width: 100%;
    padding: 14px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    outline: none;
}

#search:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(59,130,246,0.2);
}

/* =========================
   GRID
========================= */

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

/* =========================
   CARD
========================= */

.card {
    position: relative;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: var(--transition);
}

.card:hover {
    transform: translateY(-6px);
    box-shadow: var(--shadow-lg);
}

.card-img {
    height: 140px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--card-soft);
}

.card-img img {
    max-width: 90%;
    max-height: 110px;
}

.card-footer {
    text-align: center;
    padding: 10px;
    font-size: 13px;
    color: var(--text-muted);
}

/* =========================
   OVERLAY
========================= */

.overlay {
    position: absolute;
    inset: 0;
    display: flex;
    gap: 10px;
    justify-content: center;
    align-items: center;

    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(8px);

    opacity: 0;
    transition: var(--transition);
}

.card:hover .overlay {
    opacity: 1;
}

.overlay button {
    padding: 8px 12px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: white;
}

/* =========================
   MODAL
========================= */

.modal {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);

    display: none;
    justify-content: center;
    align-items: center;

    background: rgba(0,0,0,0.85);
}

.modal.active {
    display: flex;
}

.modal img {
    max-width: 90%;
    max-height: 80vh;
}

/* =========================
   TOAST
========================= */

.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: var(--z-toast);

    background: var(--accent);
    color: white;
    padding: 12px 18px;
    border-radius: var(--radius);

    opacity: 0;
    transition: var(--transition);
}

.toast.show {
    opacity: 1;
}

/* =========================
   FAB
========================= */

.fab {
    position: fixed;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: white;
}

.fab.ai { bottom: 20px; right: 20px; }
.fab.notes { bottom: 20px; right: 90px; }

/* =========================
   PANELS FIX PRO (AQUÍ ESTABA EL PROBLEMA REAL)
========================= */

.ai-panel,
.notes-panel,
#masivoPanel,
#unificadoPanel,
#cartaPanel {
    position: fixed;
    z-index: var(--z-panel);

    display: none;
    flex-direction: column;

    width: min(420px, 92vw);
    max-height: 80vh;

    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);

    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);

    box-shadow: var(--shadow);
    backdrop-filter: blur(14px);
    overflow: hidden;
}

.ai-panel.active,
.notes-panel.active,
#masivoPanel.active,
#unificadoPanel.active,
#cartaPanel.active {
    display: flex;
}

/* HEADER PANEL */
.ai-header,
.notes-header {
    display: flex;
    justify-content: space-between;
    padding: 12px;
    border-bottom: 1px solid var(--border);
}

/* BODY */
.panel-body {
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
}

/* INPUTS */
.panel-body input,
.panel-body textarea {
    padding: 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--card-soft);
    color: var(--text);
}

/* =========================
   AI CHAT FIX
========================= */

.ai-messages {
    flex: 1;
    padding: 10px;
    overflow-y: auto;
    font-size: 13px;
}

/* =========================
   MENU
========================= */

.menu-container {
    position: relative;
}

.menu-dropdown {
    position: absolute;
    right: 0;
    top: 45px;
    display: none;
    flex-direction: column;

    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.menu-dropdown.active {
    display: flex;
}

.menu-dropdown button {
    padding: 10px;
    background: transparent;
    border: none;
    color: var(--text);
}

/* =========================
   MICRO INTERACTIONS (PRO FEEL)
========================= */

button, .card, .overlay button {
    transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

button:active {
    transform: scale(0.96);
}

.card:active {
    transform: translateY(-2px) scale(0.99);
}

.overlay button:hover {
    transform: translateY(-2px);
}

/* =========================
   SCROLL POLISH
========================= */

::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-thumb {
    background: var(--card-soft);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

/* =========================
   GLASS IMPROVEMENT
========================= */

.ai-panel,
.notes-panel,
#masivoPanel,
#unificadoPanel,
#cartaPanel {
    border: 1px solid rgba(255,255,255,0.12);
    box-shadow: 0 30px 80px rgba(0,0,0,0.6);
}

#search {
    transition: all 0.2s ease;
}

#search:focus {
    transform: scale(1.01);
}

body::before {
    opacity: 0.7;
}

@media (max-width: 768px) {
    .card:hover {
        transform: none;
    }

    .overlay {
        opacity: 1;
        background: rgba(0,0,0,0.25);
    }
}

/* =========================
   LOGOUT BUTTON
========================= */

#logoutBtn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    font-size: 18px;

    display: flex;
    align-items: center;
    justify-content: center;

    transition: var(--transition);
}

/* claro */
body.light #logoutBtn {
    background: #ef4444;
    color: white;
}

/* oscuro */
body:not(.light) #logoutBtn {
    background: #7f1d1d;
    color: white;
}