/* Mobile-First CSS for PM POSHAN MDM Calculator */
/* Preserving all existing styles while enhancing mobile responsiveness */

* {
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Enhanced Mobile-First Responsive Design */
.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
}

@media (min-width: 640px) {
    .container {
        padding-left: 1rem;
        padding-right: 1rem;
    }
}

@media (min-width: 1024px) {
    .container {
        padding-left: 2rem;
        padding-right: 2rem;
    }
}

/* Mobile-Optimized Touch Targets */
.stepper-btn {
    min-width: 44px;
    min-height: 44px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

@media (max-width: 639px) {
    .stepper-btn {
        min-width: 48px;
        min-height: 48px;
        padding: 12px;
    }
}

/* Enhanced Mobile Tables - Breakdown Reports */
.mobile-table-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.category-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    font-size: 14px;
    min-width: 100%;
}

@media (max-width: 639px) {
    .category-table {
        font-size: 12px;
    }
}

.category-table th {
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    color: white;
    padding: 8px 6px;
    text-align: left;
    font-weight: 600;
    border: 1px solid #e5e7eb;
    white-space: nowrap;
}

@media (min-width: 640px) {
    .category-table th {
        padding: 12px 16px;
    }
}

.category-table td {
    padding: 8px 6px;
    border: 1px solid #e5e7eb;
    text-align: left;
    vertical-align: middle;
}

@media (min-width: 640px) {
    .category-table td {
        padding: 12px 16px;
    }
}

.category-table tbody tr:nth-child(even) {
    background-color: #f9fafb;
}

.category-table tbody tr:hover {
    background-color: #f3f4f6;
}

/* Mobile-Optimized Category Headers */
.category-header {
    background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
    color: white;
    padding: 12px 16px;
    border-radius: 12px 12px 0 0;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
}

@media (max-width: 639px) {
    .category-header {
        padding: 10px 12px;
        font-size: 14px;
    }
}

