:root {
    /* Brand */
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --accent: #f59e0b;
    --accent-secondary: #d97706;

    /* Surfaces */
    --bg-dark: #111214;
    --bg-surface: #1c1c1f;
    --bg-card: rgba(20, 20, 24, 0.85);
    --bg-elevated: rgba(28, 28, 32, 0.95);

    /* Texto — 4 niveles */
    --text-main: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #64748b;
    --text-faint: rgba(255, 255, 255, 0.35);

    /* Bordes */
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-border-focus: rgba(37, 99, 235, 0.5);
    --glass-border-elevated: rgba(255, 255, 255, 0.12);

    /* Colores semánticos */
    --color-success: #22c55e;
    --color-success-bg: rgba(34, 197, 94, 0.12);
    --color-warning: #f59e0b;
    --color-warning-bg: rgba(245, 158, 11, 0.12);
    --color-error: #ef4444;
    --color-error-bg: rgba(239, 68, 68, 0.12);

    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    overflow: hidden;
    height: 100vh;
}

.app-container {
    display: flex;
    height: 100vh;
    background: radial-gradient(circle at top right, rgba(37, 99, 235, 0.12), transparent),
        radial-gradient(circle at bottom left, rgba(245, 158, 11, 0.07), transparent);
}

/* Sidebar Styling */
.sidebar {
    width: 280px;
    background: rgba(14, 14, 17, 0.9);
    backdrop-filter: blur(12px);
    border-right: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    padding: 2rem;
    z-index: 100;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 3rem;
}

.logo-icon {
    font-size: 2rem;
    display: flex;
    align-items: center;
}

.logo-text {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    background: linear-gradient(to right, var(--primary), var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.nav-links {
    list-style: none;
}

.nav-links li {
    padding: 0.75rem 1rem;
    border-radius: 12px;
    margin-bottom: 0.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 1rem;
    color: var(--text-secondary);
    font-weight: 500;
    transition: var(--transition);
}

.nav-links li:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
}

.nav-links li.active {
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    color: white;
    border: 1px solid var(--glass-border-focus);
}

/* Main Content Area */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 2rem;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.top-bar h1 {
    font-size: 1.875rem;
    font-weight: 600;
}

.user-profile {
    background: var(--bg-card);
    padding: 0.5rem 1rem;
    border-radius: 100px;
    border: 1px solid var(--glass-border);
    font-weight: 500;
}

/* Cards & Sections */
.glass-card {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 2rem;
    margin-bottom: 2rem;
    animation: fadeIn 0.6s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Forms */
.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 500;
}

input,
textarea {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 0.75rem 1rem;
    color: white;
    font-family: inherit;
    transition: var(--transition);
}

input:focus,
textarea:focus {
    outline: none;
    border-color: var(--glass-border-focus);
    background: rgba(255, 255, 255, 0.08);
}

button {
    cursor: pointer;
    border: none;
    border-radius: 12px;
    padding: 0.75rem 1.5rem;
    font-weight: 600;
    font-family: inherit;
    transition: var(--transition);
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    border: 1px solid var(--glass-border-focus);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    border: 1px solid var(--glass-border);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--accent);
}

/* AI Results Area */
.ai-results-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 100px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-success {
    background: var(--color-success-bg);
    color: var(--color-success);
}

.badge-warning {
    background: rgba(234, 179, 8, 0.15);
    color: #eab308;
}

.badge-error {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}

.mic-btn {
    background: var(--accent);
    color: var(--bg-dark);
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.mic-btn.recording {
    background: var(--color-error);
    animation: pulse-red 1.5s infinite;
}

@keyframes pulse-red {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(255, 77, 77, 0.7);
    }

    70% {
        transform: scale(1.1);
        box-shadow: 0 0 0 10px rgba(255, 77, 77, 0);
    }

    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(255, 77, 77, 0);
    }
}

.voice-status {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
    font-weight: 500;
}

