/* ==========================================================================
   assets/portal.css
   The ONE stylesheet for the whole portal. Link it from every page with:
     <link rel="stylesheet" href="/assets/portal.css?v=<?= (int)@filemtime($_SERVER['DOCUMENT_ROOT'] . '/assets/portal.css') ?>">
   (the ?v= part makes browsers pick up changes straight away)

   Layout of this file:
     1. Theme variables (colours shared by every page; change the brand colour here)
     2. 2FA page   (<body class="auth-page">)
     3. Login page (<body class="login-page">)
     4. Sidebar: Menu / Apps / Settings tabs and the app grid   (core/header.php)
     5. "View as" menu in the top bar                             (core/header.php)
     6. Staging badge under the logo                              (core/header.php)
   Page styles are scoped under a class on <body> (e.g. .auth-page) so moving a
   page's CSS in here can never change how other pages look.
   ========================================================================== */


/* ==========================================================================
   1. THEME VARIABLES
   If header.php / other pages define these same variables, remove those copies
   once this file is linked there, so there is only one place to edit.
   ========================================================================== */
:root {
    --bg-base: #121212;
    --bg-surface: #1e1e1e;
    --bg-hover: #2a2a2a;
    --primary: #ca0088;
    --primary-hover: #a80072;
    --text-main: #ffffff;
    --text-muted: #888888;
    --border-color: #333333;
}


/* ==========================================================================
   2. 2FA PAGE  (<body class="auth-page">)
   Used by: 2fa.php
   ========================================================================== */
:where(.auth-page),
:where(.auth-page) * { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Montserrat', sans-serif; }

.auth-page {
    background-color: var(--bg-base); color: var(--text-main);
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; overflow: hidden; padding: 20px;
}

.auth-page .auth-container { width: 100%; max-width: 420px; position: relative; }
.auth-page .auth-card {
    background-color: var(--bg-surface); border: 1px solid var(--border-color);
    border-radius: 12px; padding: 40px; box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4);
    text-align: center;
}
.auth-page .auth-logo { margin-bottom: 32px; }
.auth-page .auth-logo img { max-height: 36px; }

.auth-page .auth-header h2 { font-size: 1.4rem; font-weight: 700; margin-bottom: 8px; }
.auth-page .auth-header p { color: var(--text-muted); font-size: 0.9rem; line-height: 1.5; margin-bottom: 24px; }

.auth-page .alert-error {
    color: #ff4d4d; background-color: rgba(255, 77, 77, 0.1); padding: 10px;
    border-radius: 6px; font-size: 0.85rem; margin-bottom: 20px;
    border: 1px solid rgba(255, 77, 77, 0.2);
}

/* 2FA: QR code + manual key */
.auth-page .qr-wrapper {
    background: white; padding: 16px; border-radius: 8px;
    display: inline-block; margin-bottom: 16px;
}
.auth-page .qr-wrapper img { display: block; border-radius: 4px; }
.auth-page .qr-fallback { display: none; color: var(--text-muted); font-size: 0.85rem; margin-bottom: 12px; }

.auth-page .secret-key {
    font-family: monospace; letter-spacing: 2px; color: var(--primary);
    font-size: 1.1rem; margin-bottom: 24px; font-weight: 600;
}
.auth-page .app-link { margin: -12px 0 20px; }
.auth-page .app-link a { color: var(--primary); font-size: 0.85rem; }

.auth-page .form-group { margin-bottom: 24px; }

.auth-page .code-input {
    width: 100%; background-color: var(--bg-base); border: 1px solid var(--border-color);
    color: var(--text-main); padding: 16px; border-radius: 8px;
    font-size: 1.5rem; outline: none; transition: all 0.2s;
    text-align: center; letter-spacing: 8px; font-weight: 600;
}
.auth-page .code-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(202, 0, 136, 0.1); }
.auth-page .code-input::placeholder { color: var(--border-color); letter-spacing: 8px; }

.auth-page .btn-primary {
    background-color: var(--primary); color: white; border: none;
    width: 100%; padding: 14px; border-radius: 8px; font-weight: 600;
    font-size: 0.95rem; cursor: pointer; transition: all 0.2s ease;
    display: flex; align-items: center; justify-content: center; gap: 8px;
}
.auth-page .btn-primary:hover { background-color: var(--primary-hover); }

