:root {
    /* Immo-Lens Professional Palette */
    --primary-dark: #0f172a;
    --primary: #1e293b;
    --primary-light: #334155;
    
    --accent: #0ea5e9; /* Sky Blue 500 */
    --accent-hover: #0284c7;
    
    --bg: #f8fafc; /* Lighter background for cleaner look */
    --card-bg: #ffffff;
    --border: #e2e8f0;
    
    --text-main: #1e293b;
    --text-muted: #64748b;
    --text-light: #94a3b8;
    
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;

    /* Legacy Colors Compatibility */
    --green: var(--success);
    --orange: var(--warning);
    --red: var(--danger);
    
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    
    --radius: 12px;
    --radius-sm: 6px;
    
    --nav-height: 64px;
}

*, *::before, *::after {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent; /* Remove mobile highlight */
}

html {
    font-size: 16px; 
}

body { 
    font-family: 'Inter', system-ui, -apple-system, sans-serif; 
    background: var(--bg); 
    color: var(--text-main); 
    margin: 0; 
    padding-bottom: 80px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 { 
    color: var(--primary-dark); 
    font-weight: 700; 
    letter-spacing: -0.025em; 
    margin-top: 0;
}

h1 { font-size: clamp(1.5rem, 5vw, 2.25rem); }
h2 { font-size: clamp(1.25rem, 4vw, 1.75rem); }

/* --- Navigation --- */
.navbar { 
    background: white;
    color: var(--text-main);
    height: var(--nav-height); 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: 0 1px 0 0 var(--border), var(--shadow-sm);
    border-bottom: 1px solid var(--border);
}

.logo { 
    font-weight: 700; 
    font-size: 1.25rem; 
    letter-spacing: -0.05em; 
    display: flex; 
    align-items: center; 
    gap: 0.75rem; 
    cursor: pointer; 
    color: var(--primary-dark);
    transition: opacity 0.2s;
    user-select: none;
}
.logo:hover { opacity: 0.85; }

.logo-img {
    height: 40px;
    width: auto;
    display: block;
    transition: opacity 0.2s;
}

.nav-visible-controls {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.nav-dropdown {
    display: flex;
    gap: 1rem;
    align-items: center;
}

/* Mobile Menu Toggle (Hidden on Desktop) */
.menu-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--primary-dark);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
}

/* --- Layout --- */
.container { 
    width: 100%;
    max-width: 1200px; 
    margin: 2rem auto; 
    padding: 0 1.5rem; 
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
    border: none;
    outline: none;
    min-height: 44px; /* Touch target size */
}

.btn-primary { 
    background: var(--accent); 
    color: white; 
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}
.btn-primary:hover { 
    background: var(--accent-hover); 
    transform: translateY(-1px); 
    box-shadow: var(--shadow-sm); 
}
.btn-primary:active { transform: translateY(0); }

.btn-outline { 
    background: white; 
    border: 1px solid var(--border); 
    color: var(--text-main); 
}
.btn-outline:hover { 
    background: #f8fafc; 
    border-color: #cbd5e1; 
}

.btn-icon {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: var(--primary-dark);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all 0.2s;
}
.btn-icon:hover { 
    background: var(--bg);
    border-color: var(--accent);
    color: var(--accent);
}

/* --- Cards --- */
.card { 
    background: var(--card-bg); 
    border-radius: var(--radius); 
    box-shadow: var(--shadow-sm); 
    border: 1px solid var(--border);
    padding: 2rem; 
    margin-bottom: 2rem; 
    transition: box-shadow 0.2s;
    position: relative;
    overflow: hidden; /* For contained children */
}
.card:hover { box-shadow: var(--shadow-md); }

/* --- Project List --- */
.project-list { 
    display: grid; 
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); 
    gap: 1.5rem; 
    margin-top: 2rem; 
}

.project-card { 
    background: white; 
    border: 1px solid var(--border); 
    border-radius: var(--radius); 
    padding: 0; 
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); 
    cursor: pointer; 
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
    box-shadow: var(--shadow-sm);
}

