/**
 * CSS Custom Properties (Variables)
 * These are set dynamically by the Theme Manager
 * Fallback values are provided for safety
 */
:root {
    /* Colors will be set dynamically by theme-manager.js */
    /* Fallback values provided here */
    --color-body-bg: #f5f5f7;
    --color-primary: #3b82f6;
    --font-primary: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --bg-image: url('mist-background.jpg');
}

body {
    min-height: 100vh;
    position: relative;
    background-color: var(--color-body-bg) !important;
    font-family: var(--font-primary);
    overflow-x: hidden;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 130%;
    background-image: var(--bg-image);
    background-size: cover;
    background-position: center bottom;
    background-repeat: no-repeat;
    z-index: -1;
    animation: subtle-drift 60s ease-in-out infinite alternate;
}

@keyframes subtle-drift {
    0% {
        transform: translateY(3%);
    }
    100% {
        transform: translateY(-20%);
    }
}

#app {
    max-width: 1200px;
}

nav {
    background: var(--color-glass-bg);
    backdrop-filter: blur(var(--effect-blur-standard, 10px));
    border-radius: var(--effect-radius-xl, 12px);
}

#menu-list {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

#window1, #window2, #window3 {
    background: var(--color-glass-bg);
    backdrop-filter: blur(var(--effect-blur-standard, 10px));
    border-radius: var(--effect-radius-xl, 12px);
    min-height: 300px;
    resize: horizontal;
    overflow: auto;
}

#modal, #help-modal {
    z-index: 1000;
}

/* Prevent background scrolling when modal is open */
body.modal-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
}

/* Override the fixed positioning for the modal itself to ensure it can scroll */
body.modal-open #modal {
    position: fixed;
}

body.modal-open #modal-content {
    position: relative;
}

/* Ensure modal content is scrollable */
#modal-content {
    overflow-y: auto;
    overflow-x: hidden;
    max-width: 600px;
    width: 100%;
    max-height: 85vh;
}

input, button {
    transition: all 0.3s ease;
}

button:hover {
    background-color: var(--color-primary-hover);
}

@media (max-width: 768px) {
    #app {
        padding: 10px;
    }
    #menu-list {
        flex-direction: column;
        gap: 0.5rem;
    }
    #window1, #window2, #window3 {
        width: 100%;
    }
    #modal-content {
        width: 90%;
    }
}

.nav-header {
    display: flex;
    align-items: flex-end;
    gap: 1rem;
    margin-bottom: 10px;
}

/* Enhanced Spinner Styling */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--color-border-light);
    border-top: 2px solid var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    box-shadow: 0 0 0 1px var(--color-primary-bg10, rgba(59, 130, 246, 0.1));
}

.spinner-container {
    height: 20px;
    width: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

.spinner-container::before {
    content: '';
    position: absolute;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--color-primary-bg05, rgba(59, 130, 246, 0.05));
    animation: pulse 1.5s ease-in-out infinite;
    opacity: 0;
}

.spinner:not(.hidden) + .spinner-container::before {
    opacity: 1;
}

.hidden {
    visibility: hidden;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes pulse {
    0%, 100% { transform: scale(0.8); opacity: 0.3; }
    50% { transform: scale(1.2); opacity: 0.1; }
}

/* Menu styling with enhanced keyboard hints */
.normal-item {
    color: black;
    position: relative;
    transition: all 0.2s ease;
}

.submenu-trigger,
.back-to-main,
.back-to-auth {
    color: var(--color-primary-dark);
    transition: all 0.2s ease;
}

.submenu-trigger::after {
    content: ' ↓';
    margin-left: 0.25rem;
    font-weight: bold;
}

.back-to-main::after {
    content: ' ↑';
    margin-left: 0.25rem;
    font-weight: bold;
}

.back-to-auth::after {
    content: ' ↑';
    margin-left: 0.25rem;
    font-weight: bold;
}

/* Disabled menu items styling */
.disabled-item {
    color: var(--color-disabled);
    cursor: not-allowed;
    position: relative;
    opacity: 0.5;
    transition: all 0.2s ease;
}

.disabled-item:hover {
    text-decoration: none !important;
    color: var(--color-disabled) !important;
    cursor: not-allowed;
}

.disabled-item::before {
    content: '🔒';
    margin-right: 0.25rem;
    font-size: 0.75rem;
}

.hover:underline:hover {
    text-decoration: underline;
}

/* Override hover for disabled items */
.disabled-item.hover:underline:hover {
    text-decoration: none;
}

/* Keyboard Navigation Hints */
.keyboard-hint {
    background: var(--color-primary-bg05, rgba(59, 130, 246, 0.05));
    border: 1px solid var(--color-primary-bg10, rgba(59, 130, 246, 0.1));
    border-radius: var(--effect-radius-md, 6px);
    padding: 8px 12px;
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Help Button Styling */
#help-btn {
    font-size: 0.875rem;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

#help-btn:hover {
    background-color: var(--color-primary-bg10, rgba(59, 130, 246, 0.1));
}

kbd {
    font-family: ui-monospace, SFMono-Regular, "SF Mono", monospace;
    font-size: 0.75rem;
    font-weight: 600;
}

/* Token Status Styling */
#token-status {
    padding: 4px 8px;
    border-radius: var(--effect-radius-sm, 4px);
    border-left: 3px solid var(--color-success);
    background-color: var(--color-success-bg, rgba(16, 185, 129, 0.1));
}

