/* ─── Heartbeat Design System ─── */
/* Dark premium theme with glassmorphism */

:root {
    /* Colors */
    --bg-primary: #0a0e17;
    --bg-secondary: #111827;
    --bg-glass: rgba(17, 24, 39, 0.75);
    --bg-glass-hover: rgba(17, 24, 39, 0.85);
    --bg-glass-border: rgba(255, 255, 255, 0.08);

    --text-primary: #f0f4f8;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    --accent: #6C63FF;
    --accent-light: #8B83FF;
    --accent-glow: rgba(108, 99, 255, 0.3);
    --accent-gradient: linear-gradient(135deg, #6C63FF 0%, #4ECDC4 100%);

    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --danger-hover: #dc2626;

    /* Spacing */
    --sidebar-width: 340px;
    --top-bar-height: 56px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 20px var(--accent-glow);

    /* Transitions */
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

/* ─── Map ─── */
#map {
    position: fixed;
    inset: 0;
    z-index: 1;
}

/* Override leaflet tiles for dark mode */
.leaflet-tile-pane {
    filter: brightness(0.7) contrast(1.1) saturate(0.8);
}

.leaflet-control-attribution {
    background: var(--bg-glass) !important;
    color: var(--text-muted) !important;
    backdrop-filter: blur(8px);
    border: 1px solid var(--bg-glass-border) !important;
    border-radius: var(--radius-sm) !important;
    font-size: 10px !important;
    padding: 2px 8px !important;
}

.leaflet-control-attribution a {
    color: var(--text-secondary) !important;
}

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

.leaflet-control-zoom a {
    background: var(--bg-glass) !important;
    backdrop-filter: blur(12px) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--bg-glass-border) !important;
    width: 36px !important;
    height: 36px !important;
    line-height: 36px !important;
    font-size: 18px !important;
}

.leaflet-control-zoom a:hover {
    background: var(--bg-glass-hover) !important;
}

.leaflet-control-zoom-in {
    border-radius: var(--radius-sm) var(--radius-sm) 0 0 !important;
}

.leaflet-control-zoom-out {
    border-radius: 0 0 var(--radius-sm) var(--radius-sm) !important;
}

/* ─── Top Bar ─── */
#top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--top-bar-height);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--bg-glass-border);
}

.top-bar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.top-bar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-pulse {
    width: 10px;
    height: 10px;
    background: var(--accent);
    border-radius: 50%;
    animation: pulse 2s ease-in-out infinite;
    box-shadow: 0 0 8px var(--accent-glow);
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(1.3); }
}

.logo-text {
    font-size: 18px;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.5px;
}

/* ─── Icon Buttons ─── */
.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s var(--ease);
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
}

.icon-btn-sm {
    width: 32px;
    height: 32px;
}

/* ─── Sidebar ─── */
.sidebar {
    position: fixed;
    top: var(--top-bar-height);
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    z-index: 900;
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    border-right: 1px solid var(--bg-glass-border);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s var(--ease);
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--bg-glass-border);
}

.sidebar-header h2 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
}

.sidebar-actions {
    display: flex;
    gap: 8px;
}

/* ─── Circles List ─── */
.circles-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.circles-list::-webkit-scrollbar {
    width: 4px;
}

.circles-list::-webkit-scrollbar-track {
    background: transparent;
}

.circles-list::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    border-radius: 2px;
}

.circle-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s var(--ease);
    border: 1px solid transparent;
}

.circle-card:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--bg-glass-border);
}

.circle-card.active {
    background: rgba(108, 99, 255, 0.1);
    border-color: rgba(108, 99, 255, 0.3);
}

.circle-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--accent-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 16px;
    color: white;
    flex-shrink: 0;
}

.circle-info {
    flex: 1;
    min-width: 0;
}

.circle-info-name {
    font-weight: 500;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.circle-info-meta {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.circle-arrow {
    color: var(--text-muted);
    flex-shrink: 0;
}

/* ─── Circles Empty State ─── */
.circles-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    color: var(--text-muted);
}

.circles-empty svg {
    margin-bottom: 16px;
    opacity: 0.4;
}

.circles-empty p {
    font-size: 13px;
    line-height: 1.5;
}

/* ─── Circle Detail Panel ─── */
.circle-detail {
    position: fixed;
    top: var(--top-bar-height);
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    z-index: 950;
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    border-right: 1px solid var(--bg-glass-border);
    display: flex;
    flex-direction: column;
    transform: translateX(0);
    transition: transform 0.3s var(--ease), opacity 0.3s var(--ease);
}

.circle-detail.hidden {
    transform: translateX(-100%);
    opacity: 0;
    pointer-events: none;
}

.circle-detail-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--bg-glass-border);
}

.circle-detail-header h3 {
    flex: 1;
    font-size: 16px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.circle-members {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.member-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background 0.2s var(--ease);
}

.member-card:hover {
    background: rgba(255, 255, 255, 0.05);
}

.member-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--bg-secondary);
    border: 2px solid var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    position: relative;
    flex-shrink: 0;
}

.member-avatar .member-status {
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid var(--bg-secondary);
}

.member-status-online {
    background: var(--success);
}

.member-status-offline {
    background: var(--text-muted);
}

.member-info {
    flex: 1;
    min-width: 0;
}