.project-card:hover { 
    transform: translateY(-4px); 
    box-shadow: var(--shadow-lg); 
    border-color: var(--accent); 
}

.project-img-container {
    height: 200px;
    background: #f1f5f9;
    position: relative;
    overflow: hidden;
}
.project-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s;
}
.project-card:hover .project-img { transform: scale(1.05); }

.project-status {
    position: absolute; 
    top: 12px; 
    left: 12px; 
    color: white; 
    padding: 4px 10px; 
    border-radius: 99px; 
    font-size: 0.75rem; 
    font-weight: 700; 
    box-shadow: var(--shadow-sm);
    z-index: 2;
}

.project-content { padding: 1.5rem; display: flex; flex-direction: column; height: 100%; }
.project-title { font-weight: 700; font-size: 1.15rem; line-height: 1.4; margin-bottom: 0.25rem; color: var(--primary-dark); }
.project-address { font-size: 0.9rem; color: var(--text-muted); margin-bottom: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 6px; }

.project-footer {
    margin-top: auto;
    display: flex; 
    justify-content: space-between; 
    align-items: flex-end; 
    border-top: 1px solid var(--border); 
    padding-top: 1rem;
}

/* --- Dashboard Grid --- */
.dashboard-grid { 
    display: grid; 
    grid-template-columns: 2fr 1fr; 
    gap: 2rem; 
    margin-top: 2rem; 
    align-items: start;
}

/* --- Forms --- */
.search-box { 
    background: white; 
    padding: 2rem; 
    border-radius: var(--radius); 
    box-shadow: var(--shadow-md); 
    border: 1px solid var(--border);
}

label { display: block; margin-bottom: 0.5rem; font-weight: 500; font-size: 0.9rem; color: var(--text-muted); }

input[type="text"], input[type="number"], input[type="date"], select, textarea { 
    width: 100%; 
    padding: 0.75rem 1rem; 
    border: 1px solid var(--border); 
    border-radius: var(--radius-sm); 
    font-family: inherit; 
    font-size: 1rem; /* 16px to prevent zoom on iOS */
    transition: border-color 0.2s, box-shadow 0.2s;
    box-sizing: border-box;
    background: #fff;
    -webkit-appearance: none; /* Flatten iOS styles */
    appearance: none;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.1);
}
textarea { height: 150px; resize: vertical; }