#token-status.warning {
    border-left-color: var(--color-warning);
    background-color: var(--color-warning-bg, rgba(245, 158, 11, 0.1));
    color: var(--color-warning-dark);
}

#token-status.error {
    border-left-color: var(--color-error);
    background-color: var(--color-error-bg, rgba(239, 68, 68, 0.1));
    color: var(--color-error-dark);
}

/* Toast Notifications */
#toast-container {
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    min-width: 300px;
    max-width: 400px;
    padding: 12px 16px;
    border-radius: var(--effect-radius-lg, 8px);
    box-shadow: var(--effect-shadow-md, 0 10px 25px rgba(0, 0, 0, 0.1));
    backdrop-filter: blur(var(--effect-blur-standard, 10px));
    border: 1px solid rgba(255, 255, 255, 0.2);
    animation: slideIn 0.3s ease-out;
    position: relative;
    overflow: hidden;
}

.toast.removing {
    animation: slideOut 0.3s ease-in forwards;
}

.toast-success {
    background: linear-gradient(135deg, var(--color-success-bg90, rgba(16, 185, 129, 0.9)), var(--color-success-dark-bg90, rgba(5, 150, 105, 0.9)));
    color: white;
}

.toast-error {
    background: linear-gradient(135deg, var(--color-error-bg90, rgba(239, 68, 68, 0.9)), var(--color-error-dark-bg90, rgba(220, 38, 38, 0.9)));
    color: white;
}

.toast-warning {
    background: linear-gradient(135deg, var(--color-warning-bg90, rgba(245, 158, 11, 0.9)), var(--color-warning-dark-bg90, rgba(217, 119, 6, 0.9)));
    color: white;
}

.toast-info {
    background: linear-gradient(135deg, var(--color-info-bg90, rgba(59, 130, 246, 0.9)), var(--color-info-dark-bg90, rgba(37, 99, 235, 0.9)));
    color: white;
}

.toast-title {
    font-weight: 600;
    font-size: 0.875rem;
    margin-bottom: 4px;
}

.toast-message {
    font-size: 0.8125rem;
    opacity: 0.95;
}

.toast-close {
    position: absolute;
    top: 8px;
    right: 8px;
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    opacity: 0.7;
    transition: opacity 0.2s;
    padding: 2px;
}

.toast-close:hover {
    opacity: 1;
}

.toast-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    background: rgba(255, 255, 255, 0.3);
    transition: width linear;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideOut {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(100%);
    }
}

/* Enhanced input field spacing for focus states */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="tel"],
input[type="url"],
input[type="date"],
input[type="datetime-local"],
select,
textarea {
    padding-left: 12px !important;
    padding-right: 12px !important;
}

/* Ensure focus ring appears outside the input */
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 1), 0 0 0 4px var(--color-primary, rgba(59, 130, 246, 1));
}

/* Dialog scrollbar styling */
.dialog-content {
    scrollbar-width: thin;
    scrollbar-color: var(--color-scrollbar-thumb) var(--color-scrollbar-track);
}

.dialog-content::-webkit-scrollbar {
    width: 8px;
}

