:root {
    --bg-color: #0b0f19;
    --panel-bg: rgba(17, 24, 39, 0.65);
    --text-primary: #f3f4f6;
    --text-muted: #9ca3af;
    --accent: #10b981; /* Premium Emerald Green */
    --accent-hover: #059669;
    --accent-glow: rgba(16, 185, 129, 0.3);
    --border: rgba(255, 255, 255, 0.08);
    --danger: #ef4444;
    --warning: #f59e0b;
    --surface-hover: rgba(255, 255, 255, 0.03);
    --input-bg: rgba(0, 0, 0, 0.2);
    --sidebar-width: 270px;
    --bg-card: rgba(31, 41, 55, 0.7);
    --border-color: rgba(255, 255, 255, 0.1);
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes fadeInSlideUp {
    from { opacity: 0; transform: translateY(15px); }
    to { opacity: 1; transform: translateY(0); }
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    display: flex;
    min-height: 100vh;
    font-size: 14.5px;
    line-height: 1.5;
    background-image: 
        radial-gradient(circle at 15% 50%, rgba(16, 185, 129, 0.1), transparent 30%),
        radial-gradient(circle at 85% 30%, rgba(59, 130, 246, 0.1), transparent 30%);
    background-attachment: fixed;
    animation: fadeInSlideUp 0.6s ease-out forwards;
    max-width: 100vw;
    overflow-x: hidden;
}

body.modal-open {
    overflow: hidden;
}

html {
    scrollbar-gutter: stable;
}

/* Glassmorphism Panel Utilities */
.glass-panel {
    background: var(--panel-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 4px 24px -4px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.05);
    padding: 24px;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.glass-panel:hover {
    box-shadow: 0 12px 32px -4px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

/* ===== SIDEBAR ===== */
.sidebar {
    width: var(--sidebar-width);
    background: rgba(11, 15, 25, 0.85);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 24px 0;
    position: fixed;
    height: 100vh;
    z-index: 100;
    overflow-y: auto;
}

.sidebar .brand {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text-primary);
    padding: 0 24px 28px;
    display: flex;
    align-items: center;
    gap: 14px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 24px;
    letter-spacing: -0.5px;
    flex-shrink: 0;
}

.sidebar .brand i {
    color: var(--accent);
    filter: drop-shadow(0 0 8px var(--accent-glow));
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 14px 24px;
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 500;
    transition: all 0.25s ease;
    gap: 14px;
    position: relative;
}

.nav-link:hover, .nav-link.active {
    background: linear-gradient(90deg, rgba(16, 185, 129, 0.1) 0%, transparent 100%);
    color: var(--text-primary);
}

.nav-link:hover::before, .nav-link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: var(--accent);
    border-radius: 0 4px 4px 0;
    box-shadow: 0 0 10px var(--accent-glow);
}

.nav-link i {
    font-size: 1.25rem;
    width: 24px;
    text-align: center;
    transition: transform 0.2s ease;
}

.nav-link:hover i {
    transform: scale(1.1);
    color: var(--accent);
}

/* ===== MAIN CONTENT ===== */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 32px 48px;
    display: flex;
    flex-direction: column;
    gap: 32px;
    min-width: 0;
    max-width: 100%;
    overflow-x: hidden;
}

/* ===== HEADER ===== */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

