:root{
    --qatar:#8A1538;
    --qatar-dark:#5f0f28;
    --solar:#f6c84d;
    --solar-soft:#fff3bf;
    --white:#ffffff;
    --bg:#f4f6f8;
    --ink:#1f2933;
    --muted:#65727f;
    --line:#d8dee6;
}

*{
    margin:0;
    padding:0;
    box-sizing:border-box;
    font-family:Arial,sans-serif;
}

html{
    height:100%;
}

body{
    background:#eef2f5;
    color:var(--ink);
    display:flex;
    flex-direction:column;
    height:100%;
    min-height:100vh;
}

header{
    background:linear-gradient(135deg,#ffffff 0%,#fff6d8 54%,#f4e0e6 100%);
    border-bottom:1px solid rgba(138,21,56,0.16);
    box-shadow:0 8px 24px rgba(31,41,51,0.08);
    color:var(--ink);
    padding:14px 18px 16px;
    position:relative;
    z-index:900;
}

.header-row{
    align-items:center;
    display:flex;
    gap:14px;
    justify-content:space-between;
    margin-bottom:12px;
}

header h1{
    font-size:22px;
    font-weight:700;
}

.website-link{
    align-items:center;
    background:rgba(255,255,255,0.76);
    border:1px solid rgba(138,21,56,0.18);
    border-radius:8px;
    color:var(--qatar);
    display:inline-flex;
    font-size:14px;
    font-weight:800;
    min-height:38px;
    padding:0 14px;
    text-decoration:none;
    white-space:nowrap;
}

.website-link:hover{
    background:#ffffff;
}

.search-box{
    display:flex;
    gap:10px;
}

.search-box input,
.advanced-search input,
.advanced-search select{
    flex:1;
    border:1px solid rgba(138,21,56,0.18);
    border-radius:8px;
    box-shadow:0 4px 16px rgba(31,41,51,0.06);
    font-size:15px;
    padding:11px 12px;
}

.search-box button,
.advanced-actions button,
.advanced-toggle{
    background:linear-gradient(135deg,var(--qatar),var(--qatar-dark));
    color:white;
    border:none;
    border-radius:8px;
    box-shadow:0 8px 20px rgba(138,21,56,0.24);
    font-weight:700;
    padding:11px 20px;
    cursor:pointer;
}

.location-btn{
    align-items:center;
    flex:0 0 48px;
    justify-content:center;
    padding:0;
}

.location-btn span{
    border:2px solid currentColor;
    border-radius:50%;
    display:block;
    height:18px;
    position:relative;
    width:18px;
}

.location-btn span::before,
.location-btn span::after{
    background:currentColor;
    content:"";
    left:50%;
    position:absolute;
    top:50%;
    transform:translate(-50%,-50%);
}

.location-btn span::before{
    height:28px;
    width:2px;
}

.location-btn span::after{
    height:2px;
    width:28px;
}

.location-btn.is-loading span{
    animation:locationPulse 0.9s ease-in-out infinite;
}

.location-btn:disabled{
    cursor:wait;
    opacity:0.72;
}

@keyframes locationPulse{
    0%,100%{
        transform:scale(0.92);
    }

    50%{
        transform:scale(1.08);
    }
}

.advanced-toggle{
    background:rgba(255,255,255,0.72);
    border:1px solid rgba(138,21,56,0.18);
    box-shadow:none;
    color:var(--qatar);
    margin-top:10px;
    padding:9px 12px;
}

.advanced-search{
    background:rgba(255,255,255,0.74);
    border:1px solid rgba(138,21,56,0.14);
    border-radius:12px;
    box-shadow:0 10px 26px rgba(31,41,51,0.08);
    left:58px;
    margin-top:0;
    max-width:960px;
    padding:12px;
    position:absolute;
    right:18px;
    top:calc(100% - 4px);
    z-index:940;
}

.advanced-grid{
    display:grid;
    gap:10px;
    grid-template-columns:repeat(6, minmax(0, 1fr));
}

.advanced-search label{
    color:var(--muted);
    display:flex;
    flex-direction:column;
    font-size:12px;
    font-weight:700;
    gap:5px;
}

.advanced-search input,
.advanced-search select{
    background:#fff;
    box-shadow:none;
    min-width:0;
    padding:9px 10px;
    width:100%;
}

.advanced-actions{
    align-items:center;
    display:flex;
    gap:10px;
    margin-top:10px;
}

.advanced-actions button{
    padding:9px 12px;
}

.advanced-actions button + button{
    background:#fff;
    border:1px solid rgba(138,21,56,0.18);
    box-shadow:none;
    color:var(--qatar);
}

#advancedCount{
    color:var(--muted);
    font-size:12px;
    font-weight:700;
}

