:root {
    --primary: #2563eb;
    --primary-dark: #1e40af;
    --header-bg: #ffffff;
    --bg-color: #f1f5f9;
    --text-main: #1e293b;
    --text-light: #64748b;
    --border: #e2e8f0;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

* {
    box-sizing: border-box;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Global Normalization */
input,
select,
textarea,
button {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
    border: 1px solid var(--border);
    background: white;
    border-radius: 8px;
    transition: all 0.2s;
}

select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

/* Ensure checkboxes and radio buttons are visible */
input[type="checkbox"],
input[type="radio"] {
    -webkit-appearance: checkbox !important;
    -moz-appearance: checkbox !important;
    appearance: checkbox !important;
    width: 18px;
    height: 18px;
    cursor: pointer;
    border: 1px solid #cbd5e1;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748b'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 1rem;
    padding-right: 2.5rem !important;
    cursor: pointer;
}

.searchable-select-wrapper {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
}

.searchable-select-input {
    width: 100% !important;
    padding: 8px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.9rem;
    background: white;
    box-sizing: border-box;
    cursor: text;
    appearance: none !important;
    -webkit-appearance: none !important;
}

.searchable-select-wrapper select {
    display: none !important;
}

.searchable-results-list {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    z-index: 1000;
    margin-top: 4px;
    border: 1px solid #3b82f6;
    border-radius: 8px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    background: white;
    max-height: 200px;
    overflow-y: auto;
}

.searchable-item {
    padding: 10px 12px;
    cursor: pointer;
    font-size: 0.9rem;
    border-bottom: 1px solid #f1f5f9;
    color: #1e293b;
}

.searchable-item:last-child {
    border-bottom: none;
}

.searchable-item:hover,
.searchable-item.selected {
    background: #eff6ff;
    color: #2563eb;
}

.searchable-item.no-results {
    color: #94a3b8;
    text-align: center;
    cursor: default;
}

.searchable-select-wrapper select option {
    padding: 8px;
}

body {
    margin: 0;
    font-family: 'Inter', sans-serif;
    background: var(--bg-color);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
    /* prevent horizontal scroll globally */
    max-width: 100vw;
    overflow-x: hidden;
}

html {
    overflow-x: clip;
    max-width: 100vw;
}

.hidden {
    display: none !important;
}

/* Mobile Nav Drawer */
#mobile-nav-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 900;
}
#mobile-nav-overlay.open {
    display: block;
}

#mobile-nav-drawer {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100%;
    background: #fff;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    box-shadow: 4px 0 24px rgba(0,0,0,0.12);
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
    overflow-y: auto;
}
#mobile-nav-drawer.open {
    transform: translateX(0);
}
.mobile-nav-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 18px 12px;
    border-bottom: 1px solid #f1f5f9;
}
.mobile-nav-close {
    background: none;
    border: none;
    font-size: 1.3rem;
    color: #64748b;
    cursor: pointer;
    padding: 4px 8px;
}
.mobile-nav-user {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 18px;
    border-bottom: 1px solid #f1f5f9;
    font-weight: 600;
    font-size: 0.95rem;
    color: #334155;
}
.mobile-nav-links {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 10px 10px;
    gap: 2px;
}
.mobile-nav-links .nav-link {
    padding: 12px 14px;
    border-radius: 10px;
    font-size: 0.93rem;
}
.mobile-nav-footer {
    padding: 12px 18px 24px;
    border-top: 1px solid #f1f5f9;
}

/* Hamburger button — hidden on desktop */
#mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    font-size: 1.35rem;
    color: #475569;
    cursor: pointer;
    padding: 6px 8px;
    border-radius: 8px;
    margin-right: 4px;
}
#mobile-menu-btn:hover {
    background: #f1f5f9;
}

/* Site Logo */
.site-logo {
    height: 38px;
    width: auto;
    display: block;
    object-fit: contain;
}
.login-logo {
    height: 72px;
}

