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

:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface2: #242736;
    --border: #2e3347;
    --text: #e8eaf0;
    --text-muted: #8b90a8;
    --accent: #5b8dee;
    --accent-hover: #4a7ce8;
    --green: #4caf7d;
    --orange: #f59e0b;
    --red: #ef4444;
    --purple: #8b5cf6;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 24px rgba(0,0,0,0.4);
    --sidebar-w: 360px;
    --header-h: 56px;
}

html, body { height: 100%; overflow: hidden; }
body { font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }

/* Login Screen */
#login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background: radial-gradient(ellipse at 50% 40%, #1a2540 0%, #0f1117 70%);
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 48px 40px;
    width: 360px;
    box-shadow: var(--shadow);
    text-align: center;
}

.login-icon {
    font-size: 48px;
    margin-bottom: 16px;
    display: block;
}

.login-card h1 { font-size: 22px; font-weight: 700; margin-bottom: 6px; }
.login-card p { color: var(--text-muted); margin-bottom: 28px; font-size: 13px; }

.login-card input {
    width: 100%;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 12px 16px;
    font-size: 15px;
    margin-bottom: 12px;
    outline: none;
    transition: border-color .2s;
}
.login-card input:focus { border-color: var(--accent); }
.login-card input::placeholder { color: var(--text-muted); }

.login-error { color: var(--red); font-size: 13px; margin-bottom: 10px; min-height: 18px; }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 10px 18px; border-radius: var(--radius-sm);
    border: none; cursor: pointer; font-size: 13px; font-weight: 600;
    transition: all .15s; text-decoration: none; white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-block { width: 100%; justify-content: center; padding: 13px; font-size: 15px; }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface2); color: var(--text); }
