:root {
    --bg-dark: #15171e;
    --bg-panel: #1e2129;
    --bg-card: #2b303b;
    --text-main: #ffffff;
    --text-muted: #a0a0a0;
    --accent-blue: #3b82f6;
    --accent-red: #ef4444;
    --accent-brown: #78350f;
    --border-color: #374151;
    --color-amber: #f59e0b; /* Ny färg för "Tvättad" */
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Segoe UI', sans-serif; }

/* --- TILLBAKA TILL APP-LAYOUT --- */
body { 
    background-color: var(--bg-dark); 
    color: var(--text-main); 
    height: 100vh; /* Fyll skärmen */
    overflow: hidden; /* INGEN scroll på body */
}

/* Login */
.login-container {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: var(--bg-dark); display: flex; justify-content: center; align-items: center; z-index: 1000;
}
.login-box {
    background: var(--bg-panel); padding: 2rem; border-radius: 8px; 
    width: 90%; /* Bättre för mobil */
    max-width: 350px;
    text-align: center;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}
.login-box input {
    width: 100%; padding: 10px; margin: 10px 0; background: var(--bg-card); border: 1px solid var(--border-color); color: white;
}
/* --- FIX FÖR LOGIN-KNAPP --- */
.login-box button {
    width: 100%;
    background-color: var(--accent-blue);
    color: white;
    font-weight: bold;
    padding: 10px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    margin-top: 10px;
}
.login-box button:hover {
    background-color: #2563eb;
}

/* NY LOGO-STIL */
.login-logo {
    display: block;
    max-height: 80px; /* Max höjd för logotypen */
    width: auto;      /* Behåll bildförhållandet */
    max-width: 100%;  /* Se till att den inte svämmar över rutan */
    margin: 0 auto 20px auto; /* Centrera, med 20px marginal under */
    object-fit: contain; /* Förhindra att bilden sträcks */
}


/* Layout */
#app-container { 
    display: flex; 
    flex-direction: column; 
    height: 100vh; /* Fyll skärmen */
}
.hidden { display: none !important; }

/* ---- NY HEADER-LAYOUT ---- */
/* ---- NY HEADER-LAYOUT ---- */
.top-bar {
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border-color);
    padding: 10px;
    display: flex;
    flex-direction: row;          /* Logo vänster, knappar höger */
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-shrink: 0;
}

.logo { 
    font-size: 1.2rem; 
    font-weight: bold;
    text-align: left;
}

/* LOGO I HEADER */
.header-logo {
    height: 40px;
    width: auto;
    object-fit: contain;
}

/* Rad med "Inloggad som" + knappar */
.top-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-left: auto;            /* tryck knapparna till höger */
}

.top-actions span {
    margin-right: 8px;
}

.top-actions button { 
    margin-left: 0;
}

/* NYTT: Stil för aktiv knapp */
.top-actions button.active {
    background-color: var(--accent-blue);
    border-color: var(--accent-blue);
    color: white;
}
/* ---- SLUT PÅ NY HEADER ---- */




/* --- TILLBAKA TILL APP-LAYOUT --- */
.main-layout { 
    display: flex; 
    flex: 1; /* Fyll återstående höjd */
    overflow: hidden; /* Inget scroll här */
    min-height: 0; /* Viktig flexbox-fix */
}

/* Sidebars */
.sidebar-left { 
    width: 450px; /* Ny, bredare startbredd */
    min-width: 200px; /* Minsta bredd */
    max-width: 600px; /* Största bredd */
    flex-shrink: 0; 
    background: var(--bg-panel); 
    border-right: 1px solid var(--border-color); 
    display: flex; 
    flex-direction: column; 
    padding: 10px; 
    overflow: hidden; /* Inget scroll här */
}
.sidebar-right { 
    width: 300px; 
    flex-shrink: 0;
    background: var(--bg-panel); 
    border-left: 1px solid var(--border-color); 
    padding: 15px; 
    display: flex; 
    flex-direction: column;
    overflow-y: auto; /* PÅMINNELSER SKROLLAR HÄR */
}

/* --- STIL FÖR RESIZER --- */
.resizer {
    width: 5px;
    background: var(--border-color);
    cursor: col-resize;
    flex-shrink: 0;
    position: relative;
    z-index: 10;
    transition: background 0.2s ease;
    /* Borttagen: position: sticky */
}
.resizer:hover {
    background: var(--accent-blue);
}

.year-selector select { width: 100%; padding: 8px; margin-top: 5px; background: var(--bg-card); color: white; border: none; }
.station-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 15px;
}

