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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    overflow: hidden;
    height: 100vh;
    height: -webkit-fill-available;
    color: #1d1d1f;
    background: #000;
}

/* ── Map ── */
#map {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 1;
}

/* ── Overlay Panel ── */
.panel {
    position: absolute;
    top: 12px; left: 12px; bottom: 12px;
    width: 340px;
    background: #fff;
    border-radius: 14px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 30px rgba(0,0,0,0.15);
    overflow: hidden;
    transition: transform 0.3s ease;
}
/* Inhaltsbereich innerhalb der Panels – Handle bleibt außen als Flex-Sibling */
.panel-content {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.panel.collapsed {
    height: auto;
    bottom: auto;
}
.panel.collapsed .search-box,
.panel.collapsed .tracker-list,
.panel.collapsed .panel-footer { display: none; }

.panel-header h1 { cursor: pointer; user-select: none; }
.collapse-arrow {
    transition: transform 0.2s;
}
.panel.collapsed .collapse-arrow { transform: rotate(180deg); }

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px 8px;
}
.panel-header h1 { font-size: 22px; font-weight: 700; }

.search-box { padding: 4px 14px 10px; }
.search-box input {
    width: 100%;
    padding: 10px 14px;
    border: none;
    border-radius: 10px;
    background: rgba(0,0,0,0.06);
    font-size: 15px;
    outline: none;
}
.search-box input:focus { background: rgba(0,0,0,0.09); }

.tracker-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 10px;
}

.tracker-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 10px;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.15s;
}
.tracker-item:hover { background: rgba(0,0,0,0.05); }
.tracker-item.active { background: rgba(0,122,255,0.1); }

.tracker-dot {
    width: 12px; height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}