@media (max-width: 1024px) {
    .site-logo { height: 32px; }
    .login-logo { height: 60px; }
}
@media (max-width: 640px) {
    .site-logo { height: 28px; }
    .login-logo { height: 52px; }
}

/* Header Layout */
#main-header {
    height: 70px;
    background: var(--header-bg);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 30px;
    box-shadow: var(--shadow);
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 40px;
}


.top-nav {
    display: flex;
    gap: 5px;
}

.nav-link {
    text-decoration: none;
    color: var(--text-light);
    padding: 10px 15px;
    border-radius: 8px;
    font-weight: 500;
    transition: all 0.2s;
    display: flex;
    gap: 8px;
    align-items: center;
}

.nav-link:hover,
.nav-link.active {
    background: #eff6ff;
    color: var(--primary);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

.user-name {
    font-weight: 600;
}

#logout-btn {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--text-light);
}

#logout-btn:hover {
    color: #ef4444;
}

/* Main Content */
#main-content {
    height: calc(100dvh - 70px);
    overflow-y: auto;
    overflow-x: clip;
    padding: 30px;
}
#main-content.chat-mode {
    padding: 0;
    overflow: hidden;
}

#view-container {
    max-width: 1800px;
    margin: 0 auto;
}

/* Cards & Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
}

.stat-card {
    background: white;
    padding: 25px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.projects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
}

.project-card {
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: var(--shadow);
    border-left: 5px solid #ccc;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
}

.card-header h3 {
    margin: 0;
    font-size: 1.1rem;
}

.status-badge {
    font-size: 0.75rem;
    padding: 4px 8px;
    background: #f1f5f9;
    border-radius: 4px;
}

.card-users {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.users-list {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.user-badge {
    background: #e0f2fe;
    color: #0369a1;
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 10px;
}

/* Buttons */
.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: #e2e8f0;
    color: var(--text-main);
    border: none;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
}

.btn-sm {
    padding: 5px 10px;
    font-size: 0.85rem;
}

/* Tables */
.table-container {
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: var(--shadow);
    overflow-x: auto;
    min-height: 420px;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 15px;
    text-align: left;
    border-bottom: 1px solid #e2e8f0;
}

th {
    font-weight: 600;
    color: var(--text-light);
    font-size: 0.9rem;
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 200;
}

.modal-content {
    background: white;
    width: 800px;
    max-width: 95%;
    padding: 25px;
    border-radius: 12px;
    animation: popIn 0.2s;
    max-height: 90vh;
    overflow-y: auto;
}

@keyframes popIn {
    from {
        transform: scale(0.9);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
}

.close-modal {
    cursor: pointer;
    font-size: 1.5rem;
}

/* Forms */
.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-size: 0.9rem;
    font-weight: 500;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
}

/* Login */
.login-wrapper {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f8fafc;
}

.login-box {
    background: white;
    padding: 40px;
    border-radius: 16px;
    width: 400px;
    box-shadow: var(--shadow);
}

/* Loader */
.loader-container {
    display: flex;
    justify-content: center;
    padding: 50px;
}