.filter-group {
    display: flex;
    gap: 5px;
    margin-top: 10px;
    margin-bottom: 5px;
}
.filter-btn {
    flex: 1;
    padding: 6px 8px;
    font-size: 0.8rem;
    background: var(--bg-card);
    color: var(--text-muted);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
}
.filter-btn.active {
    background: var(--accent-blue);
    color: var(--text-main);
    border-color: var(--accent-blue);
}
.filter-btn:hover:not(.active) {
    background: #3a404d;
}

/* --- **** NY SÖKRUTA STIL **** --- */
.search-box {
    margin-top: 10px;
    margin-bottom: 5px;
}
.search-box input {
    width: 100%;
    padding: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: white;
    border-radius: 4px;
    font-size: 0.9rem;
}
/* --- **** SLUT SÖKRUTA STIL **** --- */


/* --- **** TILLBAKA TILL INTERN SCROLL **** --- */
.station-list { 
    flex: 1; /* Fyller utrymmet i vänstra menyn */
    overflow-y: auto; /* INTERN SCROLLBAR */
    margin-top: 10px; 
    min-height: 0; /* Viktig flexbox-fix */
} 
/* --- **** SLUT PÅ FIX **** --- */

/* --- NYTT: STILAR FÖR STATIONS-LISTAN --- */
.station-item {
    padding: 10px; 
    cursor: pointer; 
    border-radius: 4px; 
    display: flex; 
    align-items: center;
    justify-content: space-between; /* Flytta bockar till höger */
}
.station-item-name {
    display: flex;
    align-items: center;
    gap: 10px; /* Mellanrum mellan prick och namn */
    /* Förhindra att långa namn pajar layouten */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.station-item-checks {
    display: flex;
    gap: 5px;
    flex-shrink: 0; /* Hindra från att krympa */
    margin-left: 5px; /* Avstånd från namn */
}
.check-icon, .check-icon-empty {
    font-size: 0.75rem;
    font-weight: bold;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    display: flex;
    justify-content: center;
    align-items: center;
    line-height: 18px; /* Säkerställ centrering */
}
.check-icon.servad {
    background-color: var(--accent-blue);
    color: white;
}
.check-icon.tvattad {
    background-color: var(--color-amber);
    color: white;
}
.check-icon-empty {
    color: #555;
    border: 1px solid #444;
}
/* --- SLUT PÅ NYA STILAR --- */


.station-item:hover { background: var(--bg-card); }
.station-item.active { background: var(--accent-blue); }
.dot { height: 8px; width: 8px; border-radius: 50%; flex-shrink: 0; } /* Lagt till flex-shrink */
.dot.vatten { background: #0ea5e9; }
.dot.avlopp { background: var(--accent-red); }

/* Content Area */
.content-area { 
    flex: 1; 
    position: relative; 
    background: var(--bg-dark); 
    overflow-y: auto; /* INNEHÅLLET SKROLLAR HÄR */
    min-width: 0;
}
.view-section { 
    padding: 20px; 
    height: 100%;
}
#empty-state {
    text-align: center;
    padding-top: 100px;
    color: var(--text-muted);
}
#empty-state .icon-placeholder {
    font-size: 3rem;
    margin-bottom: 1rem;
}

#station-details .details-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}


/* Map */
/* ---- NY KART-LAYOUT (Flexbox-baserad) ---- */
#map-view {
    display: flex;
    flex-direction: column;
    height: 100%;
}
#map { 
    width: 100%; 
    border-radius: 8px; 
    flex-grow: 1; /* Ta upp återstående plats */
    /* Borttagen: height: 75vh; */
}
.map-controls { 
    display: flex; 
    align-items: center; 
    gap: 10px; 
    padding-top: 10px;
    flex-shrink: 0;
    height: auto;
    padding-bottom: 10px;
}
/* ---- SLUT PÅ NY KART-LAYOUT ---- */
#map-status-text { color: var(--text-muted); }

/* Dashboard Details */
.details-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.card { background: var(--bg-panel); padding: 15px; border-radius: 8px; }
.history-card { grid-column: 1 / -1; } 

/* ---- NY LAYOUT FÖR MINI-KARTA (Flex) ---- */
.card-permanent-info {
    display: flex;
    flex-direction: column;
}
.form-group-map-preview {
    flex-grow: 1; /* Ta upp återstående plats */
    display: flex;
    flex-direction: column;
    min-height: 200px; /* Minsta höjd */
}
.map-preview-container {
    flex-grow: 1; /* Ta upp plats i form-group */
    width: 100%; 
    background: var(--bg-card); 
    border-radius: 4px; 
    margin-bottom: 10px; 
    border: 1px solid var(--border-color);
}
.map-preview-container.clickable {
    cursor: pointer;
}
/* ---- SLUT PÅ NY LAYOUT ---- */


