/* ── Design tokens ──────────────────────────────────────────── */

:root {
    /* Colors — brand */
    --c-primary: #2c3e50;
    --c-primary-light: #34495e;
    --c-accent: #3498db;
    --c-accent-dark: #2980b9;
    --c-accent-light: #ebf5fb;
    --c-success: #27ae60;
    --c-success-dark: #1e8449;
    --c-warning: #e67e22;
    --c-danger: #e74c3c;
    --c-danger-light: #fdecea;

    /* Colors — neutral */
    --c-text: #2c3e50;
    --c-text-secondary: #666;
    --c-text-muted: #888;
    --c-bg: #f5f5f5;
    --c-bg-card: #fff;
    --c-border: #e0e0e0;
    --c-border-light: #eee;

    /* Border radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 10px;
    --radius-xl: 12px;
    --radius-2xl: 16px;
    --radius-full: 999px;

    /* Shadows */
    --shadow-sm: 0 1px 4px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 4px 24px rgba(0, 0, 0, 0.15);

    /* Typography */
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-sm: 12px;
    --font-base: 14px;
    --font-lg: 16px;

    /* Z-index scale */
    --z-panel: 500;
    --z-banner: 800;
    --z-header: 1500;
    --z-modal: 2000;
    --z-loading: 3000;
    --z-barrier: 5000;
}

/* ── Reset ──────────────────────────────────────────────────── */

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font-family);
    background: var(--c-bg);
}

[hidden] {
    display: none !important;
}

/* ── Focus ──────────────────────────────────────────────────── */

:focus-visible {
    outline: 2px solid var(--c-accent);
    outline-offset: 2px;
}

button:focus:not(:focus-visible),
a:focus:not(:focus-visible) {
    outline: none;
}

/* ── App layout ─────────────────────────────────────────────── */

.app {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    position: relative;
}

.main-layout {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    position: relative;
}

/* ── Header ─────────────────────────────────────────────────── */

.header {
    background: var(--c-primary);
    color: white;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    z-index: var(--z-header);
    position: relative;
}

.header-title {
    flex: 1;
    min-width: 0;
    text-align: center;
}

.header h1 {
    font-size: 18px;
    font-weight: 600;
}

.header .subtitle {
    font-size: var(--font-sm);
    opacity: 0.8;
    margin-top: 2px;
}

.header .subtitle:empty {
    display: none;
}

/* ── Auth ───────────────────────────────────────────────────── */

.header-auth {
    flex-shrink: 0;
    position: relative;
}

.btn-login {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: var(--c-bg-card);
    color: var(--c-text);
    border: none;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}

.btn-login:hover {
    background: #f0f0f0;
}

.btn-login svg {
    width: 16px;
    height: 16px;
}

.avatar-btn {
    position: relative;
    width: 38px;
    height: 38px;
    padding: 0;
    border: none;
    background: none;
    cursor: pointer;
    border-radius: 50%;
}

.avatar-btn img {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.4);
    transition: border-color 0.15s;
}

.avatar-btn:hover img {
    border-color: rgba(255, 255, 255, 0.8);
}

.avatar-btn .admin-dot {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    background: var(--c-success);
    border: 2px solid var(--c-primary);
    border-radius: 50%;
}

/* ── Dropdown ───────────────────────────────────────────────── */

.user-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--c-bg-card);
    border-radius: var(--radius-xl);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
    min-width: 200px;
    z-index: var(--z-modal);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition:
        opacity 0.15s,
        transform 0.15s,
        visibility 0.15s;
}

.user-dropdown.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.user-dropdown::before {
    content: "";
    position: absolute;
    top: -6px;
    right: 14px;
    width: 12px;
    height: 12px;
    background: var(--c-bg-card);
    transform: rotate(45deg);
    border-radius: 2px;
}

.dropdown-header {
    padding: 12px 14px;
    border-bottom: 1px solid var(--c-border-light);
}

.dropdown-name {
    font-size: var(--font-base);
    font-weight: 600;
    color: var(--c-text);
}

.dropdown-email {
    font-size: 11px;
    color: var(--c-text-muted);
    margin-top: 2px;
    word-break: break-all;
}

.dropdown-badge {
    display: inline-block;
    margin-top: 6px;
    padding: 2px 8px;
    background: var(--c-success);
    color: white;
    font-size: 10px;
    font-weight: 600;
    border-radius: var(--radius-sm);
}

.dropdown-badge.servant-badge {
    background: var(--c-accent);
}

.dropdown-item {
    display: block;
    width: 100%;
    padding: 12px 14px;
    border: none;
    background: none;
    text-align: left;
    font-size: var(--font-base);
    color: var(--c-text);
    cursor: pointer;
    font-family: inherit;
    transition: background 0.1s;
}

.dropdown-item:hover {
    background: var(--c-bg);
}

.dropdown-item:last-child {
    border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}

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

/* ── Loading ────────────────────────────────────────────────── */

.loading-overlay {
    position: fixed;
    inset: 0;
    z-index: var(--z-loading);
    background: rgba(240, 242, 245, 0.94);
    display: none;
    align-items: center;
    justify-content: center;
}

.loading-overlay.visible {
    display: flex;
}

.loading-box {
    text-align: center;
    padding: 32px 24px;
}

.loading-box p {
    font-size: var(--font-base);
    color: var(--c-text);
    font-weight: 500;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--c-border);
    border-top-color: var(--c-accent);
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}

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

/* ── Desktop layout ─────────────────────────────────────────── */

@media (min-width: 768px) {
    .main-layout {
        flex-direction: row;
    }
}

/* ── Leaflet ────────────────────────────────────────────────── */

.leaflet-control-layers {
    border-radius: var(--radius-md) !important;
    box-shadow: var(--shadow-md) !important;
}