@media (max-width: 480px) {
    .auth-page .auth-card { padding: 32px 24px; border: none; }
    .auth-page { padding: 10px; align-items: flex-start; padding-top: 10vh; }
}


/* ==========================================================================
   3. LOGIN PAGE  (<body class="login-page">)
   Used by: login.php (sign in + forgot password)
   ========================================================================== */
:where(.login-page),
:where(.login-page) * { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Montserrat', sans-serif; }

.login-page {
    background-color: var(--bg-base);
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    overflow: hidden;
    padding: 20px;
}

/* Container & card */
.login-page .auth-container { width: 100%; max-width: 420px; position: relative; }
.login-page .auth-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 40px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4);
    position: relative;
    overflow: hidden;
}
.login-page .auth-logo { text-align: center; margin-bottom: 32px; }
.login-page .auth-logo img { max-height: 36px; }

/* View states (sign in <-> forgot password) */
.login-page .auth-view { display: none; opacity: 0; transform: translateX(20px); transition: all 0.3s ease; }
.login-page .auth-view.active { display: block; opacity: 1; transform: translateX(0); }
.login-page .auth-view.slide-left { transform: translateX(-20px); }

/* Typography */
.login-page .auth-header { text-align: center; margin-bottom: 32px; }
.login-page .auth-header h2 { font-size: 1.5rem; font-weight: 700; margin-bottom: 8px; }
.login-page .auth-header p { color: var(--text-muted); font-size: 0.9rem; line-height: 1.5; }

.login-page .alert-error {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.3);
    padding: 12px;
    border-radius: 6px;
    margin-bottom: 20px;
    font-size: 0.9rem;
    text-align: center;
}
.login-page .alert-success {
    background: rgba(16, 185, 129, 0.1);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.3);
    padding: 12px;
    border-radius: 6px;
    margin-bottom: 20px;
    font-size: 0.9rem;
    text-align: center;
}

/* Form elements */
.login-page .form-group { margin-bottom: 20px; position: relative; }
.login-page .form-group label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--text-muted); margin-bottom: 8px; }
.login-page .input-wrapper { position: relative; }
.login-page .input-wrapper i {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 1rem;
    transition: color 0.2s;
}
.login-page .form-control {
    width: 100%;
    background-color: var(--bg-base);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 12px 14px 12px 42px; /* extra left padding for the icon */
    border-radius: 8px;
    font-size: 16px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.login-page .form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(202, 0, 136, 0.1); }
.login-page .form-control:focus + i,
.login-page .input-wrapper:focus-within i { color: var(--primary); }

/* Links & buttons */
.login-page .auth-options { display: flex; justify-content: flex-end; margin-bottom: 24px; margin-top: -8px; }
.login-page .text-link { color: var(--primary); text-decoration: none; font-size: 0.85rem; font-weight: 500; transition: color 0.2s; cursor: pointer; }
.login-page .text-link:hover { color: #ff33b5; }

.login-page .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 12px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
}
.login-page .btn-primary { background-color: var(--primary); color: white; margin-bottom: 16px; }
.login-page .btn-primary:hover { background-color: var(--primary-hover); }
.login-page .btn-secondary { background-color: transparent; color: var(--text-muted); border: 1px solid var(--border-color); }
.login-page .btn-secondary:hover { background-color: var(--bg-hover); color: var(--text-main); }

/* Phones */
@media (max-width: 480px) {
    .login-page .auth-card { padding: 32px 24px; border: none; }
    .login-page { padding: 10px; align-items: flex-start; padding-top: 10vh; }
}


/* ==========================================================================
   4. SIDEBAR TABS + APP GRID  (core/header.php)
   ========================================================================== */
