/**
 * Frontend CSS - Dashboard Masyarakat
 * Core styles + Custom utilities
 */

/* ===== Alpine.js Cloak - MUST BE FIRST ===== */
[x-cloak] { 
    display: none !important; 
}

/* ===== CSS Variables ===== */
:root {
    /* Responsive Typography Scale */
    --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
    --text-sm: clamp(0.875rem, 0.8rem + 0.35vw, 1rem);
    --text-base: clamp(1rem, 0.925rem + 0.375vw, 1.125rem);
    --text-lg: clamp(1.125rem, 1rem + 0.5vw, 1.25rem);
    --text-xl: clamp(1.25rem, 1.1rem + 0.75vw, 1.5rem);
    --text-2xl: clamp(1.5rem, 1.25rem + 1.25vw, 2rem);
    --text-3xl: clamp(1.875rem, 1.5rem + 1.875vw, 2.5rem);
    --text-4xl: clamp(2.25rem, 1.75rem + 2.5vw, 3rem);
    --text-5xl: clamp(3rem, 2.25rem + 3.75vw, 4rem);
    
    /* Responsive Spacing */
    --space-xs: clamp(0.25rem, 0.2rem + 0.25vw, 0.5rem);
    --space-sm: clamp(0.5rem, 0.4rem + 0.5vw, 0.75rem);
    --space-md: clamp(1rem, 0.8rem + 1vw, 1.5rem);
    --space-lg: clamp(1.5rem, 1.2rem + 1.5vw, 2rem);
    --space-xl: clamp(2rem, 1.5rem + 2.5vw, 3rem);
    --space-2xl: clamp(3rem, 2rem + 5vw, 5rem);
    
    /* Color System */
    --primary-50: #eef2ff;
    --primary-100: #e0e7ff;
    --primary-500: #6366f1;
    --primary-600: #4f46e5;
    --primary-700: #4338ca;
    --primary-800: #3730a3;
    
    --secondary-500: #8b5cf6;
    --secondary-600: #7c3aed;
    
    --accent-500: #06b6d4;
    --accent-600: #0891b2;
    
    --success-500: #22c55e;
    --warning-500: #f59e0b;
    --danger-500: #ef4444;
}

/* ===== Base Styles ===== */
* { 
    box-sizing: border-box; 
}

body {
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: #f8fafc;
    margin: 0;
    padding: 0;
    font-size: var(--text-base);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ===== Typography Classes ===== */
.text-fluid-xs { font-size: var(--text-xs); }
.text-fluid-sm { font-size: var(--text-sm); }
.text-fluid-base { font-size: var(--text-base); }
.text-fluid-lg { font-size: var(--text-lg); }
.text-fluid-xl { font-size: var(--text-xl); }
.text-fluid-2xl { font-size: var(--text-2xl); }
.text-fluid-3xl { font-size: var(--text-3xl); }
.text-fluid-4xl { font-size: var(--text-4xl); }
.text-fluid-5xl { font-size: var(--text-5xl); }

/* ===== Spacing Classes ===== */
.space-fluid-xs { padding: var(--space-xs); }
.space-fluid-sm { padding: var(--space-sm); }
.space-fluid-md { padding: var(--space-md); }
.space-fluid-lg { padding: var(--space-lg); }
.space-fluid-xl { padding: var(--space-xl); }

/* ===== Navigation Styles ===== */
.nav-item { 
    position: relative; 
}

.nav-item::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--primary-500), var(--secondary-500));
    transition: width 0.3s ease;
}

.nav-item:hover::after,
.nav-item.active::after { 
    width: 100%; 
}

/* Disable nav-item underline effect inside dropdown */
.dropdown .nav-item::after {
    display: none;
}

.nav-link {
    position: relative;
    transition: all 0.3s ease;
}

