:root {
    /* Color Palette */
    --primary-bg: #f8fafc;
    --surface: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --brand: #3b82f6;
    --brand-hover: #2563eb;
    --accent: #10b981;
    --border: #e2e8f0;
    
    /* Effects */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.05), 0 4px 6px -2px rgba(0, 0, 0, 0.02);
    --radius-md: 8px;
    --radius-lg: 12px;
    --transition-fast: 0.15s ease-in-out;
    --transition-smooth: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--primary-bg);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Typography */
h1, h2, h3 {
    font-weight: 600;
    letter-spacing: -0.025em;
}

/* Top Navbar */
.top-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    height: 70px;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--brand);
    font-size: 100%;
    font-variant: small-caps;
    margin-right: 1em;
    width: min-content;
    line-height: 90%;
}

.nav-brand h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-main);
}

.main-menu {
    display: flex;
    gap: 0.5rem;
}

.nav-btn {
    background: none;
    border: none;
    padding: 0.5rem 1rem;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: var(--transition-fast);
}

.nav-btn:hover {
    color: var(--text-main);
    background-color: var(--primary-bg);
}

.nav-btn.active {
    color: var(--brand);
    background-color: #eff6ff; /* Light brand tint */
}

/* Nav Controls */
.nav-controls {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.select-filter {
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--surface);
    font-family: inherit;
    font-size: 0.9rem;
    color: var(--text-main);
    cursor: pointer;
    outline: none;
    transition: var(--transition-fast);
}

.select-filter:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.btn-login {
    background-color: var(--brand);
    color: white;
    border: none;
    padding: 0.5rem 1.25rem;
    border-radius: var(--radius-md);
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition-fast);
}

.btn-login:hover {
    background-color: var(--brand-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

/* Layout */
.content-area {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 2rem;
}

/* Views */
.view-section {
    display: none;
    animation: fadeIn var(--transition-smooth);
}

.view-section.active {
    display: block;
}

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

.view-header {
    margin-bottom: 2rem;
}

.view-header h2 {
    font-size: 1.75rem;
    margin-bottom: 0.5rem;
}

.view-header p {
    color: var(--text-muted);
}

/* Cards & Grid */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
}

.card {
    background: var(--surface);
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
}

.card h3 {
    margin-bottom: 1rem;
    font-size: 1.1rem;
}

/* Forms */
.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 0.9rem;
}

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

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Buttons */
.btn-primary {
    background-color: var(--brand);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-md);
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition-fast);
    width: 100%;
}

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

.btn-rating {
    flex: 1;
    padding: 6px 4px;
    font-size: 0.75rem;
    border-radius: 4px;
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text-main);
    font-weight: 500;
}

.btn-rating.selected {
    color: #fff;
}

/* Utilities */
.hidden {
    display: none !important;
}

.invisible {
    visibility: hidden !important;
}

@keyframes pulse-auth-error {
    0% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
        border-color: rgba(239, 68, 68, 1);
        color: rgba(239, 68, 68, 1);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(239, 68, 68, 0);
        border-color: rgba(239, 68, 68, 1);
        color: rgba(239, 68, 68, 1);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
        border-color: rgba(239, 68, 68, 1);
        color: rgba(239, 68, 68, 1);
    }
}

.pulse-alert {
    animation: pulse-auth-error 2s infinite;
    background-color: #fef2f2 !important;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.placeholder-text {
    color: var(--text-muted);
    text-align: center;
    font-style: italic;
    padding: 2rem;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 1rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1.5rem;
}

.tab-btn {
    background: none;
    border: none;
    padding: 0.75rem 0;
    font-family: inherit;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    position: relative;
    border-bottom: 2px solid transparent;
}

.tab-btn:hover {
    color: var(--text-main);
}

.tab-btn.active {
    color: var(--brand);
    border-bottom-color: var(--brand);
}

/* Toggle Switch */
.toggle {
    position: relative;
    display: inline-flex;
    align-items: center;
    cursor: pointer;
}

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

.slider {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    background-color: #ccc;
    border-radius: 34px;
    transition: .4s;
    margin-right: 10px;
}

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

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

input:focus + .slider {
    box-shadow: 0 0 1px var(--accent);
}

input:checked + .slider:before {
    transform: translateX(20px);
}

.toggle-label {
    font-size: 0.9rem;
    font-weight: 500;
}

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

#auth-refresh-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.6);
    z-index: 90; /* below top-nav which is 100 */
    transition: opacity var(--transition-smooth);
}

#data-loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(2px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    color: var(--primary);
    font-size: 1.2rem;
    font-weight: 500;
    transition: opacity var(--transition-smooth);
}

.top-nav.auth-refresh-active {
    position: relative;
    z-index: 101; /* bring it above the overlay explicitly if needed */
}

/* Group List Item */
.group-list-item {
    padding: 0.5rem;
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--surface);
    color: var(--text-main);
    font-weight: normal;
    border-left: 3px solid transparent;
    transition: var(--transition-fast);
}

.group-list-item:hover {
    background: var(--primary-bg);
}

.group-list-item.selected {
    background: var(--primary-bg);
    color: var(--brand);
    font-weight: 600;
    border-left: 3px solid var(--brand);
}

/* Form Labels */
.form-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.form-label-sm {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 4px;
}

/* List Cards */
.list-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
}

/* Scrollable Panels */
.scrollable-panel {
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px;
    background: #fff;
}

/* Buttons */
.btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
    width: auto;
}

.btn-danger {
    color: #ef4444;
    border: 1px solid #ef4444;
    background: none;
    border-radius: 4px;
    cursor: pointer;
}

.btn-danger:hover {
    background: #fef2f2;
}

.btn-icon {
    font-size: 1.1rem;
    opacity: 0.7;
    cursor: pointer;
    background: none;
    border: none;
    color: inherit;
    padding: 0;
}

.btn-icon:hover {
    opacity: 1;
}

/* Flexbox Utilities */
.flex-row {
    display: flex;
}

.flex-col {
    display: flex;
    flex-direction: column;
}

.flex-between {
    display: flex;
    justify-content: space-between;
}

.align-center {
    align-items: center;
}

.align-start {
    align-items: flex-start;
}

.align-end {
    align-items: flex-end;
}

/* Spacing Utilities */
.gap-sm {
    gap: 0.5rem;
}

.gap-md {
    gap: 1rem;
}

.gap-lg {
    gap: 1.5rem;
}

.gap-xl {
    gap: 24px;
}

/* Layout */
.two-column-layout {
    display: grid;
    grid-template-columns: 250px 1fr;
    gap: 1.5rem;
    align-items: start;
}

/* Section Dividers */
.section-divider {
    border-top: 1px solid var(--border);
    padding-top: 1rem;
    margin-top: 1rem;
}

/* Checkbox Labels */
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    cursor: pointer;
}

.floating-save-btn {
    position: fixed;
    width: max-content;
    bottom: 32px;
    right: 32px;
    z-index: 9999;
    box-shadow: 0 8px 16px rgba(0,0,0,0.3);
    border-radius: 24px;
    padding: 12px 24px;
    font-size: 1.1rem;
    transition: all 0.2s;
    cursor: pointer;
}