h1.page-title {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.8px;
    background: linear-gradient(135deg, #fff 0%, #a1a1aa 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 15px;
    min-width: 0;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.header-actions {
    display: flex;
    gap: 16px;
    align-items: center;
}

/* ===== USER CHIP ===== */
.user-chip {
    padding: 6px 16px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
}

.user-chip img {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    flex-shrink: 0;
}

.user-chip span {
    font-weight: 500;
    font-size: 0.95rem;
}

.btn-logout {
    background: rgba(218, 54, 51, 0.1);
    color: #ff7b72;
    border: 1px solid rgba(218,54,51,0.3);
    padding: 7px 14px;
    border-radius: 20px;
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.btn-logout:hover {
    background: rgba(218, 54, 51, 0.2);
    transform: translateY(-1px);
}

/* ===== BUTTONS ===== */
.btn {
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid var(--border);
    font-size: 14.5px;
    background: var(--panel-bg);
    color: var(--text-primary);
    white-space: nowrap;
}

.btn:hover {
    background: var(--surface-hover);
    transform: translateY(-2px);
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
    color: #fff;
    border: none;
    box-shadow: 0 4px 12px var(--accent-glow);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #12d494 0%, var(--accent) 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px var(--accent-glow);
}

/* ===== DASHBOARD GRID ===== */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 24px;
}

.stat-card {
    display: flex;
    flex-direction: column;
    gap: 12px;
    position: relative;
    overflow: hidden;
}

.stat-card::after {
    content: '';
    position: absolute;
    top: 0; right: 0; bottom: 0; left: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.05) 0%, transparent 100%);
    pointer-events: none;
    border-radius: 16px;
}

.stat-card .title {
    color: var(--text-muted);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
}

.stat-card .value {
    font-size: 2.2rem;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -1px;
    word-break: break-word;
}

.stat-card .trend {
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 500;
}
.trend.positive { color: var(--accent); }
.trend.negative { margin-top: auto; color: var(--danger); }

/* ===== CHARTS GRID ===== */
.charts-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 24px;
}

.chart-wrapper {
    height: 350px;
    width: 100%;
    position: relative;
}

/* ===== TABLES ===== */
.table-container {
    width: 100%;
    overflow-x: auto;
    border-radius: 12px;
    background: rgba(0,0,0,0.15);
    border: 1px solid var(--border);
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    table-layout: auto;
}

th, td {
    padding: 12px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    background: rgba(255,255,255,0.02);
    white-space: nowrap;
}

tr {
    transition: background-color 0.2s;
}

tr:hover td {
    background-color: var(--surface-hover);
}

tr:last-child td {
    border-bottom: none;
}

td {
    color: var(--text-primary);
    vertical-align: middle;
}

.badge {
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
}
.badge.activo { 
    background: rgba(16, 185, 129, 0.15); 
    color: var(--accent); 
    border: 1px solid rgba(16, 185, 129, 0.3); 
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.1);
}

/* ===== FORMS ===== */
.form-group input, .form-group select, .form-group textarea {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border);
    background: var(--input-bg);
    color: var(--text-primary);
    border-radius: 8px;
    font-size: 14.5px;
    transition: all 0.3s ease;
}

.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
    background: rgba(0,0,0,0.3);
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-primary);
    font-weight: 500;
}

/* Generic inline form inputs (inline styled in PHP) */
input[type="text"], input[type="number"], input[type="date"], input[type="email"],
input[type="password"], select, textarea {
    max-width: 100%;
}
.modal-wrapper {
    display: none;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.modal-wrapper[style*="block"] {
    display: flex !important;
}

.modal-panel {
    width: 90%;
    max-width: 600px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 2rem;
    position: relative;
    animation: modalIn 0.3s ease-out;
}


/* ===== OVERLAY (mobile sidebar) ===== */
#overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.6);
    z-index: 90;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: opacity 0.3s;
}

/* ===== MOBILE MENU BUTTON ===== */
.mobile-menu-btn {
    display: none;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: background 0.2s;
    flex-shrink: 0;
}

.mobile-menu-btn:hover {
    background: var(--surface-hover);
}

/* ===== TICKER (index.php) ===== */
.ticker-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    width: 100%;
}

.ticker-prices {
    display: flex;
    gap: 20px;
    align-items: center;
    flex-wrap: wrap;
    min-width: 0;
}

.ticker-divider {
    height: 30px;
    width: 1px;
    background: var(--border);
    flex-shrink: 0;
}

.ticker-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

/* ===== LOTE CARDS (index.php) ===== */
.lotes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
}