.loader {
    width: 40px;
    height: 40px;
    border: 4px solid #e2e8f0;
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Lang Dropdown */
.lang-dropdown:hover .lang-content {
    display: flex !important;
}

/* Premium Dashboard Styles */
.glass-card {
    background: #ffffff;
    /* Solid white for performance */
    border: 1px solid #e2e8f0;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    /* Lighter shadow */
    border-radius: 16px;
    padding: 25px;
    transition: transform 0.2s;
    /* Removed backdrop-filter: blur(10px) to prevent high GPU usage */
}

.glass-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

.dashboard-charts-grid,
.dashboard-bottom-grid {
    display: grid;
    gap: 25px;
    margin-top: 25px;
}

/* Desktop Layouts */
@media (min-width: 1024px) {
    .dashboard-charts-grid {
        grid-template-columns: 2fr 1fr;
    }

    .dashboard-bottom-grid {
        grid-template-columns: 1fr 1fr;
    }
}

/* Mobile/Tablet: Stack them */
@media (max-width: 1023px) {

    .dashboard-charts-grid,
    .dashboard-bottom-grid {
        grid-template-columns: 1fr;
    }
}

.gradient-text {
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 800;
}

.grad-blue {
    background-image: linear-gradient(135deg, #2563eb 0%, #a855f7 100%);
}

.grad-green {
    background-image: linear-gradient(135deg, #10b981 0%, #06b6d4 100%);
}

.grad-orange {
    background-image: linear-gradient(135deg, #f97316 0%, #f43f5e 100%);
}

.progress-bar-bg {
    background: #f1f5f9;
    border-radius: 10px;
    height: 8px;
    width: 100%;
    margin-top: 8px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    border-radius: 10px;
    transition: width 1s ease-in-out;
}

.activity-item {
    display: flex;
    gap: 15px;
    padding: 12px 0;
    border-bottom: 1px solid #f1f5f9;
}

.activity-item:last-child {
    border-bottom: none;
}

.activity-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: #f8fafc;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-light);
}

/* Toast Notifications */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    min-width: 300px;
    background: white;
    padding: 15px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    display: flex;
    align-items: center;
    justify-content: space-between;
    animation: slideIn 0.3s ease-out;
    border-left: 4px solid #cbd5e1;
}

.toast.success {
    border-left-color: #22c55e;
}

.toast.error {
    border-left-color: #ef4444;
}

.toast-content {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.95rem;
    color: #334155;
}

.toast-close {
    cursor: pointer;
    color: #94a3b8;
    margin-left: 10px;
}

.toast-close:hover {
    color: #64748b;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }

    to {
        transform: translateX(100%);
        opacity: 0;
    }
}
/* Modern Permissions UI */
.perm-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 12px;
    margin-top: 10px;
}

.perm-card {
    position: relative;
    cursor: pointer;
    user-select: none;
}

.perm-card input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    cursor: pointer;
    height: 0;
    width: 0;
}

.perm-label {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 15px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    color: #475569;
    font-size: 0.9rem;
    font-weight: 500;
}

.perm-label:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
    transform: translateY(-1px);
}

.perm-card input[type="checkbox"]:checked + .perm-label {
    background: #eff6ff;
    border-color: #3b82f6;
    color: #2563eb;
    box-shadow: 0 4px 6px -1px rgba(37, 99, 235, 0.1);
}

.perm-card input[type="checkbox"]:checked + .perm-label:before {
    content: '\f00c';
    font-family: 'Font Awesome 5 Free';
    font-weight: 900;
    margin-right: 2px;
}

/* =============================================
   RESPONSIVE — Tablet & Mobile
   ============================================= */

