/* === DASHBOARD LAYOUT === */
body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    padding: 0;
    background: var(--bg-gradient);
    color: var(--text-color);
    transition: background 0.3s, color 0.3s;
    min-height: 100vh;
    display: flex;
    overflow-x: hidden;
    max-width: 100vw;
}

/* === SIDEBAR === */
.sidebar {
    width: 280px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(20px);
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 100;
    transition: all 0.3s ease;
    left: 0;
    top: 0;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-logo {
    width: 40px;
    height: 40px;
    filter: drop-shadow(0 2px 4px rgba(131, 2, 2, 0.3));
}

.sidebar-title {
    font-size: 20px;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.95);
    text-shadow: 0 2px 4px rgba(131, 2, 2, 0.3);
}

.sidebar-menu {
    list-style: none;
    padding: 0;
    margin: 0;
    flex: 1;
    padding: 20px 0;
}

.menu-item {
    margin: 4px 16px;
    border-radius: 12px;
    transition: all 0.3s ease;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.menu-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(131, 2, 2, 0.1), rgba(214, 174, 123, 0.1));
    opacity: 0;
    transition: opacity 0.3s ease;
}

.menu-item:hover::before {
    opacity: 1;
}

.menu-item.active::before {
    opacity: 1;
    background: linear-gradient(135deg, rgba(131, 2, 2, 0.2), rgba(214, 174, 123, 0.2));
}

.menu-item {
    display: flex;
    align-items: center;
    padding: 16px 20px;
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    position: relative;
    z-index: 1;
}

.menu-item.active {
    color: rgba(255, 255, 255, 0.95);
    font-weight: 600;
}

.menu-icon {
    font-size: 20px;
    margin-right: 16px;
    width: 24px;
    text-align: center;
}

.menu-text {
    font-size: 15px;
    font-weight: 500;
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

/* === MAIN CONTENT === */
.main-content {
    flex: 1;
    margin-left: 280px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    position: relative;
    z-index: 1;
    width: calc(100% - 280px);
    max-width: calc(100vw - 280px);
    overflow-x: hidden;
}

/* === PREVENCIÓN DE DESBORDAMIENTO GLOBAL === */
* {
    box-sizing: border-box;
}

.dashboard-content {
    flex: 1;
    padding: 30px;
    overflow-y: auto;
    overflow-x: hidden;
    max-width: 100%;
    width: 100%;
}

.container {
    max-width: 100%;
    width: 100%;
    margin: 0 auto;
    padding: 0 15px;
    box-sizing: border-box;
}

.card {
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--card-border);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    color: var(--text-color);
    max-width: 100%;
    overflow: hidden;
    word-wrap: break-word;
}

.dashboard-header {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding: 20px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 10;
    max-width: 100%;
    overflow: hidden;
    box-sizing: border-box;
}

.header-left h1 {
    margin: 0;
    font-size: 28px;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.95);
    text-shadow: 0 2px 4px rgba(131, 2, 2, 0.3);
}

.header-left p {
    margin: 4px 0 0 0;
    color: rgba(255, 255, 255, 0.7);
    font-size: 14px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 20px;
    max-width: 300px;
    overflow: hidden;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--card-bg);
    padding: 8px 16px;
    border-radius: 20px;
    backdrop-filter: blur(10px);
    border: 1px solid var(--card-border);
    max-width: 200px;
    overflow: hidden;
    white-space: nowrap;
}

.user-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-color);
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
}

/* === DASHBOARD CONTENT === */
.dashboard-content {
    flex: 1;
    padding: 30px;
    overflow-y: auto;
}

.dashboard-section {
    display: none;
    animation: fadeIn 0.5s ease-in-out;
}

.dashboard-section.active {
    display: block;
}

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

/* === DASHBOARD GRID === */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 2fr 1fr;
    grid-template-rows: auto 1fr;
    gap: 30px;
    height: calc(100vh - 200px);
    max-width: 100%;
    overflow-x: hidden;
}

.stats-cards {
    grid-column: 1;
    grid-row: 1 / -1;
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-width: 0;
    overflow: hidden;
}

.map-container {
    grid-column: 2;
    grid-row: 1 / -1;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    padding: 20px;
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px rgba(131, 2, 2, 0.1);
    min-width: 0;
    overflow: hidden;
}

.charts-sidebar {
    grid-column: 3;
    grid-row: 1 / -1;
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-width: 0;
    overflow: hidden;
}

/* === STAT CARDS === */
.stat-card {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 24px;
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px rgba(131, 2, 2, 0.1);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--primary-color), #d6ae7b);
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 40px rgba(131, 2, 2, 0.2);
}