.sb-tabs { display: flex; gap: 4px; padding: 10px 12px; position: sticky; top: 0; z-index: 5; background: var(--bg-surface); border-bottom: 1px solid var(--border-color); }
.sb-tab { flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 9px 6px; border: 1px solid transparent; border-radius: 8px; background: transparent; color: var(--text-muted); font: 600 0.8rem 'Montserrat', sans-serif; cursor: pointer; transition: .15s; }
.sb-tab:hover { color: var(--text-main); background: var(--bg-hover); }
.sb-tab.active { background: rgba(202,0,136,0.14); border-color: var(--primary); color: var(--primary); }
.sb-tab.sb-tab-icon { flex: 0 0 42px; }
.sb-pane { display: none; }
.sb-pane.active { display: block; }
.app-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 12px; }
.app-tile { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 14px 8px 10px; border: 1px solid var(--border-color); border-radius: 12px; background: var(--bg-base); color: var(--text-main); text-decoration: none; text-align: center; transition: .15s; min-width: 0; }
.app-tile:hover { border-color: var(--primary); transform: translateY(-2px); background: var(--bg-hover); }
.app-tile-icon { width: 54px; height: 54px; border-radius: 12px; background: #fff; display: flex; align-items: center; justify-content: center; overflow: hidden; flex-shrink: 0; }
.app-tile-icon img { width: 100%; height: 100%; object-fit: contain; padding: 7px; }
.app-tile-icon i { font-size: 1.5rem; color: var(--primary); }
.app-tile-title { font-size: 0.78rem; font-weight: 600; line-height: 1.25; max-width: 100%; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; word-break: break-word; }
.sb-empty { padding: 30px 16px; text-align: center; color: var(--text-muted); font-size: 0.85rem; }


/* ==========================================================================
   5. "VIEW AS" MENU  (core/header.php; admins only)
   ========================================================================== */
body.viewing-as .topbar { box-shadow: inset 0 -3px 0 #8b5cf6; }
.va-wrap { position: relative; }
.va-btn { display: inline-flex; align-items: center; gap: 7px; height: 38px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--border-color); background: var(--bg-surface); color: var(--text-main); font-size: 0.85rem; font-weight: 600; cursor: pointer; white-space: nowrap; }
.va-btn:hover { border-color: var(--primary); }
.va-btn.on { background: rgba(139,92,246,0.15); border-color: #8b5cf6; color: #c4b5fd; }
.va-pop { display: none; position: absolute; right: 0; top: calc(100% + 8px); width: 290px; max-width: calc(100vw - 30px); background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: 10px; box-shadow: 0 14px 30px rgba(0,0,0,0.55); z-index: 9000; overflow: hidden; }
.va-pop.open { display: block; }
.va-head { padding: 12px 14px; border-bottom: 1px solid var(--border-color); font-size: 0.72rem; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); font-weight: 700; }
.va-search { width: calc(100% - 20px); margin: 10px; padding: 8px 10px; border-radius: 6px; border: 1px solid var(--border-color); background: var(--bg-base); color: var(--text-main); font-size: 0.85rem; outline: none; }
.va-search:focus { border-color: var(--primary); }
.va-list { max-height: 300px; overflow-y: auto; }
.va-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; padding: 9px 14px; background: none; border: none; border-top: 1px solid var(--border-color); color: var(--text-main); font-size: 0.88rem; text-align: left; cursor: pointer; }
.va-item:hover { background: var(--bg-hover); }
.va-item.current { color: #c4b5fd; font-weight: 700; }
.va-item small { color: var(--text-muted); font-size: 0.7rem; text-transform: uppercase; }
.va-return { display: flex; width: 100%; align-items: center; gap: 8px; padding: 11px 14px; background: rgba(139,92,246,0.15); border: none; border-bottom: 1px solid var(--border-color); color: #c4b5fd; font-weight: 700; font-size: 0.85rem; cursor: pointer; }
.va-return:hover { background: rgba(139,92,246,0.28); }

/* iPhones zoom the page when you tap a box with text smaller than 16px, so keep the search box at 16px on touch screens */
@media (max-width: 768px), (pointer: coarse) { .va-search { font-size: 16px; } }

/* MOBILE: the View as dropdown moves out of the crowded top bar into its own full-width strip at the very top (the script in header.php does the moving) */
.va-mobile-bar { display: none; }
@media (max-width: 768px) {
    .va-mobile-bar.has { display: block; position: relative; z-index: 1100; background: var(--bg-surface); border-bottom: 1px solid var(--border-color); padding: 8px 12px; }
    body.viewing-as .va-mobile-bar.has { background: rgba(139,92,246,0.12); border-bottom-color: #8b5cf6; }
    .va-mobile-bar .va-wrap { width: 100%; }
    .va-mobile-bar .va-btn { width: 100%; height: 42px; }
    .va-mobile-bar .va-label { flex: 1; text-align: left; overflow: hidden; text-overflow: ellipsis; }
    .va-mobile-bar .va-pop { left: 0; right: 0; width: auto; max-width: none; }
    .va-mobile-bar .va-list { max-height: 50vh; }
}


/* ==========================================================================
   6. STAGING BADGE  (core/header.php shows it under the logo on the staging site only)
   A small pill so nobody mistakes the staging site for the live system. The top bar is not changed.
   ========================================================================== */
.env-tag { display: block; margin: 8px auto 0; width: fit-content; background: #f97316; color: #fff; font: 700 11px/1 'Montserrat', sans-serif; letter-spacing: 1.5px; text-transform: uppercase; padding: 5px 12px; border-radius: 50px; }

/* ==========================================================================
   7. MANAGE USERS PAGE  (admin.php)
   The generic names (.data-table, .table-responsive, .role-tag, .edit-layout)
   are scoped under .admin-page (a class on the page's two main views) because
   other pages use the same names with different looks.
   ========================================================================== */
.admin-page .action-btn-hover:hover { background-color: var(--bg-hover) !important; }
.admin-page .action-btn-hover-primary:hover { background-color: var(--bg-hover) !important; color: var(--primary) !important; }
.admin-page .action-btn-hover-danger:hover { background-color: var(--bg-hover) !important; color: #ff4d4d !important; }
.admin-page .role-tag { display: inline-block; background: rgba(255,255,255,0.1); color: var(--text-muted); font-size: 0.7rem; padding: 2px 6px; border-radius: 4px; margin-right: 4px; margin-top: 4px; }

/* Responsive layout */
.admin-page .edit-layout { display: grid; grid-template-columns: 2fr 1fr; gap: 24px; align-items: start; }
.admin-page .table-responsive { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border-color); border-radius: 8px; background: var(--bg-surface); }
.admin-page .data-table { width: 100%; min-width: 800px; border-collapse: collapse; }

@media (max-width: 1024px) {
    .admin-page .edit-layout { grid-template-columns: 1fr; }
    .admin-page .data-table { min-width: 600px; }
}

/* "Reassign assets" pop-up (class names start with ra-, so they cannot clash with other pages) */
    .ra-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.8); z-index: 9999; display: none; justify-content: center; align-items: flex-start; padding: 20px; backdrop-filter: blur(5px); overflow-y: auto; }
    .ra-box { background: var(--bg-surface); width: 100%; max-width: 720px; border-radius: 12px; border: 1px solid var(--border-color); overflow: hidden; box-shadow: 0 20px 40px rgba(0,0,0,0.8); margin: 5vh auto; }
    .ra-head { padding: 18px 24px; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; background: var(--bg-base); }
    .ra-head h3 { margin: 0; color: #fff; font-size: 1.1rem; }
    .ra-close { background: none; border: none; color: var(--text-muted); font-size: 1.5rem; cursor: pointer; }
    .ra-body { padding: 20px 24px; max-height: 60vh; overflow-y: auto; }
    .ra-foot { padding: 16px 24px; border-top: 1px solid var(--border-color); display: flex; gap: 10px; background: var(--bg-base); }
    .ra-filter { background: rgba(0,0,0,0.2); border: 1px solid var(--border-color); border-radius: 8px; padding: 12px 14px; margin-bottom: 16px; }
    .ra-filter-title { font-size: 0.75rem; text-transform: uppercase; color: var(--text-muted); margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
    .ra-filter-title a { color: var(--primary); cursor: pointer; text-transform: none; font-size: 0.8rem; margin-left: 10px; }
    .ra-chips { display: flex; flex-wrap: wrap; gap: 8px; }
    .ra-chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border: 1px solid var(--border-color); border-radius: 50px; font-size: 0.85rem; color: #fff; cursor: pointer; background: rgba(255,255,255,0.04); }
    .ra-chip:hover { border-color: var(--primary); }
    .ra-all { display: flex; align-items: center; gap: 8px; font-weight: bold; color: #fff; padding-bottom: 12px; margin-bottom: 12px; border-bottom: 1px solid var(--border-color); cursor: pointer; }
    .ra-group { margin-bottom: 20px; }
    .ra-group[hidden] { display: none !important; }
    .ra-group-head { display: flex; align-items: center; gap: 8px; color: var(--primary); font-size: 0.85rem; text-transform: uppercase; margin-bottom: 8px; cursor: pointer; }
    .ra-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--border-color); border-radius: 8px; margin-bottom: 6px; cursor: pointer; background: rgba(255,255,255,0.03); }
    .ra-item:hover { background: var(--bg-hover); }
    .ra-item-off { opacity: 0.55; cursor: not-allowed; }
    .ra-item-off:hover { background: rgba(255,255,255,0.03); }
    .ra-item .ra-main { flex: 1; min-width: 0; }
    .ra-item .ra-main strong { color: #fff; display: block; }
    .ra-item .ra-main small { color: var(--text-muted); }
    .ra-type { color: var(--text-muted); width: 20px; text-align: center; }
    .ra-status { font-size: 0.75rem; font-weight: bold; white-space: nowrap; }
    .ra-ok { color: #10b981; } .ra-warn { color: #f59e0b; } .ra-bad { color: #ef4444; }
    /* ==========================================================================
   8. MY PROFILE PAGE  (profile.php)
   The full-screen ID card pop-up. These names are unique to this page.
   ========================================================================== */
.id-card-trigger {
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    border-radius: 8px;
}
.id-card-trigger:hover {
    transform: scale(1.02);
    box-shadow: 0 10px 25px rgba(202, 0, 136, 0.3);
}

#idCardFullscreenOverlay {
    display: none;
    position: fixed;
    inset: 0;
    background-color: #ffffff; /* Explicitly requested white background */
    z-index: 999999;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.id-card-close-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    background: #111;
    color: #fff;
    border: none;
    padding: 10px 20px;
    border-radius: 50px;
    font-weight: bold;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    transition: background 0.2s;
    z-index: 10;
}
.id-card-close-btn:hover { background: #333; }

#idCardScaleWrapper {
    width: 95%;
    max-width: 500px;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* FIX: Ignore 320px max-width, fill wrapper, and strip the 5% padding! */
#idCardScaleWrapper > div { 
    pointer-events: none; 
    width: 100% !important; 
    max-width: 100% !important; 
    padding: 0 !important; 
}

#idCardScaleWrapper > div > div {
    width: 100% !important; 
    max-width: 100% !important; 
}


/* ==========================================================================
   9. DOCUMENT VIEWER  (profile.php?view_doc=...  full-screen page for a compliance document)
   It is its own page (no sidebar), so it links this stylesheet itself.
   Scoped under .doc-viewer (class on its <body>) because .top-bar etc. are common names.
   ========================================================================== */
.doc-viewer { margin: 0; padding: 0; background-color: #000; color: #fff; font-family: 'Montserrat', sans-serif; height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
.doc-viewer .top-bar { display: flex; justify-content: space-between; align-items: center; padding: 15px 20px; background-color: #111; border-bottom: 1px solid #333; z-index: 10; }
.doc-viewer .top-bar h2 { margin: 0; font-size: 1.1rem; font-weight: 600; }
.doc-viewer .btn-close { color: #fff; text-decoration: none; display: flex; align-items: center; gap: 8px; padding: 8px 16px; background: rgba(255,255,255,0.1); border-radius: 6px; font-size: 0.9rem; font-weight: 600; transition: background 0.2s; }
.doc-viewer .btn-close:hover { background: rgba(255,255,255,0.2); }
.doc-viewer .viewer-container { flex: 1; display: flex; justify-content: center; align-items: center; background-color: #000; overflow: auto; padding: 20px; }
.doc-viewer .viewer-container img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 4px; box-shadow: 0 10px 30px rgba(0,0,0,0.5); }
.doc-viewer .viewer-container iframe { width: 100%; height: 100%; border: none; background: #fff; }
/* ==========================================================================
   10. EMAIL HEALTH WIDGET  (core/email_log.php -> el_health_widget(), shown in the System Security widget)
   ========================================================================== */
.el-health-ok { display: flex; align-items: center; gap: 10px; padding: 10px 0; }
.el-health-ok i { color: #10b981; }
.el-health-ok span { color: var(--text-muted); font-size: 0.9rem; }

.el-health-bad { padding: 10px 12px; border-left: 4px solid #ef4444; background: rgba(239,68,68,0.08); border-radius: 6px; }
.el-health-title { color: #ef4444; font-weight: 700; }
.el-health-item { font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; }
.el-health-item strong { color: #fff; }
.el-health-time { opacity: .7; }
.el-health-err { color: #ef4444; }
.el-health-link { display: inline-block; margin-top: 8px; font-size: 0.82rem; color: #ef4444; }