/* Tablet: 768px – 1024px */
@media (max-width: 1024px) {
    body {
        overflow-y: auto;
        overflow-x: hidden;
        height: auto;
    }

    /* Show hamburger, hide desktop nav */
    #mobile-menu-btn { display: flex; }
    .top-nav { display: none; }

    /* Header adjustments */
    #main-header {
        height: 58px;
        padding: 0 14px;
        position: sticky;
        top: 0;
        z-index: 200;
    }
    .header-left { gap: 6px; }
    .logo { font-size: 1.15rem; }
    .user-name { display: none; }
    .lang-dropdown { display: none; }
    #whatsapp-btn { display: none; }
    .header-right { gap: 8px; }

    /* Main content */
    #main-content {
        height: calc(100dvh - 58px);
        padding: 16px;
        overflow-x: clip;
    }

    /* Tables: smaller text, horizontal scroll */
    .table-container {
        padding: 12px;
        min-height: auto;
        border-radius: 10px;
    }
    th, td { padding: 10px 12px; font-size: 0.82rem; }

    /* View headers: wrap on small screens */
    .view-header {
        flex-wrap: wrap !important;
        gap: 10px !important;
        align-items: center !important;
        margin-bottom: 14px !important;
    }
    .view-header h2 { font-size: 1.1rem; margin: 0; }
    .view-header > div { flex-wrap: wrap; gap: 8px; }

    /* Modals: full-width with margin */
    .modal-content {
        width: 95% !important;
        max-width: 95% !important;
        padding: 18px;
        max-height: 92vh;
        border-radius: 14px;
    }

    /* ── ALL grids inside modals → single column ── */
    .modal-content [style*="grid-template-columns"],
    .modal-content [class*="tw-grid-cols"] {
        grid-template-columns: 1fr !important;
    }
    /* Reset all grid-column spans */
    .modal-content [style*="grid-column"],
    .modal-content [class*="tw-col-span"] {
        grid-column: auto !important;
    }
    /* View-level grids (outside modals) */
    [style*="grid-template-columns: 1fr 1fr"],
    [style*="grid-template-columns:1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }
    /* Service rows: 2-col compact layout on tablet */
    .service-row {
        grid-template-columns: 1fr 1fr !important;
        gap: 8px !important;
    }
    .service-row > div:first-child {
        grid-column: 1 / -1 !important;
    }

    /* Stat cards */
    .dashboard-grid {
        grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
        gap: 12px;
    }
    .stat-card { padding: 16px; }

    /* Project cards */
    .projects-grid {
        grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    }

    /* Toast position */
    #toast-container { right: 10px; top: 10px; }
    .toast { min-width: 260px; font-size: 0.88rem; }

    /* Login box */
    .login-box {
        width: 90%;
        max-width: 400px;
        padding: 28px;
    }

    /* Notif dropdown width */
    #notif-dropdown { width: 260px !important; }

    /* ── Chat monitor: same panel-toggle as chat ── */
    #monitor-layout {
        position: relative !important;
        height: calc(100dvh - 58px) !important;
    }
    #monitor-sidebar {
        width: 100% !important;
        min-width: 100% !important;
        position: absolute !important;
        top: 0; left: 0; right: 0; bottom: 0;
        z-index: 5;
        transition: transform .25s ease;
    }
    #monitor-msgs-panel { width: 100% !important; }
    #monitor-layout.mobile-room-open #monitor-sidebar {
        transform: translateX(-100%);
    }
    #monitor-back-btn { display: flex !important; }

    /* ── Hosting modal Tailwind grids → 1-col ── */
    #hosting-form { grid-template-columns: 1fr !important; }
    #hosting-form [class*="tw-grid-cols"] { grid-template-columns: 1fr !important; }
    #hosting-form [class*="tw-col-span"] { grid-column: auto !important; }

    /* ── Dashboard revenue filter wrap ── */
    #revenue-filter-container { flex-wrap: wrap !important; gap: 6px !important; }

    /* ── Flex rows in modals wrap ── */
    .modal-content .tw-flex:not(.tw-items-center):not(.tw-gap-1):not(.tw-gap-2) {
        flex-wrap: wrap;
    }

    /* ── All inputs/selects full-width inside modals ── */
    .modal-content input[style*="width"],
    .modal-content select[style*="width"] {
        width: 100% !important;
        min-width: 0 !important;
    }
}

