/* ============================================================
   Portal Digital JPP Sabah — Custom CSS
   Strategy: Mobile-First | Breakpoints: 640px / 1024px
   ============================================================ */

/* --------------------------------------------------------
   1. CSS CUSTOM PROPERTIES
   -------------------------------------------------------- */
:root {
    --primary:    #064e3b;
    --primary-lt: #065f46;
    --accent:     #f97316;
    --soft-blue:  #60a5fa;
    --white:      #ffffff;
    --gray-50:    #f9fafb;
    --gray-100:   #f3f4f6;
    --gray-200:   #e5e7eb;
    --gray-500:   #6b7280;
    --gray-700:   #374151;
    --gray-900:   #111827;
    --red-500:    #ef4444;
    --red-800:    #991b1b;
    --green-600:  #16a34a;
    --green-800:  #166534;
    --blue-800:   #1e40af;
    --purple-800: #6b21a8;

    /* Typography — responsive via clamp */
    --fs-h1:   clamp(1.5rem, 4vw, 2.5rem);
    --fs-h2:   clamp(1.25rem, 3vw, 2rem);
    --fs-h3:   clamp(1.1rem, 2.5vw, 1.5rem);
    --fs-body: 1rem;
    --fs-sm:   0.875rem;
    --fs-xs:   0.75rem;

    /* Spacing */
    --section-gap: clamp(1rem, 3vw, 2rem);
    --card-pad:    clamp(0.75rem, 2vw, 1.5rem);
}

/* --------------------------------------------------------
   2. BASE & TYPOGRAPHY
   -------------------------------------------------------- */
html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    font-size: var(--fs-body);
    line-height: 1.6;
    color: var(--gray-900);
    background: var(--gray-50);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

h1, .h1 { font-size: var(--fs-h1); font-weight: 800; line-height: 1.2; }
h2, .h2 { font-size: var(--fs-h2); font-weight: 700; line-height: 1.25; }
h3, .h3 { font-size: var(--fs-h3); font-weight: 700; line-height: 1.3; }
h4, .h4 { font-size: var(--fs-body); font-weight: 600; }

small, .text-sm { font-size: var(--fs-sm); }
.text-xs      { font-size: var(--fs-xs); }

a {
    color: var(--primary);
    text-decoration: none;
}

img { max-width: 100%; height: auto; }

/* --------------------------------------------------------
   3. FOCUS & ACCESSIBILITY (WCAG AA)
   -------------------------------------------------------- */
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-radius: 4px;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.skip-link {
    position: absolute;
    top: -100%;
    left: 0;
    background: var(--primary);
    color: var(--white);
    padding: 0.5rem 1rem;
    z-index: 10000;
}
.skip-link:focus { top: 0; }

/* --------------------------------------------------------
   4. SCROLLBAR
   -------------------------------------------------------- */
::-webkit-scrollbar           { width: 6px; height: 6px; }
::-webkit-scrollbar-track     { background: var(--gray-100); }
::-webkit-scrollbar-thumb     { background: #9ca3af; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #6b7280; }

/* --------------------------------------------------------
   5. ANIMATIONS (performance-safe)
   -------------------------------------------------------- */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes spin {
    to { transform: rotate(360deg); }
}
@keyframes pulse-soft {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.6; }
}

.fade-in        { animation: fadeIn 0.35s ease-out; }
.pulse-notify   { animation: pulse-soft 2s infinite; }

.loading-spinner {
    width: 40px; height: 40px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

/* --------------------------------------------------------
   6. LAYOUT: SIDEBAR
   -------------------------------------------------------- */
.sidebar {
    background: linear-gradient(180deg, var(--primary) 0%, #065f46 100%);
    width: 260px;
    flex-shrink: 0;
    transition: transform 0.3s ease;
    z-index: 50;
}

/* Mobile: sidebar hidden off-screen by default */
@media (max-width: 1023px) {
    #mobile-sidebar {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        width: 260px;
        transform: translateX(-100%);
        overflow-y: auto;
        box-shadow: 4px 0 20px rgba(0,0,0,0.3);
        transition: transform 0.3s ease;
    }
    #mobile-sidebar.open {
        transform: translateX(0);
    }
    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.45);
        z-index: 49;
    }
}