#advancedResults{
    background:white;
    border:1px solid rgba(138,21,56,0.18);
    border-radius:8px;
    margin-top:10px;
    max-height:112px;
    padding:6px;
    width:100%;
}

.container{
    flex:1 1 auto;
    min-height:0;
}

#map{
    background:#dfe6ec;
    height:100%;
    min-height:560px;
    overflow:hidden;
    position:relative;
    width:100%;
}

#map .leaflet-container{
    background:#dfe6ec;
}

.leaflet-tile-pane{
    filter:none;
}

.map-mode{
    background:rgba(255,255,255,0.90);
    border:1px solid rgba(95,107,122,0.28);
    border-radius:8px;
    box-shadow:0 8px 20px rgba(31,41,51,0.12);
    display:flex;
    gap:2px;
    left:58px;
    overflow:hidden;
    position:absolute;
    top:18px;
    z-index:520;
}

.map-mode button{
    background:transparent;
    border:0;
    color:var(--ink);
    cursor:pointer;
    font-size:13px;
    font-weight:700;
    padding:9px 12px;
}

.map-mode button.active{
    background:var(--qatar);
    color:white;
}

.map-panel{
    background:rgba(255,255,255,0.92);
    border:1px solid var(--line);
    border-radius:8px;
    box-shadow:0 10px 28px rgba(31,41,51,0.10);
    left:50%;
    max-width:min(520px, calc(100% - 32px));
    padding:10px 14px 8px;
    pointer-events:auto;
    position:absolute;
    top:18px;
    transform:translateX(-50%);
    width:520px;
    z-index:500;
}

.satellite-mode .map-panel,
.satellite-mode .solar-legend,
.satellite-mode .map-mode{
    background:rgba(255,255,255,0.86);
}

.shade-title{
    color:var(--muted);
    font-size:12px;
    font-weight:700;
    margin-bottom:4px;
    text-transform:uppercase;
}

.map-panel input{
    accent-color:var(--qatar);
    display:block;
    width:100%;
}

.shade-times{
    color:var(--ink);
    display:flex;
    font-size:12px;
    justify-content:space-between;
}

.solar-legend{
    align-items:center;
    background:rgba(255,255,255,0.92);
    border:1px solid var(--line);
    border-radius:8px;
    bottom:22px;
    box-shadow:0 10px 28px rgba(31,41,51,0.10);
    color:var(--muted);
    display:flex;
    gap:8px;
    left:18px;
    padding:10px 12px;
    pointer-events:none;
    position:absolute;
    z-index:500;
}

