/* ==================== PHISHGUARD IMPROVEMENTS ====================
   Dark Mode + Responsive + Pagination + Progress Bar + Session Warning
   ================================================================ */

/* ==================== DARK MODE VARIABLES ==================== */
[data-theme="dark"] {
    --gray-50:  #0f1117;
    --gray-100: #1a1d27;
    --gray-200: #252836;
    --gray-300: #363a4f;
    --gray-400: #6e7191;
    --gray-500: #8b8fa8;
    --gray-600: #a5a9c4;
    --gray-700: #c4c7de;
    --gray-800: #dde0f4;
    --gray-900: #f0f1fc;

    --surface:        #1a1d27;
    --surface-2:      #252836;
    --surface-3:      #363a4f;
    --border-color:   #363a4f;
    --text-primary:   #f0f1fc;
    --text-secondary: #a5a9c4;
}

/* ==================== DARK MODE OVERRIDES ==================== */
[data-theme="dark"] body {
    background: var(--gray-50);
    color: var(--gray-900);
}

[data-theme="dark"] nav,
[data-theme="dark"] .header-content {
    background: #12141f !important;
    border-bottom: 1px solid #363a4f;
}

[data-theme="dark"] .nav-btn {
    color: var(--gray-700) !important;
}

[data-theme="dark"] .nav-btn:hover {
    background: var(--gray-200) !important;
    color: var(--gray-900) !important;
}

[data-theme="dark"] .card,
[data-theme="dark"] .stat-card,
[data-theme="dark"] [class*="card"] {
    background: var(--gray-100) !important;
    border-color: var(--gray-300) !important;
    color: var(--gray-900) !important;
}

[data-theme="dark"] .modal {
    background: var(--gray-100) !important;
    border: 1px solid var(--gray-300);
    color: var(--gray-900) !important;
}

[data-theme="dark"] .modal-body,
[data-theme="dark"] .modal-footer {
    background: var(--gray-100) !important;
    border-color: var(--gray-300) !important;
}

[data-theme="dark"] table {
    background: var(--gray-100) !important;
    color: var(--gray-900) !important;
}

[data-theme="dark"] th {
    background: var(--gray-200) !important;
    color: var(--gray-800) !important;
    border-color: var(--gray-300) !important;
}

[data-theme="dark"] td {
    border-color: var(--gray-300) !important;
    color: var(--gray-800) !important;
}

[data-theme="dark"] tr:hover td {
    background: var(--gray-200) !important;
}

[data-theme="dark"] input,
[data-theme="dark"] select,
[data-theme="dark"] textarea {
    background: var(--gray-200) !important;
    border-color: var(--gray-300) !important;
    color: var(--gray-900) !important;
}

[data-theme="dark"] input::placeholder,
[data-theme="dark"] textarea::placeholder {
    color: var(--gray-500) !important;
}

[data-theme="dark"] .btn-outline {
    border-color: var(--gray-400) !important;
    color: var(--gray-700) !important;
}

[data-theme="dark"] .btn-outline:hover {
    background: var(--gray-300) !important;
}

[data-theme="dark"] .toast {
    background: var(--gray-100) !important;
    border: 1px solid var(--gray-300) !important;
    color: var(--gray-900) !important;
}

[data-theme="dark"] div[style*="background: white"],
[data-theme="dark"] div[style*="background:white"] {
    background: var(--gray-100) !important;
}

[data-theme="dark"] div[style*="background: #f8fafc"],
[data-theme="dark"] div[style*="background:#f8fafc"],
[data-theme="dark"] div[style*="background: #f1f5f9"],
[data-theme="dark"] div[style*="background: #f0f9ff"] {
    background: var(--gray-200) !important;
}

[data-theme="dark"] p,
[data-theme="dark"] h1,
[data-theme="dark"] h2,
[data-theme="dark"] h3,
[data-theme="dark"] h4,
[data-theme="dark"] span,
[data-theme="dark"] label {
    color: inherit;
}

[data-theme="dark"] div[style*="color: #334155"],
[data-theme="dark"] div[style*="color:#334155"],
[data-theme="dark"] p[style*="color: #334155"],
[data-theme="dark"] span[style*="color: #334155"] {
    color: var(--gray-800) !important;
}

[data-theme="dark"] div[style*="color: #64748b"],
[data-theme="dark"] span[style*="color: #64748b"],
[data-theme="dark"] p[style*="color: #64748b"] {
    color: var(--gray-600) !important;
}

/* ==================== THEME TOGGLE BUTTON ==================== */
.theme-toggle-btn {
    font-size: 1.1rem;
    min-width: 40px;
    padding: 0.4rem 0.6rem !important;
}

/* ==================== TOP PROGRESS BAR ==================== */
#pg-topbar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 3px;
    z-index: 99999;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
}

#pg-topbar.pg-topbar-visible {
    opacity: 1;
}

#pg-topbar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--primary-500), var(--primary-300));
    transition: width 0.3s ease;
    border-radius: 0 2px 2px 0;
    box-shadow: 0 0 8px var(--primary-400);
}

/* ==================== MODULE PROGRESS BAR ==================== */
.module-progress-wrap {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 0.5rem 0;
}

.module-progress-bar {
    flex: 1;
    height: 8px;
    background: var(--gray-200);
    border-radius: 999px;
    overflow: hidden;
}

.module-progress-fill {
    height: 100%;
    border-radius: 999px;
    background: var(--primary-500);
    transition: width 0.4s ease;
}

