/**
 * DESIGN SYSTEM TOKENS
 * --------------------
 * Using CSS variables for consistent glassmorphism effects and colors.
 */
:root {
    --text-color: #f8fafc;
    --glass-bg: rgba(10, 15, 30, 0.65);
    --glass-border: rgba(59, 130, 246, 0.3);
    --glass-glow: 0 0 20px rgba(59, 130, 246, 0.15);
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --secondary: rgba(255, 255, 255, 0.1);
    --secondary-hover: rgba(255, 255, 255, 0.2);
    --bg-color-2d: #060b14;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    overflow-x: hidden;
}

body {
    font-family: 'Inter', sans-serif;
    color: var(--text-color);
    background-color: #000;
    transition: background-color 0.3s ease;
    overflow-x: hidden;
}

/* 3D Mode Specifics: UI floats over the canvas */
body.mode-3d {
    overflow: hidden;
}

body.mode-3d #canvas-container {
    opacity: 1;
    pointer-events: auto;
}

body.mode-3d .ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 10;
    pointer-events: none; 
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 2rem;
}

/* 2D Mode Specifics: Classic scrollable web layout */
body.mode-2d {
    overflow: auto;
    background-color: var(--bg-color-2d);
    background-image: 
        radial-gradient(circle at 15% 50%, rgba(59, 130, 246, 0.15), transparent 25%),
        radial-gradient(circle at 85% 30%, rgba(236, 72, 153, 0.15), transparent 25%);
}

body.mode-2d #canvas-container {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

body.mode-3d #canvas-container {
    opacity: 1;
    pointer-events: auto;
    transition: opacity 0.4s ease;
}

/* Panel Collapsing (Mobile & Sync) */
.top-left-panel, .stats-panel {
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
}

.top-left-panel.collapsed {
    transform: translateX(-110%);
    opacity: 0;
    pointer-events: none;
}

.stats-panel.collapsed {
    transform: translateX(110%);
    opacity: 0;
    pointer-events: none;
}

body.mode-2d .ui-layer {
    position: relative;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
    pointer-events: auto;
    display: flex;
    flex-direction: column;
    align-items: center; /* Center all items horizontally */
    gap: 2rem;
}

body.mode-2d .top-left-panel {
    max-width: 800px; /* Sync with legend width for symmetry */
    width: 100%;
    align-self: center;
}

body.mode-2d .stats-panel {
    max-width: 800px;
    width: 100%;
    align-self: center;
    order: 0;
}

body.mode-2d .bottom-panel {
    max-width: 800px;
    width: 100%;
    align-self: center;
    order: -1; /* Move legend up in 2D mode */
}

/* Utility */
.d-none {
    display: none !important;
}

#canvas-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1;
    transition: opacity 0.3s ease;
}

.top-left-panel, .bottom-panel {
    pointer-events: auto; 
}

.top-left-panel {
    align-self: flex-start;
    max-width: 500px;
}

.bottom-panel {
    align-self: center;
    width: 100%;
    max-width: 800px;
}

/* Glassmorphism Panel Template */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: var(--glass-glow);
    transition: transform 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.glass-panel:hover {
    border-color: rgba(59, 130, 246, 0.6);
    box-shadow: 0 0 30px rgba(59, 130, 246, 0.25);
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.lang-btn {
    all: unset;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.2rem 0.5rem;
    min-width: 30px;
    height: 24px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    font-size: 0.65rem;
    font-weight: 800;
    color: var(--primary);
    text-transform: uppercase;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
    letter-spacing: 0.5px;
}

.lang-btn:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

header h1 {
    font-size: 2.2rem;
    margin-bottom: 0;
    font-weight: 800;
    letter-spacing: -0.5px;
    background: linear-gradient(to right, #60a5fa, #a78bfa, #f472b6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-transform: uppercase;
}

header p {
    color: #cbd5e1;
    margin-bottom: 1.5rem;
    font-size: 0.95rem;
    line-height: 1.5;
}

.controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.upload-wrapper {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.5rem;
}

.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background-color 0.3s cubic-bezier(0.4, 0, 0.2, 1),
        border-color 0.3s cubic-bezier(0.4, 0, 0.2, 1),
        box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1),
        transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid transparent;
    color: white;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    width: 100%;
    min-height: 44px;
    white-space: nowrap;
}

