/* ============================================================
   GPMS Guard — Mobile PWA Stylesheet
   Dark-first, safe-area aware, no Tabler/Syncfusion
   ============================================================ */

/* ── CSS Custom Properties ───────────────────────────────────────────────── */
:root {
    --bg-deep:       #0f172a;
    --bg-surface:    #1e293b;
    --bg-card:       #273347;
    --accent:        #3b82f6;
    --accent-hover:  #2563eb;
    --success:       #22c55e;
    --danger:        #ef4444;
    --warning:       #f59e0b;
    --text-primary:  #f1f5f9;
    --text-muted:    #94a3b8;
    --border:        #334155;
    --nav-height:    64px;
    --header-height: 56px;
    --safe-bottom:   env(safe-area-inset-bottom, 0px);
    --safe-top:      env(safe-area-inset-top, 0px);
}

/* ── Reset / Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    overscroll-behavior: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
}

/* ── Body variants ────────────────────────────────────────────────────────── */
.guard-body {
    background: var(--bg-deep);
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    padding-top: var(--safe-top);
}

.login-body {
    background: var(--bg-deep);
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem 1rem calc(1.5rem + var(--safe-bottom));
}

/* ── App Header ───────────────────────────────────────────────────────────── */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    padding-top: var(--safe-top);
    z-index: 100;
}

.header-brand {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-primary);
    letter-spacing: 0.02em;
}

.header-guard-info {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 1px;
}

.header-guard-name {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-primary);
}

.header-gate-badge {
    font-size: 0.65rem;
    color: var(--text-muted);
}

/* ── App Main ─────────────────────────────────────────────────────────────── */
.app-main {
    flex: 1;
    margin-top: var(--header-height);
    margin-bottom: calc(var(--nav-height) + var(--safe-bottom));
    overflow: hidden;
    position: relative;
}

/* ── Bottom Navigation ────────────────────────────────────────────────────── */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--nav-height) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: var(--bg-surface);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: stretch;
    z-index: 100;
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    text-decoration: none;
    color: var(--text-muted);
    transition: color 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.nav-item.active,
.nav-item:active {
    color: var(--accent);
}

.nav-icon {
    font-size: 1.35rem;
    line-height: 1;
}

.nav-label {
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

/* ── Scanner Screen ───────────────────────────────────────────────────────── */
.scanner-screen {
    position: relative;
    width: 100%;
    height: 100%;
    background: #000;
    overflow: hidden;
}

/* html5-qrcode fills the parent */
.qr-reader {
    width: 100% !important;
    height: 100% !important;
}

/* Force the inner video to fill container */
.qr-reader video {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
}

/* Hide the html5-qrcode default UI chrome */
.qr-reader img,
.qr-reader #html5-qrcode-anchor-scan-type-change,
.qr-reader #html5-qrcode-button-camera-start,
.qr-reader #html5-qrcode-button-camera-stop,
.qr-reader #html5-qrcode-button-file-selection,
#html5-qrcode-select-camera { display: none !important; }

/* ── Scan Overlay ─────────────────────────────────────────────────────────── */
.scan-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.scan-target {
    position: relative;
    width: min(68vw, 260px);
    aspect-ratio: 1;
}

/* Corner brackets */
.corner {
    position: absolute;
    width: 28px;
    height: 28px;
    border-color: #fff;
    border-style: solid;
    border-width: 0;
    border-radius: 3px;
}
.corner.tl { top: 0;    left: 0;  border-top-width: 3px; border-left-width: 3px; }
.corner.tr { top: 0;    right: 0; border-top-width: 3px; border-right-width: 3px; }
.corner.bl { bottom: 0; left: 0;  border-bottom-width: 3px; border-left-width: 3px; }
.corner.br { bottom: 0; right: 0; border-bottom-width: 3px; border-right-width: 3px; }

/* Animated scan line */
.scan-line {
    position: absolute;
    left: 6px;
    right: 6px;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
    top: 10%;
    animation: scanMove 2s ease-in-out infinite;
    border-radius: 1px;
}

@keyframes scanMove {
    0%   { top: 10%; opacity: 0.9; }
    50%  { top: 85%; opacity: 1; }
    100% { top: 10%; opacity: 0.9; }
}

.scan-hint {
    margin-top: 1.5rem;
    color: rgba(255,255,255,0.85);
    font-size: 0.85rem;
    text-align: center;
    text-shadow: 0 1px 4px rgba(0,0,0,0.6);
}

/* ── Scanner Loading / Error overlays ────────────────────────────────────── */
.scanner-loading,
.scanner-error {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.75);
}