.tracker-info { flex: 1; min-width: 0; }
.tracker-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tracker-sub { font-size: 12px; color: #86868b; margin-top: 2px; }

.battery-badge { display: inline-flex; vertical-align: middle; color: #34c759; margin-left: 2px; }
.battery-badge svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.battery-badge.medium { color: #86868b; }
.battery-badge.low { color: #ff9500; }
.battery-badge.critical { color: #ff3b30; }

.panel-footer { padding: 10px 14px 14px; display: flex; flex-direction: column; gap: 6px; }

.fetch-timer-bar {
    width: 100%;
    height: 4px;
    background: rgba(0,0,0,0.06);
    border-radius: 2px;
    overflow: hidden;
}
.fetch-timer-fill {
    height: 100%;
    width: 0%;
    background: #34c759;
    border-radius: 2px;
}

/* ── Buttons ── */
.btn {
    padding: 10px 16px;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s;
}
.btn:hover { opacity: 0.85; }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn-primary { background: #007aff; color: white; }
.btn-secondary { background: rgba(0,0,0,0.06); color: #1d1d1f; }
.btn-danger { background: #ff3b30; color: white; }
.btn-with-icon { display: inline-flex; align-items: center; justify-content: center; gap: 6px; overflow: hidden; }
.btn-icon { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

.icon-btn {
    background: none; border: none;
    cursor: pointer;
    padding: 4px 6px; border-radius: 8px;
    display: inline-flex; align-items: center; justify-content: center;
    color: #86868b;
    transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: rgba(0,0,0,0.06); color: #1d1d1f; }
.icon-btn.danger { color: #86868b; }
.icon-btn.danger:hover { background: rgba(255,59,48,0.1); color: #ff3b30; }
.icon-btn.solo-active { background: rgba(0,122,255,0.12); color: #007aff; }
.icon-btn.solo-active:hover { background: rgba(0,122,255,0.18); }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.sm svg { width: 15px; height: 15px; }


/* ── Modals ── */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(4px);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal.hidden { display: none; }

.modal-content {
    background: white;
    border-radius: 16px;
    width: 90%;
    max-width: 440px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal-large { max-width: 600px; }
.modal-small { max-width: 360px; }

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px 10px;
    border-bottom: 1px solid #f0f0f0;
}
.modal-header h2 { font-size: 18px; font-weight: 700; }
.modal-close {
    background: rgba(0,0,0,0.06);
    border: none; border-radius: 50%;
    width: 30px; height: 30px;
    font-size: 18px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}

.modal-body {
    padding: 16px 20px 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.modal-body input, .modal-body select {
    padding: 10px 14px;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    font-size: 15px;
    outline: none;
}
.modal-body input:focus { border-color: #007aff; }

.color-picker-label {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 500;
    color: #555;
    cursor: pointer;
    transition: border-color 0.15s;
}
.color-picker-label:hover { border-color: #007aff; }
.color-picker-label svg {
    width: 18px; height: 18px;
    fill: none; stroke: #86868b;
    stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.color-picker-label input[type="color"] {
    width: 0; height: 0; padding: 0; border: none;
    position: absolute; opacity: 0; pointer-events: none;
}
.color-preview {
    width: 22px; height: 22px;
    border-radius: 50%;
    border: 2px solid rgba(0,0,0,0.1);
    flex-shrink: 0;
}

/* ── Tabs ── */
.tabs { display: flex; gap: 4px; margin-bottom: 12px; }
.tab {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 10px;
    background: rgba(0,0,0,0.04);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}
.tab.active { background: #007aff; color: white; }
.tab-content.hidden { display: none; }

/* ── Account List ── */
.account-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: rgba(0,0,0,0.03);
    border-radius: 10px;
    margin-bottom: 6px;
}
.account-email { font-weight: 600; font-size: 14px; }
.account-status { font-size: 12px; color: #86868b; }
.account-status.active { color: #34c759; }
.account-status.error { color: #ff3b30; }

.add-account-form { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.add-account-form h3 { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.add-account-form input {
    padding: 10px 14px;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    font-size: 15px;
}

/* ── Flash Section ── */
.flash-section { display: flex; flex-direction: column; gap: 10px; }
.flash-section select {
    padding: 10px;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    font-size: 15px;
}
.flash-controls { display: flex; gap: 8px; }
.progress-bar {
    width: 100%;
    height: 8px;
    background: rgba(0,0,0,0.08);
    border-radius: 4px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    background: #007aff;
    border-radius: 4px;
    width: 0%;
    transition: width 0.2s;
}

/* ── Detail Panel ── */
.detail-panel {
    position: absolute;
    top: 12px; left: 12px; bottom: 12px;
    width: 340px;
    background: #fff;
    border-radius: 14px;
    z-index: 1100;
    box-shadow: 0 4px 30px rgba(0,0,0,0.15);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.detail-panel.hidden { display: none; }
.detail-panel.minimized {
    bottom: auto;
    height: auto;
    z-index: 1200;
}
.detail-panel.minimized #detail-location,
.detail-panel.minimized #detail-account,
.detail-panel.minimized #detail-history-controls,
.detail-panel.minimized #detail-history { display: none; }
.detail-panel.minimized #detail-selected-point { display: block !important; }
.panel.detail-open { display: none; }

.detail-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 16px 14px 12px;
    border-bottom: 1px solid #f0f0f0;
}
.detail-header h2 { flex: 1; font-size: 18px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mobile-only { display: none; }
@media (max-width: 768px) { .mobile-only { display: inline-flex; } }

.detail-info {
    padding: 6px 14px;
    font-size: 14px;
    color: #555;
    line-height: 1.5;
    flex-shrink: 0;
}
.detail-info.history-scroll {
    flex-shrink: 1;
    padding-top: 0;
}
.detail-info select {
    margin-top: 4px;
    width: 100%;
    padding: 6px 8px;
    border: 1px solid #d2d2d7;
    border-radius: 8px;
    font-size: 14px;
    background: #fff;
}

/* ── Status Messages ── */
.status-msg { font-size: 13px; color: #86868b; min-height: 20px; }
.status-msg.error { color: #ff3b30; }
.status-msg.success { color: #34c759; }

.hidden { display: none !important; }

/* ── Resize Handle (mobile only) ── */
.resize-handle {
    display: none;
}

/* ── Mobile ── */
@media (max-width: 768px) {
    .panel {
        width: calc(100% - 24px);
        top: calc(12px + constant(safe-area-inset-top, 0px));
        top: calc(12px + env(safe-area-inset-top, 0px));
        bottom: auto;
        max-height: 55vh;
    }
    .panel.collapsed {
        max-height: none;
    }
    .panel.collapsed .resize-handle { display: none; }
    .detail-panel {
        width: calc(100% - 24px);
        top: calc(12px + constant(safe-area-inset-top, 0px));
        top: calc(12px + env(safe-area-inset-top, 0px));
        bottom: auto;
        max-height: 70vh;
    }
    .detail-panel.minimized .resize-handle { display: none; }
    /* Smaller fonts on mobile */
    .panel-header h1 { font-size: 18px; }
    .detail-header h2 { font-size: 16px; }
    /* History mindestens ~3 Einträge sichtbar */
    .detail-panel .history-scroll { min-height: 130px; }
    /* Leaflet zoom control ausblenden auf mobile */
    .leaflet-control-zoom { display: none; }
    /* panel-content: scrollbarer/clippbarer Inhaltsbereich, Handle bleibt außen */
    .panel-content {
        flex: 1;
        min-height: 0;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }
    /* Zeitraum offen: history-scroll darf komplett schrumpfen, Inputs bleiben sichtbar */
    .detail-panel.zeitraum-open .history-scroll {
        min-height: 0;
    }
    /* Resize handle als Flex-Kind außerhalb des Overflow-Bereichs – immer sichtbar */
    .resize-handle {
        display: flex;
        align-items: center;
        justify-content: center;
        height: 28px;
        min-height: 28px;
        cursor: ns-resize;
        flex-shrink: 0;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
        position: relative;
        z-index: 10;
    }
    .resize-handle-bar {
        width: 40px;
        height: 5px;
        background: rgba(0,0,0,0.25);
        border-radius: 3px;
        pointer-events: none;
    }
}

/* ── iOS Safe Areas ── */
@supports (padding: constant(safe-area-inset-top)) or (padding: env(safe-area-inset-top)) {
    /* Karte in Safe-Areas ausdehnen, kein grauer Rand */
    #map {
        top: 0; left: 0; right: 0; bottom: 0;
    }
    /* Leaflet-Controls nicht unter Notch/Home-Indicator */
    .leaflet-top {
        top: constant(safe-area-inset-top, 0px) !important;
        top: env(safe-area-inset-top, 0px) !important;
    }
    .leaflet-bottom {
        bottom: constant(safe-area-inset-bottom, 0px) !important;
        bottom: env(safe-area-inset-bottom, 0px) !important;
    }
}

/* ── Settings ── */
.setting-group { margin-bottom: 16px; }
.setting-group h3 { font-size: 15px; font-weight: 600; margin-bottom: 8px; }
.setting-label { font-size: 14px; color: #555; margin-bottom: 4px; display: block; }
.setting-row { display: flex; align-items: center; gap: 10px; }
.setting-row input[type="range"] { flex: 1; }
.setting-row span { font-size: 15px; font-weight: 600; min-width: 24px; text-align: center; }
.setting-hint { font-size: 12px; color: #86868b; margin-top: 4px; }
.setting-row input[type="checkbox"] {
    width: 20px; height: 20px; accent-color: #007aff; cursor: pointer;
}

/* ── Groups ── */
.group-section {
    margin-bottom: 2px;
    border-radius: 10px;
    transition: background 0.15s;
}
.group-section.drag-over {
    background: rgba(0,122,255,0.08);
}
.group-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    cursor: pointer;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 700;
    color: #555;
    user-select: none;
}
.group-header:hover { background: rgba(0,0,0,0.04); }
.ungrouped-header { font-weight: 600; color: #86868b; font-size: 12px; }
.group-arrow { width: 14px; text-align: center; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; }
.group-arrow-svg { width: 14px; height: 14px; fill: none; stroke: #86868b; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.group-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.group-name { flex: 1; }
.group-count { font-size: 11px; color: #86868b; font-weight: 400; }
.group-header .icon-btn { padding: 2px 4px; }

.eye-btn { flex-shrink: 0; }
.tracker-item.dimmed { opacity: 0.4; }
.tracker-item[draggable="true"] { cursor: grab; }
.tracker-item[draggable="true"]:active { cursor: grabbing; }

/* ── History Timeframe ── */
.timeframe-selector {
    display: flex;
    gap: 4px;
    margin-top: 4px;
}
.timeframe-selector:first-of-type { margin-top: 6px; }
.timeframe-btn {
    flex: 1;
    padding: 6px 10px;
    border: none;
    border-radius: 8px;
    background: rgba(0,0,0,0.06);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.timeframe-btn:hover { background: rgba(0,0,0,0.1); }
.timeframe-btn.active {
    background: #007aff;
    color: white;
}

/* ── Export & Range ── */
.export-buttons { display: flex; gap: 6px; }
.range-row { display: flex; align-items: center; gap: 6px; font-size: 13px; margin-bottom: 4px; }
.range-row label { width: 30px; font-weight: 600; color: #555; flex-shrink: 0; }
.range-row input {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid #d2d2d7;
    border-radius: 6px;
    font-size: 13px;
    background: #fff;
    cursor: pointer;
}
.custom-range { margin-top: 4px; }
/* flatpickr inside detail panel */
.flatpickr-calendar { font-size: 13px; }

@media (max-width: 768px) {
    .flatpickr-calendar {
        position: fixed !important;
        top: 50% !important;
        left: 50% !important;
        transform: translate(-50%, -50%) !important;
        right: auto !important;
        bottom: auto !important;
    }
}

/* ── History List ── */
.history-scroll {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}
.history-item {
    padding: 8px 10px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    line-height: 1.4;
    transition: background 0.15s;
}
.history-item:hover {
    background: rgba(0,122,255,0.08);
}
.history-item.active {
    background: rgba(255,149,0,0.15);
}
.history-time { font-weight: 600; }
.history-coords { color: #86868b; font-size: 12px; }

/* ── Scrollbar ── */
.tracker-list::-webkit-scrollbar { width: 4px; }
.tracker-list::-webkit-scrollbar-track { background: transparent; }
.tracker-list::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 2px; }
