/* Custom styles to supplement Tailwind */
body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Mobile Responsive Table Styles */
@media (max-width: 768px) {

    /* Prevent horizontal scrolling on mobile */
    body {
        overflow-x: hidden !important;
    }

    /* Fix table container overflow */
    .overflow-hidden,
    .overflow-x-hidden {
        overflow-x: hidden !important;
    }

    /* Ensure main content doesn't overflow */
    main {
        overflow-x: hidden !important;
        max-width: 100vw;
    }

    /* Hide table headers on mobile */
    table thead {
        display: none !important;
    }

    /* Make table rows display as cards */
    table,
    table tbody {
        display: block !important;
        width: 100% !important;
        min-width: 0 !important;
        /* Override Tailwind min-w-full */
        overflow-x: hidden !important;
    }

    table tr {
        display: block !important;
        margin-bottom: 1rem;
        border: 1px solid #e5e7eb;
        border-radius: 0.5rem;
        background: white;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
        overflow: hidden;
        max-width: 100%;
    }

    table td {
        display: flex !important;
        justify-content: space-between;
        align-items: center;
        padding: 0.75rem 1rem !important;
        border-bottom: 1px solid #f3f4f6;
        text-align: right !important;
        white-space: normal !important;
        word-wrap: break-word;
        overflow-wrap: break-word;
        max-width: 100%;
    }

    table td:last-child {
        border-bottom: none;
    }

    /* Add labels before each cell using data attributes */
    table td:before {
        content: attr(data-label);
        font-weight: 600;
        color: #4b5563;
        text-align: left;
        flex: 1;
        padding-right: 1rem;
        white-space: nowrap;
    }

    /* Remove before content for action buttons */
    table td:last-child:before {
        display: none;
    }

    /* Make action cells centered */
    table td:last-child {
        justify-content: center;
        gap: 1rem;
    }

    /* --- MOBILE & TOUCH POLISH --- */

    /* 1. Hard-Fix Sidebar Layout */
    #sidebar nav {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
    }

    #sidebar a {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        width: 100% !important;
        justify-content: flex-start !important;
        min-height: 48px !important;
        /* Touch target size */
        margin-bottom: 4px !important;
    }

    #sidebar a i {
        min-width: 24px;
        text-align: center;
        margin-right: 12px !important;
    }

    /* 2. Touch Targets & Inputs */
    input,
    select,
    textarea,
    button {
        min-height: 44px !important;
        /* Standard touch size */
    }

    /* 3. Visual Polish */
    .sidebar-overlay {
        background: rgba(0, 0, 0, 0.6) !important;
        /* Darker backdrop */
        backdrop-filter: blur(2px);
        /* Modern blur effect */
    }

    /* Fix for avatar/icon cells */
    table td .flex.items-center {
        justify-content: flex-end;
        max-width: 100%;
    }

    /* Ensure text content wraps properly */
    table td span,
    table td div {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        /* Added to ensure ellipsis works */
    }

    /* Calendar mobile adjustments */
    .calendar-grid {
        gap: 1px !important;
    }

    .calendar-cell {
        min-height: 70px !important;
        padding: 2px !important;
        font-size: 0.75rem;
        overflow: hidden !important;
    }

    .calendar-cell .text-xs {
        font-size: 0.65rem !important;
        padding: 2px !important;
        line-height: 1.1;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        display: block;
        max-width: 100%;
        margin-bottom: 2px;
    }

    /* Hide day names on very small screens if needed, or abbreviate using JS? 
       For now, just shrink font */
    .calendar-header {
        font-size: 0.7rem;
        padding: 0.25rem 0;
    }

    .calendar-header div {
        overflow: hidden;
        text-overflow: clip;
    }

    /* On mobile, maybe only show first 3 letters of day? 
       CSS text-overflow won't do that easily without fixed width. 
       Let's rely on font shrinkage. */

    /* Utility class for stacking on mobile */
    .mobile-stack {
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0.75rem !important;
        /* Updated gap */
        width: 100% !important;
    }

    .mobile-stack>* {
        width: 100% !important;
        justify-content: center !important;
    }

    /* Make stats cards stack (1 column) on mobile */
    .grid.grid-cols-2.md\:grid-cols-2.lg\:grid-cols-4 {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
        max-width: 100%;
    }

    .grid.grid-cols-2.md\:grid-cols-2.lg\:grid-cols-4 a,
    .grid.grid-cols-2.md\:grid-cols-2.lg\:grid-cols-4>div {
        padding: 1.25rem !important;
        max-width: 100%;
    }

    .grid.grid-cols-2.md\:grid-cols-2.lg\:grid-cols-4 h3 {
        font-size: 1.75rem !important;
    }

    /* Document grid on mobile */
    #documents-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 0.75rem !important;
    }

    /* Daily briefing adjust */
    #daily-briefing {
        flex-direction: column !important;
        text-align: center;
        padding: 1.5rem !important;
    }

    #daily-briefing .flex.items-center.space-x-2 {
        justify-content: center;
        margin-bottom: 0.5rem;
    }

    /* Prevent all containers from overflowing */
    .bg-white,
    .rounded-lg,
    .shadow-md {
        max-width: 100%;
        overflow-x: hidden;
    }

    /* Sidebar overlay fix */
    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 40;
        transition: opacity 0.3s;
    }

    /* Fix input fields */
    input,
    select,
    textarea {
        max-width: 100% !important;
    }

    /* Mobile sidebar adjustment for better visibility */
    #sidebar {
        width: 85vw !important;
        max-width: 280px !important;
    }
}

/* Tablet adjustments */
@media (min-width: 769px) and (max-width: 1024px) {
    .calendar-cell {
        min-height: 90px;
        font-size: 0.875rem;
    }

    .calendar-cell .text-xs {
        font-size: 0.7rem;
    }
}

/* Ensure tooltips and truncated text work properly */
.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Better touch targets for mobile */
@media (max-width: 768px) {

    button,
    a.flex.items-center {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
}