@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: auto;
        padding: 0.5rem 1rem;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        border-right: none;
        border-top: 1px solid var(--glass-border);
        position: fixed;
        bottom: 0;
        top: auto;
        background: rgba(14, 14, 17, 0.98);
        padding-bottom: env(safe-area-inset-bottom, 0.5rem);
    }

    .logo {
        display: none;
    }

    .nav-links {
        display: flex;
        width: 100%;
        justify-content: space-around;
        gap: 0;
        padding: 0;
    }

    .nav-links li {
        margin-bottom: 0;
        padding: 0.5rem;
        flex-direction: column;
        gap: 0.25rem;
        font-size: 0.65rem;
        flex: 1;
        text-align: center;
        background: none !important;
        box-shadow: none !important;
    }

    .nav-links li.active {
        color: var(--primary);
    }

    .nav-links li .nav-icon {
        font-size: 1.2rem;
    }

    .main-content {
        padding: 1rem;
        padding-bottom: 90px;
    }

    .top-bar {
        margin-bottom: 1.5rem;
        padding-top: env(safe-area-inset-top, 0);
    }

    .top-bar h1 {
        font-size: 1.4rem;
    }

    .ai-results-grid {
        grid-template-columns: 1fr;
    }

    .glass-card {
        padding: 1rem;
        border-radius: 18px;
    }

    .mic-btn {
        width: 44px;
        height: 44px;
        font-size: 1.2rem;
    }
}

/* WhatsApp Admin Styles */
.admin-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    text-align: center;
    padding: 1.5rem;
}

.stat-card h2 {
    font-size: 1.875rem;
    color: var(--accent);
    margin-top: 0.5rem;
    margin-bottom: 0.1rem;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.table-container {
    overflow-x: auto;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}

.admin-table th,
.admin-table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--glass-border);
}

.admin-table th {
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Modal Chat */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(12px);
}

.modal-content {
    margin: 5vh auto;
    width: 90%;
    max-width: 600px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    padding: 0 !important;
    overflow: hidden;
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.close-modal {
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    color: var(--text-muted);
}

.close-modal:hover {
    color: white;
}

.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    background: rgba(0, 0, 0, 0.2);
}

.message-bubble {
    max-width: 80%;
    padding: 0.75rem 1rem;
    border-radius: 18px;
    position: relative;
    font-size: 0.875rem;
    line-height: 1.4;
}