.primary-btn {
    background: var(--primary);
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.4);
}
.primary-btn:hover {
    background: var(--primary-hover);
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 0 25px rgba(59, 130, 246, 0.7);
}

.download-btn {
    background: var(--secondary);
    border: 1px solid rgba(255,255,255,0.1);
    padding: 0.75rem;
    width: auto;
    aspect-ratio: 1 / 1;
}
.download-btn:hover {
    background: var(--secondary-hover);
    transform: translateY(-2px) scale(1.02);
    border-color: rgba(255,255,255,0.3);
    box-shadow: 0 0 15px rgba(255,255,255,0.1);
}

.secondary-btn, .toggle-btn, .warning-btn {
    background: var(--secondary);
    border: 1px solid rgba(255,255,255,0.1);
}
.warning-btn {
    background-color: #ef4444;
    border: none;
    box-shadow: 0 4px 14px rgba(239, 68, 68, 0.4);
}
.secondary-btn:hover, .toggle-btn:hover {
    background: var(--secondary-hover);
    transform: translateY(-2px) scale(1.02);
    border-color: rgba(255,255,255,0.3);
    box-shadow: 0 0 15px rgba(255,255,255,0.1);
}
.warning-btn:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 0 25px rgba(239, 68, 68, 0.8) !important;
}

.status-message {
    font-size: 0.85rem;
    color: #94a3b8;
    min-height: 20px;
    font-family: monospace;
}

.legend-panel h3 {
    font-size: 1rem;
    margin-bottom: 1rem;
    color: #e2e8f0;
    text-transform: uppercase;
    letter-spacing: 1px;
    text-align: center;
}

.legend-bar-container {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.legend-gradient {
    flex-grow: 1;
    height: 12px;
    border-radius: 6px;
    background: linear-gradient(to right, hsl(240, 100%, 50%), hsl(120, 100%, 50%), hsl(60, 100%, 50%), hsl(0, 100%, 50%));
    box-shadow: 0 0 10px rgba(255,255,255,0.1);
}

.legend-label {
    font-size: 0.9rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    min-width: 60px;
    text-align: center;
}

.legend-info {
    text-align: center;
    font-size: 0.8rem;
    color: #94a3b8;
    margin-top: 0.75rem;
}

/* Tooltip for 3D */
.tooltip {
    position: absolute;
    background: rgba(10, 15, 30, 0.9);
    border: 1px solid rgba(59, 130, 246, 0.4);
    border-left: 4px solid #60a5fa;
    backdrop-filter: blur(12px);
    padding: 1.2rem;
    border-radius: 4px 8px 8px 4px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s, transform 0.1s;
    font-size: 0.95rem;
    color: white;
    box-shadow: 0 10px 30px rgba(0,0,0,0.8), 0 0 15px rgba(59, 130, 246, 0.2);
    z-index: 20;
    transform: translate(-50%, -100%) scale(0.95);
    margin-top: -15px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    will-change: opacity, transform;
}
.tooltip.visible { 
    opacity: 1; 
    transform: translate(-50%, -100%) scale(1);
}
.tooltip div { margin-bottom: 6px; }
.tooltip span { font-weight: 800; color: #93c5fd; }
.tooltip-reason {
    max-width: 260px;
    line-height: 1.35;
    text-transform: none;
}


/* 2D Building Grid Styles */
.building-container {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    align-items: center;
    width: 100%;
}

.floor-row {
    display: flex;
    gap: 1.5rem;
    align-items: center;
    background: rgba(0, 0, 0, 0.3);
    padding: 1.5rem 2rem;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    width: 100%;
    max-width: 800px; /* Aligned with other 2D panels */
    justify-content: center;
    position: relative;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}

.floor-label {
    position: absolute;
    left: 2rem;
    font-weight: 700;
    color: #94a3b8;
    font-size: 1.1rem;
}

.apartments-wrapper {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
    justify-content: center;
    padding-left: 80px; 
}

.apartment-card {
    width: 110px;
    height: 110px;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    cursor: default;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.3s ease;
    box-shadow: inset 0 0 20px rgba(255, 255, 255, 0.15), 0 4px 10px rgba(0, 0, 0, 0.4);
    border: 2px solid rgba(255, 255, 255, 0.2);
    overflow: hidden;
    will-change: transform;
}

.apartment-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.4) 0%, rgba(255,255,255,0) 50%);
    pointer-events: none;
}