/* Balvatika Colors */
.balvatika-theme .category-header {
    background: linear-gradient(135deg, #ec4899 0%, #db2777 100%);
}
.balvatika-theme .category-table th {
    background: linear-gradient(135deg, #ec4899 0%, #db2777 100%);
}

/* Primary Colors */
.primary-theme .category-header {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
}
.primary-theme .category-table th {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
}

/* Upper Primary Colors */
.upper-primary-theme .category-header {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}
.upper-primary-theme .category-table th {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}

/* High School Colors */
.high-school-theme .category-header {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
}
.high-school-theme .category-table th {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
}

/* Mobile-Friendly Auto-Balance Indicators */
.auto-balance-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
    color: #92400e;
    padding: 2px 6px;
    border-radius: 12px;
    font-weight: 600;
    white-space: nowrap;
}

@media (min-width: 640px) {
    .auto-balance-indicator {
        font-size: 11px;
        padding: 3px 8px;
    }
}

/* Mobile-Optimized Tooltip */
.tooltip {
    position: relative;
    cursor: help;
}

.tooltip .tooltip-text {
    visibility: hidden;
    width: 280px;
    max-width: 90vw;
    background-color: #1f2937;
    color: #fff;
    text-align: center;
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 12px;
    line-height: 1.4;
    position: absolute;
    z-index: 1000;
    bottom: 125%;
    left: 50%;
    margin-left: -140px;
    opacity: 0;
    transition: opacity 0.2s;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

@media (max-width: 639px) {
    .tooltip .tooltip-text {
        width: 250px;
        margin-left: -125px;
        font-size: 11px;
        padding: 6px 10px;
    }
}

.tooltip .tooltip-text::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -5px;
    border-width: 5px;
    border-style: solid;
    border-color: #1f2937 transparent transparent transparent;
}

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

/* Mobile-Optimized Summary Cards */
.summary-card {
    background: white;
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    border-left: 4px solid;
    text-align: center;
    min-height: 80px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

@media (min-width: 640px) {
    .summary-card {
        padding: 16px;
        min-height: 100px;
    }
}

.summary-card-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    opacity: 0.8;
    margin-bottom: 4px;
}

@media (min-width: 640px) {
    .summary-card-label {
        font-size: 12px;
        margin-bottom: 6px;
    }
}

.summary-card-value {
    font-size: 14px;
    font-weight: 700;
    color: #1f2937;
}

@media (min-width: 640px) {
    .summary-card-value {
        font-size: 18px;
    }
}

@media (min-width: 1024px) {
    .summary-card-value {
        font-size: 20px;
    }
}

/* Category Totals - Mobile Optimized */
.category-total {
    background: linear-gradient(135deg, #059669 0%, #047857 100%);
    color: white;
    padding: 12px 16px;
    border-radius: 0 0 12px 12px;
    font-weight: bold;
    text-align: right;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

@media (max-width: 639px) {
    .category-total {
        padding: 10px 12px;
        font-size: 14px;
        text-align: center;
        flex-direction: column;
        gap: 4px;
    }
}

/* Responsive Text Alignment */
.text-amount {
    text-align: right;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
    font-weight: 600;
}

@media (max-width: 639px) {
    .text-amount {
        text-align: center;
    }
}

.text-quantity {
    text-align: center;
    font-weight: 500;
}

/* Enhanced Mobile Form Controls */
input[type="number"], input[type="date"] {
    -webkit-appearance: none;
    -moz-appearance: textfield;
    appearance: none;
    border-radius: 8px;
    border: 2px solid #d1d5db;
    padding: 12px 16px;
    font-size: 16px;
    transition: all 0.2s;
    width: 100%;
}

@media (min-width: 640px) {
    input[type="number"], input[type="date"] {
        font-size: 14px;
        padding: 10px 14px;
    }
}

input[type="number"]:focus, input[type="date"]:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Remove spinner arrows on mobile */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* Mobile-Optimized Animations */
@keyframes slideInUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.animate-slide-in {
    animation: slideInUp 0.3s ease-out forwards;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

.animate-pulse-gentle {
    animation: pulse 2s infinite;
}

/* Enhanced Mobile Export Bar */
#exportBar {
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    background: rgba(255, 255, 255, 0.95);
}

/* Mobile-Optimized Admin Panel */
@media (max-width: 639px) {
    #adminPanel .bg-white {
        margin: 8px;
        max-height: calc(100vh - 16px);
    }
    
    #adminContent {
        padding: 16px 12px;
    }
}

/* Improved Mobile Loading States */
.loading-shimmer {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

/* Enhanced Mobile Accessibility */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Focus states for better mobile accessibility */
button:focus-visible,
input:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .category-table th {
        background: #000000;
        color: #ffffff;
    }
    
    .category-table td {
        border-color: #000000;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Mobile-Specific Styles for Better UX */
@media (max-width: 639px) {
    /* Larger tap targets on mobile */
    button, .stepper-btn {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Better text readability */
    body {
        font-size: 16px;
        line-height: 1.5;
    }
    
    /* Improved spacing */
    .space-y-4 > * + * {
        margin-top: 1rem;
    }
    
    /* Better form layout */
    .grid-cols-2 {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
}

/* Admin Modal Z-Index Fixes */
#adminPanel {
    z-index: 90 !important;
}

#addPeriodModal,
#editPeriodModal,
#editMenuModal,
#editLaddooModal {
    z-index: 100 !important;
}

/* Ensure modals appear above everything */
.admin-modal {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    z-index: 100 !important;
    background-color: rgba(0, 0, 0, 0.5) !important;
}

/* Tablet-specific adjustments */
@media (min-width: 640px) and (max-width: 1023px) {
    .container {
        padding-left: 1.5rem;
        padding-right: 1.5rem;
    }
    
    .grid-cols-2 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* Desktop enhancements */
@media (min-width: 1024px) {
    .category-table {
        font-size: 15px;
    }
    
    .summary-card {
        min-height: 120px;
        padding: 20px;
    }
    
    .summary-card-value {
        font-size: 24px;
    }
}

/* Print styles for mobile */
@media print {
    body {
        font-size: 12px;
        line-height: 1.4;
    }
    
    .hidden,
    #exportBar,
    #adminToggle,
    .stepper-btn,
    button {
        display: none !important;
    }
    
    .category-table {
        font-size: 10px;
    }
    
    .category-table th,
    .category-table td {
        padding: 4px 6px;
    }
}

/* Enhanced Error States */
.error-border {
    border-color: #ef4444 !important;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1) !important;
}

.error-text {
    color: #ef4444;
    font-size: 12px;
    font-weight: 500;
}

/* Success States */
.success-border {
    border-color: #10b981 !important;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1) !important;
}

/* Mobile-Optimized Dark Mode Support */
@media (prefers-color-scheme: dark) {
    .tooltip .tooltip-text {
        background-color: #374151;
        border: 1px solid #4b5563;
    }
    
    .tooltip .tooltip-text::after {
        border-color: #374151 transparent transparent transparent;
    }
}