.btn-danger { background: rgba(239,68,68,.15); color: var(--red); border: 1px solid rgba(239,68,68,.3); }
.btn-danger:hover { background: rgba(239,68,68,.25); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-icon { padding: 8px; border-radius: 8px; }

/* App Layout */
#app { display: none; height: 100vh; flex-direction: column; }
#app.visible { display: flex; }

/* Header */
.app-header {
    height: var(--header-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center;
    padding: 0 16px;
    gap: 12px;
    z-index: 100;
    flex-shrink: 0;
}

.app-header .logo { font-size: 18px; font-weight: 800; letter-spacing: -0.5px; flex: 1; }
.app-header .logo span { color: var(--accent); }

.view-toggle {
    display: flex;
    background: var(--surface2);
    border-radius: var(--radius-sm);
    padding: 3px;
    gap: 2px;
}
.view-btn {
    padding: 5px 10px; border-radius: 6px; border: none; cursor: pointer;
    font-size: 12px; background: transparent; color: var(--text-muted); transition: all .15s;
}
.view-btn.active { background: var(--accent); color: #fff; }

/* Main Content */
.app-body { display: flex; flex: 1; overflow: hidden; }

/* Sidebar */
.sidebar {
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    display: flex; flex-direction: column; gap: 10px;
}

.sidebar-stats {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
}
.stat-card {
    background: var(--surface2);
    border-radius: var(--radius-sm);
    padding: 10px;
    text-align: center;
}
.stat-card .stat-num { font-size: 20px; font-weight: 800; }
.stat-card .stat-label { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.stat-wunsch .stat-num { color: var(--accent); }
.stat-geplant .stat-num { color: var(--orange); }
.stat-besucht .stat-num { color: var(--green); }

.filter-row { display: flex; gap: 6px; align-items: center; }
.filter-select {
    flex: 1;
    background: var(--surface2); border: 1px solid var(--border);
    color: var(--text); padding: 7px 10px; border-radius: var(--radius-sm);
    font-size: 12px; outline: none; cursor: pointer;
}
.filter-select:focus { border-color: var(--accent); }

.status-filters { display: flex; gap: 4px; }
.status-btn {
    padding: 5px 10px; border-radius: 20px; border: none; cursor: pointer;
    font-size: 11px; font-weight: 600; transition: all .15s;
    background: var(--surface2); color: var(--text-muted);
}
.status-btn:hover { color: var(--text); }
.status-btn.active-all { background: var(--accent); color: #fff; }
.status-btn.active-wunsch { background: rgba(91,141,238,.2); color: var(--accent); }
.status-btn.active-geplant { background: rgba(245,158,11,.2); color: var(--orange); }
.status-btn.active-besucht { background: rgba(76,175,125,.2); color: var(--green); }

.destination-list {
    flex: 1; overflow-y: auto; padding: 8px;
}
.destination-list::-webkit-scrollbar { width: 4px; }
.destination-list::-webkit-scrollbar-track { background: transparent; }
.destination-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.dest-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; border-radius: var(--radius-sm);
    cursor: pointer; transition: background .15s;
    border: 1px solid transparent;
    margin-bottom: 4px;
}
.dest-item:hover { background: var(--surface2); }
.dest-item.active { background: var(--surface2); border-color: var(--accent); }

.dest-thumb {
    width: 44px; height: 44px; border-radius: 8px;
    background: var(--surface2);
    overflow: hidden; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px;
}
.dest-thumb img { width: 100%; height: 100%; object-fit: cover; }

.dest-info { flex: 1; min-width: 0; }
.dest-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dest-meta { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.dest-badge {
    font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 10px; flex-shrink: 0;
}
.badge-wunsch { background: rgba(91,141,238,.2); color: var(--accent); }
.badge-geplant { background: rgba(245,158,11,.2); color: var(--orange); }
.badge-besucht { background: rgba(76,175,125,.2); color: var(--green); }

/* Priority stars */
.dest-priority { color: var(--orange); font-size: 10px; }

.empty-list { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.empty-list .empty-icon { font-size: 40px; margin-bottom: 12px; }

/* Map */
#map-container { flex: 1; position: relative; }
#map { width: 100%; height: 100%; }

/* Leaflet overrides */
.leaflet-popup-content-wrapper {
    background: var(--surface) !important;
    color: var(--text) !important;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm) !important;
    box-shadow: var(--shadow) !important;
}
.leaflet-popup-tip { background: var(--surface) !important; }
.leaflet-popup-content { margin: 12px 14px !important; }
.popup-name { font-weight: 700; font-size: 14px; margin-bottom: 4px; }
.popup-meta { font-size: 12px; color: var(--text-muted); }

/* Grid View */
#grid-view {
    flex: 1; overflow-y: auto; padding: 16px;
    display: none;
}
#grid-view.visible { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; align-content: start; }

.grid-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); overflow: hidden; cursor: pointer;
    transition: transform .15s, border-color .15s;
}
.grid-card:hover { transform: translateY(-2px); border-color: var(--accent); }

.grid-card-img {
    height: 140px; background: var(--surface2);
    display: flex; align-items: center; justify-content: center;
    font-size: 48px; overflow: hidden;
}
.grid-card-img img { width: 100%; height: 100%; object-fit: cover; }

.grid-card-body { padding: 12px; }
.grid-card-name { font-weight: 700; font-size: 14px; margin-bottom: 4px; }
.grid-card-meta { font-size: 12px; color: var(--text-muted); }
.grid-card-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; }

/* Modal */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,.7);
    display: flex; align-items: center; justify-content: center;
    z-index: 1000; opacity: 0; pointer-events: none; transition: opacity .2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); width: 520px; max-width: 95vw;
    max-height: 90vh; overflow: hidden; display: flex; flex-direction: column;
    box-shadow: var(--shadow);
    transform: scale(.95); transition: transform .2s, width .25s ease;
}
.modal-overlay.open .modal { transform: scale(1); }
.modal.panel-open { width: 820px; }

.modal-header {
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
}
.modal-title { font-size: 16px; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 20px; padding: 4px; line-height: 1; }
.modal-close:hover { color: var(--text); }

.modal-body { padding: 20px 24px; overflow-y: auto; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }

/* Form */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full { grid-column: 1 / -1; }
.form-label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .4px; }

.form-input, .form-select, .form-textarea {
    background: var(--surface2); border: 1px solid var(--border);
    color: var(--text); padding: 10px 12px; border-radius: var(--radius-sm);
    font-size: 13px; outline: none; transition: border-color .15s; width: 100%;
    font-family: inherit;
}
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: var(--accent); }
.form-input::placeholder, .form-textarea::placeholder { color: var(--text-muted); }
.form-textarea { resize: vertical; min-height: 80px; }
.form-select option { background: var(--surface2); }