/* ===== PANEL HEADER UTILS ===== */
.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 10px;
}

/* ===== FORM GRID ===== */
.form-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

/* =====================
   BREAKPOINT: TABLET (≤1024px)
   ===================== */
@media (max-width: 1024px) {
    .main-content {
        padding: 24px 28px;
    }

    .charts-grid {
        grid-template-columns: 1fr;
    }

    .stat-card .value {
        font-size: 1.9rem;
    }
}

/* =====================
   BREAKPOINT: MOBILE (≤768px)
   ===================== */
@media (max-width: 768px) {

    /* Sidebar: hidden off-screen, toggled via JS */
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 4px 0 24px rgba(0,0,0,0.5);
    }
    
    .sidebar.active {
        transform: translateX(0);
    }

    /* Main content: full width */
    .main-content {
        margin-left: 0;
        padding: 16px;
        gap: 20px;
    }

    /* Show hamburger button */
    .mobile-menu-btn {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Show overlay when active */
    #overlay.active {
        display: block;
    }

    /* Header: stack on small screens */
    header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .header-left {
        width: 100%;
    }

    .header-right {
        width: 100%;
        justify-content: space-between;
    }

    h1.page-title {
        font-size: 1.5rem;
    }

    /* User chip: hide username on very small screens */
    .user-chip .user-name {
        display: none;
    }

    /* Dashboard grid: single column */
    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .stat-card .value {
        font-size: 1.8rem;
    }

    /* Charts: single column */
    .charts-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    /* Glass panel: reduce padding */
    .glass-panel {
        padding: 16px;
        border-radius: 12px;
    }

    /* Ticker bar: stack */
    .ticker-bar {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .ticker-divider {
        display: none;
    }

    .ticker-actions {
        width: 100%;
        justify-content: space-between;
    }

    /* Lote cards: single column */
    .lotes-grid {
        grid-template-columns: 1fr;
    }

    /* Form grids: single column */
    .form-grid-2 {
        grid-template-columns: 1fr;
    }

    /* ===== RESPONSIVE TABLES (Card View) ===== */
    .table-container {
        background: transparent;
        border: none;
        overflow-x: visible;
    }

    .table-container table {
        min-width: unset;
    }

    .table-container table,
    .table-container thead,
    .table-container tbody,
    .table-container th,
    .table-container td,
    .table-container tr {
        display: block;
    }

    .table-container thead tr {
        display: none;
    }

    .table-container tr {
        margin-bottom: 16px;
        background: var(--panel-bg);
        border-radius: 12px;
        border: 1px solid var(--border);
        box-shadow: 0 4px 16px rgba(0,0,0,0.2);
        overflow: hidden;
    }

    .table-container td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        text-align: right;
        padding: 12px 16px;
        border-bottom: 1px solid rgba(255,255,255,0.05);
        min-height: 44px;
    }

    .table-container td:last-child {
        border-bottom: none;
        background: rgba(0,0,0,0.15);
        justify-content: flex-end;
        gap: 10px;
    }

    .table-container td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-muted);
        text-transform: uppercase;
        font-size: 0.72rem;
        letter-spacing: 0.8px;
        text-align: left;
        margin-right: 12px;
        flex-shrink: 0;
        max-width: 45%;
    }

    /* Modal: full width on mobile */
    .modal-wrapper {
        padding: 12px;
    }

    .modal-panel {
        max-width: 100%;
        margin-bottom: 20px;
        border-radius: 20px 20px 0 0;
    }

    /* Buttons: ensure touch targets */
    .btn {
        min-height: 40px;
    }
}

/* =====================
   BREAKPOINT: VERY SMALL MOBILE (≤400px)
   ===================== */
@media (max-width: 400px) {
    h1.page-title {
        font-size: 1.3rem;
    }

    .stat-card .value {
        font-size: 1.6rem;
    }

    .btn {
        padding: 9px 14px;
        font-size: 13.5px;
        gap: 7px;
    }
}
