/* ============================================
   ENHANCED RESPONSIVE DESIGN IMPROVEMENTS
   ============================================ */

/* Mobile-First Approach */
@media (max-width: 640px) {
    /* Sidebar becomes collapsible on mobile */
    aside.col-span-2 {
        position: fixed;
        left: -100%;
        top: 0;
        width: 100%;
        height: 100vh;
        background: white;
        z-index: 1000;
        transition: left 0.3s ease;
        overflow-y: auto;
    }
    
    aside.col-span-2.mobile-open {
        left: 0;
    }
    
    main#mainContent {
        width: 100%;
        padding: 1rem;
    }
    
    .grid.md\:grid-cols-12 {
        grid-template-columns: 1fr;
    }
    
    .md\:col-span-8,
    .md\:col-span-4 {
        grid-column: span 1;
    }
    
    .hidden.md\:block {
        display: none \!important;
    }
    
    .md\:p-16 {
        padding: 1rem;
    }
    
    .text-2xl {
        font-size: 1.25rem;
    }
    
    .chart-container {
        width: 100%;
        height: 300px;
        padding: 1rem;
    }
    
    /* Responsive tables */
    table {
        font-size: 0.875rem;
    }
    
    table th,
    table td {
        padding: 0.5rem;
    }
}

/* Tablet (640px - 1024px) */
@media (min-width: 641px) and (max-width: 1024px) {
    aside.col-span-2 {
        width: 200px;
    }
    
    main#mainContent {
        padding: 1.5rem;
    }
    
    .lg\:col-span-8 {
        grid-column: span 6;
    }
    
    .lg\:col-span-4 {
        grid-column: span 6;
    }
    
    .chart-container {
        width: 100%;
        height: 350px;
    }
}

/* Desktop (1025px+) */
@media (min-width: 1025px) {
    aside.col-span-2 {
        width: auto;
    }
    
    main#mainContent {
        padding: 2rem;
    }
    
    .lg\:col-span-8 {
        grid-column: span 8;
    }
    
    .lg\:col-span-4 {
        grid-column: span 4;
    }
    
    .chart-container {
        width: 750px;
        height: 420px;
    }
}

/* Flexible Grid System */
.responsive-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

@media (max-width: 640px) {
    .responsive-grid {
        grid-template-columns: 1fr;
    }
}

/* Flexible Typography */
h1, h2, h3, h4, h5, h6 {
    word-break: break-word;
    overflow-wrap: break-word;
}

/* Touch-friendly buttons on mobile */
@media (max-width: 640px) {
    button, a.button {
        min-height: 44px;
        min-width: 44px;
    }
}

/* Improved form responsiveness */
form {
    width: 100%;
}

input, textarea, select {
    width: 100%;
    box-sizing: border-box;
}

/* Flexible containers */
.container-responsive {
    width: 100%;
    padding: 0 1rem;
    margin: 0 auto;
}

@media (min-width: 640px) {
    .container-responsive {
        max-width: 640px;
    }
}

@media (min-width: 768px) {
    .container-responsive {
        max-width: 768px;
    }
}

@media (min-width: 1024px) {
    .container-responsive {
        max-width: 1024px;
    }
}

@media (min-width: 1280px) {
    .container-responsive {
        max-width: 1280px;
    }
}

/* Improved spacing on different screen sizes */
@media (max-width: 640px) {
    .p-8 { padding: 1rem; }
    .p-6 { padding: 1rem; }
    .mb-8 { margin-bottom: 1rem; }
    .mb-6 { margin-bottom: 0.75rem; }
}

/* Flexible sidebar navigation */
.sidebar-link {
    transition: all 0.2s ease-in-out;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (max-width: 640px) {
    .sidebar-link span {
        display: none;
    }
    
    .sidebar-link span.mobile-label {
        display: inline;
    }
}

/* Improved header responsiveness */
header#mainHeader {
    position: sticky;
    top: 0;
    z-index: 100;
    width: 100%;
}

/* Flexible modals */
.modal {
    width: 90vw;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
}

@media (max-width: 640px) {
    .modal {
        width: 95vw;
        max-width: 100%;
    }
}

/* Improved table responsiveness */
@media (max-width: 768px) {
    table {
        font-size: 0.75rem;
    }
    
    table th,
    table td {
        padding: 0.25rem 0.5rem;
    }
}

/* Flexible spacing utilities */
.gap-responsive {
    gap: 0.5rem;
}

@media (min-width: 768px) {
    .gap-responsive {
        gap: 1rem;
    }
}

@media (min-width: 1024px) {
    .gap-responsive {
        gap: 1.5rem;
    }
}

