/* Custom CSS for 5UP System */

/* ===================================================
   0. CSS VARIABLES — Viewport Height (iOS Safari fix)
   =================================================== */
:root {
    --vh: 1vh;
}

/* ===================================================
   1. Global Modal Centering
   =================================================== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 50;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

/* Elements ending in 'Modal' — hidden by default, NO backdrop unless .open is added */
[id$="Modal"] {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 50;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

/* When explicitly opened via JS — add class 'open' */
[id$="Modal"].open,
.modal.open {
    display: flex !important;
    opacity: 1;
}

/* Modal Content Box */
[id$="Modal"] > div,
.modal > div {
    max-height: 90vh;
    max-height: 90dvh; /* dynamic viewport height for mobile browsers */
    overflow-y: auto;
    margin: 0.75rem;
    position: relative;
    width: calc(100% - 1.5rem);
    max-width: 600px;
}

/* Modal larger variant */
[id$="Modal"] > div.modal-lg,
.modal > div.modal-lg {
    max-width: 900px;
}

/* ===================================================
   2. Responsive Tables — ALL tables auto-scroll on mobile
   =================================================== */
.table-responsive {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Auto-apply overflow scroll to table containers */
.overflow-x-auto {
    -webkit-overflow-scrolling: touch;
}

/* Tables inside cards/panels are scrollable by default on mobile */
@media (max-width: 768px) {
    .card-table,
    .bg-white table:not(.sheet-table),
    .dark\:bg-slate-800 table:not(.sheet-table) {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Compact table text on mobile */
    table th,
    table td {
        font-size: 0.75rem;
        padding: 0.5rem 0.625rem;
    }

    /* Sheet tables (mensetsu form) scroll horizontally */
    .sheet-table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* ===================================================
   3. Mobile Sidebar Overrides
   =================================================== */
@media (max-width: 767px) {
    .sidebar-mobile-open {
        display: flex !important;
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        height: 100dvh;
        width: 16rem; /* w-64 */
        box-shadow: 4px 0 15px rgba(0, 0, 0, 0.5);
    }

    .sidebar-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 40;
    }

    /* Reduce header padding on small screens */
    header.h-16 {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    /* Main content full padding on mobile */
    #main-content {
        padding: 0.75rem;
    }

    /* Cards stack vertically */
    .grid {
        gap: 0.75rem;
    }
}

/* ===================================================
   4. Touch-Friendly Targets (Mobile / Tablet)
   =================================================== */
@media (max-width: 1024px) {
    /* Minimum 44px touch target for interactive elements */
    button,
    a.flex,
    [role="button"] {
        min-height: 36px;
    }

    /* Sidebar links bigger tap area */
    #main-sidebar a,
    #main-sidebar button {
        min-height: 44px;
    }

    /* Action buttons larger on touch screens */
    .action-btn {
        width: 40px;
        height: 40px;
        font-size: 1.15rem;
    }
}

/* ===================================================
   5. iOS Safari Height Fix
   =================================================== */
html,
body {
    height: 100%;
    /* Fallback for browsers that don't support dvh */
}

@supports (height: 100dvh) {
    .h-screen-safe {
        height: 100dvh;
    }

    #main-sidebar {
        height: 100dvh;
    }
}

/* Fix iOS Safari bounce scroll on body */
body {
    overscroll-behavior: none;
    -webkit-overflow-scrolling: auto;
}

/* ===================================================
   6. SweetAlert2 — match dark theme + mobile safe
   =================================================== */
div.swal2-container {
    z-index: 60 !important;
}

.dark div.swal2-popup {
    background: #1e293b;
    color: #e2e8f0;
}

.dark div.swal2-title {
    color: #fff;
}

@media (max-width: 480px) {
    div.swal2-popup {
        width: 90vw !important;
        padding: 1.25rem !important;
    }
}

/* ===================================================
   7. Premium Action Buttons (Glassmorphism + Glow)
   =================================================== */
.action-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    cursor: pointer;
    font-size: 1.1rem;
}

.action-btn:hover {
    transform: translateY(-2px) scale(1.05);
    border-color: rgba(255, 255, 255, 0.3);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.2);
}

.action-btn:active {
    transform: translateY(0) scale(0.95);
}

.action-btn i {
    transition: transform 0.3s ease;
}

.action-btn:hover i {
    transform: scale(1.1);
}