/* Coords row */
.coords-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* Detail Panel */
.detail-panel {
    position: absolute; bottom: 16px; left: 16px;
    width: 300px; background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow);
    transform: translateY(20px); opacity: 0; pointer-events: none;
    transition: all .2s; z-index: 500;
}
.detail-panel.open { transform: translateY(0); opacity: 1; pointer-events: all; }

.detail-img {
    height: 120px; background: var(--surface2);
    border-radius: var(--radius) var(--radius) 0 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 48px; overflow: hidden;
}
.detail-img img { width: 100%; height: 100%; object-fit: cover; border-radius: var(--radius) var(--radius) 0 0; }

.detail-body { padding: 14px; }
.detail-name { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.detail-meta { font-size: 12px; color: var(--text-muted); margin-bottom: 10px; }
.detail-desc { font-size: 13px; color: var(--text-muted); line-height: 1.5; margin-bottom: 12px; }
.detail-actions { display: flex; gap: 6px; }

/* Search hint */
.search-hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; min-height: 16px; }

/* Modal two-column layout */
.modal-inner { display: flex; overflow: hidden; }
.modal-inner .modal-body { flex: 1; min-width: 0; }

/* Search Panel */
.search-panel {
    width: 0; overflow: hidden; transition: width .25s ease;
    border-left: 1px solid transparent;
    display: flex; flex-direction: column;
    flex-shrink: 0;
}
.search-panel.open {
    width: 280px;
    border-left-color: var(--border);
}

.search-panel-header {
    padding: 14px 14px 10px;
    font-size: 11px; font-weight: 700; text-transform: uppercase;
    letter-spacing: .5px; color: var(--text-muted);
    display: flex; align-items: center; gap: 8px;
    flex-shrink: 0;
}

.search-spinner {
    width: 12px; height: 12px; border: 2px solid var(--border);
    border-top-color: var(--accent); border-radius: 50%;
    display: none;
}
.search-spinner.spinning { display: inline-block; animation: spin .6s linear infinite; }

.search-results {
    flex: 1; overflow-y: auto; padding: 0 8px 8px;
}
.search-results::-webkit-scrollbar { width: 3px; }
.search-results::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.search-result-item {
    border-radius: var(--radius-sm); overflow: hidden;
    cursor: pointer; margin-bottom: 8px;
    border: 1px solid var(--border);
    transition: border-color .15s, transform .1s;
}
.search-result-item:hover { border-color: var(--accent); transform: translateY(-1px); }

.search-result-img {
    height: 100px; background: var(--surface2);
    display: flex; align-items: center; justify-content: center;
    font-size: 32px; overflow: hidden; position: relative;
}
.search-result-img img {
    width: 100%; height: 100%; object-fit: cover;
}
.search-result-img .img-placeholder {
    display: flex; align-items: center; justify-content: center;
    width: 100%; height: 100%; font-size: 32px;
}

.search-result-body { padding: 8px 10px; }
.search-result-name { font-weight: 600; font-size: 12px; margin-bottom: 2px; line-height: 1.3; }
.search-result-meta { font-size: 11px; color: var(--text-muted); }
.search-result-type {
    position: absolute; top: 6px; right: 6px;
    background: rgba(0,0,0,.6); color: #fff;
    font-size: 10px; padding: 2px 6px; border-radius: 4px;
}

.no-results-hint {
    padding: 16px 12px; text-align: center;
    font-size: 12px; color: var(--text-muted); line-height: 1.6;
}

/* Loading */
.spinner {
    width: 20px; height: 20px; border: 2px solid var(--border);
    border-top-color: var(--accent); border-radius: 50%;
    animation: spin .6s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Toast */
.toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 12px 16px;
    font-size: 13px; box-shadow: var(--shadow);
    display: flex; align-items: center; gap: 10px;
    transform: translateX(120%); transition: transform .3s;
    min-width: 200px;
}
.toast.show { transform: translateX(0); }
.toast-success { border-left: 3px solid var(--green); }
.toast-error { border-left: 3px solid var(--red); }

/* Responsive */
@media (max-width: 768px) {
    :root { --sidebar-w: 100%; }
    .app-body { flex-direction: column; }
    .sidebar { width: 100%; height: 50vh; border-right: none; border-bottom: 1px solid var(--border); }
    #map-container { height: 50vh; }
}