/* --------------------------------------------------------
   7. LAYOUT: TOP BAR / HEADER
   -------------------------------------------------------- */
.top-bar {
    background: var(--white);
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    position: sticky;
    top: 0;
    z-index: 40;
}

/* --------------------------------------------------------
   8. GLASSMORPHISM (reduced on mobile)
   -------------------------------------------------------- */
.glass-card {
    background: rgba(255,255,255,0.7);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255,255,255,0.25);
    box-shadow: 0 4px 16px rgba(0,0,0,0.06);
}

@media (max-width: 640px) {
    .glass-card {
        backdrop-filter: blur(6px);
        box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    }
}

/* --------------------------------------------------------
   9. CARDS (Dashboard / Stats / Profile)
   -------------------------------------------------------- */
.card {
    background: var(--white);
    border-radius: 1rem;
    padding: var(--card-pad);
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    transition: box-shadow 0.2s, transform 0.2s;
}

.card-hover:hover {
    box-shadow: 0 6px 20px rgba(0,0,0,0.1);
    transform: translateY(-3px);
}

/* Stat card accent border */
.card-stat {
    border-bottom: 4px solid var(--soft-blue);
}

/* Dashboard stat grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

@media (min-width: 768px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1024px) {
    .stats-grid { grid-template-columns: repeat(4, 1fr); }
}

/* Profile card */
.profile-card {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.profile-card .avatar {
    width: 44px; height: 44px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

/* --------------------------------------------------------
   10. TABLES — responsive: horizontal scroll + card fallback
   -------------------------------------------------------- */
.table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 0.75rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

table {
    width: 100%;
    border-collapse: collapse;
    white-space: nowrap;
    font-size: var(--fs-sm);
}

thead {
    background: var(--gray-100);
}
thead th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-500);
    border-bottom: 2px solid var(--gray-200);
}

tbody td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--gray-100);
    vertical-align: middle;
}
tbody tr:hover { background: var(--gray-50); }

/* ----- Mobile: card list (hide table, show cards) ----- */
.table-card-list { display: none; }

@media (max-width: 639px) {
    .table-wrap table       { display: none; }
    .table-card-list        { display: block; }

    .table-card {
        background: var(--white);
        border-radius: 0.75rem;
        padding: 0.75rem 1rem;
        margin-bottom: 0.5rem;
        box-shadow: 0 1px 2px rgba(0,0,0,0.04);
    }
    .table-card:active { background: var(--gray-100); }

    .table-card .card-row {
        display: flex;
        align-items: flex-start;
        gap: 0.75rem;
    }
    .table-card .card-avatar {
        width: 42px; height: 42px;
        border-radius: 50%;
        background: var(--gray-100);
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
        overflow: hidden;
    }
    .table-card .card-info { flex: 1; min-width: 0; }
    .table-card .card-info .card-name {
        font-weight: 600;
        font-size: var(--fs-body);
        color: var(--gray-900);
        word-break: break-word;
    }
    .table-card .card-info .card-sub {
        font-size: var(--fs-xs);
        color: var(--gray-500);
        margin-top: 2px;
    }
    .table-card .card-meta {
        display: flex;
        flex-wrap: wrap;
        gap: 4px;
        margin-top: 6px;
    }
    .table-card .card-actions {
        display: flex;
        gap: 2px;
        margin-top: 8px;
    }
    .table-card .card-actions .btn-pill {
        display: inline-flex;
        align-items: center;
        gap: 4px;
        padding: 6px 12px;
        border-radius: 8px;
        font-size: 0.75rem;
        font-weight: 600;
        border: none;
        cursor: pointer;
        transition: background 0.15s;
    }
}

/* --------------------------------------------------------
   11. FORMS
   -------------------------------------------------------- */
.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--gray-200);
    border-radius: 0.5rem;
    font-size: 1rem;           /* ≥16px prevents iOS zoom */
    font-family: inherit;
    background: var(--white);
    transition: border-color 0.15s, box-shadow 0.15s;
    box-sizing: border-box;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(6,78,59,0.15);
    outline: none;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
}
@media (min-width: 640px) {
    .form-grid { grid-template-columns: 1fr 1fr; }
}