.form-group { margin-bottom: 10px; }
.form-group label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted) !important; 
    margin-bottom: 4px;
}
input[type="text"], textarea, select {
    width: 100%; 
    padding: 8px; 
    background: var(--bg-card); 
    border: 1px solid var(--border-color); 
    color: white; 
    border-radius: 4px;
}
input[type="date"] {
    width: 100%;
    padding: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: white;
    border-radius: 4px;
}

textarea {
    min-height: 80px;
}

.checkbox-group {
    display: flex;
    flex-direction: column; 
    gap: 10px; 
    margin-top: 10px;
}
.checkbox-group label {
    display: flex; 
    align-items: center; 
    gap: 8px;
    color: var(--text-main); 
    font-size: 0.9rem;
}

/* Custom checkbox style */
input[type="checkbox"] {
    -webkit-appearance: none;
    appearance: none;
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    width: 1.15em;
    height: 1.15em;
    border-radius: 4px;
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
}
input[type="checkbox"]:checked {
    background-color: var(--accent-blue);
    border-color: var(--accent-blue);
}
input[type="checkbox"]:checked::before {
    content: '✔';
    position: absolute;
    color: white;
    font-size: 0.9em;
    top: -2px; 
    left: 2px;  
}

/* Photos */
.photo-grid { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 10px; }
.photo-thumb { width: 60px; height: 60px; object-fit: cover; border-radius: 4px; cursor: pointer; position: relative; }
.photo-container { position: relative; display: inline-block; }
.del-photo { 
    position: absolute; 
    top: -5px; 
    right: -5px; 
    background: red; 
    color: white; 
    font-size: 10px; 
    cursor: pointer; 
    padding: 0px 4px;
    border-radius: 50%;
    border: 1px solid white;
}

/* History & Reminders */
#history-list, #reminder-list { list-style: none; margin-top: 10px; }
.history-item, .reminder-item {
    background: var(--bg-card); padding: 10px; margin-bottom: 5px; border-radius: 4px; font-size: 0.9rem;
}
.history-meta { font-size: 0.75rem; color: var(--text-muted); display: block; margin-bottom: 3px; }
.reminder-input .row {
    display: flex;
    gap: 10px;
    margin-top: 5px;
}
.reminder-input select {
    flex-basis: 100px;
}
.reminder-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.reminder-item.priority-Hög { border-left: 3px solid var(--accent-red); }
.reminder-item.priority-Normal { border-left: 3px solid var(--accent-blue); }
.reminder-item.priority-Låg { border-left: 3px solid #6b7280; }


.reminder-personal {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.reminder-item.personal {
    border-left-style: dashed; /* bara för att se skillnad på “Endast du” */
}

.reminder-tag {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-right: 8px;
}



/* Buttons */
button { cursor: pointer; padding: 8px 12px; border: none; border-radius: 4px; font-weight: bold; color: white; }
.btn-primary { background: var(--accent-blue); }
.btn-secondary { background: var(--bg-card); color: white; border: 1px solid var(--border-color); }
.btn-danger { background: var(--accent-red); }
.btn-danger-text { background: transparent; color: var(--accent-red); padding: 0; }
.btn-icon { background: var(--accent-blue); width: 24px; height: 24px; padding: 0; display: flex; justify-content: center; align-items: center;}
.btn-small {
    padding: 4px 8px;
    font-size: 0.8rem;
}
.mt-auto { margin-top: auto; }

/* Modal */
.modal { position: fixed; top:0; left:0; width:100%; height:100%; background:rgba(0,0,0,0.7); display:flex; align-items:center; justify-content:center; z-index:2000;}
.modal-content { 
    background: var(--bg-panel); 
    padding: 20px; 
    width: 90%; /* Bättre för mobil */
    max-width: 400px; /* Bredare för användarlistan */
    border-radius: 8px; 
    position: relative;
}
.close { position:absolute; top:10px; right:15px; cursor:pointer; font-size:20px;}
.modal-content hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 15px 0;
}
.modal-content input {
    margin-bottom: 10px;
}

/* --- NY STIL FÖR ANVÄNDARLISTA --- */
.user-item-setting {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px;
    border-bottom: 1px solid var(--border-color);
}
.user-item-setting:last-child {
    border-bottom: none;
}
.user-item-name {
    font-weight: 500;
}
.user-item-actions button {
    margin-left: 5px;
}
/* --- SLUT NY STIL --- */


/* --- Fixar för Leaflet Popup (Karta) --- */
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
    color: #333 !important; 
    font-size: 14px;
}
.leaflet-popup-content h3, 
.leaflet-popup-content b {
    color: #000 !important; 
    font-size: 1.1em;
}
.leaflet-popup-content div, .leaflet-popup-content {
    color: #555 !important; 
}
.leaflet-popup-content button {
    margin-top: 8px;
    width: 100%;
    color: white !important; 
    border: none;
    padding: 6px;
    border-radius: 4px;
    cursor: pointer;
}
.leaflet-popup-content select {
    width: 100%;
    margin-top: 5px;
    color: #333; 
    background: #f4f4f4;
    border: 1px solid #ccc;
}
.btn-popup-open {
    background-color: #3b82f6 !important; 
}
.btn-popup-open:hover {
    background-color: #2563eb !important;
}
.btn-popup-delete {
    background-color: #ef4444 !important;
}
.btn-popup-delete:hover {
    background-color: #dc2626 !important;
}

