:root {
    /* Dark Theme (Default) */
    --background-color: #0c111f;
    --component-bg: rgba(30, 41, 59, 0.75);
    --border-color: rgba(122, 162, 255, 0.15);
    --primary-blue: #007aff;
    --text-primary: #f9fafb;
    --text-secondary: #9ca3af;
    --hover-bg: rgba(55, 65, 81, 0.5);
    --bottom-nav-height: 60px;
}

:root.light-mode {
    /* Light Theme Overrides */
    --background-color: #f0f2f5; /* Light grey background */
    --component-bg: rgba(255, 255, 255, 0.75); /* Semi-transparent white */
    --border-color: rgba(0, 0, 0, 0.1);
    --primary-blue: #007aff; /* Blue remains the same */
    --text-primary: #111827; /* Dark text */
    --text-secondary: #6b7280; /* Grey text */
    --hover-bg: rgba(0, 0, 0, 0.05);
}

/* FIX: Apply a better box model to all elements */
*, *::before, *::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--background-color);
    color: var(--text-primary);
    overflow: hidden;
}

canvas {
    position: fixed;
    top: 0;
    left: 0;
    z-index: -1;
    width: 100vw;
    height: 100vh;
}

main {
    height: 100vh;
    width: 100vw;
    position: relative;
}

#map {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* --- FINAL ADAPTIVE LOGO STYLES --- */

/* 1. Shared Styles for the logo container */
#logo-container {
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 500;
    border-radius: 16px;
    padding: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s ease, background-color 0.3s ease, border-color 0.3s ease;
    width: 100px;
    height: 100px;
}
#logo-container:hover {
    transform: scale(1.05);
}
/* This rule is too general, so we will handle display properties in the specific rules below */
#logo-container img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* 2. Default State (Dark Mode) */
#logo-container {
    background-color: var(--component-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
}
/* Make selectors more specific to override the general 'img' rule */
#logo-container .logo-light {
    display: none; /* Hide light logo by default */
}
#logo-container .logo-dark {
    display: block; /* Show dark logo by default */
}

/* 3. Light Mode Override */
.light-mode #logo-container {
    background-color: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(0, 0, 0, 0.1);
}
/* Make selectors more specific */
.light-mode #logo-container .logo-light {
    display: block; /* Show light logo in light mode */
}
.light-mode #logo-container .logo-dark {
    display: none; /* Hide dark logo in light mode */
}

/* 4. Desktop Override (applies to both themes) */
@media (min-width: 768px) {
    #logo-container {
        width: 150px;
        height: auto;
    }
}
/* --- Bottom Navigation Bar --- */
#bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: var(--bottom-nav-height);
    background-color: var(--component-bg);
    border-top: 1px solid var(--border-color);
    backdrop-filter: blur(12px); /* ADD THIS LINE */
    -webkit-backdrop-filter: blur(12px); /* For Safari compatibility */
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 1000;
}

.nav-link {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.75rem;
    transition: color 0.2s ease;
}

.nav-link.active {
    color: var(--primary-blue);
}

/* --- Info Panel --- */
#info-panel {
    position: absolute;
     /* FIX: Position it 20px ABOVE the navigation bar, dynamically */
    bottom: calc(var(--bottom-nav-height) + 80px);
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 400px;
    background-color: var(--component-bg);
    backdrop-filter: blur(12px); /* ADD THIS LINE */
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    z-index: 500;
    overflow: hidden;
}

.info-panel-view {
    display: none;
    padding: 1rem;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.info-panel-view.active {
    display: flex;
}

.spinner-small {
    border: 3px solid var(--border-color);
    border-left-color: var(--primary-blue);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- UNIFIED BUTTON STYLES --- */
.btn {
    width: 100%;
    padding: 12px;
    font-size: 1rem;
    font-weight: 500;
    border-radius: 12px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

/* Primary Action Button */
.btn.btn-primary {
    background-color: var(--primary-blue);
    border-color: var(--primary-blue);
    color: var(--text-primary);
}
.btn.btn-primary:hover {
    opacity: 0.9;
}

/* Secondary Action Button */
.btn.btn-secondary {
    background-color: transparent;
    border-color: var(--text-secondary);
    color: var(--text-secondary);
}
.btn.btn-secondary:hover {
    background-color: var(--hover-bg);
    border-color: var(--text-primary);
    color: var(--text-primary);
}

/* Danger Action Button */
.btn.btn-danger {
    background-color: transparent;
    border-color: #dc3545;
    color: #dc3545;
}
.btn.btn-danger:hover {
    background-color: #dc3545;
    color: var(--text-primary);
}

/* --- Bottom Sheet & Registration Form Styles --- */
#bottom-sheet-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1999;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none; /* FIX: Allow clicks through when hidden */
}
#bottom-sheet-overlay.is-open { opacity: 1; pointer-events: auto; }

#bottom-sheet-modal {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    max-height: 90vh;
    background-color: var(--component-bg);
    backdrop-filter: blur(12px); /* ADD THIS LINE */
    -webkit-backdrop-filter: blur(12px);
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
    z-index: 2000;
    transform: translateY(100%);
    transition: transform 0.3s ease-in-out;
    display: flex;
    flex-direction: column;
}
#bottom-sheet-modal.is-open { transform: translateY(0); }

.sheet-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}
.sheet-header h4 { margin: 0; font-size: 1.2rem; }
#close-sheet-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 2rem;
    cursor: pointer;
}