.message-bubble.user {
    align-self: flex-end;
    background: var(--primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.message-bubble.assistant {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    border: 1px solid var(--glass-border);
    border-bottom-left-radius: 4px;
}

.message-time {
    font-size: 0.7rem;
    margin-top: 0.4rem;
    opacity: 0.6;
    text-align: right;
}

/* Admin Styles */
.admin-select {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    color: white;
    font-size: 0.875rem;
    cursor: pointer;
    transition: var(--transition);
}

.admin-select:focus {
    outline: none;
    border-color: var(--primary);
}

.admin-select option {
    background: #1e293b;
    color: white;
}

/* Activity Feed */
.activity-feed-container {
    margin-top: 2rem;
}

.activity-feed-container h3 {
    margin-bottom: 1rem;
    font-size: 1.125rem;
    color: var(--text-main);
}

.activity-feed {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-height: 400px;
    overflow-y: auto;
    padding-right: 0.5rem;
}

.activity-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    transition: all 0.3s ease;
}

.activity-item:hover {
    background: rgba(255, 255, 255, 0.05);
    transform: translateX(5px);
}

.activity-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.icon-user { background: rgba(37, 99, 235, 0.1); color: #2563eb; }
.icon-assistant { background: rgba(16, 185, 129, 0.1); color: #10b981; }

.activity-content {
    flex-grow: 1;
}

.activity-content p {
    font-size: 0.875rem;
    margin: 0;
    line-height: 1.4;
}

.activity-content small {
    display: block;
    margin-top: 0.25rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.activity-phone {
    font-weight: 600;
    color: var(--accent);
    margin-right: 0.5rem;
}

.activity-feed::-webkit-scrollbar {
    width: 4px;
}

.activity-feed::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

/* =============================================
   Clases migradas desde inline styles de app.js
   ============================================= */

/* Navegación */
.nav-logout {
    margin-top: auto;
    color: var(--color-error) !important;
}

/* Auth views — login / register */
.view-card-centered {
    max-width: 400px;
    margin: 10vh auto;
}

.view-heading-centered {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-footer-text {
    margin-top: 1.5rem;
    text-align: center;
    font-size: 0.875rem;
    color: var(--text-muted);
}

.link-accent {
    color: var(--accent);
}

.link-accent:hover {
    opacity: 0.8;
}

/* Botones */
.btn-full {
    width: 100%;
}

.btn-primary {
    border: 1px solid transparent;
}

.btn-primary.btn-accent {
    background: var(--accent);
    color: var(--bg-dark);
    border-color: transparent;
}

.btn-sm {
    font-size: 0.875rem;
}

.btn-xs {
    padding: 4px 8px;
    font-size: 0.75rem;
}

.btn-danger {
    background: #ef4444;
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-danger:hover {
    background: #dc2626;
}

.search-input {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 0.45rem 0.9rem;
    color: var(--text-primary);
    font-size: 0.875rem;
    min-width: 220px;
    outline: none;
    transition: border-color 0.2s;
}

.search-input:focus {
    border-color: var(--accent);
}

.btn-group {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

/* Textos descriptivos */
.view-subtitle {
    color: var(--text-muted);
    margin: 0.5rem 0;
}

/* Dashboard — features grid */
.features-grid {
    margin-top: 1rem;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

.glass-card--feature {
    margin-bottom: 0;
    text-align: center;
    padding: 1rem;
}

.feature-icon {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.feature-desc {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Feed states */
.feed-empty {
    text-align: center;
    padding: 1rem;
    color: var(--text-muted);
}

.feed-error {
    text-align: center;
    color: var(--color-error);
}

/* Sección con header flex */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

/* AI Parser — mic button wrapper */
.form-group {
    position: relative;
}

.mic-wrapper {
    position: absolute;
    right: 10px;
    bottom: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Budget rows */
.budget-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Tablas */
.td-center {
    text-align: center;
}

/* Logo thumbnail en tabla admin */
.logo-thumb {
    height: 36px;
    max-width: 80px;
    object-fit: contain;
    border-radius: 4px;
    border: 1px solid var(--glass-border);
}

.text-muted-sm {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.admin-select--narrow {
    max-width: 160px;
}

#budgets-list {
    margin-top: 1rem;
}

#btn-parse,
#btn-create-parsed {
    margin-top: 1rem;
}

/* =============================================
   Iconos SVG del sidebar
   ============================================= */

.nav-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    opacity: 0.65;
    transition: var(--transition);
}

.nav-links li:hover .nav-icon,
.nav-links li.active .nav-icon {
    opacity: 1;
}

/* Animación de entrada escalonada del sidebar */
@keyframes slideInNav {
    from { opacity: 0; transform: translateX(-10px); }
    to   { opacity: 1; transform: translateX(0); }
}

.nav-links li {
    animation: slideInNav 0.35s ease-out both;
}

.nav-links li:nth-child(1) { animation-delay: 0.04s; }
.nav-links li:nth-child(2) { animation-delay: 0.08s; }
.nav-links li:nth-child(3) { animation-delay: 0.12s; }
.nav-links li:nth-child(4) { animation-delay: 0.16s; }
.nav-links li:nth-child(5) { animation-delay: 0.20s; }
.nav-links li:nth-child(6) { animation-delay: 0.24s; }
.nav-links li:nth-child(7) { animation-delay: 0.28s; }

/* =============================================
   Animaciones — skeleton loader y tablas
   ============================================= */

@keyframes skeleton-shimmer {
    0%   { background-position: -400px 0; }
    100% { background-position: 400px 0; }
}

.skeleton {
    background: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0.04) 25%,
        rgba(255, 255, 255, 0.09) 50%,
        rgba(255, 255, 255, 0.04) 75%
    );
    background-size: 400px 100%;
    animation: skeleton-shimmer 1.4s ease-in-out infinite;
    border-radius: 8px;
}

.skeleton-line {
    height: 14px;
    margin-bottom: 10px;
    border-radius: 4px;
}

.skeleton-line--short { width: 40%; }
.skeleton-line--mid   { width: 65%; }
.skeleton-line--long  { width: 90%; }

@keyframes rowFadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.admin-table tbody tr {
    animation: rowFadeIn 0.3s ease-out both;
}

.admin-table tbody tr:nth-child(1)  { animation-delay: 0.04s; }
.admin-table tbody tr:nth-child(2)  { animation-delay: 0.08s; }
.admin-table tbody tr:nth-child(3)  { animation-delay: 0.12s; }
.admin-table tbody tr:nth-child(4)  { animation-delay: 0.16s; }
.admin-table tbody tr:nth-child(5)  { animation-delay: 0.20s; }
.admin-table tbody tr:nth-child(6)  { animation-delay: 0.24s; }
.admin-table tbody tr:nth-child(7)  { animation-delay: 0.28s; }
.admin-table tbody tr:nth-child(8)  { animation-delay: 0.32s; }
.admin-table tbody tr:nth-child(9)  { animation-delay: 0.36s; }
.admin-table tbody tr:nth-child(10) { animation-delay: 0.40s; }

/* Hover lift en tarjetas de presupuesto */
.budget-row {
    transition: var(--transition);
}

.budget-row:hover {
    transform: translateY(-2px);
    border-color: var(--glass-border-elevated);
    background: var(--bg-elevated);
}