.stat-card {
    display: flex;
    align-items: center;
    gap: 16px;
}

.stat-icon {
    font-size: 32px;
    width: 60px;
    height: 60px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.stat-content h3 {
    margin: 0 0 8px 0;
    font-size: 14px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.8);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-number {
    font-size: 24px;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.95);
    margin: 0 0 4px 0;
    text-shadow: 0 2px 4px rgba(131, 2, 2, 0.3);
}

.stat-change {
    font-size: 12px;
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 6px;
    display: inline-block;
}

.stat-change.positive {
    background: rgba(34, 197, 94, 0.2);
    color: #22c55e;
}

.stat-change.negative {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

/* === MAP CONTAINER === */
.map-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.map-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.95);
}

.map-controls {
    display: flex;
    gap: 10px;
}

.map-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    padding: 8px 16px;
    color: rgba(255, 255, 255, 0.8);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.map-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.95);
}

.map-3d {
    height: 100%;
    border-radius: 12px;
    overflow: hidden;
    position: relative;
    background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 50%, #06b6d4 100%);
    transition: all 0.8s cubic-bezier(0.4, 0, 0.2, 1);
    perspective: 1000px;
}

/* Efecto Planeta 3D */
.map-3d.planet-view {
    border-radius: 50%;
    transform: rotateX(15deg) rotateY(0deg);
    box-shadow: 
        0 0 50px rgba(59, 130, 246, 0.5),
        inset -20px -20px 50px rgba(0, 0, 0, 0.3),
        inset 20px 20px 50px rgba(255, 255, 255, 0.1);
    background: 
        radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.3) 0%, transparent 50%),
        radial-gradient(circle at 70% 70%, rgba(0, 0, 0, 0.2) 0%, transparent 50%),
        linear-gradient(135deg, #1e3a8a 0%, #3b82f6 50%, #06b6d4 100%);
    animation: planetRotate 20s linear infinite;
}

@keyframes planetRotate {
    from { transform: rotateX(15deg) rotateY(0deg); }
    to { transform: rotateX(15deg) rotateY(360deg); }
}

/* Marcadores flotantes en vista planeta */
.map-3d.planet-view::before {
    content: '';
    position: absolute;
    top: 20%;
    left: 30%;
    width: 8px;
    height: 8px;
    background: #22c55e;
    border-radius: 50%;
    box-shadow: 0 0 20px #22c55e;
    animation: float 3s ease-in-out infinite;
}

.map-3d.planet-view::after {
    content: '';
    position: absolute;
    top: 60%;
    right: 25%;
    width: 6px;
    height: 6px;
    background: #f59e0b;
    border-radius: 50%;
    box-shadow: 0 0 15px #f59e0b;
    animation: float 3s ease-in-out infinite 1.5s;
}

@keyframes float {
    0%, 100% { transform: translateY(0px) scale(1); }
    50% { transform: translateY(-10px) scale(1.2); }
}

/* Controles del mapa */
.map-controls {
    display: flex;
    gap: 10px;
    align-items: center;
}

.map-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    padding: 8px 16px;
    color: rgba(255, 255, 255, 0.8);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.map-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.95);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(131, 2, 2, 0.2);
}

/* Indicador de vista actual */
.map-btn.active {
    background: linear-gradient(135deg, rgba(131, 2, 2, 0.3), rgba(214, 174, 123, 0.3));
    border-color: rgba(255, 255, 255, 0.4);
    color: rgba(255, 255, 255, 0.95);
}

/* === CHART CARDS === */
.chart-card {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 20px;
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px rgba(131, 2, 2, 0.1);
    flex: 1;
    max-width: 100%;
    overflow: hidden;
}

/* === TABLAS RESPONSIVAS === */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    max-width: 100%;
    table-layout: fixed;
}

.data-table th, 
.data-table td {
    padding: 0.7rem;
    text-align: left;
    border-bottom: 1px solid var(--card-border);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.data-table th {
    font-weight: bold;
    color: var(--primary-color);
}

.data-table tbody tr:nth-child(even) {
    background-color: var(--table-row-bg-even);
}

.chart-card h4 {
    margin: 0 0 16px 0;
    font-size: 16px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.95);
}

.chart-card canvas {
    max-height: 200px;
}