/* Mobile: up to 640px */
@media (max-width: 640px) {
    #main-content { padding: 10px; }

    /* Header */
    #main-header { height: 54px; padding: 0 10px; }
    #main-content { height: calc(100dvh - 54px); }
    .logo { font-size: 1rem; }
    .logo i { display: none; }  /* Hide cube icon to save space */

    /* Tables: hide less-important columns via data-mobile-hide */
    th[data-mobile-hide="true"],
    td[data-mobile-hide="true"] { display: none; }
    th, td { padding: 8px 10px; font-size: 0.78rem; }

    /* Modals: truly full-screen */
    .modal-overlay { align-items: flex-end; }
    .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 16px 16px 0 0 !important;
        max-height: 95vh;
        padding: 16px;
        margin: 0;
    }

    /* Stat cards: 2 per row */
    .dashboard-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    .stat-card { padding: 12px; }
    .stat-card .stat-icon { display: none; }

    /* Projects: single column */
    .projects-grid { grid-template-columns: 1fr; }

    /* Buttons in view-header: smaller */
    .view-header .btn-primary,
    .view-header .btn-secondary {
        padding: 8px 12px;
        font-size: 0.82rem;
    }
    .view-header .btn-primary i,
    .view-header .btn-secondary i { margin-right: 3px; }

    /* Table container */
    .table-container { padding: 8px; border-radius: 8px; }

    /* Toast */
    #toast-container { right: 8px; left: 8px; top: 8px; }
    .toast { min-width: unset; width: 100%; font-size: 0.82rem; }

    /* Login */
    .login-box { width: 95%; padding: 22px; }
    .login-box h2 { font-size: 1.3rem; }

    /* Chat: ensure it fills properly */
    #main-content.chat-mode { height: calc(100dvh - 54px); }

    /* Stronger grid override for mobile */
    .modal-content [style*="grid-template-columns"],
    .modal-content [class*="tw-grid-cols"],
    .modal-content .tw-grid { grid-template-columns: 1fr !important; }
    .modal-content [style*="grid-column"],
    .modal-content [class*="tw-col-span"] { grid-column: auto !important; }

    /* Service rows: stack completely on mobile */
    .service-row { grid-template-columns: 1fr !important; }
    .service-row > * { grid-column: auto !important; }

    /* Chat/monitor on smallest screens */
    #chat-layout { height: calc(100dvh - 54px) !important; }
    #monitor-layout { height: calc(100dvh - 54px) !important; }

    /* Notif dropdown */
    #notif-dropdown {
        width: calc(100vw - 20px) !important;
        right: -60px !important;
    }

    /* Print preview modal */
    #print-preview-modal .modal-content {
        width: 100% !important;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0 !important;
    }
}

/* ── Mobile table: hide .mob-hide columns ── */
@media (max-width: 640px) {
    /* All mob-hide columns disappear */
    .mob-hide { display: none !important; }

    /* Global table: smaller text, tighter cells */
    td, th { font-size: 0.76rem !important; padding: 8px 6px !important; }

    /* Contracts filter: hide date range */
    .contract-date-range { display: none !important; }

    /* Search input stretches */
    .contract-search-wrap { flex: 1 1 100% !important; }
    .contract-search-wrap input { width: 100% !important; box-sizing: border-box; }
}

/* Very small screens */
@media (max-width: 380px) {
    .dashboard-grid { grid-template-columns: 1fr; }
    #mobile-nav-drawer { width: 260px; }
}

/* ═══════════════════════════════════════════════════════════
   CORE MOBILE FIX — Tables fit at 375px, zero horizontal scroll
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 640px) {
    /* 1. Remove horizontal scroll from table containers entirely */
    .table-container { overflow-x: hidden !important; }

    /* 2. Fixed table layout — columns obey assigned widths */
    table { table-layout: fixed !important; width: 100% !important; min-width: 0 !important; }

    /* 3. Operations (last) column — fixed 28% so buttons fit */
    thead th:last-child,
    tbody td:last-child { width: 28% !important; max-width: 28% !important; }

    /* 4. Data cells — truncate overflow text */
    tbody td:not(:last-child) {
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        white-space: nowrap !important;
    }

    /* 5. Operations cell — no scroll, buttons tightly packed */
    tbody td:last-child {
        overflow: hidden !important;
        white-space: nowrap !important;
        padding-right: 4px !important;
    }

    /* 6. All operation buttons → icon-only (font-size:0 hides text nodes,
          FA icons use ::before so they stay visible at the re-set size) */
    tbody td:last-child button {
        font-size: 0 !important;
        padding: 5px 7px !important;
        min-width: 0 !important;
        min-height: 0 !important;
        line-height: 1 !important;
    }
    tbody td:last-child button i { font-size: 0.78rem !important; }

    /* Tighten flex gaps inside operations cells */
    tbody td:last-child .tw-flex  { gap: 2px !important; }
    tbody td:last-child .tw-gap-1 { gap: 2px !important; }
    tbody td:last-child .tw-gap-2 { gap: 3px !important; }

    /* 7. perm-grid: 2 columns on mobile */
    .perm-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 6px !important;
    }
    .perm-label { padding: 8px 10px !important; font-size: 0.8rem !important; }

    /* 8. Fix inline-width inputs that bust viewport */
    input[style*="width: 180px"] { width: 100% !important; max-width: 100% !important; }
    select[style*="width: 120px"],
    select[style*="width: 130px"] { width: 100% !important; max-width: 100% !important; }

    /* 9. Remove any remaining min-width from supplements table */
    .modal-content th[style*="min-width"],
    .modal-content td[style*="min-width"] { min-width: 0 !important; }
}