.sheet-content {
    padding: 1.5rem;
    overflow-y: auto; /* FIX: Make the form content scrollable */
}

.form-group { margin-bottom: 1.25rem; }
.form-group label { display: block; margin-bottom: 0.5rem; color: var(--text-secondary); font-weight: 500; }
.form-group input, .form-group select {
    width: 100%;
    padding: 12px;
    background-color: var(--background-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 1rem;
}

/* FIX: Override browser autofill styles that cause a white background */
input:-webkit-autofill,
input:-webkit-autofill:hover, 
input:-webkit-autofill:focus, 
input:-webkit-autofill:active {
    -webkit-text-fill-color: var(--text-primary); /* Set the text color */
    -webkit-box-shadow: 0 0 0px 1000px var(--background-color) inset; /* Force our background color */
    transition: background-color 5000s ease-in-out 0s; /* A trick to delay the browser's style override */
}
.form-group select:disabled { background-color: #2a3447; opacity: 0.7; }

/* --- UNIFIED PHONE INPUT STYLES --- */
.phone-input-wrapper {
    display: flex;
    align-items: center;
    background-color: var(--background-color); /* Use main background for the input area */
    border: 1px solid var(--border-color);
    border-radius: 8px;
    transition: border-color 0.2s ease;
    width: 100%;
}
.phone-input-wrapper:focus-within {
    border-color: var(--primary-blue); /* Highlight when focused */
}

.phone-input-wrapper span {
    padding: 12px 16px;
    border-right: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-weight: 500;
}

.phone-input-wrapper input {
    /* CRITICAL: Reset browser styles */
    border: none;
    background: none;
    outline: none;
    
    /* Layout & Theming */
    flex-grow: 1; /* Fill available space */
    padding: 12px 16px;
    font-size: 1.1rem; /* Slightly larger font for numbers */
    color: var(--text-primary);
    width: 100%; /* Needed for flex calculation */
}

/* --- Login Modal "Register Now" Link --- */
.register-link-container {
    text-align: center;
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-top: 1rem;
}
.register-link-container a {
    color: var(--primary-blue);
    text-decoration: none;
    font-weight: 500;
}
.register-link-container a:hover {
    text-decoration: underline;
}

.form-divider { border: 0; height: 1px; background-color: var(--border-color); margin: 2rem 0; }
.static-display .code-display { margin-top: 0.5rem; }

.hidden { display: none !important; }

/* --- UNIFIED AUTH MODAL STYLES --- */
#otp-modal-overlay, #login-modal-overlay {
    position: fixed; inset: 0; background-color: rgba(0, 0, 0, 0.6);
    z-index: 2999; opacity: 0; transition: opacity 0.3s ease; pointer-events: none;
}
#otp-modal-overlay.is-open, #login-modal-overlay.is-open { opacity: 1; pointer-events: auto; }

#otp-modal, #login-modal {
    position: fixed; top: 50%; left: 50%;
    width: 90%; max-width: 380px; background-color: var(--component-bg);
    backdrop-filter: blur(12px); /* ADD THIS LINE */
    -webkit-backdrop-filter: blur(12px);
    border-radius: 16px; z-index: 3000;
    border: 1px solid var(--border-color);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    opacity: 0; transform: translate(-50%, -40%) scale(0.95); transition: all 0.3s ease;
}
#otp-modal.is-open, #login-modal.is-open { opacity: 1; transform: translate(-50%, -50%) scale(1); }

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}
.modal-header h4 { margin: 0; font-size: 1.2rem; }

.close-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 2rem;
    line-height: 1;
    padding: 0;
    cursor: pointer;
    transition: color 0.2s ease;
}
.close-btn:hover { color: var(--text-primary); }

.modal-content { padding: 1.5rem; display: flex; flex-direction: column; gap: 1rem; }
.modal-content p { margin: 0 0 0.5rem 0; color: var(--text-secondary); text-align: center; }

