/* CSS Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary: #4A90A4;
    --primary-dark: #3a7a8a;
    --danger: #e74c3c;
    --danger-dark: #c0392b;
    --gray-100: #f8f9fa;
    --gray-200: #e9ecef;
    --gray-300: #dee2e6;
    --gray-600: #6c757d;
    --gray-800: #343a40;
    --white: #ffffff;
    --shadow: 0 2px 8px rgba(0,0,0,0.1);
    --radius: 8px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    line-height: 1.6;
    color: var(--gray-800);
    background: var(--gray-100);
}

/* Header */
.header {
    background: var(--white);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    max-width: 1200px;
    margin: 0 auto;
}

.logo {
    text-decoration: none;
    display: flex;
    align-items: center;
}

.logo img {
    width: 200px;
    height: 50px;
}

.nav {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav a {
    color: var(--gray-600);
    text-decoration: none;
    margin-left: 1rem;
}

.nav a:hover {
    color: var(--primary);
}

.nav-user {
    color: var(--gray-600);
    font-size: 0.85rem;
    margin-left: 1rem;
    padding: 0.25rem 0.5rem;
    background: var(--gray-100);
    border-radius: 4px;
}

.nav-logout {
    color: var(--danger) !important;
}

/* Profile dropdown container */
.profile-dropdown-container {
    position: relative;
    margin-left: 0.5rem;
}

/* Profile trigger button in nav */
.profile-trigger {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;

}

.nav-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--gray-300);
    transition: border-color 0.2s, transform 0.2s;
}

.profile-trigger:hover .nav-avatar {
    border-color: var(--primary);
    transform: scale(1.05);
}

.nav-avatar-initials {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    border: 2px solid var(--gray-300);
    transition: border-color 0.2s, transform 0.2s;
}

.profile-trigger:hover .nav-avatar-initials {
    border-color: var(--primary-dark);
    transform: scale(1.05);
}

.profile-chevron {
    font-size: 0.7rem;
    color: var(--gray-800);
    margin-left: 3px;
    transition: transform 0.2s;
}

/* Profile Dropdown Menu */
.profile-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--white);
    border-radius: 12px;
    min-width: 220px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    z-index: 1000;
    overflow: hidden;
    animation: dropdownFadeIn 0.15s ease;
}

.profile-dropdown.open {
    display: block;
}

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

.profile-dropdown-header {
    padding: 16px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    display: flex;
    align-items: center;
    gap: 12px;
}

.profile-dropdown-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255,255,255,0.5);
    flex-shrink: 0;
}

.profile-dropdown-avatar-initials {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    font-weight: 600;
    flex-shrink: 0;
}

.profile-dropdown-email {
    font-size: 0.8rem;
    opacity: 0.9;
    word-break: break-all;
    line-height: 1.3;
}

.profile-dropdown-divider {
    height: 1px;
    background: var(--gray-200);
}

.profile-dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    color: var(--gray-800);
    text-decoration: none;
    font-size: 0.9rem;
    transition: background 0.15s;
}

.profile-dropdown-item:hover {
    background: var(--gray-100);
}

.profile-dropdown-icon {
    font-size: 1rem;
    width: 20px;
    text-align: center;
}

.profile-dropdown-logout {
    color: var(--danger);
}

.profile-dropdown-logout:hover {
    background: #fde8e8;
}

.nav .btn-sm {
    padding: 0.35rem 0.75rem;
    font-size: 0.85rem;
    margin-left: 0.5rem;
}

/* Main content */
.main {
    min-height: calc(100vh - 60px);
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem;
}

/* Page header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.page-header h1 {
    font-size: 1.75rem;
}

/* Quiz grid */
.quiz-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
}

.quiz-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

.quiz-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin: -1.25rem -1.25rem 0.75rem -1.25rem;
    padding: 1rem 1.25rem;
    background: var(--primary);
    border-radius: var(--radius) var(--radius) 0 0;
}

.quiz-card h3 {
    margin: 0;
    color: white;
}

.join-code {
    background: rgba(255, 255, 255, 0.2);
    color: var(--white);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9rem;
    font-weight: bold;
    letter-spacing: 0.1em;
    cursor: pointer;
    white-space: nowrap;
}

.join-code:hover {
    background: rgba(255, 255, 255, 0.35);
}

.quiz-meta .status {
    margin-left: 1rem;
    padding: 0.15rem 0.5rem;
    border-radius: 1rem;
    font-size: 0.75rem;
}

.quiz-meta .status.active {
    background: #d4edda;
    color: #155724;
}

.quiz-meta .status.inactive {
    background: #f8d7da;
    color: #721c24;
}

.quiz-meta .status.scheduled {
    background: #fff3cd;
    color: #856404;
}

.quiz-meta .status.closed {
    background: #6c757d;
    color: white;
}

.quiz-org-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.quiz-org-logo {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    object-fit: contain;
    flex-shrink: 0;
}

.quiz-org-name {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--gray-700);
}

.quiz-description {
    color: var(--gray-600);
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.quiz-meta {
    color: var(--gray-600);
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

.quiz-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* Preview map in quiz cards */
.preview-map {
    height: 150px;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    background: var(--gray-200);
    overflow: hidden;
}

.no-questions-preview {
    height: 80px;
    background: var(--gray-100);
    border-radius: var(--radius);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--gray-600);
    font-size: 0.85rem;
    border: 1px dashed var(--gray-300);
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    transition: background 0.2s, transform 0.1s;
}

.btn:active {
    transform: scale(0.98);
}

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

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--gray-200);
    color: var(--gray-800);
}

.btn-secondary:hover {
    background: var(--gray-300);
}

.btn-danger {
    background: var(--danger);
    color: var(--white);
}

.btn-danger:hover {
    background: var(--danger-dark);
}

/* Classification badges */
.badge {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
    color: white;
    margin-right: 0.25rem;
}

.badge-age-adult {
    background: #6c757d;
}

.badge-age-children {
    background: #17a2b8;
}

.badge-difficulty-easy {
    background: #28a745;
}

.badge-difficulty-normal {
    background: #ffc107;
    color: #333;
}

.badge-difficulty-hard {
    background: #dc3545;
}

.badge-difficulty-very_hard {
    background: #7b1fa2;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

.modal-content {
    background: var(--white);
    border-radius: var(--radius);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-large {
    max-width: 600px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--gray-200);
}

.modal-header h2 {
    font-size: 1.25rem;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--gray-600);
    line-height: 1;
}

.close-btn:hover {
    color: var(--gray-800);
}

/* Forms */
form {
    padding: 1.5rem;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--gray-800);
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 1rem;
    font-family: inherit;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(74, 144, 164, 0.1);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--gray-200);
}

.location-display {
    background: var(--gray-100);
    padding: 0.75rem;
    border-radius: var(--radius);
    font-family: monospace;
    font-size: 0.9rem;
}

/* States */
.loading,
.empty-state,
.error {
    text-align: center;
    padding: 3rem;
    color: var(--gray-600);
}

.error {
    color: var(--danger);
}

/* Responsive */
@media (max-width: 600px) {
    .page-header {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .quiz-actions {
        flex-direction: column;
    }

    .quiz-actions .btn {
        width: 100%;
    }
}