/* ===== Card & Hover Effects ===== */
.card-hover {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.card-hover:hover {
    transform: translateY(-4px);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

/* ===== Glass Effect ===== */
.glass-effect {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

/* ===== Gradient Backgrounds ===== */
.gradient-primary {
    background: linear-gradient(135deg, var(--primary-500) 0%, var(--secondary-500) 100%);
}

.gradient-accent {
    background: linear-gradient(135deg, var(--accent-500) 0%, var(--primary-500) 100%);
}

.gradient-bg {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.text-gradient {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ===== Icon Button ===== */
.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    border-radius: 0.5rem;
    transition: all 0.2s ease;
}

.icon-btn:hover {
    background-color: var(--primary-50);
    color: var(--primary-600);
}

/* ===== Loading States ===== */
.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
}

.loading-spinner {
    border: 3px solid #f3f3f3;
    border-top: 3px solid #3498db;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.table-loading {
    position: relative;
}

.table-loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
}

/* ===== Lucide Icons Default Size ===== */
[data-lucide] {
    width: 1.25rem;
    height: 1.25rem;
    stroke-width: 2;
}

/* ===== Mobile Menu Animations ===== */
.mobile-menu-enter {
    transform: translateX(-100%);
    opacity: 0;
}

.mobile-menu-enter-active {
    transform: translateX(0);
    opacity: 1;
    transition: all 0.3s ease;
}

.mobile-menu-exit {
    transform: translateX(0);
    opacity: 1;
}

.mobile-menu-exit-active {
    transform: translateX(-100%);
    opacity: 0;
    transition: all 0.3s ease;
}

/* ===== WhatsApp Widget ===== */
.whatsapp-widget {
    display: block;
    aspect-ratio: 1 / 1;
    box-sizing: border-box;
    transition: all 0.3s ease;
}

.whatsapp-widget.visible {
    opacity: 1;
    visibility: visible;
}

.whatsapp-widget .whatsapp-icon {
    width: 100%;
    height: 100%;
    border-radius: 9999px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.whatsapp-widget .whatsapp-icon svg {
    width: 52%;
    height: 52%;
}

.whatsapp-widget:hover .whatsapp-icon {
    transform: scale(1.1);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

.whatsapp-widget.bounce {
    animation: whatsappBounce 2s infinite;
}

.whatsapp-widget .whatsapp-tooltip {
    transform: translateY(-50%) translateX(0);
}

.whatsapp-widget:hover .whatsapp-tooltip {
    opacity: 1;
    visibility: visible;
}

.whatsapp-widget .whatsapp-badge {
    animation: pulse 2s infinite;
}

@keyframes whatsappBounce {
    0%, 20%, 53%, 80%, 100% { transform: translate3d(0, 0, 0); }
    40%, 43% { transform: translate3d(0, -20px, 0); }
    70% { transform: translate3d(0, -10px, 0); }
    90% { transform: translate3d(0, -4px, 0); }
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
    100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

.whatsapp-widget:focus { 
    outline: 3px solid var(--primary-500); 
    outline-offset: 2px; 
}

.whatsapp-widget:focus:not(:focus-visible) { 
    outline: none; 
}

.whatsapp-widget:focus-visible { 
    outline: 3px solid var(--primary-500); 
    outline-offset: 2px; 
}

@media (max-width: 768px) {
    .whatsapp-widget {
        width: 52px !important;
        height: 52px !important;
        max-width: 52px !important;
        max-height: 52px !important;
        bottom: calc(env(safe-area-inset-bottom, 0px) + 0.9rem) !important;
    }
    .whatsapp-widget[data-position="bottom-right"] {
        right: 1rem !important;
        left: auto !important;
    }
    .whatsapp-widget[data-position="bottom-left"] {
        left: 1rem !important;
        right: auto !important;
    }
    .whatsapp-widget .whatsapp-tooltip { 
        display: none; 
    }
    .whatsapp-widget .whatsapp-badge { 
        width: 18px; 
        height: 18px; 
        font-size: 10px; 
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .whatsapp-widget {
        width: 56px !important;
        height: 56px !important;
        max-width: 56px !important;
        max-height: 56px !important;
        bottom: calc(env(safe-area-inset-bottom, 0px) + 1rem) !important;
    }
    .whatsapp-widget[data-position="bottom-right"] {
        right: 1rem !important;
        left: auto !important;
    }
    .whatsapp-widget[data-position="bottom-left"] {
        left: 1rem !important;
        right: auto !important;
    }
}

/* ===== Data Section ===== */
.data-card {
    background: white;
    border-radius: 1rem;
    padding: var(--space-md);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.data-card:hover {
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
}

/* ===== Map Container ===== */
.map-container {
    width: 100%;
    height: 400px;
    border-radius: 1rem;
    overflow: hidden;
    background: #e2e8f0;
}

@media (min-width: 768px) {
    .map-container { height: 500px; }
}

@media (min-width: 1024px) {
    .map-container { height: 600px; }
}

/* ===== Stats Grid ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-md);
}

@media (min-width: 640px) {
    .stats-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 1024px) {
    .stats-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ===== Sectoral Data Layout ===== */
.sectoral-layout {
    display: grid;
    gap: var(--space-lg);
    grid-template-columns: 1fr;
}

@media (min-width: 1024px) {
    .sectoral-layout {
        grid-template-columns: 300px 1fr;
    }
}

/* ===== Dropdown Menu ===== */
.dropdown {
    position: relative !important;
    display: inline-block;
}

.dropdown-menu {
    display: none;
    position: absolute !important;
    top: 100% !important;
    left: 0 !important;
    width: max-content;
    min-width: 150px;
    margin-top: 4px;
    padding: 8px 0;
    background: white;
    border-radius: 0.75rem;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    z-index: 9999 !important;
}

.dropdown:hover > .dropdown-menu {
    display: block;
}

.dropdown-item {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    font-size: 0.875rem;
    white-space: nowrap;
    color: #475569;
    text-decoration: none;
    transition: all 0.15s ease;
}

.dropdown-item:hover {
    background-color: #f1f5f9;
    color: #4f46e5;
}

.dropdown-item i,
.dropdown-item svg {
    flex-shrink: 0;
}

/* ===== Filter & Chart Components ===== */
.filter-card {
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    padding: 1.5rem;
    margin-bottom: 2rem;
}

.chart-container {
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    padding: 1.5rem;
    margin-bottom: 2rem;
    min-height: 400px;
}

.chart-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 300px;
    color: #6b7280;
    text-align: center;
}

.chart-placeholder i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

/* ===== Table Components ===== */
.table-container {
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.category-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 1rem 1.5rem;
    font-weight: 600;
    font-size: 1.1rem;
}

.price-row {
    border-bottom: 1px solid #e5e7eb;
    transition: background-color 0.2s ease;
}

.price-row:hover {
    background-color: #f9fafb;
}

.price-row:last-child {
    border-bottom: none;
}

/* ===== Status Badges ===== */
.status-naik {
    color: #059669;
    background-color: #d1fae5;
    padding: 0.25rem 0.5rem;
    border-radius: 0.375rem;
    font-size: 0.75rem;
    font-weight: 500;
}

.status-turun {
    color: #dc2626;
    background-color: #fee2e2;
    padding: 0.25rem 0.5rem;
    border-radius: 0.375rem;
    font-size: 0.75rem;
    font-weight: 500;
}

.status-stabil {
    color: #6b7280;
    background-color: #f3f4f6;
    padding: 0.25rem 0.5rem;
    border-radius: 0.375rem;
    font-size: 0.75rem;
    font-weight: 500;
}

/* ===== Date Range Inputs ===== */
.date-range-inputs {
    display: none;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid #e5e7eb;
}

.date-range-inputs.show {
    display: block;
}

/* ===== Responsive Adjustments ===== */
@media (max-width: 768px) {
    .filter-card {
        padding: 1rem;
        margin-bottom: 1rem;
    }
    
    .chart-container {
        padding: 1rem;
        margin-bottom: 1rem;
        min-height: 300px;
    }
    
    .category-header {
        padding: 0.75rem 1rem;
        font-size: 1rem;
    }
}