#otp-input {
    font-size: 2rem; text-align: center; letter-spacing: 0.5em;
    padding: 12px; background-color: var(--background-color);
    border: 1px solid var(--border-color); border-radius: 8px;
    color: var(--text-primary); width: 100%; box-sizing: border-box;
}

.error-message { color: #ff4d4d; text-align: center; font-size: 0.9rem; }

.resend-container {
    text-align: center;
    margin-top: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
}
#resend-otp-btn {
    background: none;
    border: none;
    color: var(--primary-blue);
    cursor: pointer;
    text-decoration: underline;
    font-size: inherit;
}
#resend-otp-btn:disabled {
    color: var(--text-secondary);
    text-decoration: none;
    cursor: not-allowed;
}

/* --- Polished Info Panel Styles --- */
#info-panel-address {
    gap: 1rem; /* Increased gap for better vertical spacing */
    position: relative; /* Needed for positioning the action icons */
}

/* This is the main header that will now be centered */
.info-panel-header {
    display: flex;
    flex-direction: column; /* Stack pill and text vertically */
    align-items: center;
    gap: 0.25rem;
}

.code-pill {
    background-color: var(--background-color);
    border: 1px solid var(--border-color);
    border-radius: 999px;
    padding: 8px 16px;
    font-size: 1.25rem;
    font-weight: bold;
    font-family: 'Courier New', Courier, monospace;
    color: var(--text-secondary);
}

.code-part-red { color: #D32F2F; }
.code-part-green { color: #388E3C; }
.code-part-blue { color: #1976D2; }

/* NEW: Position the action icons absolutely, flanking the header */
.info-panel-actions {
    position: absolute;
    top: 50px; /* Adjust this value to vertically align with the pill */
    width: 100%;
    display: flex;
    justify-content: space-between;
    padding: 0 1rem;
}

.icon-btn {
    background: transparent;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease, color 0.2s ease;
}
.icon-btn:hover {
    background-color: var(--hover-bg);
    color: var(--text-primary);
}

.address-text {
    text-align: center;
    width: 100%;
}
.address-text p {
    margin: 0;
    line-height: 1.4;
}
#address-district {
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--text-primary);
}
#address-region {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

#gps-accuracy-display {
    width: 100%;
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-secondary);
    padding: 4px 8px;
    background-color: rgba(0, 122, 255, 0.1);
    border: 1px solid rgba(0, 122, 255, 0.2);
    border-radius: 8px;
}
/* --- OTP Modal Styles --- */
#otp-modal-overlay {
    position: fixed; inset: 0; background-color: rgba(0, 0, 0, 0.6);
    z-index: 2999; opacity: 0; transition: opacity 0.3s ease; pointer-events: none;
}
#otp-modal-overlay.is-open { opacity: 1; pointer-events: auto; }

#otp-modal {
    position: fixed; top: 50%; left: 50%;
    width: 90%; max-width: 380px; background-color: var(--component-bg);
    border-radius: 16px; z-index: 3000;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    opacity: 0; transform: translate(-50%, -40%) scale(0.95); transition: all 0.3s ease;
}
#otp-modal.is-open { opacity: 1; transform: translate(-50%, -50%) scale(1); }

.modal-header { padding: 1rem 1.5rem; border-bottom: 1px solid var(--border-color); }
.modal-header h4 { margin: 0; font-size: 1.2rem; }
.modal-content { padding: 1.5rem; display: flex; flex-direction: column; gap: 1rem; }
.modal-content p { margin: 0 0 0.5rem 0; color: var(--text-secondary); text-align: center; }
#otp-input {
    font-size: 2rem; text-align: center; letter-spacing: 0.5em;
    padding: 12px; background-color: var(--background-color);
    border: 1px solid var(--border-color); border-radius: 8px;
    color: var(--text-primary);
    width: 100%;
    box-sizing: border-box;
}
.error-message { color: #ff4d4d; text-align: center; font-size: 0.9rem; }

/* --- Main View Management --- */
.main-view {
    display: none;
    width: 100%;
    height: 100%;
    /* Apply the effect to all main views */
    background-color: var(--component-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    /* Ensure content inside can scroll if needed */
    overflow-y: auto;
}

.main-view.active {
    display: block;
}
/* --- Dashboard View Styles --- */
#view-dashboard {
    padding: 1.5rem;
    overflow-y: auto;
}
.address-card {
    background-color: var(--component-bg);
    border-radius: 16px;
    border: 1px solid var(--border-color);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    max-width: 500px;
    margin: 0 auto;
}

.content-card {
    background-color: var(--component-bg);
    border-radius: 16px;
    border: 1px solid var(--border-color);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    max-width: 500px;
    margin: 0 auto;
    padding: 1.5rem; /* ADD THIS LINE */
}
.card-content { padding: 1.5rem; }
.card-address-details { text-align: center; margin-bottom: 1.5rem; }

#dashboard-6d-code.code-pill {
    display: inline-block;
    padding: 8px 16px;
    font-size: 1.5rem;
    font-weight: bold;
    font-family: 'Courier New', Courier, monospace;
    color: var(--text-secondary);
    background-color: var(--background-color);
    border: 1px solid var(--border-color);
    border-radius: 999px;
}