.dialog-content::-webkit-scrollbar-track {
    background: var(--color-scrollbar-track);
    border-radius: var(--effect-radius-sm, 4px);
}

.dialog-content::-webkit-scrollbar-thumb {
    background: var(--color-scrollbar-thumb);
    border-radius: var(--effect-radius-sm, 4px);
}

.dialog-content::-webkit-scrollbar-thumb:hover {
    background: var(--color-scrollbar-thumb-hover);
}

/* Keyboard Key Styling */
.keyboard-key {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px; /* Slightly smaller */
    height: 22px;
    margin-right: 10px; /* More space between key and label */
    background: linear-gradient(145deg, var(--color-key-bg), var(--color-key-bg-alt));
    border: 1px solid var(--color-key-border);
    border-radius: var(--effect-radius-xs, 3px);
    font-family: var(--font-mono);
    font-size: 0.6875rem; /* Smaller text */
    font-weight: 500;
    color: var(--color-key-text); /* More muted color */
    box-shadow:
        var(--effect-shadow-sm, 0 1px 2px rgba(0, 0, 0, 0.05)),
        inset 0 1px 0 rgba(255, 255, 255, 0.4);
    transition: all 0.15s ease;
    opacity: 0.85; /* Slightly transparent */
}

.menu-item {
    display: flex;
    align-items: center;
    text-decoration: none;
    padding: 6px 8px;
    border-radius: var(--effect-radius-md, 6px);
    transition: all 0.2s ease;
}

.menu-label {
    font-size: 0.9375rem; /* Slightly larger than before */
    line-height: 1.375rem;
    font-weight: 500; /* Medium weight for better readability */
    color: var(--color-text-primary); /* Darker, more readable color */
    letter-spacing: 0.025em; /* Subtle letter spacing for clarity */
}

/* Interactive effects */
.menu-item:hover .keyboard-key {
    background: linear-gradient(145deg, var(--color-gray-light), var(--color-gray-darker));
    border-color: var(--color-border-gray);
    box-shadow:
        0 1px 2px rgba(0, 0, 0, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.4);
    transform: translateY(0.5px);
}

/* Hover effects prioritize label visibility */
.menu-item:hover .menu-label {
    color: var(--color-text-dark); /* Even darker on hover */
}

.menu-item:active .keyboard-key {
    background: linear-gradient(145deg, var(--color-gray-darker), var(--color-gray-darkest));
    border-color: var(--color-border-gray);
    box-shadow:
        inset 0 1px 3px rgba(0, 0, 0, 0.2),
        0 0 0 rgba(255, 255, 255, 0);
    transform: translateY(1px);
}

/* Color coding for different menu types */
.submenu-trigger .keyboard-key,
.back-to-main .keyboard-key,
.back-to-auth .keyboard-key {
    background: linear-gradient(145deg, var(--color-primary-light, #dbeafe), var(--color-primary-lighter, #bfdbfe));
    border-color: var(--color-primary-border, #93c5fd);
    color: var(--color-primary-darker);
}

/* Color-specific label enhancements */
.submenu-trigger .menu-label,
.back-to-main .menu-label,
.back-to-auth .menu-label {
    color: var(--color-primary-darker); /* Blue for navigation items */
    font-weight: 600;
}

.submenu-trigger:hover .menu-label,
.back-to-main:hover .menu-label,
.back-to-auth:hover .menu-label {
    color: var(--color-primary-darkest); /* Deeper blue on hover */
}

.disabled-item .keyboard-key {
    background: linear-gradient(145deg, var(--color-key-bg), var(--color-key-bg-alt));
    border-color: var(--color-border-pale);
    color: var(--color-key-text-alt);
    opacity: 0.6;
}

.disabled-item .menu-label {
    color: var(--color-disabled); /* Muted for disabled items */
    font-weight: 400;
}

/* Special styling for login key (0) */
.menu-item:last-child .keyboard-key {
    background: linear-gradient(145deg, var(--color-success-light), var(--color-success-lighter));
    border-color: var(--color-success-border);
    color: var(--color-success-dark);
}

/* Special emphasis for login */
.menu-item:last-child .menu-label {
    color: var(--color-success-dark); /* Green for login */
    font-weight: 600;
}

.menu-item:last-child:hover .menu-label {
    color: var(--color-success-darkest); /* Deeper green on hover */
}

/* Copy button styling */
.copy-btn {
    display: inline-flex;
    align-items: center;
    padding: 4px 8px;
    margin-left: 8px;
    background: var(--color-gray-lightest);
    border: 1px solid var(--color-border);
    border-radius: var(--effect-radius-sm, 4px);
    cursor: pointer;
    font-size: 0.75rem;
    color: var(--color-text-darkest);
    transition: all 0.2s ease;
}

.copy-btn:hover {
    background: var(--color-border-light);
    border-color: var(--color-disabled);
}

.copy-btn:active {
    background: var(--color-border);
    transform: translateY(1px);
}

.copy-btn.copied {
    background: var(--color-success-light);
    border-color: var(--color-success-border);
    color: var(--color-success-dark);
}

/* Menu search styling */
#menu-search {
    background: var(--color-glass-bg-light);
    backdrop-filter: blur(var(--effect-blur-standard, 10px));
    transition: all 0.2s ease;
}

#menu-search:focus {
    background: rgba(255, 255, 255, 1);
    box-shadow: 0 0 0 3px var(--color-primary-bg10, rgba(59, 130, 246, 0.1));
}

#search-results {
    background: var(--color-glass-bg-full);
    backdrop-filter: blur(var(--effect-blur-intense, 15px));
    border: 1px solid rgba(0, 0, 0, 0.1);
    box-shadow: var(--effect-shadow-lg, 0 10px 25px rgba(0, 0, 0, 0.15));
}