/* --- NY STIL FÖR KART-BYTARE (MÖRKT LÄGE) --- */
.leaflet-control-layers {
    background: var(--bg-panel) !important;
    border: 1px solid var(--border-color) !important;
    color: var(--text-main) !important;
}
.leaflet-control-layers-base label {
    color: var(--text-main) !important;
    display: flex;
    align-items: center;
}
.leaflet-control-layers-separator {
    border-top: 1px solid var(--border-color) !important;
}

.photo-modal {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
}

.photo-modal-hidden {
    display: none;
}

.photo-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
}

.photo-modal-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    background: #111;
    padding: 12px 16px 16px;
    border-radius: 8px;
    box-shadow: 0 0 20px rgba(0,0,0,0.7);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.photo-modal-img {
    max-width: 80vw;
    max-height: 70vh;
    object-fit: contain;
    border-radius: 4px;
    background: #000;
}

.photo-modal-close {
    position: absolute;
    top: 6px;
    right: 8px;
    border: none;
    background: transparent;
    color: #fff;
    font-size: 26px;
    cursor: pointer;
    padding: 0 6px;
    line-height: 1;
}

.photo-modal-close:hover {
    color: #ff6666;
}

.photo-modal-nav {
    display: flex;
    align-items: center;
    gap: 12px;
    color: #fff;
    font-size: 14px;
}

.photo-modal-nav-btn {
    border: none;
    background: #333;
    color: #fff;
    font-size: 22px;
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
}

.photo-modal-nav-btn:hover {
    background: #555;
}

.photo-modal-counter {
    min-width: 80px;
    text-align: center;
    opacity: 0.9;
}

/* Extra anpassning för riktigt små skärmar */
@media (max-width: 600px) {
    .photo-modal-content {
        max-width: 95vw;
        max-height: 90vh;
        padding: 10px 12px 12px;
    }

    .photo-modal-img {
        max-width: 90vw;
        max-height: 65vh;
    }
}

.reminder-personal {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.reminder-item.personal {
    border-left-style: dashed;          /* bara för att se skillnad */
}

.reminder-tag {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-right: 8px;
}

/* ================================================================
--- MOBILANPASSNING (MEDIA QUERIES) ---
================================================================
*/
@media (max-width: 800px) {
    /* --- TILLBAKA TILL "WEBSITE" SCROLL --- */
    body {
        height: auto;
        overflow-y: auto;
    }
    #app-container {
        height: auto;
        min-height: 100vh;
    }
    .main-layout {
        flex-direction: column;
        min-height: 0; 
        overflow: visible;
    }

    /* Göm resizer */
    #resizer {
        display: none;
    }

    /* Gör sidomenyerna 100% breda */
    .sidebar-left {
        width: 100% !important; 
        max-width: 100%;
        min-width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        /* Ta bort sticky-layout */
        position: static;
        height: auto;
    }
    .sidebar-right {
        width: 100%;
        border-left: none;
        border-top: 1px solid var(--border-color);
        /* Ta bort sticky-layout */
        position: static;
        height: auto;
    }

    /* Ge stationslistan en fast höjd på mobil */
    .station-list {
        flex: none; /* Ta bort flex för desktop */
        height: 400px; /* Fast höjd */
    }

    /* **** NYTT: Sätt fast höjd på kartan för mobil **** */
    #map {
        height: 400px;
        flex-grow: 0; /* Ta bort flex-grow på mobil */
    }
    .content-area {
        overflow: visible; /* Låt body sköta scroll */
    }

       /* Stapla toppmenyn */
        .top-bar {
        height: auto;
        padding: 10px;
        position: static;
        flex-direction: column;    /* på mobil: logga överst */
        align-items: flex-start;
    }


    .logo {
        display: none;           /* om du vill gömma texttiteln på mobil */
    }

    .top-actions {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: wrap;
        gap: 6px;
    }

    .top-actions span {
        width: auto;
        text-align: left;
    }



    /* Stapla korten i service-vyn */
    .details-grid {
        grid-template-columns: 1fr;
    }

    /* Gör modalen bredare på mobil */
    .modal-content {
        max-width: 90%;
    }
}