/* ── Result Panel ─────────────────────────────────────────────────────────── */
.result-panel {
    position: fixed;
    bottom: calc(var(--nav-height) + var(--safe-bottom));
    left: 0;
    right: 0;
    z-index: 200;
    max-height: 82dvh;
    overflow: hidden;
    animation: slideUp 0.32s cubic-bezier(0.32, 0.72, 0, 1) both;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
}

.result-panel-inner {
    background: var(--bg-surface);
    border-radius: 20px 20px 0 0;
    border: 1px solid var(--border);
    overflow-y: auto;
    max-height: 82dvh;
    padding: 0 1rem 1.5rem;
}

.result-drag-handle {
    width: 40px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 10px auto 14px;
}

/* ── Status Banner ────────────────────────────────────────────────────────── */
.result-status-banner {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    border-radius: 12px;
    margin-bottom: 1rem;
}

.result-status-banner.valid   { background: rgba(34,197,94,0.15);  }
.result-status-banner.invalid { background: rgba(239,68,68,0.15);  }
.result-status-banner.warning { background: rgba(245,158,11,0.15); }

.result-status-icon {
    font-size: 1.5rem;
}

.result-status-banner.valid   .result-status-icon { color: var(--success); }
.result-status-banner.invalid .result-status-icon { color: var(--danger);  }
.result-status-banner.warning .result-status-icon { color: var(--warning); }

.result-status-text {
    font-weight: 700;
    font-size: 1rem;
}

.result-status-banner.valid   .result-status-text { color: var(--success); }
.result-status-banner.invalid .result-status-text { color: var(--danger);  }
.result-status-banner.warning .result-status-text { color: var(--warning); }

/* ── Labour Info Row ──────────────────────────────────────────────────────── */
.result-labour-row {
    display: flex;
    gap: 0.85rem;
    align-items: center;
    margin-bottom: 0.85rem;
}

.result-labour-photo {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--bg-card);
    border: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    color: var(--text-muted);
    overflow: hidden;
    flex-shrink: 0;
}

.result-labour-photo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.result-labour-name {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-primary);
}