/* === RESPONSIVE DESIGN === */
@media (max-width: 1200px) {
    .dashboard-content {
        padding: 20px;
    }
    
    .dashboard-grid {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
        gap: 20px;
        height: auto;
        min-height: calc(100vh - 200px);
    }
    
    .stats-cards {
        grid-column: 1;
        grid-row: 1;
        flex-direction: row;
        overflow-x: auto;
        padding-bottom: 10px;
    }
    
    .stats-cards::-webkit-scrollbar {
        height: 6px;
    }
    
    .stats-cards::-webkit-scrollbar-track {
        background: rgba(255, 255, 255, 0.1);
        border-radius: 3px;
    }
    
    .stats-cards::-webkit-scrollbar-thumb {
        background: rgba(131, 2, 2, 0.3);
        border-radius: 3px;
    }
    
    .stat-card {
        min-width: 200px;
        flex-shrink: 0;
    }
    
    .map-container {
        grid-column: 1;
        grid-row: 2;
    }
    
    .charts-sidebar {
        grid-column: 1;
        grid-row: 3;
        flex-direction: row;
        overflow-x: auto;
    }
    
    .chart-card {
        min-width: 300px;
        flex-shrink: 0;
    }
}

@media (max-width: 1024px) {
    .dashboard-content {
        padding: 20px;
    }
    
    .dashboard-grid {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
        gap: 20px;
        height: auto;
    }
    
    .stats-cards {
        grid-column: 1;
        grid-row: 1;
        flex-direction: row;
        overflow-x: auto;
    }
    
    .map-container {
        grid-column: 1;
        grid-row: 2;
    }
    
    .charts-sidebar {
        grid-column: 1;
        grid-row: 3;
        flex-direction: row;
        overflow-x: auto;
    }
    
    .chart-card {
        min-width: 300px;
        flex-shrink: 0;
    }
}

@media (max-width: 768px) {
    .sidebar {
        width: 280px;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 200;
    }
    
    .sidebar.open {
        transform: translateX(0);
        width: 280px;
    }
    
    .sidebar .menu-text {
        display: none;
    }
    
    .sidebar.open .menu-text {
        display: inline;
    }
    
    .main-content {
        margin-left: 0;
        width: 100%;
        max-width: 100vw;
    }
    
    .dashboard-header {
        padding: 15px 20px;
        flex-wrap: wrap;
        gap: 10px;
    }
    
    .dashboard-header h1 {
        font-size: 1.5rem;
    }
    
    .dashboard-header p {
        font-size: 0.9rem;
    }
    
    .header-right {
        max-width: 100%;
        flex-shrink: 1;
    }
    
    .user-info {
        max-width: 150px;
    }
    
    .user-name {
        max-width: 80px;
    }
    
    .dashboard-content {
        padding: 20px;
    }
    
    .dashboard-grid {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
        gap: 15px;
        height: auto;
    }
    
    .stats-cards {
        grid-column: 1;
        grid-row: 1;
        flex-direction: row;
        overflow-x: auto;
        gap: 15px;
    }
    
    .stat-card {
        min-width: 180px;
        padding: 15px;
        flex-shrink: 0;
    }
    
    .stat-card h3 {
        font-size: 0.9rem;
    }
    
    .stat-number {
        font-size: 1.5rem;
    }
    
    .map-container {
        grid-column: 1;
        grid-row: 2;
        height: 250px;
        padding: 15px;
    }
    
    .charts-sidebar {
        grid-column: 1;
        grid-row: 3;
        flex-direction: row;
        overflow-x: auto;
        gap: 15px;
    }
    
    .chart-card {
        min-width: 280px;
        padding: 15px;
        flex-shrink: 0;
    }
    
    .chart-card h4 {
        font-size: 1rem;
    }
    
    /* Botón hamburguesa para móvil */
    .mobile-menu-toggle {
        display: block;
        background: rgba(255, 255, 255, 0.1);
        border: 1px solid rgba(255, 255, 255, 0.2);
        border-radius: 8px;
        padding: 10px;
        color: rgba(255, 255, 255, 0.8);
        cursor: pointer;
        backdrop-filter: blur(10px);
    }
    
    .mobile-menu-toggle:hover {
        background: rgba(255, 255, 255, 0.2);
        color: rgba(255, 255, 255, 0.95);
    }
    
    /* Overlay para móvil */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 150;
    }
    
    .sidebar-overlay.active {
        display: block;
    }
}

@media (max-width: 480px) {
    .dashboard-header {
        padding: 10px 15px;
        flex-direction: column;
        gap: 10px;
        align-items: flex-start;
    }
    
    .dashboard-header h1 {
        font-size: 1.3rem;
    }
    
    .dashboard-content {
        padding: 15px;
    }
    
    .dashboard-grid {
        gap: 10px;
    }
    
    .stat-card {
        min-width: 150px;
        padding: 12px;
    }
    
    .stat-card h3 {
        font-size: 0.8rem;
    }
    
    .stat-number {
        font-size: 1.3rem;
    }
    
    .map-container {
        height: 200px;
        padding: 12px;
    }
    
    .chart-card {
        min-width: 250px;
        padding: 12px;
    }
    
    .chart-card h4 {
        font-size: 0.9rem;
    }
    
    .user-info {
        flex-direction: column;
        gap: 5px;
    }
}