/* Custom Select Arrow */
.select-wrapper { position: relative; }
.select-wrapper::after {
    content: '\f078';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* --- Tabs --- */
.tabs-container {
    background: white;
    position: sticky;
    top: var(--nav-height);
    z-index: 40;
    margin-bottom: 2rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    border-bottom: 2px solid var(--border);
}

.tabs { 
    display: flex; 
    gap: 0;
    justify-content: center;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0;
}

.tab-btn { 
    background: none; 
    border: none; 
    padding: 1rem 1.5rem; 
    cursor: pointer; 
    color: var(--text-muted); 
    font-weight: 600; 
    font-size: 0.95rem;
    border-bottom: 3px solid transparent; 
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
    justify-content: center;
    white-space: nowrap;
}

.tab-btn i {
    font-size: 1.1rem;
}

.tab-btn:hover { 
    color: var(--primary); 
    background: rgba(14, 165, 233, 0.05);
}

.tab-btn.active { 
    color: var(--accent); 
    border-bottom-color: var(--accent);
    background: rgba(14, 165, 233, 0.08);
}

/* --- Scenarios --- */
.scenario-grid { 
    display: grid; 
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); 
    gap: 1.5rem; 
}
.scenario-card { 
    border: 2px solid var(--border); 
    border-radius: var(--radius); 
    padding: 1.5rem; 
    cursor: pointer; 
    transition: all 0.2s ease; 
    background: white;
}
.scenario-card:hover { border-color: var(--accent); transform: translateY(-3px); box-shadow: var(--shadow-md); }
.scenario-card.selected { border-color: var(--accent); background: #f0f9ff; box-shadow: 0 0 0 2px rgba(14, 165, 233, 0.2); }
.scenario-total { font-size: 1.5rem; font-weight: 800; color: var(--primary-dark); margin: 0.75rem 0; letter-spacing: -0.05em; }

/* --- Components --- */
.badge { 
    display: inline-flex; 
    align-items: center;
    padding: 0.35rem 0.75rem; 
    border-radius: 9999px; 
    font-size: 0.75rem; 
    font-weight: 700; 
    margin-right: 0.5rem; 
    line-height: 1;
}
.badge-blue { background: #e0f2fe; color: #0369a1; }
.feature-tag { 
    background: #e0f2fe; 
    color: #0369a1; 
    padding: 0.5rem 1rem; 
    border-radius: 9999px; 
    font-size: 0.85rem; 
    font-weight: 600; 
    display: inline-flex; 
    align-items: center; 
    gap: 0.5rem;
}
.subsidy-tag { background: #ecfdf5; color: #047857; padding: 0.25rem 0.6rem; border-radius: 6px; font-size: 0.75rem; font-weight: 600; border: 1px solid #a7f3d0; display: inline-block; margin-top: 0.4rem; margin-right: 4px; }

/* Cost Table - Responsive */
.cost-table { width: 100%; border-collapse: separate; border-spacing: 0; margin-top: 1.5rem; }
.cost-table td { padding: 0.75rem 0; border-bottom: 1px solid var(--border); vertical-align: middle; }
.cost-table tr:last-child td { border-bottom: none; }
.val { font-family: 'JetBrains Mono', monospace; font-weight: 600; text-align: right; color: var(--primary); white-space: nowrap; }

/* Dark Theme Overrides for Cost Card */
.theme-dark .cost-table td { border-bottom-color: rgba(255,255,255,0.1); color: #e2e8f0; }
.theme-dark .val { color: #fff; } /* Make values crisp white on dark bg */

/* Gallery Top Strip */
.gallery-strip {
    display: flex;
    gap: 0.75rem;
    overflow-x: auto;
    padding-bottom: 0.5rem;
    margin-bottom: 1.5rem;
    scrollbar-width: thin;
}
.gallery-strip::-webkit-scrollbar { height: 6px; }
.gallery-strip::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }
.gallery-item {
    width: 120px;
    height: 80px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    flex-shrink: 0;
    cursor: pointer;
    position: relative;
    border: 1px solid var(--border);
}
.gallery-item img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.3s; }
.gallery-item:hover img { transform: scale(1.1); }

.loader { display: none; text-align: center; padding: 4rem 1rem; }
.spinner { border: 4px solid #f1f5f9; border-top: 4px solid var(--accent); border-radius: 50%; width: 48px; height: 48px; animation: spin 0.8s linear infinite; margin: 0 auto 1.5rem; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* --- Lightbox --- */
.lightbox { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(15, 23, 42, 0.95); z-index: 1000; justify-content: center; align-items: center; flex-direction: column; backdrop-filter: blur(5px); }
.lightbox img { max-width: 90%; max-height: 80vh; border-radius: 8px; box-shadow: var(--shadow-lg); object-fit: contain; }
.lightbox-controls { display: flex; gap: 2rem; margin-top: 1.5rem; }
.lightbox-btn { background: rgba(255,255,255,0.1); color: white; border: 1px solid rgba(255,255,255,0.2); padding: 0.75rem 1.5rem; border-radius: 8px; cursor: pointer; font-size: 1.25rem; transition: background 0.2s; }
.lightbox-btn:hover { background: rgba(255,255,255,0.25); }
.lightbox-close { position: absolute; top: 25px; right: 25px; color: white; background: none; border: none; font-size: 2.5rem; cursor: pointer; opacity: 0.7; transition: opacity 0.2s; padding: 0.5rem; }
.lightbox-close:hover { opacity: 1; }

.hidden { display: none !important; }

/* --- Mobile / Responsive Tweaks --- */
@media (max-width: 900px) {
    .dashboard-grid { grid-template-columns: 1fr; gap: 1.5rem; }
    .sidebar { order: -1; } /* Summary on top */
    .search-box { padding: 1.5rem; }
    .card { padding: 1.5rem; }
    
    /* Welcome nav - tablet optimization */
    #welcome-nav a.nav-link {
        padding: 0.5rem 0.8rem !important;
        font-size: 0.85rem !important;
    }
    
    /* Improve header metrics - 2 columns on tablet */
    #view-detail .card:first-of-type > div:first-child {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)) !important;
    }
}

@media (max-width: 600px) {
    .container { margin: 1rem auto; padding: 0 1rem; }
    .navbar { padding: 0 1rem; }
    
    /* Welcome nav - compact mobile layout */
    #welcome-nav {
        gap: 0.25rem !important;
    }
    
    #welcome-nav a.nav-link {
        padding: 0.5rem 0.6rem !important;
        font-size: 0.8rem !important;
    }
    
    #welcome-nav a.nav-link i {
        display: none !important; /* Hide icons on very small screens */
    }
    
    /* Hide separator on mobile */
    #welcome-nav > div {
        display: none !important;
    }

    /* Hide usage counters in navbar on mobile */
    #usageLimits {
        display: none !important;
    }
    /* If you want to show usage counters elsewhere on mobile, add a new container and style here. */
    
    .nav-dropdown {
        display: none; /* Hide dropdown by default on mobile */
        position: absolute;
        top: var(--nav-height);
        left: 0;
        right: 0;
        background: var(--primary-dark);
        flex-direction: column;
        padding: 1rem;
        border-top: 1px solid rgba(255,255,255,0.1);
        gap: 1rem;
        box-shadow: 0 4px 6px rgba(0,0,0,0.2);
    }
    
    .nav-dropdown.open { display: flex; }
    .menu-toggle { display: block; }
    
    .hero-btn-group { flex-direction: column; align-items: stretch; }
    .btn { width: 100%; }
    
    /* Header improvements for mobile */
    #view-detail > div:first-child {
        flex-direction: column;
        gap: 1rem;
    }
    
    #view-detail > div:first-child > div {
        width: 100%;
        justify-content: space-between;
    }
    
    /* Compact header card */
    #view-detail .card h1 {
        font-size: 1.25rem !important;
    }
    
    /* Price and investment boxes on mobile */
    #view-detail .card > div:first-child > div:nth-child(2) {
        grid-template-columns: 1fr !important;
    }
    
    #propPrice, #propTotalInvest {
        font-size: 1.25rem !important;
    }
    
    #originalLink {
        font-size: 0.8rem !important;
        word-break: break-all;
    }
    
    /* Key metrics - horizontal scroll on tiny screens */
    #view-detail .card > div:last-child {
        grid-template-columns: repeat(3, minmax(100px, 1fr)) !important;
        gap: 0.75rem !important;
        padding: 1rem !important;
    }
    
    #view-detail .card > div:last-child > div > div:first-child {
        font-size: 0.65rem !important;
    }
    
    #view-detail .card > div:last-child > div > div:last-child {
        font-size: 0.95rem !important;
    }
    
    /* Tabs - Mobile optimized */
    .tabs-container {
        position: sticky;
        top: var(--nav-height);
        margin: 0 0 1.5rem 0;
        padding: 0;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }
    
    .tabs {
        display: flex;
        justify-content: space-around;
        gap: 0;
        padding: 0;
    }
    
    .tab-btn {
        flex: 1;
        padding: 0.75rem 0.5rem;
        font-size: 0.7rem;
        flex-direction: column;
        gap: 0.25rem;
        min-width: 0;
    }
    
    .tab-btn i {
        font-size: 1.25rem;
    }
    
    .tab-btn span {
        font-size: 0.7rem;
        text-overflow: ellipsis;
        overflow: hidden;
        max-width: 100%;
    }
    
    /* Improve table readability on small screens */
    .cost-table { font-size: 0.9rem; }
    
    .modal-content {
        margin: 0;
        height: 100%;
        border-radius: 0;
        max-width: 100%;
    }
}