.address-plaque { margin: 1.5rem 0; }
.address-line { line-height: 1.6; margin: 0; }
#plaque-name { font-weight: 600; font-size: 1.2rem; color: var(--text-primary); }
#plaque-neighborhood, #plaque-district-region, #plaque-city-country { font-size: 1rem; color: var(--text-secondary); }

#dashboard-registered-to { font-size: 0.9rem; color: var(--text-secondary); margin-top: 1rem; }
.card-actions { display: flex; flex-direction: column; gap: 0.75rem; }
.update-info { text-align: center; font-size: 0.8rem; color: var(--text-secondary); padding: 0.75rem; margin-top: 1rem; background-color: rgba(0,0,0,0.2); border-radius: 8px; }

.card-hero-title {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0 0 0.5rem 0;
    color: var(--text-primary);
}

.card-hero-subtitle {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin: 0;
    max-width: 300px; /* Constrain line width */
    margin-left: auto;
    margin-right: auto;
}

.card-divider {
    border: none;
    height: 1px;
    background-color: var(--border-color);
    margin: 1.5rem 0;
}


/* --- Login Modal Styles (Consistent with OTP Modal) --- */
#login-modal-overlay {
    position: fixed; inset: 0; background-color: rgba(0, 0, 0, 0.6);
    z-index: 2998; /* Just below the OTP modal */
    opacity: 0; transition: opacity 0.3s ease; pointer-events: none;
}
#login-modal-overlay.is-open { opacity: 1; pointer-events: auto; }

#login-modal {
    position: fixed; top: 50%; left: 50%;
    width: 90%; max-width: 380px; background-color: var(--component-bg);
    border-radius: 16px; z-index: 3000;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    opacity: 0; transform: translate(-50%, -40%) scale(0.95); transition: all 0.3s ease;
}
#login-modal.is-open { opacity: 1; transform: translate(-50%, -50%) scale(1); }


.otp-resend-container {
    margin-top: 1rem;
    text-align: center;
    font-size: 0.9rem;
}

.btn-link {
    background: none;
    border: none;
    color: var(--primary-blue);
    cursor: pointer;
    text-decoration: underline;
}

.btn-link:disabled {
    color: var(--text-secondary);
    cursor: not-allowed;
    text-decoration: none;
}

#otp-timer {
    margin-left: 0.5rem;
    color: var(--text-secondary);
}

/* --- Toast Notification Styles --- */
.toast {
    position: fixed;
    bottom: 100px; /* Position above the info panel/nav bar */
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--component-bg);
    color: var(--text-primary);
    padding: 12px 24px;
    border-radius: 999px;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 4000;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
}

.toast.show {
    opacity: 1;
    transform: translate(-50%, -10px); /* Animate upwards slightly */
}

/* --- Settings View Styles --- */
#view-settings {
    padding: 1.5rem; /* RE-ADD THIS LINE */
    overflow-y: auto;
}
.settings-header h1 {
    font-size: 1.75rem;
    margin-bottom: 1.5rem; /* MODIFIED LINE */
}
.settings-section {
    margin-bottom: 2.5rem;
}
.settings-section h2 {
    font-size: 1.2rem;
    color: var(--text-secondary);
    padding-bottom: 0.75rem;
    margin-bottom: 1.5rem;
}

/* --- History View Styles --- */
#view-history {
    padding: 1.5rem; /* RE-ADD THIS LINE */
    overflow-y: auto;
}
.history-header h1 {
    font-size: 1.75rem;
    margin-bottom: 1.5rem; /* MODIFIED LINE */
}
.history-content .loading-message {
    color: var(--text-secondary);
    text-align: center;
}
.history-item {
    background-color: var(--component-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1rem;
    margin-bottom: 1rem;
}
.history-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}
.history-item-code {
    font-family: 'Courier New', Courier, monospace;
    font-size: 1.2rem;
    font-weight: bold;
}
.history-item-dates {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-align: right;
}
.history-item-address {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* --- Theme Toggle Switch Styles --- */
.theme-toggle-group {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #374151;
    transition: .4s;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--primary-blue);
}

input:checked + .slider:before {
    transform: translateX(22px);
}
#animated-background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
}

body {
    /* Ensure this has no background-color, or set it to transparent */
    background-color: transparent;
}