/**
 * Main Stylesheet
 * Extracted from index.html for better organization
 */

/* Alpine.js cloak */
[x-cloak] { display: none !important; }

/* Sidebar */
.sidebar-item:hover { background-color: rgba(255, 255, 255, 0.1); }
.sidebar-item.active { background-color: rgba(255, 255, 255, 0.15); border-left: 3px solid #60a5fa; }

/* Loading skeleton animation */
.skeleton {
    background: linear-gradient(90deg, #e5e7eb 25%, #f3f4f6 50%, #e5e7eb 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}
.dark .skeleton {
    background: linear-gradient(90deg, #374151 25%, #4b5563 50%, #374151 75%);
    background-size: 200% 100%;
}
@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Mobile sidebar transition */
.sidebar-mobile {
    transform: translateX(-100%);
    transition: transform 0.3s ease-in-out;
}
.sidebar-mobile.open {
    transform: translateX(0);
}

/* D3 Chart Styles */
.d3-chart-container {
    width: 100%;
    height: 100%;
    position: relative;
}
.d3-chart-container svg {
    width: 100%;
    height: 100%;
}
.d3-tooltip {
    position: absolute;
    padding: 10px 14px;
    background: rgba(15, 23, 42, 0.95);
    color: white;
    border-radius: 8px;
    font-size: 13px;
    pointer-events: none;
    z-index: 100;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    border: 1px solid rgba(255,255,255,0.1);
    max-width: 200px;
}
.d3-tooltip .tooltip-title {
    font-weight: 600;
    margin-bottom: 4px;
    color: #60a5fa;
}
.d3-tooltip .tooltip-value {
    font-size: 16px;
    font-weight: 700;
}
.d3-tooltip .tooltip-subtitle {
    font-size: 11px;
    color: #94a3b8;
    margin-top: 2px;
}
.chart-legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 16px;
    margin-top: 12px;
}
.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: opacity 0.2s;
}
.legend-item:hover {
    opacity: 0.8;
}
.legend-item.inactive {
    opacity: 0.4;
}
.legend-color {
    width: 12px;
    height: 12px;
    border-radius: 3px;
}
.donut-center-text {
    font-size: 24px;
    font-weight: 700;
    fill: currentColor;
}
.donut-center-label {
    font-size: 12px;
    fill: #6b7280;
}
.bar-label {
    font-size: 11px;
    fill: #6b7280;
}
.axis-label {
    font-size: 12px;
    fill: #6b7280;
}
.grid-line {
    stroke: #e5e7eb;
    stroke-dasharray: 3,3;
}
.dark .grid-line {
    stroke: #374151;
}
.trend-line {
    fill: none;
    stroke-width: 3;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.trend-area {
    opacity: 0.15;
}
.trend-dot {
    cursor: pointer;
    transition: r 0.2s;
}
.trend-dot:hover {
    r: 7;
}
.treemap-cell {
    cursor: pointer;
    transition: opacity 0.2s;
}
.treemap-cell:hover {
    opacity: 0.85;
}
.treemap-label {
    font-size: 12px;
    font-weight: 600;
    fill: white;
    pointer-events: none;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}
.treemap-value {
    font-size: 10px;
    fill: rgba(255,255,255,0.8);
    pointer-events: none;
}

/* Mobile Optimizations */
@media (max-width: 640px) {
    /* Ensure minimum touch target size of 44px */
    button, a, select, input[type="checkbox"], input[type="radio"] {
        min-height: 44px;
    }

    /* Larger form inputs on mobile */
    input[type="text"], input[type="email"], input[type="password"],
    input[type="number"], input[type="date"], input[type="tel"],
    textarea, select {
        font-size: 16px !important; /* Prevents iOS zoom on focus */
        padding: 12px !important;
    }

    /* Stack action buttons on mobile */
    .action-buttons-row {
        flex-direction: column;
        gap: 8px;
    }
    .action-buttons-row > * {
        width: 100%;
    }

    /* Adjust modal padding on mobile */
    .modal-content {
        padding: 16px !important;
    }

    /* Hide less important columns on mobile tables */
    .mobile-hidden {
        display: none !important;
    }

    /* Full-width buttons on mobile */
    .mobile-full-width {
        width: 100% !important;
    }

    /* Sticky bottom actions for modals */
    .modal-sticky-footer {
        position: sticky;
        bottom: 0;
        background: inherit;
        padding: 16px;
        border-top: 1px solid rgba(0,0,0,0.1);
        margin: 0 -16px -16px;
    }
    .dark .modal-sticky-footer {
        border-top-color: rgba(255,255,255,0.1);
    }

    /* Better touch feedback */
    button:active, a:active {
        opacity: 0.7;
        transform: scale(0.98);
    }

    /* Compact stats cards on mobile */
    .stat-card-mobile {
        padding: 12px !important;
    }
    .stat-card-mobile .text-2xl {
        font-size: 1.25rem !important;
    }
}

/* Tablet optimizations */
@media (min-width: 641px) and (max-width: 1024px) {
    /* Slightly larger touch targets on tablets */
    button, a {
        min-height: 40px;
    }
}

/* Safe area insets for notched phones */
@supports (padding: max(0px)) {
    body {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
    }
    .modal-sticky-footer {
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }
}

/* Prevent text selection during swipe on mobile */
.swipe-container {
    -webkit-user-select: none;
    user-select: none;
    touch-action: pan-x;
}

/* Better scrolling performance */
.scroll-container {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* Mobile bottom navigation padding */
@media (max-width: 1023px) {
    .scroll-container {
        padding-bottom: 80px; /* Space for bottom nav */
    }
}

/* Safe area for bottom navigation */
.safe-area-bottom {
    padding-bottom: env(safe-area-inset-bottom, 0);
}

/* Pull-to-refresh visual indicator */
.pull-to-refresh {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%) translateY(-100%);
    transition: transform 0.2s;
}
.pull-to-refresh.pulling {
    transform: translateX(-50%) translateY(0);
}

/* Print Styles */
@media print {
    /* Hide non-essential elements */
    .no-print,
    nav,
    aside,
    button:not(.print-only),
    .sidebar,
    .sidebar-overlay,
    [x-cloak],
    .toast-container,
    .modal-backdrop,
    .fixed:not(.print-modal),
    footer,
    .pagination,
    .filters-panel,
    input,
    select {
        display: none !important;
    }

    /* Reset dark mode for print */
    body,
    .dark body,
    * {
        background-color: white !important;
        color: black !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    /* Full width for content */
    .main-content,
    main,
    .container {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    /* Table styles for print */
    table {
        width: 100% !important;
        table-layout: fixed !important;
        border-collapse: collapse !important;
        font-size: 8pt !important;
    }
    th, td {
        border: 1px solid #ddd !important;
        padding: 3px 4px !important;
        text-align: left !important;
        word-wrap: break-word !important;
        overflow-wrap: break-word !important;
        hyphens: auto !important;
    }
    th {
        background-color: #f3f4f6 !important;
        font-weight: bold !important;
        font-size: 8pt !important;
        white-space: nowrap !important;
    }
    tr:nth-child(even) {
        background-color: #f9fafb !important;
    }

    /* Column width optimization for reports */
    table th:first-child,
    table td:first-child {
        width: 8% !important; /* ID column */
    }
    table th:nth-child(2),
    table td:nth-child(2) {
        width: 15% !important; /* Account/Entity name */
    }

    /* Status badges for print */
    .badge,
    span[class*="bg-green"],
    span[class*="bg-yellow"],
    span[class*="bg-red"],
    span[class*="bg-blue"] {
        padding: 2px 6px !important;
        border-radius: 4px !important;
        font-size: 9pt !important;
    }
    span[class*="bg-green"] { background-color: #d1fae5 !important; color: #065f46 !important; }
    span[class*="bg-yellow"] { background-color: #fef3c7 !important; color: #92400e !important; }
    span[class*="bg-red"] { background-color: #fee2e2 !important; color: #991b1b !important; }
    span[class*="bg-blue"] { background-color: #dbeafe !important; color: #1e40af !important; }

    /* Page break controls */
    .page-break-before { page-break-before: always !important; }
    .page-break-after { page-break-after: always !important; }
    .no-page-break { page-break-inside: avoid !important; }
    tr { page-break-inside: avoid !important; }

    /* Print header */
    .print-header {
        display: block !important;
        text-align: center;
        margin-bottom: 20px;
        border-bottom: 2px solid #333;
        padding-bottom: 10px;
    }
    .print-header h1 {
        font-size: 18pt !important;
        margin: 0 !important;
    }
    .print-header .print-date {
        font-size: 10pt !important;
        color: #666 !important;
    }

    /* Print footer and page setup */
    @page {
        size: landscape;
        margin: 0.5in 0.75in;
        @bottom-center {
            content: "Page " counter(page) " of " counter(pages);
        }
    }

    /* Hide scrollbars */
    ::-webkit-scrollbar {
        display: none !important;
    }
}

/* Print-only elements (hidden on screen, shown in print) */
.print-only {
    display: none !important;
}
@media print {
    .print-only {
        display: block !important;
    }
}
