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

body {
    font-family: 'Inter', system-ui, sans-serif;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ── Topbar ─────────────────────────────────────────────────────────────── */
#topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    height: 54px;
    background: #1e3a5f;
    color: white;
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    flex-shrink: 0;
}

#logo {
    font-size: 1.1rem;
    font-weight: 600;
    color: #7dd3fc;
    white-space: nowrap;
}

#search-container {
    flex: 1;
    position: relative;
    max-width: 420px;
}

#search-container::before {
    content: '🔍';
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.8rem;
    pointer-events: none;
}

#search-input {
    width: 100%;
    padding: 8px 12px 8px 32px;
    border-radius: 20px;
    border: none;
    background: rgba(255,255,255,0.15);
    color: white;
    font-size: 0.9rem;
    font-family: inherit;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    transition: background 0.2s;
}
#search-input::-webkit-search-cancel-button { filter: invert(1); cursor: pointer; }
#search-input::placeholder { color: rgba(255,255,255,0.5); }
#search-input:focus { background: rgba(255,255,255,0.25); }

#search-results {
    position: absolute;
    top: calc(100% + 6px);
    left: 0; right: 0;
    background: white;
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
    z-index: 2000;
    overflow: hidden;
    max-height: 300px;
    overflow-y: auto;
}
#search-results.hidden { display: none; }