/* Modal styling which was inline before */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(2px);
}
.modal-content {
    background: white;
    width: 90%;
    max-width: 600px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    max-height: 90vh;
}
.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
}
.modal-footer {
    padding: 1.5rem;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    background: #f8fafc;
    border-radius: 0 0 var(--radius) var(--radius);
}

/* Funding Program Cards */
.funding-card {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.funding-card:hover {
    transform: translateY(-2px);
}

.funding-card.priority-card {
    animation: pulse-border 2s ease-in-out infinite;
}

@keyframes pulse-border {
    0%, 100% {
        border-color: #16a34a;
        box-shadow: 0 2px 8px rgba(22, 163, 74, 0.2);
    }
    50% {
        border-color: #22c55e;
        box-shadow: 0 4px 16px rgba(34, 197, 94, 0.4);
    }
}

.funding-card.warning-card {
    border-color: #f59e0b !important;
}

.funding-card.disabled-card {
    opacity: 0.6;
    background: #f8fafc !important;
}
/* === Demo-inspired Visual Enhancements === */

/* Enhanced Score Cards */
.score-card {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    border-radius: 12px;
}

.score-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.12);
}

/* Demo-style colored left borders for renovation items */
.renovation-item {
    border-left: 4px solid #e2e8f0;
    padding-left: 1rem;
    margin-bottom: 1rem;
    transition: border-color 0.2s ease;
}