.member-name {
    font-weight: 500;
    font-size: 14px;
}

.member-name .badge {
    font-size: 10px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--accent-light);
    margin-left: 6px;
}

.member-location {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.circle-detail-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--bg-glass-border);
}

/* ─── Dropdown Menu ─── */
.dropdown-menu {
    position: fixed;
    z-index: 1100;
    background: var(--bg-secondary);
    border: 1px solid var(--bg-glass-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 6px;
    min-width: 180px;
}

.dropdown-menu.hidden {
    display: none;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 14px;
    border: none;
    background: none;
    color: var(--text-primary);
    font-size: 13px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s var(--ease);
    font-family: inherit;
}

.dropdown-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

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

.dropdown-item.danger:hover {
    background: rgba(239, 68, 68, 0.1);
}

/* ─── Buttons ─── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 18px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s var(--ease);
    white-space: nowrap;
}

.btn-primary {
    background: var(--accent);
    color: white;
    box-shadow: 0 2px 8px var(--accent-glow);
}

.btn-primary:hover {
    background: var(--accent-light);
    box-shadow: var(--shadow-glow);
    transform: translateY(-1px);
}

.btn-outline {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--bg-glass-border);
}

.btn-outline:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    border-color: rgba(255, 255, 255, 0.15);
}

.btn-sm {
    padding: 7px 14px;
    font-size: 12px;
}

.btn-full {
    width: 100%;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* ─── Modal ─── */
.modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s var(--ease);
}

.modal.hidden {
    display: none;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    width: 420px;
    max-width: calc(100vw - 40px);
    background: var(--bg-secondary);
    border: 1px solid var(--bg-glass-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.25s var(--ease);
}

.modal-content-sm {
    width: 360px;
}

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

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 0;
}

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

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
    transition: color 0.15s var(--ease);
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 20px 24px;
}

.modal-body-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 0 24px 20px;
}

/* ─── Inputs ─── */
.input-label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.input {
    width: 100%;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--bg-glass-border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    transition: all 0.2s var(--ease);
    outline: none;
}

.input::placeholder {
    color: var(--text-muted);
}

.input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.input-code {
    text-align: center;
    font-size: 24px;
    font-weight: 700;
    letter-spacing: 8px;
    text-transform: uppercase;
    font-family: 'SF Mono', 'Fira Code', monospace;
}

.input-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 8px;
}

/* ─── QR Code ─── */
.qr-container {
    padding: 20px;
    background: white;
    border-radius: var(--radius-md);
    margin-bottom: 16px;
}

.qr-container img {
    display: block;
    width: 200px;
    height: 200px;
}

.invite-code-display {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.invite-code-text {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: 6px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    color: var(--accent-light);
}

/* ─── Settings Info ─── */
.settings-info {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--bg-glass-border);
}

.settings-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
}

.settings-label {
    font-size: 13px;
    color: var(--text-muted);
}

.settings-value {
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.settings-value.mono {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 11px;
    color: var(--text-secondary);
}

/* Status Dots */
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.status-dot-active {
    background: var(--success);
    box-shadow: 0 0 6px rgba(16, 185, 129, 0.4);
}

/* ─── Connection Status ─── */
.connection-status {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    border: 1px solid var(--bg-glass-border);
    border-radius: 20px;
    font-size: 12px;
    color: var(--text-secondary);
    transition: all 0.3s var(--ease);
}

.connection-status .status-dot {
    width: 6px;
    height: 6px;
    background: var(--warning);
    animation: pulse 1.5s ease-in-out infinite;
}

.connection-status.connected .status-dot {
    background: var(--success);
    animation: none;
}

.connection-status.disconnected .status-dot {
    background: var(--danger);
    animation: none;
}

/* ─── Toast ─── */
.toast {
    position: fixed;
    bottom: 70px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    z-index: 3000;
    padding: 12px 24px;
    background: var(--bg-secondary);
    border: 1px solid var(--bg-glass-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    font-size: 13px;
    color: var(--text-primary);
    opacity: 0;
    transition: all 0.3s var(--ease);
    pointer-events: none;
}

.toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast.hidden {
    display: none;
}

/* ─── Custom Map Markers ─── */
.device-marker {
    position: relative;
    width: 40px;
    height: 40px;
}

.device-marker-dot {
    width: 16px;
    height: 16px;
    background: var(--accent);
    border: 3px solid white;
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 2px 8px rgba(108, 99, 255, 0.5);
}

.device-marker-self .device-marker-dot {
    background: #4ECDC4;
    box-shadow: 0 2px 8px rgba(78, 205, 196, 0.5);
}

.device-marker-pulse {
    width: 40px;
    height: 40px;
    background: rgba(108, 99, 255, 0.15);
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation: marker-pulse 2s ease-out infinite;
}

.device-marker-self .device-marker-pulse {
    background: rgba(78, 205, 196, 0.15);
}

@keyframes marker-pulse {
    0% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(2.5); opacity: 0; }
}

.device-marker-label {
    position: absolute;
    top: calc(100% + 4px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-glass);
    backdrop-filter: blur(8px);
    padding: 3px 10px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
    border: 1px solid var(--bg-glass-border);
    color: var(--text-primary);
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
    :root {
        --sidebar-width: 100vw;
    }

    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .circle-detail {
        width: 100vw;
    }
}