.search-item {
    padding: 10px 14px;
    cursor: pointer;
    color: #1a2a3a;
    font-size: 0.88rem;
    border-bottom: 1px solid #f0f0f0;
    transition: background 0.1s;
}
.search-item:last-child { border-bottom: none; }
.search-item:hover { background: #f0f7ff; }
.search-item.no-results { color: #999; cursor: default; }

.search-item-kommun {
    display: flex;
    align-items: baseline;
    gap: 6px;
    background: #f8fafc;
}
.search-item-sub {
    font-size: 0.76rem;
    color: #999;
    margin-left: auto;
}

/* ── Auth ────────────────────────────────────────────────────────────────── */
#auth-container {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.user-avatar {
    width: 30px; height: 30px;
    border-radius: 50%;
    border: 2px solid #7dd3fc;
    object-fit: cover;
}

.user-name {
    font-size: 0.85rem;
    color: #e2e8f0;
    max-width: 130px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-logout {
    padding: 5px 12px;
    border: 1px solid rgba(255,255,255,0.35);
    border-radius: 16px;
    background: transparent;
    color: white;
    font-size: 0.82rem;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-logout:hover { background: rgba(255,255,255,0.15); }

.btn-lang {
    padding: 5px 10px;
    border: 1px solid rgba(255,255,255,0.35);
    border-radius: 16px;
    background: transparent;
    color: white;
    font-size: 0.78rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.2s;
    flex-shrink: 0;
}
.btn-lang:hover { background: rgba(255,255,255,0.15); }

.btn-filter {
    padding: 5px 12px;
    border: 1px solid rgba(255,255,255,0.35);
    border-radius: 16px;
    background: transparent;
    color: white;
    font-size: 0.8rem;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
    flex-shrink: 0;
    white-space: nowrap;
}
.btn-filter:hover { background: rgba(255,255,255,0.15); }
.btn-filter.active {
    background: #7dd3fc;
    color: #1e3a5f;
    border-color: #7dd3fc;
    font-weight: 600;
}
.btn-filter.active:hover { background: #a5e2fd; }
.btn-filter.hidden { display: none; }

.auth-note {
    font-size: 0.78rem;
    color: rgba(255,255,255,0.45);
    cursor: help;
}

/* ── Map ─────────────────────────────────────────────────────────────────── */
#map { flex: 1; z-index: 1; }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.modal.hidden { display: none; }

.modal-content {
    background: white;
    border-radius: 14px;
    padding: 24px;
    max-width: 420px;
    width: 100%;
    box-shadow: 0 10px 40px rgba(0,0,0,0.25);
}

.modal-content h2 {
    font-size: 1.15rem;
    color: #1a2a3a;
    margin-bottom: 20px;
}

.form-group { margin-bottom: 16px; }

.form-group > label {
    display: block;
    font-size: 0.82rem;
    font-weight: 500;
    color: #666;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.form-group input[type="text"],
.form-group textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1.5px solid #e2e8f0;
    border-radius: 8px;
    font-size: 0.9rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
    color: #1a2a3a;
}
.form-group input[type="text"]:focus,
.form-group textarea:focus { border-color: #3b82f6; }

.form-group textarea { height: 72px; resize: vertical; }

.checkbox-group {
    display: flex;
    align-items: center;
    gap: 8px;
}
.checkbox-group input[type="checkbox"] {
    width: 16px; height: 16px; cursor: pointer; accent-color: #1e3a5f;
}
.rate-hint {
    margin: 0 0 12px;
    font-size: 0.8rem;
    color: #666;
}
.checkbox-group label {
    margin-bottom: 0;
    cursor: pointer;
    font-size: 0.9rem;
    color: #444;
    text-transform: none;
    letter-spacing: 0;
    font-weight: 400;
}

/* Fish species buttons */
#fish-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.fish-btn {
    padding: 8px 16px;
    border: 2px solid var(--fish-color, #ccc);
    border-radius: 20px;
    background: white;
    color: var(--fish-color, #555);
    font-weight: 600;
    font-size: 0.88rem;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
    user-select: none;
}
.fish-btn:hover {
    background: var(--fish-color);
    color: white;
}
.fish-btn.selected {
    background: var(--fish-color);
    color: white;
}
#other-species { margin-top: 10px; }
#other-species.hidden { display: none; }

/* Modal buttons */
.modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 22px;
}

.btn-primary {
    padding: 10px 22px;
    background: #1e3a5f;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-primary:hover { background: #2563eb; }
.btn-primary:disabled { opacity: 0.6; cursor: default; }

.btn-secondary {
    padding: 10px 18px;
    background: white;
    color: #666;
    border: 1.5px solid #e2e8f0;
    border-radius: 8px;
    font-size: 0.9rem;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-secondary:hover { background: #f8fafc; }

.btn-delete {
    display: inline-block;
    margin-top: 8px;
    padding: 4px 10px;
    background: #fee2e2;
    color: #dc2626;
    border: none;
    border-radius: 5px;
    font-size: 0.8rem;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s;
}
.btn-delete:hover { background: #fecaca; }

/* ── Notification ────────────────────────────────────────────────────────── */
.notification {
    position: fixed;
    bottom: 28px;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 22px;
    border-radius: 24px;
    font-size: 0.9rem;
    font-family: inherit;
    z-index: 4000;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    pointer-events: none;
    white-space: nowrap;
}
.notification.hidden { display: none; }
.notification.success  { background: #dcfce7; color: #166534; }
.notification.error    { background: #fee2e2; color: #991b1b; }
.notification.warning  { background: #fef3c7; color: #854d0e; }
.notification.info     { background: #dbeafe; color: #1e40af; }

/* ── Leaflet legend ──────────────────────────────────────────────────────── */
.legend {
    background: white;
    padding: 10px 14px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.15);
    font-size: 0.82rem;
    font-family: 'Inter', system-ui, sans-serif;
}
.legend.collapsed {
    padding: 0;
    background: none;
    box-shadow: none;
}
.legend.collapsed .legend-body { display: none; }
.legend-body {
    max-height: calc(100vh - 140px);
    overflow-y: auto;
}
.legend:not(.collapsed) .legend-toggle { display: none; }

.legend-toggle {
    width: 36px; height: 36px;
    border-radius: 50%;
    border: none;
    background: white;
    color: #1e3a5f;
    font: italic 700 1.15rem Georgia, 'Times New Roman', serif;
    box-shadow: 0 2px 10px rgba(0,0,0,0.25);
    cursor: pointer;
}
.legend-toggle:hover { background: #f0f7ff; }

.legend-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 6px;
}
.legend-close {
    width: 24px; height: 24px;
    margin-right: -6px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: #666;
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
}
.legend-close:hover { background: #f0f0f0; color: #1a2a3a; }

.legend strong {
    display: block;
    color: #1a2a3a;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.legend-item {
    display: flex;
    align-items: center;
    gap: 7px;
    color: #333;
    line-height: 1.9;
}
.legend-dot {
    display: inline-block;
    width: 12px; height: 12px;
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 0 0 1px rgba(0,0,0,0.2);
    flex-shrink: 0;
}
.legend-item { cursor: pointer; user-select: none; }
.legend-item input { margin: 0; cursor: pointer; }
.legend-item.hidden { display: none; }
.legend .legend-subtitle {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #eee;
}
.legend-show-all {
    margin-top: 4px;
    padding: 2px 0;
    border: none;
    background: none;
    color: #2563eb;
    font: inherit;
    font-size: 0.78rem;
    cursor: pointer;
}
.legend-show-all:hover { text-decoration: underline; }
.legend-mine {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid #eee;
    font-weight: 500;
}
.legend-count {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #eee;
    font-size: 0.78rem;
    color: #666;
    font-weight: 500;
}

/* ── Din plats ───────────────────────────────────────────────────────────── */
.user-location-dot {
    width: 16px; height: 16px;
    border-radius: 50%;
    background: #2563eb;
    border: 2px solid white;
    box-shadow: 0 0 0 1px rgba(0,0,0,0.25), 0 0 0 6px rgba(37,99,235,0.25);
}

/* ── Popup ───────────────────────────────────────────────────────────────── */
.popup-content { font-family: 'Inter', system-ui, sans-serif; min-width: 150px; }
.popup-fish    { font-weight: 700; font-size: 1rem; margin-bottom: 4px; }
.popup-water   { font-size: 0.84rem; color: #555; margin-bottom: 2px; }
.popup-header  { display: flex; align-items: center; gap: 8px; margin-bottom: 2px; }
.popup-header .popup-water { margin-bottom: 0; }
.btn-share {
    margin-left: auto;
    padding: 2px 8px;
    border: 1px solid #bfdbfe;
    border-radius: 10px;
    background: #eff6ff;
    color: #2563eb;
    font: inherit;
    font-size: 0.75rem;
    cursor: pointer;
    white-space: nowrap;
}
.btn-share:hover { background: #dbeafe; }
.popup-notes   { font-size: 0.82rem; color: #777; font-style: italic; margin-bottom: 4px; max-width: 200px; }
.popup-meta    { font-size: 0.76rem; color: #aaa; margin-top: 4px; }

/* ── Foto ────────────────────────────────────────────────────────────────── */
.photo-upload-label {
    display: inline-block;
    padding: 7px 14px;
    background: #f0f7ff;
    border: 1.5px dashed #93c5fd;
    border-radius: 8px;
    font-size: 0.88rem;
    color: #1e40af;
    cursor: pointer;
    transition: background 0.15s;
}
.photo-upload-label:hover { background: #dbeafe; }

.photo-preview {
    display: block;
    margin-top: 8px;
    max-width: 100%;
    max-height: 160px;
    border-radius: 8px;
    object-fit: cover;
    border: 1px solid #e2e8f0;
}
.photo-preview.hidden { display: none; }

.popup-photo {
    display: block;
    width: 100%;
    max-width: 220px;
    border-radius: 6px;
    margin-top: 8px;
    cursor: pointer;
    object-fit: cover;
}

/* ── Popup fångstrad ─────────────────────────────────────────────────────── */
.popup-catch-row {
    display: flex;
    align-items: baseline;
    gap: 5px;
    padding: 3px 0;
    border-top: 1px solid #f0f0f0;
    flex-wrap: wrap;
}
.popup-catch-row:first-of-type { border-top: none; }
.popup-catch-species { font-weight: 600; font-size: 0.95rem; }
.popup-catch-meta    { font-size: 0.75rem; color: #aaa; margin-left: auto; }
.popup-catch-notes   { font-size: 0.8rem; color: #777; font-style: italic; width: 100%; padding-left: 16px; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
    /* Sökrutan får en egen rad i full bredd under logga och knappar */
    #topbar {
        flex-wrap: wrap;
        height: auto;
        gap: 8px;
        padding: 8px 10px;
    }
    #logo   { font-size: 0.95rem; margin-right: auto; }
    #search-container {
        order: 10;
        flex: 1 1 100%;
        max-width: none;
    }
    #search-input {
        padding: 10px 14px 10px 36px;
        font-size: 16px; /* under 16px zoomar iOS in vid fokus */
    }
    #search-container::before { left: 12px; font-size: 0.9rem; }
    #search-results { max-height: 60vh; }
    .search-item { padding: 13px 14px; font-size: 0.95rem; }
    .user-name { display: none; }
    .modal-content { padding: 18px; }
    .btn-filter {
        font-size: 0.72rem;
        padding: 5px 8px;
        max-width: 140px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}