/* === COMING SOON === */
.coming-soon {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 60vh;
    text-align: center;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 20px;
    border: 2px dashed rgba(255, 255, 255, 0.2);
}

.coming-soon h2 {
    font-size: 32px;
    margin: 0 0 16px 0;
    color: rgba(255, 255, 255, 0.8);
}

.coming-soon p {
    font-size: 18px;
    color: rgba(255, 255, 255, 0.6);
    margin: 0;
}

/* === CONSULTA DE PREDIOS RESPONSIVE === */
#section-predios .dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto auto;
    gap: 20px;
    max-width: 100%;
    overflow-x: hidden;
    width: 100%;
    box-sizing: border-box;
}

#section-predios .info-card {
    grid-column: 1;
    grid-row: 1;
}

#section-predios .adeudos-card {
    grid-column: 2;
    grid-row: 1;
}

#section-predios .map-card {
    grid-column: 1;
    grid-row: 2;
}

#section-predios .consumos-card {
    grid-column: 2;
    grid-row: 2;
}

#section-predios .pagos-card {
    grid-column: 1;
    grid-row: 3;
}

#section-predios .ots-card {
    grid-column: 2;
    grid-row: 3;
}

@media (max-width: 1200px) {
    #section-predios .dashboard-grid {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto auto auto auto;
        height: auto !important;
        min-height: unset !important;
    }
    
    #section-predios .info-card {
        grid-column: 1;
        grid-row: 1;
    }
    
    #section-predios .adeudos-card {
        grid-column: 1;
        grid-row: 2;
    }
    
    #section-predios .map-card {
        grid-column: 1;
        grid-row: 3;
    }
    
    #section-predios .consumos-card {
        grid-column: 1;
        grid-row: 4;
    }
    
    #section-predios .pagos-card {
        grid-column: 1;
        grid-row: 5;
    }
    
    #section-predios .ots-card {
        grid-column: 1;
        grid-row: 6;
    }
}

@media (max-width: 1024px) {
    #section-predios .dashboard-grid {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto auto auto auto;
        height: auto !important;
        min-height: unset !important;
    }
    
    #section-predios .info-card {
        grid-column: 1;
        grid-row: 1;
    }
    
    #section-predios .adeudos-card {
        grid-column: 1;
        grid-row: 2;
    }
    
    #section-predios .map-card {
        grid-column: 1;
        grid-row: 3;
    }
    
    #section-predios .consumos-card {
        grid-column: 1;
        grid-row: 4;
    }
    
    #section-predios .pagos-card {
        grid-column: 1;
        grid-row: 5;
    }
    
    #section-predios .ots-card {
        grid-column: 1;
        grid-row: 6;
    }
}

.card, .info-card, .adeudos-card, .map-card, .consumos-card, .pagos-card, .ots-card {
    height: auto !important;
    min-height: unset !important;
    overflow: visible;
}

#section-predios .dashboard-grid > .card {
    height: 380px !important;
    overflow: auto;
}

@media (max-width: 1200px) {
    #section-predios .dashboard-grid > .card {
        height: auto !important;
        overflow: visible;
    }
}

@media (max-width: 1024px) {
    #section-predios .dashboard-grid > .card {
        height: auto !important;
        overflow: visible;
    }
}

/* Ajustes de contenidos internos para altura fija */
#section-predios .dashboard-grid > .card canvas {
    max-height: 240px;
}
#section-predios .dashboard-grid > .card .table-search,
#section-predios .dashboard-grid > .card table {
    max-height: 240px;
    overflow: auto;
    display: block;
}

/* Ocultar scrollbars visualmente pero mantener el desplazamiento */
body,
.dashboard-content,
#section-predios .dashboard-grid > .card,
#section-predios .dashboard-grid > .card .table-search,
#section-predios .dashboard-grid > .card table {
    -ms-overflow-style: none; /* IE y Edge */
    scrollbar-width: none; /* Firefox */
}
body::-webkit-scrollbar,
.dashboard-content::-webkit-scrollbar,
#section-predios .dashboard-grid > .card::-webkit-scrollbar,
#section-predios .dashboard-grid > .card .table-search::-webkit-scrollbar,
#section-predios .dashboard-grid > .card table::-webkit-scrollbar {
    display: none; /* Chrome, Safari */
}