.result-labour-contractor {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.result-labour-pass {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ── Eligibility Chips ────────────────────────────────────────────────────── */
.result-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 0.85rem;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 600;
}

.chip-pass  { background: rgba(34,197,94,0.15);  color: #4ade80; border: 1px solid rgba(34,197,94,0.3); }
.chip-fail  { background: rgba(239,68,68,0.15);  color: #f87171; border: 1px solid rgba(239,68,68,0.3); }
.chip-warn  { background: rgba(245,158,11,0.15); color: #fcd34d; border: 1px solid rgba(245,158,11,0.3); }

/* ── Fail reason ──────────────────────────────────────────────────────────── */
.result-fail-reason {
    font-size: 0.85rem;
    margin-bottom: 0.85rem;
}

/* ── Action Buttons ───────────────────────────────────────────────────────── */
.result-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 0.5rem;
}

.btn-action {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 0.75rem 0.5rem;
    border-radius: 14px;
    border: none;
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    transition: opacity 0.15s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
}

.btn-action:active { transform: scale(0.96); opacity: 0.85; }

.btn-action i { font-size: 1.4rem; }

.btn-allow { background: rgba(34,197,94,0.18);  color: #4ade80; }
.btn-exit  { background: rgba(59,130,246,0.18); color: #60a5fa; }
.btn-deny  { background: rgba(239,68,68,0.18);  color: #f87171; }

.btn-allow:hover { background: rgba(34,197,94,0.28);  }
.btn-exit:hover  { background: rgba(59,130,246,0.28); }
.btn-deny:hover  { background: rgba(239,68,68,0.28);  }

/* ── Denial Form ──────────────────────────────────────────────────────────── */
.denial-form {
    margin-top: 0.5rem;
}

.denial-form .form-control {
    background: var(--bg-card);
    border-color: var(--border);
    color: var(--text-primary);
    font-size: 0.875rem;
    border-radius: 10px;
}

.denial-form .form-control::placeholder { color: var(--text-muted); }
.denial-form .form-control:focus {
    background: var(--bg-card);
    border-color: var(--accent);
    color: var(--text-primary);
    box-shadow: 0 0 0 0.2rem rgba(59,130,246,0.25);
}

/* ── Action Confirmation ──────────────────────────────────────────────────── */
.action-confirmation {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem 0 0.5rem;
    text-align: center;
}

.action-confirm-icon {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.action-confirm-text {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* ── Login Screen ─────────────────────────────────────────────────────────── */
.login-screen {
    width: 100%;
    max-width: 420px;
    padding: 0 0.25rem;
}

.login-logo {
    text-align: center;
    margin-bottom: 2rem;
}

.login-logo-icon {
    font-size: 3rem;
    color: var(--accent);
    margin-bottom: 0.5rem;
}

.login-logo-text {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.login-logo-sub {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.login-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.5rem;
}

.login-hint {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
    text-align: center;
}

/* Guard list */
.guard-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.guard-card {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.75rem 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    text-align: left;
    width: 100%;
    transition: background 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.guard-card:hover,
.guard-card:active { background: #2d3f58; }

.guard-card-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.guard-card-info {
    flex: 1;
    min-width: 0;
}

.guard-card-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.guard-card-badge {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 1px;
}

/* ── Password Overlay ─────────────────────────────────────────────────────── */
.password-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 500;
    display: flex;
    align-items: flex-end;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.password-overlay.visible .password-sheet {
    transform: translateY(0);
}

.password-sheet {
    width: 100%;
    background: var(--bg-surface);
    border-radius: 20px 20px 0 0;
    padding: 1.5rem 1.5rem calc(1.5rem + var(--safe-bottom));
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
    position: relative;
}

.password-back {
    position: absolute;
    top: 1rem;
    left: 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1rem;
}

.password-guard-avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.3rem;
    margin: 0 auto 0.5rem;
}

.password-guard-name {
    text-align: center;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text-primary);
}

.password-guard-badge {
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 1.25rem;
}

.password-form .form-control {
    background: var(--bg-card);
    border-color: var(--border);
    color: var(--text-primary);
}

.password-form .form-control:focus {
    background: var(--bg-card);
    border-color: var(--accent);
    color: var(--text-primary);
    box-shadow: 0 0 0 0.2rem rgba(59,130,246,0.25);
}

.password-form .input-group-text {
    background: var(--bg-card);
    border-color: var(--border);
    color: var(--text-muted);
}

.password-form .btn-outline-secondary {
    border-color: var(--border);
    color: var(--text-muted);
}

/* ── Login button ─────────────────────────────────────────────────────────── */
.btn-login {
    height: 48px;
    font-weight: 700;
    font-size: 0.95rem;
    border-radius: 12px;
}

/* ── Device Prompt ────────────────────────────────────────────────────────── */
.device-prompt {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.75);
    z-index: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.device-prompt-inner {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 2rem 1.5rem;
    text-align: center;
    width: 100%;
    max-width: 360px;
}

.device-prompt-icon {
    font-size: 2.5rem;
    color: var(--warning);
}

/* ── Device UID badge ─────────────────────────────────────────────────────── */
.device-uid-badge {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    display: flex;
    align-items: center;
    color: var(--text-muted);
    font-size: 0.75rem;
    word-break: break-all;
}

/* ── Pending device pulse animation ──────────────────────────────────────── */
.pending-pulse {
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%,100% { opacity: 1; transform: scale(1); }
    50%      { opacity: 0.6; transform: scale(0.95); }
}

.pending-device-name {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--warning);
    padding: 0.75rem 1rem;
    background: rgba(245,158,11,0.1);
    border-radius: 10px;
    border: 1px solid rgba(245,158,11,0.3);
}

/* ── Profile Screen ───────────────────────────────────────────────────────── */
.profile-screen {
    padding: 1.25rem 1rem;
    height: 100%;
    overflow-y: auto;
}

.profile-hero {
    text-align: center;
    padding: 1.5rem 0 1.25rem;
}

.profile-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    font-weight: 700;
    margin: 0 auto 0.75rem;
    border: 3px solid rgba(59,130,246,0.4);
}

.profile-name {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

.profile-badge {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.profile-info-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 1.5rem;
}

.profile-info-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 0.9rem 1rem;
}

.profile-info-icon {
    font-size: 1.4rem;
    flex-shrink: 0;
    width: 28px;
    text-align: center;
}

.profile-info-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 2px;
}

.profile-info-value {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    word-break: break-all;
}

.btn-profile-logout {
    width: 100%;
    padding: 0.875rem;
    background: rgba(239,68,68,0.12);
    color: #f87171;
    border: 1px solid rgba(239,68,68,0.3);
    border-radius: 14px;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.btn-profile-logout:hover,
.btn-profile-logout:active { background: rgba(239,68,68,0.22); }

/* ── Bootstrap overrides for dark theme ──────────────────────────────────── */
.form-control,
.form-control:disabled {
    background-color: var(--bg-card);
    border-color: var(--border);
    color: var(--text-primary);
}

.form-control::placeholder { color: var(--text-muted); }

.form-label { color: var(--text-primary); }

.alert-danger {
    background: rgba(239,68,68,0.12);
    border-color: rgba(239,68,68,0.3);
    color: #fca5a5;
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
}

.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

/* ── Launch Splash ────────────────────────────────────────────────────────── */
.app-splash {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: linear-gradient(135deg, #0f172a, #1e293b);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: #fff;
    opacity: 1;
    transition: opacity 0.4s ease;
}

.app-splash.visible { display: flex; }
.app-splash.hide    { opacity: 0; }

.splash-inner { animation: splashFadeIn 1s ease; }

.splash-logo {
    width: 120px;
    height: 120px;
    margin: 0 auto 24px;
}

.splash-logo img {
    width: 100%;
    height: 100%;
    display: block;
    border-radius: 24px;
}

.splash-title {
    font-size: 32px;
    font-weight: 700;
    letter-spacing: 1px;
}

.splash-subtitle {
    margin-top: 10px;
    font-size: 15px;
    color: #cbd5e1;
    letter-spacing: 0.5px;
}

.splash-loader {
    width: 180px;
    height: 5px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50px;
    overflow: hidden;
    margin: 40px auto 0;
}

.splash-loader span {
    display: block;
    height: 100%;
    width: 40%;
    background: #38bdf8;
    border-radius: 50px;
    animation: splashLoading 1.5s infinite;
}

.splash-footer {
    position: absolute;
    bottom: calc(24px + var(--safe-bottom));
    font-size: 12px;
    color: #94a3b8;
}

@keyframes splashLoading {
    0%   { transform: translateX(-100%); }
    100% { transform: translateX(350%); }
}

@keyframes splashFadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Utility ──────────────────────────────────────────────────────────────── */
.font-monospace { font-family: 'SF Mono', 'Fira Code', monospace; }