/* Improved image responsiveness */
img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Flexible badge sizing */
.badge {
    font-size: clamp(0.625rem, 2vw, 0.875rem);
    padding: clamp(0.25rem, 1vw, 0.5rem) clamp(0.5rem, 2vw, 0.75rem);
}

/* Improved focus states for accessibility */
button:focus-visible,
a:focus-visible,
input:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* Smooth transitions */
* {
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

/* Prevent layout shift */
html {
    scroll-behavior: smooth;
}

body {
    overflow-x: hidden;
}

/* Improved print styles */
@media print {
    aside, header, nav, .no-print {
        display: none;
    }
    
    body {
        background: white;
    }
    
    main {
        padding: 0;
    }
}
/* ============================================
   LAPTOP RESPONSIVE FIXES (PRIMARY BREAKPOINT)
   ============================================ */

/* Laptop/Desktop (1024px+) - PRIMARY BREAKPOINT */
@media (min-width: 1024px) {
    /* Icon sizing fixes */
    svg.h-3 { height: 0.75rem; width: 0.75rem; }
    svg.h-4 { height: 1rem; width: 1rem; }
    svg.h-5 { height: 1.25rem; width: 1.25rem; }
    svg.h-6 { height: 1.5rem; width: 1.5rem; }
    
    svg.w-3 { width: 0.75rem; }
    svg.w-4 { width: 1rem; }
    svg.w-5 { width: 1.25rem; }
    svg.w-6 { width: 1.5rem; }
    
    /* Ensure icons don't scale beyond their intended size */
    svg[class*="h-"] {
        max-width: 100%;
        max-height: 100%;
    }
    
    /* Sidebar icon sizing */
    .sidebar-link svg {
        height: 1.25rem;
        width: 1.25rem;
        flex-shrink: 0;
    }
    
    /* Detail title icons */
    .detail-title svg {
        height: 1rem;
        width: 1rem;
        flex-shrink: 0;
    }
    
    /* Result card icons */
    .result-card-title svg {
        height: 0.875rem;
        width: 0.875rem;
        flex-shrink: 0;
    }
    
    /* Button icons */
    button svg {
        height: 1.25rem;
        width: 1.25rem;
        flex-shrink: 0;
    }
    
    /* Navigation icons */
    nav svg {
        height: 1.25rem;
        width: 1.25rem;
        flex-shrink: 0;
    }
    
    /* Ensure proper spacing around icons */
    .flex.items-center.gap-2 svg {
        flex-shrink: 0;
    }
    
    .flex.items-center.gap-1.5 svg {
        flex-shrink: 0;
    }
    
    /* Fix icon container sizing */
    [class*="icon"] {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    
    /* Prevent icon scaling in flex containers */
    .flex svg {
        flex-shrink: 0;
    }
    
    /* Ensure consistent icon rendering */
    svg {
        display: inline-block;
        vertical-align: middle;
    }
}

/* Medium screens (768px - 1023px) */
@media (min-width: 768px) and (max-width: 1023px) {
    svg.h-4 { height: 0.875rem; width: 0.875rem; }
    svg.h-5 { height: 1.125rem; width: 1.125rem; }
    svg.h-6 { height: 1.25rem; width: 1.25rem; }
    
    .sidebar-link svg {
        height: 1.125rem;
        width: 1.125rem;
    }
}

/* Small screens (640px - 767px) */
@media (max-width: 767px) {
    svg.h-4 { height: 0.75rem; width: 0.75rem; }
    svg.h-5 { height: 0.875rem; width: 0.875rem; }
    svg.h-6 { height: 1rem; width: 1rem; }
    
    .sidebar-link svg {
        height: 1rem;
        width: 1rem;
    }
}

/* ============================================
   LAYOUT FIXES FOR LAPTOP
   ============================================ */

@media (min-width: 1024px) {
    /* Main layout */
    body {
        display: grid;
        grid-template-columns: auto 1fr;
        grid-template-rows: auto 1fr;
        min-height: 100vh;
    }
    
    header#mainHeader {
        grid-column: 1 / -1;
        grid-row: 1;
    }
    
    aside {
        grid-column: 1;
        grid-row: 2;
        width: 250px;
        min-width: 250px;
    }
    
    main#mainContent {
        grid-column: 2;
        grid-row: 2;
        overflow-y: auto;
    }
    
    /* Sidebar width consistency */
    .col-span-2 {
        width: 250px \!important;
        min-width: 250px \!important;
    }
    
    /* Main content width */
    .md\:col-span-8 {
        grid-column: span 8;
    }
    
    .md\:col-span-4 {
        grid-column: span 4;
    }
    
    /* Proper grid layout */
    .grid.md\:grid-cols-12 {
        grid-template-columns: repeat(12, minmax(0, 1fr));
    }
    
    /* Chart container sizing */
    .chart-container {
        width: 100%;
        max-width: 750px;
        height: 420px;
    }
    
    /* Padding consistency */
    main#mainContent {
        padding: 2rem;
    }
    
    /* Content cards */
    .result-card {
        min-height: 150px;
    }
    
    /* Table responsiveness */
    table {
        width: 100%;
        font-size: 0.875rem;
    }
    
    table th,
    table td {
        padding: 0.75rem;
    }
}