.apartment-card:hover {
    transform: scale(1.1) translateY(-5px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.6), inset 0 0 20px rgba(255, 255, 255, 0.3);
    z-index: 10;
}

/* Suspect Anomaly Pulse Animation */
.apartment-card.suspect {
    border: 3px solid #ef4444;
    box-shadow: 0 0 20px rgba(239, 68, 68, 0.8), inset 0 0 20px rgba(239, 68, 68, 0.4);
    animation: pulse-suspect 1.5s infinite;
}

@keyframes pulse-suspect {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.apt-no {
    font-size: 1.6rem;
    font-weight: 800;
    text-shadow: 0 2px 4px rgba(0,0,0,0.6);
    z-index: 1;
}

.apt-area {
    font-size: 0.7rem;
    color: white;
    font-weight: 700;
    margin-top: 2px;
    background: rgba(0, 0, 0, 0.45);
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    backdrop-filter: blur(2px);
    text-shadow: 0 1px 2px rgba(0,0,0,0.8);
    z-index: 1;
    letter-spacing: 0.2px;
}

.apt-bill {
    font-size: 0.9rem;
    font-weight: 600;
    margin-top: 0.3rem;
    background: rgba(0, 0, 0, 0.7);
    padding: 0.25rem 0.6rem;
    border-radius: 6px;
    text-shadow: none;
    z-index: 1;
}

.apt-risk {
    position: absolute;
    top: 0.35rem;
    right: 0.35rem;
    z-index: 2;
    border-radius: 999px;
    background: rgba(127, 29, 29, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.35);
    color: #fee2e2;
    font-size: 0.65rem;
    font-weight: 800;
    line-height: 1;
    padding: 0.25rem 0.35rem;
}

/* ======== STATISTICS PANEL ======== */
.stats-panel {
    pointer-events: auto;
    animation: statsSlideIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

body.mode-3d .stats-panel {
    position: absolute;
    top: 2rem;
    right: 2rem;
    width: 360px;
    max-height: calc(100vh - 4rem);
    overflow-y: auto;
    overflow-x: hidden;
}

body.mode-2d .stats-panel {
    max-width: 800px;
    width: 100%;
    align-self: center;
    order: 0;
    margin-top: 0;
}

@keyframes statsSlideIn {
    from { opacity: 0; transform: translateY(-15px); }
    to { opacity: 1; transform: translateY(0); }
}

.stats-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.stats-header h3 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.95rem;
    font-weight: 700;
    color: #e2e8f0;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin: 0;
}

.stats-header h3 svg {
    color: #60a5fa;
}


.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.6rem;
}

.stat-card {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    padding: 0.75rem 0.4rem;
    text-align: center;
    transition: background-color 0.3s ease, border-color 0.3s ease, transform 0.3s ease;
    min-width: 0;
}

.stat-card:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(59, 130, 246, 0.3);
    transform: translateY(-1px);
}

.stat-value {
    font-size: 1.15rem;
    font-weight: 800;
    color: #f1f5f9;
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
    margin-bottom: 0.3rem;
}

.stat-label {
    font-size: 0.6rem;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    font-weight: 600;
    line-height: 1.2;
    overflow-wrap: break-word;
}

.stat-sub {
    font-size: 0.58rem;
    color: #475569;
    margin-top: 0.2rem;
    line-height: 1.1;
}