.renovation-item.priority-high {
    border-left-color: #f59e0b;
    background: linear-gradient(90deg, #fff7ed 0%, transparent 100%);
}

.renovation-item.priority-medium {
    border-left-color: #3b82f6;
    background: linear-gradient(90deg, #eff6ff 0%, transparent 100%);
}

.renovation-item.priority-low {
    border-left-color: #10b981;
    background: linear-gradient(90deg, #f0fdf4 0%, transparent 100%);
}

/* Enhanced Funding Program Cards with Demo style */
.funding-program-card {
    background: #f0f9ff;
    border: 2px solid #3b82f6;
    border-radius: 12px;
    padding: 1.25rem;
    margin-bottom: 1rem;
    transition: all 0.2s ease;
}

.funding-program-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(59, 130, 246, 0.15);
}

.funding-program-card.kfw-card {
    background: #f0fdf4;
    border-color: #10b981;
}

.funding-program-card.kfw-card:hover {
    box-shadow: 0 8px 20px rgba(16, 185, 129, 0.15);
}

.funding-program-card.bafa-card {
    background: #f0f9ff;
    border-color: #3b82f6;
}

/* Demo-style AI Analysis Box */
.ai-analysis-box {
    background: linear-gradient(135deg, #faf5ff 0%, #f3e8ff 100%);
    border: 2px solid #e9d5ff;
    border-radius: 12px;
    padding: 1.5rem;
}

.ai-analysis-box .ai-icon {
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, #7c3aed, #6d28d9);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-analysis-box .ai-icon i {
    font-size: 1.5rem;
    color: white;
}

/* Demo-style Rating Bars */
.rating-bar {
    display: flex;
    gap: 4px;
    margin-top: 0.5rem;
}

.rating-bar .segment {
    width: 24px;
    height: 8px;
    background: #e2e8f0;
    border-radius: 4px;
    transition: background-color 0.2s ease;
}

.rating-bar .segment.filled {
    background: #10b981;
}

.rating-bar .segment.filled.warning {
    background: #f59e0b;
}

.rating-bar .segment.filled.danger {
    background: #ef4444;
}

/* Demo Total Summary Box */
.total-summary-box {
    padding: 1.5rem;
    background: #f8fafc;
    border-radius: 12px;
    border: 2px dashed #cbd5e1;
    text-align: center;
}

.total-summary-box .amount {
    font-size: 2rem;
    font-weight: 800;
    color: var(--primary);
    letter-spacing: -0.025em;
}

/* Accent gradient buttons like demo */
.btn-accent-gradient {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    transition: all 0.2s ease;
}

.btn-accent-gradient:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.35);
}