.legend-ramp{
    background:linear-gradient(90deg,#7b4a3a 0%,#b65a2d 24%,#dc7623 48%,#f09d1f 66%,#f6c84d 82%,#fff2a6 100%);
    border-radius:999px;
    height:10px;
    width:130px;
}

.data-loading{
    align-items:center;
    background:rgba(255,255,255,0.96);
    border:1px solid rgba(138,21,56,0.16);
    border-radius:12px;
    box-shadow:0 18px 44px rgba(31,41,51,0.16);
    color:var(--ink);
    display:flex;
    gap:16px;
    left:50%;
    min-width:min(420px,calc(100% - 32px));
    padding:14px 16px;
    pointer-events:none;
    position:absolute;
    top:18px;
    transform:translateX(-50%);
    transition:opacity 180ms ease, visibility 180ms ease;
    z-index:700;
}

.data-loading.is-hidden{
    opacity:0;
    visibility:hidden;
}

.data-loading span{
    display:block;
    font-size:14px;
    font-weight:800;
    line-height:1.2;
}

.data-loading small{
    color:var(--muted);
    display:block;
    font-size:12px;
    font-weight:700;
    margin-top:4px;
}

.data-loading small:empty{
    display:none;
}

.data-loading-bar{
    background:#f4e7c2;
    border-radius:999px;
    flex:1;
    height:8px;
    min-width:120px;
    overflow:hidden;
}

.data-loading-bar span{
    animation:dataLoadingBar 1.1s ease-in-out infinite;
    background:linear-gradient(90deg,var(--qatar),#d66a24,var(--solar));
    border-radius:inherit;
    display:block;
    height:100%;
    width:45%;
}

@keyframes dataLoadingBar{
    0%{
        transform:translateX(-115%);
    }

    100%{
        transform:translateX(255%);
    }
}

.dashboard{
    background:rgba(255,255,255,0.94);
    border:1px solid rgba(138,21,56,0.18);
    border-radius:14px;
    box-shadow:0 24px 60px rgba(31,41,51,0.22);
    overflow:hidden;
    padding:0;
    pointer-events:auto;
    position:absolute;
    right:18px;
    top:18px;
    width:340px;
    z-index:510;
}

.panel-header{
    background:linear-gradient(135deg,var(--qatar),#b65a2d);
    color:white;
    padding:16px 18px;
}

.panel-header p{
    color:rgba(255,255,255,0.74);
    font-size:11px;
    font-weight:700;
    letter-spacing:0.08em;
    margin-bottom:4px;
    text-transform:uppercase;
}

.panel-header h2{
    font-size:21px;
    line-height:1.15;
}

.summary-row{
    background:linear-gradient(180deg,#fff8df,#ffffff);
    border-bottom:1px solid rgba(138,21,56,0.12);
    display:grid;
    gap:10px;
    grid-template-columns:1fr 1fr;
    padding:14px 16px;
}

.summary-row div,
.card{
    color:var(--muted);
    font-size:12px;
    font-weight:700;
}

.summary-row span,
.card span{
    display:block;
    color:var(--ink);
    font-size:15px;
    line-height:1.25;
    margin-top:6px;
    font-weight:bold;
}

.metric-grid{
    display:grid;
    gap:10px;
    grid-template-columns:1fr 1fr;
    padding:14px;
}

.card{
    background:#fff;
    border:1px solid rgba(138,21,56,0.12);
    border-radius:10px;
    box-shadow:0 8px 18px rgba(31,41,51,0.06);
    min-height:76px;
    padding:12px;
}

.card.primary{
    background:linear-gradient(180deg,#fff6ce,#ffffff);
    border-color:rgba(246,200,77,0.55);
}

.card.primary span{
    color:var(--qatar);
    font-size:17px;
}

.simulation-button,
.photo-button{
    background:linear-gradient(135deg,var(--solar),#d66a24);
    border:0;
    border-radius:10px;
    box-shadow:0 10px 22px rgba(214,106,36,0.24);
    color:#3b1e13;
    cursor:pointer;
    font-size:14px;
    font-weight:800;
    margin:0 14px 14px;
    padding:12px 14px;
    width:calc(100% - 28px);
}

.photo-button{
    background:linear-gradient(135deg,#1f4f78,#122d44);
    box-shadow:0 10px 22px rgba(31,79,120,0.20);
    color:white;
    margin-top:-6px;
}

.simulation-modal{
    align-items:center;
    background:rgba(20,24,31,0.52);
    inset:0;
    justify-content:center;
    padding:22px;
    position:fixed;
    z-index:1200;
}

.simulation-modal:not([hidden]){
    display:flex;
}

.simulation-window{
    background:#fff;
    border:1px solid rgba(138,21,56,0.20);
    border-radius:16px;
    box-shadow:0 28px 80px rgba(0,0,0,0.32);
    max-height:92vh;
    max-width:1180px;
    overflow:hidden;
    width:min(1180px, 100%);
}

.simulation-header{
    align-items:center;
    background:linear-gradient(135deg,var(--qatar),#b65a2d);
    color:white;
    display:flex;
    justify-content:space-between;
    padding:16px 18px;
}

.simulation-header p{
    color:rgba(255,255,255,0.76);
    font-size:11px;
    font-weight:800;
    letter-spacing:0.08em;
    margin-bottom:4px;
    text-transform:uppercase;
}

.simulation-header h2{
    font-size:22px;
}

.simulation-header button,
.simulation-actions button{
    background:white;
    border:0;
    border-radius:8px;
    color:var(--qatar);
    cursor:pointer;
    font-weight:800;
    padding:10px 14px;
}

.simulation-body{
    display:grid;
    gap:0;
    grid-template-columns:320px 1fr;
    height:calc(92vh - 72px);
    max-height:calc(92vh - 72px);
    min-height:0;
}

.simulation-controls{
    background:linear-gradient(180deg,#fff8df,#ffffff);
    border-right:1px solid rgba(138,21,56,0.14);
    display:flex;
    flex-direction:column;
    gap:12px;
    min-height:0;
    overflow:auto;
    padding:16px;
}

.simulation-controls label{
    color:var(--muted);
    display:flex;
    flex-direction:column;
    font-size:12px;
    font-weight:800;
    gap:6px;
}

.simulation-controls input,
.simulation-controls select{
    border:1px solid rgba(138,21,56,0.18);
    border-radius:8px;
    font-size:14px;
    padding:10px;
}

.panel-edit-buttons{
    display:grid;
    gap:6px;
    grid-template-columns:repeat(4, 1fr);
}

.panel-edit-buttons button{
    background:#fff;
    border:1px solid rgba(138,21,56,0.18);
    border-radius:8px;
    color:var(--qatar);
    cursor:pointer;
    font-size:11px;
    font-weight:900;
    min-height:30px;
    padding:6px 4px;
}

.panel-edit-buttons button:hover{
    background:#fff8df;
    border-color:rgba(138,21,56,0.34);
}

.simulation-actions button{
    background:linear-gradient(135deg,var(--qatar),var(--qatar-dark));
    color:white;
    width:100%;
}

.simulation-actions{
    display:grid;
    gap:8px;
    grid-template-columns:1fr 1fr;
}

#exportedTrainingLayout{
    border:1px solid rgba(138,21,56,0.18);
    border-radius:8px;
    color:#26333b;
    display:none;
    font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono",monospace;
    font-size:11px;
    min-height:110px;
    padding:10px;
    resize:vertical;
    width:100%;
}

#exportedTrainingLayout.visible{
    display:block;
}

.simulation-summary{
    display:grid;
    gap:10px;
    grid-template-columns:1fr 1fr;
    margin-top:4px;
}

.simulation-summary div{
    background:#fff;
    border:1px solid rgba(138,21,56,0.12);
    border-radius:10px;
    color:var(--muted);
    font-size:12px;
    font-weight:800;
    min-height:70px;
    padding:10px;
}

.simulation-summary span{
    color:var(--ink);
    display:block;
    font-size:15px;
    margin-top:6px;
}

.simulation-preview{
    background:#e8eef4;
    cursor:grab;
    height:100%;
    min-height:0;
    min-width:0;
    overflow:auto;
    overscroll-behavior:contain;
    padding:18px;
    position:relative;
    touch-action:none;
    user-select:none;
}

.simulation-preview.is-panning{
    cursor:grabbing;
}

.simulation-zoom-controls,
.simulation-roof-controls{
    align-items:center;
    background:rgba(255,255,255,0.94);
    border:1px solid rgba(31,41,51,0.14);
    border-radius:8px;
    box-shadow:0 8px 20px rgba(31,41,51,0.12);
    display:flex;
    gap:4px;
    left:30px;
    padding:5px;
    position:sticky;
    top:0;
    width:max-content;
    z-index:2;
}

.simulation-roof-controls{
    left:30px;
    margin-top:8px;
    top:42px;
}

.simulation-zoom-controls button,
.simulation-roof-controls button{
    align-items:center;
    background:#fff;
    border:1px solid rgba(138,21,56,0.16);
    border-radius:6px;
    color:var(--ink);
    display:flex;
    font-size:13px;
    font-weight:800;
    height:30px;
    justify-content:center;
    min-width:34px;
    padding:0 10px;
}

.simulation-zoom-controls button:hover,
.simulation-roof-controls button:hover{
    background:#fff8df;
    border-color:rgba(138,21,56,0.32);
}

#simulationSvg{
    background:#dfe6ec;
    border:1px solid rgba(31,41,51,0.14);
    border-radius:12px;
    box-shadow:inset 0 0 0 1px rgba(255,255,255,0.7);
    display:block;
    height:760px;
    min-width:720px;
    width:100%;
}

.simulation-roof-layer{
    cursor:move;
}

.simulation-roof-layer.dragging{
    cursor:grabbing;
}

.simulation-panel{
    cursor:pointer;
    stroke:#d7ecff;
    stroke-width:1.2;
    transition:fill 0.16s ease, opacity 0.16s ease, stroke 0.16s ease;
}

.simulation-panel.selected{
    stroke:#ffffff;
    stroke-width:2.4;
}

.simulation-panel.dragging{
    cursor:grabbing;
}

.simulation-panel.invalid-drop{
    fill:#d71920;
    opacity:0.65;
    stroke:#ffffff;
}

.simulation-panel.active{
    fill:#1f4f78;
    opacity:0.8;
}

.simulation-panel.inactive{
    fill:#c9d2da;
    opacity:0.12;
    stroke:#8795a1;
}

.simulation-panel:focus-visible{
    outline:2px solid #8A1538;
    outline-offset:2px;
}

.site-footer{
    align-items:center;
    background:linear-gradient(135deg,var(--qatar-dark),var(--qatar));
    color:rgba(255,255,255,0.86);
    display:flex;
    flex-wrap:wrap;
    font-size:12px;
    font-weight:700;
    gap:8px 14px;
    justify-content:center;
    min-height:34px;
    padding:8px 16px;
}

.site-footer a{
    color:#fff3a3;
    text-decoration:none;
}

.site-footer a:hover{
    text-decoration:underline;
}

@media (max-width: 860px){
    .advanced-grid{
        grid-template-columns:1fr 1fr;
    }

    .advanced-actions{
        align-items:stretch;
        flex-wrap:wrap;
    }

    .container{
        flex:1;
        min-height:0;
    }

    #map{
        min-height:640px;
    }

    .dashboard{
        bottom:14px;
        left:12px;
        max-height:42vh;
        overflow:auto;
        right:12px;
        top:auto;
        width:auto;
    }

    .data-loading{
        align-items:stretch;
        flex-direction:column;
        gap:10px;
        left:12px;
        min-width:0;
        right:12px;
        top:74px;
        transform:none;
    }

    .metric-grid{
        grid-template-columns:1fr 1fr;
    }

    .simulation-modal{
        padding:10px;
    }

    .simulation-body{
        grid-template-columns:1fr;
        height:calc(92vh - 72px);
        max-height:calc(92vh - 72px);
        overflow:auto;
    }

    .simulation-controls{
        border-right:0;
        border-bottom:1px solid rgba(138,21,56,0.14);
    }

    .simulation-preview{
        height:420px;
        min-height:0;
    }

    #simulationSvg{
        height:520px;
        min-width:520px;
    }
}