.form-label {
    display: block;
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 0.25rem;
}

.input-error   { border-color: var(--red-500) !important; background: #fef2f2 !important; }
.input-success { border-color: var(--green-600) !important; background: #f0fdf4 !important; }
.error-message { color: var(--red-500); font-size: var(--fs-xs); margin-top: 0.25rem; }

/* --------------------------------------------------------
   12. BUTTONS
   -------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    min-height: 44px;          /* WCAG touch target */
    min-width:  44px;
    padding: 0.5rem 1.25rem;
    border-radius: 0.5rem;
    font-size: var(--fs-sm);
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
    white-space: nowrap;
    user-select: none;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
    background: var(--primary);
    color: var(--white);
}
.btn-primary:hover   { background: var(--primary-lt); }
.btn-primary:focus-visible { box-shadow: 0 0 0 3px rgba(6,78,59,0.35); }

.btn-outline {
    background: transparent;
    border: 1px solid var(--gray-200);
    color: var(--gray-700);
}
.btn-outline:hover { background: var(--gray-50); }

.btn-danger  { background: var(--red-500); color: var(--white); }
.btn-danger:hover { background: #dc2626; }

.btn-sm { min-height: 36px; padding: 0.375rem 0.875rem; font-size: var(--fs-xs); }
.btn-lg { min-height: 48px; padding: 0.75rem 1.5rem; font-size: var(--fs-body); }

.btn-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.btn-group .btn { flex: 1 1 auto; }

/* --------------------------------------------------------
   13. MODAL
   -------------------------------------------------------- */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal-content {
    background: var(--white);
    border-radius: 1rem;
    padding: 1.5rem;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    animation: fadeIn 0.25s ease-out;
}

@media (max-width: 639px) {
    .modal-content {
        width: 95%;
        max-width: none;
        margin: 0.5rem;
        border-radius: 1rem 1rem 0 0;
        max-height: 85vh;
    }
    .modal-backdrop {
        align-items: flex-end;
        padding: 0;
    }
}

/* --------------------------------------------------------
   14. BADGES & STATUS
   -------------------------------------------------------- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.15rem 0.6rem;
    border-radius: 9999px;
    font-size: 0.7rem;
    font-weight: 700;
    white-space: nowrap;
}

.badge-pending    { background: #fef3c7; color: #92400e; }
.badge-approved   { background: #d1fae5; color: #065f46; }
.badge-rejected   { background: #fee2e2; color: #991b1b; }
.badge-processing { background: #dbeafe; color: #1e40af; }
.badge-completed  { background: #f3e8ff; color: #6b21a8; }
.badge-active     { background: #d1fae5; color: #065f46; }
.badge-inactive   { background: #e5e7eb; color: #374151; }
.badge-suspended  { background: #fee2e2; color: #991b1b; }

.badge-admin { background: #fee2e2; color: var(--red-800); }
.badge-pic   { background: #f3e8ff; color: var(--purple-800); }
.badge-staff { background: #dbeafe; color: var(--blue-800); }

.badge-counter {
    position: absolute;
    top: -6px; right: -6px;
    min-width: 20px; height: 20px;
    border-radius: 10px;
    background: var(--red-500);
    color: var(--white);
    font-size: 0.7rem;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
}

/* --------------------------------------------------------
   15. BREADCRUMB
   -------------------------------------------------------- */
.breadcrumb {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem;
    font-size: var(--fs-xs);
    color: var(--gray-500);
    margin-bottom: 1rem;
    padding: 0.5rem 0;
}
.breadcrumb a       { color: var(--primary); }
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb .sep    { color: #9ca3af; margin: 0 0.25rem; }

/* --------------------------------------------------------
   16. PAGINATION
   -------------------------------------------------------- */
.pagination {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    justify-content: center;
    padding: 1rem 0;
}
.pagination a,
.pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 38px; min-height: 38px;
    padding: 0 0.5rem;
    border-radius: 0.375rem;
    font-size: var(--fs-sm);
    font-weight: 500;
    border: 1px solid var(--gray-200);
    background: var(--white);
    color: var(--gray-700);
    transition: background 0.15s;
}
.pagination a:hover          { background: var(--gray-50); }
.pagination .active          { background: var(--primary); color: var(--white); border-color: var(--primary); }
.pagination .disabled        { opacity: 0.4; pointer-events: none; }

/* --------------------------------------------------------
   17. SEARCH & FILTER SECTION
   -------------------------------------------------------- */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: flex-end;
}
.filter-bar .form-input,
.filter-bar .form-select {
    flex: 1 1 180px;
    min-width: 150px;
}
.filter-bar .btn { flex-shrink: 0; }

@media (max-width: 639px) {
    .filter-bar {
        flex-direction: column;
    }
    .filter-bar .form-input,
    .filter-bar .form-select {
        width: 100%;
        flex: auto;
    }
    .filter-bar .btn { width: 100%; }
}

/* Collapsible toggle */
.collapse-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.5rem 0;
    background: none;
    border: none;
    font-weight: 600;
    color: var(--primary);
    cursor: pointer;
}
.collapse-toggle .icon { transition: transform 0.25s; }
.collapse-toggle.open .icon { transform: rotate(180deg); }