/* Specific Action Colors & Glows */
.btn-edit {
    background: rgba(14, 165, 233, 0.15);
    color: #0ea5e9;
}
.btn-edit:hover {
    background: #0ea5e9;
    color: white;
    box-shadow: 0 0 15px rgba(14, 165, 233, 0.4);
}

.btn-delete {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}
.btn-delete:hover {
    background: #ef4444;
    color: white;
    box-shadow: 0 0 15px rgba(239, 68, 68, 0.4);
}

.btn-view {
    background: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
}
.btn-view:hover {
    background: #f59e0b;
    color: white;
    box-shadow: 0 0 15px rgba(245, 158, 11, 0.4);
}

.btn-file {
    background: rgba(71, 85, 105, 0.15);
    color: #475569;
}
.btn-file:hover {
    background: #475569;
    color: white;
    box-shadow: 0 0 15px rgba(71, 85, 105, 0.4);
}

.btn-toggle {
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
}
.btn-toggle:hover {
    background: #10b981;
    color: white;
    box-shadow: 0 0 15px rgba(16, 185, 129, 0.4);
}

.btn-reset {
    background: rgba(244, 63, 94, 0.15);
    color: #f43f5e;
}
.btn-reset:hover {
    background: #f43f5e;
    color: white;
    box-shadow: 0 0 15px rgba(244, 63, 94, 0.4);
}

.btn-perms {
    background: rgba(79, 70, 229, 0.15);
    color: #4f46e5;
}
.btn-perms:hover {
    background: #4f46e5;
    color: white;
    box-shadow: 0 0 15px rgba(79, 70, 229, 0.4);
}

/* Disabled State */
.action-btn:disabled {
    background: rgba(148, 163, 184, 0.1);
    color: #64748b;
    cursor: not-allowed;
    border-color: transparent;
    box-shadow: none;
    transform: none;
}

/* ===================================================
   8. Responsive Forms
   =================================================== */
@media (max-width: 640px) {
    /* Stack form fields vertically */
    .form-row {
        flex-direction: column;
    }

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

/* ===================================================
   9. Smart TV / Large Display Support (1920px+)
   =================================================== */
@media (min-width: 1920px) {
    /* Larger base font for TV viewing distance */
    body {
        font-size: 1.05rem;
    }

    /* Sidebar wider on TV */
    #main-sidebar {
        width: 18rem;
    }

    /* Cards bigger */
    .rounded-2xl {
        border-radius: 1.25rem;
    }

    /* Better reading line length on wide displays */
    #main-content > * {
        max-width: 1800px;
    }
}

@media (min-width: 2560px) {
    /* 4K / Ultra-wide */
    body {
        font-size: 1.125rem;
    }

    #main-sidebar {
        width: 20rem;
    }

    #main-content > * {
        max-width: 2400px;
    }

    .action-btn {
        width: 44px;
        height: 44px;
        font-size: 1.25rem;
    }
}

/* ===================================================
   10. Tablet Landscape Optimizations (768–1024px)
   =================================================== */
@media (min-width: 768px) and (max-width: 1023px) {
    /* Sidebar fixed, content adjusts */
    #main-sidebar {
        width: 14rem; /* narrower on tablet */
    }

    #main-content {
        padding: 1rem;
    }

    /* 2-col grids on tablet */
    .lg\:grid-cols-4 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* ===================================================
   11. Scrollbar Styling (non-invasive, cross-browser)
   =================================================== */
/* Sidebar scrollbar */
.sidebar-scroll::-webkit-scrollbar {
    width: 4px;
}
.sidebar-scroll::-webkit-scrollbar-track {
    background: transparent;
}
.sidebar-scroll::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}
.sidebar-scroll::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Main content scrollbar */
#main-content::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
#main-content::-webkit-scrollbar-track {
    background: transparent;
}
#main-content::-webkit-scrollbar-thumb {
    background: rgba(100, 116, 139, 0.4);
    border-radius: 3px;
}
#main-content::-webkit-scrollbar-thumb:hover {
    background: rgba(100, 116, 139, 0.7);
}

/* ===================================================
   12. Print Media
   =================================================== */
@media print {
    #main-sidebar,
    header,
    #sidebar-backdrop,
    #open-sidebar-btn,
    #theme-toggle,
    #user-menu-btn {
        display: none !important;
    }

    body {
        background: white;
    }

    #main-content {
        padding: 0;
        overflow: visible;
    }

    table {
        page-break-inside: auto;
    }

    tr {
        page-break-inside: avoid;
        page-break-after: auto;
    }
}