/* Accent colors for specific stats */
.stat-card.stat-min .stat-value { color: #60a5fa; }
.stat-card.stat-max .stat-value { color: #f87171; }
.stat-card.stat-avg .stat-value { color: #a78bfa; }
.stat-card.stat-count .stat-value { color: #34d399; }
.stat-card.stat-median .stat-value { color: #fbbf24; }
.stat-card.stat-std .stat-value { color: #fb923c; }
.stat-card.stat-total .stat-value { color: #38bdf8; }
.stat-card.stat-risk .stat-value { color: #ef4444; }
.stat-card.stat-floor-low .stat-value { color: #22d3ee; }
.stat-card.stat-floor-high .stat-value { color: #f97316; }

/* Divider for normalized section */
.stats-divider {
    text-align: center;
    font-size: 0.7rem;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin: 0.8rem 0;
    position: relative;
}

.stats-divider::before,
.stats-divider::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 25%;
    height: 1px;
    background: linear-gradient(to right, transparent, rgba(255,255,255,0.15));
}

.stats-divider::before { left: 0; }
.stats-divider::after { right: 0; background: linear-gradient(to left, transparent, rgba(255,255,255,0.15)); }

/* ======== MOBILE TOGGLE BUTTON ======== */
.mobile-toggle-btn {
    display: none;
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 100;
    width: 48px;
    height: 48px;
    border-radius: 14px;
    border: 1px solid var(--glass-border);
    background: rgba(10, 15, 30, 0.75);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    color: #93c5fd;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 20px rgba(59, 130, 246, 0.2), 0 4px 12px rgba(0, 0, 0, 0.4);
    transition: transform 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease, color 0.3s ease;
}

.mobile-toggle-btn:active {
    transform: scale(0.92);
}

.mobile-toggle-btn:hover {
    border-color: rgba(59, 130, 246, 0.7);
    box-shadow: 0 0 30px rgba(59, 130, 246, 0.4), 0 4px 12px rgba(0, 0, 0, 0.4);
    color: #bfdbfe;
}

/* SVG icon toggle: show menu by default, close when active */
.mobile-toggle-btn .icon-close {
    display: none;
}

.mobile-toggle-btn.active .icon-menu {
    display: none;
}

.mobile-toggle-btn.active .icon-close {
    display: block;
}

/* ======== MOBILE RESPONSIVE ======== */
@media (max-width: 768px) {
    .mobile-toggle-btn {
        display: flex;
        top: max(0.75rem, env(safe-area-inset-top));
        right: max(0.75rem, env(safe-area-inset-right));
        width: 44px;
        height: 44px;
    }

    body.mode-3d .ui-layer {
        height: 100dvh;
        padding: calc(0.75rem + env(safe-area-inset-top)) 0.75rem calc(0.75rem + env(safe-area-inset-bottom));
        gap: 0.75rem;
        justify-content: flex-start;
        overflow-y: auto;
        overscroll-behavior: contain;
    }

    body.mode-3d .top-left-panel {
        width: min(100%, 420px);
        max-width: 100%;
        max-height: calc(100dvh - 9.5rem);
        overflow-y: auto;
        transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.25s ease;
    }

    body.mode-3d .top-left-panel.collapsed {
        transform: translateY(-120%);
        opacity: 0;
        pointer-events: none;
        position: absolute;
    }

    body.mode-3d .stats-panel {
        position: relative;
        top: auto;
        right: auto;
        width: min(100%, 420px);
        max-height: 42dvh;
        overflow-y: auto;
        order: 1;
    }

    body.mode-3d .bottom-panel {
        margin-top: auto;
        max-width: 100%;
        width: 100%;
        order: 10;
    }

    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.5rem;
    }

    .stat-value {
        font-size: 0.95rem;
    }

    .stat-label {
        font-size: 0.58rem;
        line-height: 1.2;
        overflow-wrap: anywhere;
    }

    .stats-panel.collapsed {
        transform: translateY(-120%);
        opacity: 0;
        pointer-events: none;
        position: absolute;
    }

    .stats-panel {
        transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.25s ease;
    }

    .glass-panel {
        padding: 0.875rem;
        border-radius: 10px;
    }

    .header-top {
        margin-bottom: 0.25rem;
        padding-right: 3rem;
    }

    header h1 {
        font-size: 1.25rem;
        margin-bottom: 0;
        line-height: 1.1;
    }

    header p {
        font-size: 0.75rem;
        margin-bottom: 0.5rem;
        line-height: 1.35;
    }

    .controls {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.5rem;
        margin-bottom: 0.5rem;
    }

    .upload-wrapper,
    #modeToggleBtn {
        grid-column: 1 / -1;
    }

    .btn {
        padding: 0.55rem 0.75rem;
        font-size: 0.7rem;
        gap: 0.35rem;
        justify-content: center;
        letter-spacing: 0.3px;
        min-width: 0;
        white-space: normal;
        line-height: 1.15;
    }

    .btn svg {
        width: 14px;
        height: 14px;
        flex-shrink: 0;
    }

    .status-message {
        font-size: 0.72rem;
        line-height: 1.35;
    }

    .bottom-panel {
        max-width: 100%;
        width: 100%;
        align-self: center;
    }

    .legend-panel h3 {
        font-size: 0.75rem;
        margin-bottom: 0.5rem;
        letter-spacing: 0.5px;
    }

    .legend-bar-container {
        gap: 0.5rem;
    }

    .legend-gradient {
        height: 8px;
        border-radius: 4px;
        background: linear-gradient(to right, hsl(240, 100%, 50%), hsl(120, 100%, 50%), hsl(60, 100%, 50%), hsl(0, 100%, 50%));
    }

    .legend-label {
        font-size: 0.72rem;
        min-width: 50px;
        white-space: nowrap;
    }

    .legend-info {
        font-size: 0.65rem;
        margin-top: 0.4rem;
        line-height: 1.3;
        padding: 0 0.5rem;
    }


    .tooltip {
        font-size: 0.8rem;
        padding: 0.8rem;
        max-width: calc(100vw - 1.5rem);
    }

    body.mode-2d .ui-layer {
        padding: calc(4rem + env(safe-area-inset-top)) 1rem calc(1rem + env(safe-area-inset-bottom));
        gap: 1rem;
        align-items: center;
        max-width: 100%;
    }

    body.mode-2d .top-left-panel {
        order: 1;
        transition: max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.25s ease;
        overflow: hidden;
        max-width: 100%;
    }

    body.mode-2d .top-left-panel.collapsed {
        max-height: 0;
        opacity: 0;
        pointer-events: none;
        margin: 0;
        padding: 0;
    }

    body.mode-2d .bottom-panel {
        order: 4;
    }

    body.mode-2d .building-container {
        order: 2;
    }

    body.mode-2d .stats-panel {
        order: 3;
        max-width: 100%;
    }

    .building-container {
        gap: 0.75rem;
    }

    .floor-row {
        display: grid;
        grid-template-columns: minmax(42px, auto) minmax(0, 1fr);
        align-items: center;
        padding: 0.65rem 0.55rem;
        gap: 0.45rem;
        width: 100%;
        justify-content: center;
        border-radius: 10px;
    }

    .floor-label {
        position: relative;
        left: 0;
        font-size: 0.78rem;
        min-width: 0;
        text-align: center;
    }

    .apartments-wrapper {
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        padding-left: 0;
        gap: 0.35rem;
        width: 100%;
        min-width: 0;
    }

    .apartment-card {
        width: 100%;
        height: auto;
        min-height: 62px;
        aspect-ratio: 1 / 1;
        max-width: 72px;
        justify-self: center;
        border-radius: 10px;
    }

    .apt-no {
        font-size: 1rem;
    }

    .apt-bill {
        font-size: 0.6rem;
        padding: 0.1rem 0.25rem;
        max-width: calc(100% - 0.35rem);
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .apt-risk {
        top: 0.25rem;
        right: 0.25rem;
        font-size: 0.55rem;
        padding: 0.2rem 0.28rem;
    }
}

/* ======== VERY SMALL SCREENS ======== */
@media (max-width: 380px) {
    header h1 {
        font-size: 1.1rem;
    }

    header p {
        font-size: 0.72rem;
    }

    .controls {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .btn {
        padding: 0.5rem 0.6rem;
        font-size: 0.65rem;
    }

    .apartment-card {
        min-height: 56px;
        max-width: 64px;
    }

    .apt-no {
        font-size: 0.92rem;
    }

    .apt-bill {
        font-size: 0.55rem;
    }

    .stat-value {
        font-size: 0.85rem;
    }

    .stat-card {
        padding: 0.6rem 0.45rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
    }
}