/* ============================================
   TYPOGRAPHY FIXES FOR LAPTOP
   ============================================ */

@media (min-width: 1024px) {
    h1 { font-size: 2rem; line-height: 2.5rem; }
    h2 { font-size: 1.5rem; line-height: 2rem; }
    h3 { font-size: 1.25rem; line-height: 1.75rem; }
    h4 { font-size: 1.125rem; line-height: 1.5rem; }
    h5 { font-size: 1rem; line-height: 1.5rem; }
    h6 { font-size: 0.875rem; line-height: 1.25rem; }
    
    p { font-size: 1rem; line-height: 1.5rem; }
    
    .text-sm { font-size: 0.875rem; }
    .text-base { font-size: 1rem; }
    .text-lg { font-size: 1.125rem; }
    .text-xl { font-size: 1.25rem; }
    .text-2xl { font-size: 1.5rem; }
}

/* ============================================
   SPACING FIXES FOR LAPTOP
   ============================================ */

@media (min-width: 1024px) {
    /* Consistent spacing */
    .gap-2 { gap: 0.5rem; }
    .gap-3 { gap: 0.75rem; }
    .gap-4 { gap: 1rem; }
    .gap-6 { gap: 1.5rem; }
    .gap-8 { gap: 2rem; }
    
    /* Padding consistency */
    .p-2 { padding: 0.5rem; }
    .p-4 { padding: 1rem; }
    .p-6 { padding: 1.5rem; }
    .p-8 { padding: 2rem; }
    
    /* Margin consistency */
    .m-2 { margin: 0.5rem; }
    .m-4 { margin: 1rem; }
    .m-6 { margin: 1.5rem; }
    .m-8 { margin: 2rem; }
}

@media (min-width: 1024px) {
  h2#sectionTitle-dashboard { writing-mode: horizontal-tb; white-space: normal; word-break: normal; line-height: 1.3; }
  main#mainContent { width: 100%; }
  aside.col-span-2 { position: relative; left: 0; height: auto; min-width: 240px; }
}
/* App shell grid layout */
.app-shell { display: grid; grid-template-areas: "header header" "sidebar content"; grid-template-columns: 280px 1fr; grid-template-rows: auto 1fr; height: 100vh; }
.app-header { grid-area: header; position: sticky; top: 0; width: 100%; z-index: 100; }
.app-sidebar { grid-area: sidebar; overflow-y: auto; border-right: 1px solid #f1f5f9; }
.app-content { grid-area: content; overflow-y: auto; }
@media (min-width: 641px) and (max-width: 1024px) { .app-shell { grid-template-columns: 220px 1fr; } }
@media (max-width: 640px) {
  .app-shell { grid-template-areas: "header" "content"; grid-template-columns: 1fr; }
  .app-sidebar { position: fixed; left: -100%; top: 0; width: 85vw; max-width: 320px; height: 100vh; background: #fff; z-index: 1000; transition: left .3s ease; }
  .app-sidebar.mobile-open { left: 0; }
  .app-content { width: 100%; }
}
/* === App shell grid layout === */
.app-shell { display: grid; grid-template-areas: "header header" "sidebar content"; grid-template-columns: 280px 1fr; grid-template-rows: auto 1fr; height: 100vh; }
.app-header { grid-area: header; position: sticky; top: 0; width: 100%; z-index: 100; }
.app-sidebar { grid-area: sidebar; overflow-y: auto; border-right: 1px solid #f1f5f9; }
.app-content { grid-area: content; overflow-y: auto; }
@media (min-width: 641px) and (max-width: 1024px) { .app-shell { grid-template-columns: 220px 1fr; } }
@media (max-width: 640px) {
  .app-shell { grid-template-areas: "header" "content"; grid-template-columns: 1fr; }
  .app-sidebar { position: fixed; left: -100%; top: 0; width: 85vw; max-width: 320px; height: 100vh; background: #fff; z-index: 1000; transition: left .3s ease; }
  .app-sidebar.mobile-open { left: 0; }
  .app-content { width: 100%; }
}