.module-progress-text {
    font-size: 0.8rem;
    color: var(--gray-600);
    white-space: nowrap;
    min-width: 120px;
}

/* ==================== PAGINATION ==================== */
.pagination-controls {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 1rem 0;
    flex-wrap: wrap;
}

.pg-btn {
    min-width: 36px;
    height: 36px;
    padding: 0 0.5rem;
    border: 1px solid var(--gray-300);
    background: white;
    color: var(--gray-700);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.875rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.pg-btn:hover:not(:disabled) {
    background: var(--primary-50);
    border-color: var(--primary-400);
    color: var(--primary-700);
}

.pg-btn.pg-active {
    background: var(--primary-600);
    border-color: var(--primary-600);
    color: white;
    font-weight: 600;
}

.pg-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.pg-btn.pg-nav {
    color: var(--gray-500);
}

.pg-ellipsis {
    padding: 0 0.25rem;
    color: var(--gray-400);
    line-height: 36px;
}

.pg-info {
    margin-left: 0.5rem;
    font-size: 0.8rem;
    color: var(--gray-500);
}

[data-theme="dark"] .pg-btn {
    background: var(--gray-200) !important;
    border-color: var(--gray-300) !important;
    color: var(--gray-700) !important;
}

[data-theme="dark"] .pg-btn.pg-active {
    background: var(--primary-600) !important;
    border-color: var(--primary-600) !important;
    color: white !important;
}

/* ==================== SESSION WARNING ==================== */
#session-warning-overlay {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 50000;
    background: #1f2937;
    color: white;
    border-radius: var(--radius-lg);
    padding: 1rem 1.25rem;
    box-shadow: var(--shadow-xl);
    display: flex;
    align-items: center;
    gap: 1rem;
    max-width: 380px;
    animation: slideUp 0.3s ease;
    border-left: 4px solid var(--warning);
}

#session-warning-overlay .sw-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
}

#session-warning-overlay .sw-content {
    flex: 1;
}

#session-warning-overlay .sw-title {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
}

#session-warning-overlay .sw-timer {
    font-size: 0.8rem;
    color: #fbbf24;
}

#session-warning-overlay .sw-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

#session-warning-overlay .sw-btn-extend {
    background: var(--primary-600);
    color: white;
    border: none;
    padding: 0.35rem 0.75rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
}

#session-warning-overlay .sw-btn-logout {
    background: transparent;
    color: #9ca3af;
    border: 1px solid #374151;
    padding: 0.35rem 0.75rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.8rem;
}

/* ==================== RESPONSIVE — TABLET (≤1024px) ==================== */
@media (max-width: 1024px) {
    .stats-grid,
    .grid-4,
    [class*="grid-cols-4"] {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .grid-3,
    [class*="grid-cols-3"] {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    table {
        font-size: 0.85rem;
    }

    .header-content {
        padding: 0 1rem !important;
    }
}

/* ==================== RESPONSIVE — MOBILE (≤768px) ==================== */
@media (max-width: 768px) {
    nav .header-content {
        flex-wrap: wrap;
        gap: 0.5rem;
        padding: 0.5rem 1rem !important;
    }

    .nav {
        flex-wrap: wrap;
        gap: 0.25rem;
    }

    .nav-btn {
        font-size: 0.75rem !important;
        padding: 0.35rem 0.6rem !important;
        min-height: 36px;
    }

    .nav-btn svg {
        display: none;
    }

    .stats-grid,
    .grid-4,
    .grid-3,
    .grid-2,
    [class*="grid-cols"] {
        grid-template-columns: 1fr !important;
    }

    .modal {
        width: 95% !important;
        margin: 1rem !important;
        max-height: 85vh !important;
    }

    .modal-body {
        padding: 1rem !important;
    }

    /* Tables become scrollable on mobile */
    .table-wrap,
    div[style*="overflow-x: auto"] {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    table {
        min-width: 600px;
        font-size: 0.8rem;
    }

    th, td {
        padding: 0.5rem 0.75rem !important;
    }

    /* Stack card content */
    .card {
        padding: 1rem !important;
    }

    /* Hide less important columns on mobile */
    .col-hide-mobile {
        display: none !important;
    }

    /* Forms */
    .form-row {
        flex-direction: column !important;
    }

    input, select, textarea {
        font-size: 16px !important; /* prevents zoom on iOS */
    }

    /* Dynamic content area */
    #dynamicContent {
        padding: 0.5rem !important;
    }

    /* Admin tabs */
    .admin-tabs,
    .tab-list {
        flex-wrap: wrap !important;
        gap: 0.25rem !important;
    }

    #session-warning-overlay {
        bottom: 0;
        right: 0;
        left: 0;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        max-width: 100%;
    }
}

/* ==================== RESPONSIVE — SMALL MOBILE (≤480px) ==================== */
@media (max-width: 480px) {
    .logo-text {
        font-size: 1rem !important;
    }

    h1 { font-size: 1.5rem !important; }
    h2 { font-size: 1.25rem !important; }
    h3 { font-size: 1.1rem !important; }

    .btn {
        width: 100%;
        justify-content: center;
    }

    .pagination-controls {
        justify-content: center;
    }
}

/* ==================== REAL-TIME NOTIFICATION DOT ==================== */
.notif-live-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    background: var(--danger);
    border-radius: 50%;
    margin-left: 4px;
    animation: pulse-dot 1.5s infinite;
    vertical-align: middle;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.8); }
}