/* ── Kanban: stack columns vertically on mobile ── */
@media (max-width: 1024px) {
    .kanban-board {
        flex-direction: column !important;
        height: auto !important;
        overflow-x: hidden !important;
        padding-bottom: 20px !important;
    }
    .kanban-column {
        min-width: unset !important;
        width: 100% !important;
        flex: none !important;
        max-height: none !important;
    }
    .kanban-items {
        overflow-y: visible !important;
        max-height: none !important;
        min-height: 0 !important;
    }
}

/* ── Chat: full-screen panels, toggle sidebar/messages ── */
@media (max-width: 768px) {
    #chat-layout {
        position: relative !important;
        height: calc(100dvh - 54px) !important;
    }
    #chat-rooms-panel {
        width: 100% !important;
        min-width: 100% !important;
        position: absolute !important;
        top: 0; left: 0; right: 0; bottom: 0;
        z-index: 5;
        transition: transform .25s ease;
    }
    #chat-messages-panel {
        width: 100% !important;
        min-width: 100% !important;
    }
    /* When a room is open, slide rooms panel off-screen */
    #chat-layout.mobile-room-open #chat-rooms-panel {
        transform: translateX(-100%);
    }
    /* Back button visible on mobile only */
    #chat-back-btn {
        display: flex !important;
    }
    /* Reduce chat bubble max width */
    .chat-msg { max-width: 85% !important; }
    /* Chat input area padding */
    #chat-messages-body { padding: 10px 12px !important; }
}

/* ── Contracts filter bar: wrap ── */
@media (max-width: 1024px) {
    #contracts-filters-row {
        flex-wrap: wrap !important;
        gap: 8px !important;
    }
    #contracts-filters-row > * {
        flex: 1 1 130px !important;
        min-width: 0 !important;
    }
    #contracts-filters-row input[type="date"] {
        min-width: 120px !important;
    }
}

/* ── General: prevent anything from busting viewport width ── */
#app, #view-container, #main-content {
    max-width: 100vw;
    overflow-x: hidden;
}
/* Header must NOT clip overflow — dropdowns need to escape it */
#main-header {
    max-width: 100vw;
    overflow: visible;
    position: relative;
    z-index: 300;
}
/* Tables scroll within their container only */
.table-container { overflow-x: auto; overflow-y: visible; }
table { min-width: 0; width: 100%; }

/* Contract table action dropdowns — must overflow table container */
.dropdown-menu { position: absolute; z-index: 9999 !important; }
.tw-hidden { display: none !important; }

/* Touch improvements */
@media (hover: none) and (pointer: coarse) {
    .btn-primary, .btn-secondary, .nav-link, .close-modal {
        min-height: 44px;
        min-width: 44px;
    }
    th, td { padding: 10px 8px; }
    .form-group input,
    .form-group select,
    .form-group textarea {
        font-size: 16px; /* Prevent iOS zoom on focus */
    }
}