/* --------------------------------------------------------
   18. TOOLTIP
   -------------------------------------------------------- */
.tooltip {
    position: relative;
}
.tooltip::after {
    content: attr(aria-label);
    position: absolute;
    bottom: 120%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--gray-900);
    color: var(--white);
    font-size: 0.75rem;
    padding: 4px 10px;
    border-radius: 4px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
}
.tooltip:hover::after { opacity: 1; }

/* --------------------------------------------------------
   19. PRINT
   -------------------------------------------------------- */
@media print {
    .no-print   { display: none !important; }
    .sidebar    { display: none !important; }
    body        { font-size: 12pt; color: #000; background: #fff; }
    .card       { box-shadow: none; border: 1px solid #ccc; }
    a           { color: #000; }
}

/* --------------------------------------------------------
   20. BREAKPOINT: MOBILE ≤ 640px
   -------------------------------------------------------- */
@media (max-width: 640px) {
    /* Typography scale-down */
    h1, .h1 { font-size: clamp(1.3rem, 5vw, 1.75rem); }
    h2, .h2 { font-size: clamp(1.1rem, 4vw, 1.5rem);  }

    /* Full-width on mobile */
    .form-input,
    .form-select,
    .form-textarea,
    .btn-mobile-full { width: 100%; }

    /* Reduce shadows */
    .card, .glass-card {
        box-shadow: 0 1px 2px rgba(0,0,0,0.04);
    }

    /* Compact padding */
    .card-compact { padding: 0.75rem; }

    /* Side-by-side grids become stacked */
    .grid-2-mobile { grid-template-columns: 1fr !important; }

    /* Buttons: full-width in groups */
    .btn-group-mobile .btn { width: 100%; }

    /* Hide desktop-only elements */
    .hide-mobile { display: none !important; }
}

/* --------------------------------------------------------
   21. BREAKPOINT: TABLET 641px – 1023px
   -------------------------------------------------------- */
@media (min-width: 641px) and (max-width: 1023px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }

    .sidebar {
        width: 220px;
    }
}

/* --------------------------------------------------------
   22. BREAKPOINT: DESKTOP ≥ 1024px
   -------------------------------------------------------- */
@media (min-width: 1024px) {
    .stats-grid { grid-template-columns: repeat(4, 1fr); }

    .show-desktop { display: block; }
    .hide-desktop { display: none !important; }

    /* Sidebar always visible on desktop */
    #mobile-sidebar { display: none !important; }
    .sidebar-overlay { display: none !important; }
}

/* --------------------------------------------------------
   23. UTILITY: RESPONSIVE HELPERS
   -------------------------------------------------------- */
.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Calendar event colors */
.cal-event-meeting      { background: #3b82f6; color: #fff; }
.cal-event-training     { background: #10b981; color: #fff; }
.cal-event-maintenance  { background: #f59e0b; color: #fff; }
.cal-event-public       { background: #8b5cf6; color: #fff; }

/* Gradient backgrounds */
.bg-gradient-primary { background: linear-gradient(135deg, var(--primary) 0%, #1a365d 100%); }
.bg-gradient-accent  { background: linear-gradient(135deg, #7FBFA0 0%, #5da07f 100%); }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