.search-result-item {
    transition: all 0.15s ease;
}

.search-result-item:hover {
    background: var(--color-primary-bg10, rgba(59, 130, 246, 0.1)) !important;
}

.search-result-item.bg-blue-100 {
    background: var(--color-primary-bg15, rgba(59, 130, 246, 0.15)) !important;
}

.search-key {
    min-width: 24px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    font-weight: 600;
    background: linear-gradient(145deg, var(--color-key-bg), var(--color-key-bg-alt));
    border: 1px solid var(--color-key-border);
    box-shadow: var(--effect-shadow-sm, 0 1px 2px rgba(0, 0, 0, 0.05));
}

/* Window headers and toggle buttons */
.window-header {
    user-select: none;
    /* Ensure consistent border rendering */
    box-sizing: border-box;
}

.window-toggle {
    touch-action: manipulation;
    min-width: 32px;
    min-height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    border-radius: var(--effect-radius-md, 6px);
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--color-text-secondary);
}

.window-toggle:hover {
    background: var(--color-text-secondary-bg10, rgba(107, 114, 128, 0.1));
    color: var(--color-text-darkest);
    transform: scale(1.05);
}

.window-toggle:active {
    transform: scale(0.95);
    background: var(--color-text-secondary-bg20, rgba(107, 114, 128, 0.2));
}

.window-toggle svg {
    transition: all 0.2s ease;
    /* Prevent distortion and ensure crisp rendering */
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

/* Enhanced mobile support */
@media (max-width: 768px) {
    .window-toggle {
        min-width: 40px;
        min-height: 40px;
    }

    .window-header {
        padding: 8px 12px;
    }

    .window-header span {
        font-size: 0.875rem;
        font-weight: 600;
    }
}

/* Clerk Integration Styles */
.clerk-container {
    padding: 20px;
}

.clerk-container h2 {
    color: var(--color-text-very-dark);
    margin-bottom: 10px;
}

.clerk-container .info-text {
    color: var(--color-text-secondary);
    margin-bottom: 20px;
    font-size: 0.9rem;
}

#clerk-sign-in {
    max-width: 400px;
    margin: 0 auto;
}

.info-panel {
    padding: 20px;
}

.info-panel h3 {
    color: var(--color-text-very-dark);
    margin-top: 20px;
    margin-bottom: 10px;
    font-size: 1.1rem;
}

.info-panel ul {
    list-style-type: disc;
    padding-left: 20px;
    color: var(--color-text-muted);
    line-height: 1.8;
}

.info-panel pre {
    background: var(--color-gray-lightest);
    padding: 15px;
    border-radius: var(--effect-radius-lg, 8px);
    overflow-x: auto;
    font-size: 0.85rem;
    margin-top: 10px;
}

