:root {
    --bg-base: #0B0E14;
    --bg-surface: #151A22;
    --bg-surface-glass: rgba(21, 26, 34, 0.7);
    --bg-surface-elevated: #1D2430;
    --border-glass: rgba(255, 255, 255, 0.08);
    --border-highlight: rgba(255, 255, 255, 0.15);

    --text-primary: #F0F4F8;
    --text-secondary: #9BA3AF;
    --text-muted: #5C677D;

    --brand-primary: #3B82F6;
    --brand-primary-light: #60A5FA;
    --brand-primary-glass: rgba(59, 130, 246, 0.15);

    --status-complete: #10B981;
    --status-wip: #F59E0B;
    --status-empty: #EF4444;

    --pct-5: #10B981;
    --pct-4: #84CC16;
    --pct-3: #EAB308;
    --pct-2: #F97316;
    --pct-1: #EF4444;

    /* Group Colors */
    --group-apartments: #8B5CF6;
    --group-handover: #EC4899;
    --group-common: #06B6D4;
    --group-external: #F97316;

    --font-main: 'Inter', system-ui, -apple-system, sans-serif;
    --easing: cubic-bezier(0.4, 0.0, 0.2, 1);
    --shadow-glass: 0 8px 32px rgba(0, 0, 0, 0.37);
    --shadow-card: 0 4px 12px rgba(0, 0, 0, 0.2);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

body {
    background: var(--bg-base);
    color: var(--text-primary);
    font-family: var(--font-main);
    line-height: 1.5;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    height: 100vh;
}

/* Ambient glow */
body::before {
    content: '';
    position: fixed;
    top: -20vh; left: -20vw;
    width: 60vw; height: 60vw;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(59,130,246,0.08) 0%, transparent 70%);
    z-index: -1; pointer-events: none;
}

#app {
    position: relative;
    max-width: 800px;
    margin: 0 auto;
    height: 100vh;
    overflow: hidden;
}

/* ═══════════════════════ SCREEN SYSTEM ═══════════════════════ */
.screen {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    opacity: 0;
    transition: transform 0.3s var(--easing), opacity 0.25s var(--easing);
    pointer-events: none;
    z-index: 1;
}

.screen.active {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
    z-index: 10;
}

/* ═══════════════════════ HEADER ═══════════════════════ */
header {
    flex-shrink: 0;
    background: var(--bg-surface-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-glass);
    padding: 1rem 1rem 0 1rem;
    z-index: 20;
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.header-left h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, #fff 0%, #a5b4fc 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.header-actions { display: flex; gap: 0.25rem; }

.icon-btn {
    position: relative;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    width: 40px; height: 40px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    transition: all 0.2s var(--easing);
}
.icon-btn:hover { background: var(--border-glass); color: var(--text-primary); }

.badge {
    position: absolute; top: 2px; right: 2px;
    background: var(--brand-primary);
    color: white; font-size: 0.6rem; font-weight: 700;
    min-width: 16px; height: 16px; line-height: 16px;
    text-align: center; border-radius: 8px; padding: 0 3px;
}
.badge.bg-tertiary { background: #8B5CF6; }
.badge.bg-secondary { background: #10B981; }

.header-bottom {
    display: flex; flex-direction: column; gap: 0.6rem;
    padding-bottom: 0.75rem;
}

/* Tower chips */
.tower-chips { display: flex; gap: 0.75rem; }
.chip {
    flex: 1; background: transparent;
    border: 1px solid var(--border-glass);
    color: var(--text-secondary);
    padding: 0.45rem; border-radius: 8px;
    font-family: inherit; font-size: 0.9rem; font-weight: 500;
    cursor: pointer; transition: all 0.2s var(--easing);
}
.chip.active {
    background: var(--brand-primary-glass);
    border-color: var(--brand-primary);
    color: var(--brand-primary-light);
}

/* Search */
.search-container { position: relative; display: flex; align-items: center; }
.search-container input {
    width: 100%;
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-glass);
    color: var(--text-primary);
    border-radius: 20px;
    padding: 0.55rem 2.5rem;
    font-family: inherit; font-size: 0.85rem;
    transition: border-color 0.2s;
}
.search-container input:focus { outline: none; border-color: var(--brand-primary); }
.search-icon, .clear-icon { position: absolute; color: var(--text-muted); font-size: 18px; }
.search-icon { left: 12px; }
.clear-icon { right: 12px; cursor: pointer; color: var(--text-secondary); }

.filter-label {
    font-size: 0.65rem; font-weight: 600;
    letter-spacing: 0.12em; color: var(--text-muted);
    text-transform: uppercase;
}

/* ═══════════════════════ MAIN CONTENT ═══════════════════════ */
main {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    -webkit-overflow-scrolling: touch;
}

.center-content {
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    height: 40vh; color: var(--text-secondary);
}

.spinner {
    width: 32px; height: 32px;
    border: 3px solid var(--border-glass);
    border-top-color: var(--brand-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}
@keyframes spin { 100% { transform: rotate(360deg); } }

/* ═══════════════════════ ACTIVITY CARDS (Home) ═══════════════════════ */
.activity-list {
    display: flex; flex-direction: column; gap: 0.6rem;
    padding-bottom: 5rem;
}

.activity-card {
    background: rgba(29, 36, 48, 0.4);
    border: 1px solid var(--border-glass);
    border-radius: 14px; padding: 0.9rem 1rem;
    cursor: pointer;
    transition: transform 0.2s var(--easing), background 0.2s, box-shadow 0.2s;
}
.activity-card:hover {
    background: rgba(29, 36, 48, 0.7);
    transform: translateY(-1px);
    box-shadow: var(--shadow-card);
}

.card-header {
    display: flex; justify-content: space-between;
    align-items: center; margin-bottom: 0.6rem;
}
.card-title-row {
    display: flex; align-items: center; gap: 0.6rem; flex: 1; min-width: 0;
}
.group-dot { width: 8px; height: 8px; flex-shrink: 0; border-radius: 50%; }
.group-bar { width: 4px; height: 28px; flex-shrink: 0; border-radius: 2px; }
.title-text-col { display: flex; flex-direction: column; min-width: 0; }
.activity-name {
    font-size: 0.9rem; font-weight: 600;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.activity-meta {
    font-size: 0.7rem; color: var(--text-secondary);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.card-stats-row { display: flex; align-items: center; gap: 0.4rem; flex-shrink: 0; }
.pct-indicator, .weight-badge {
    font-size: 0.6rem; font-weight: 700; padding: 2px 4px; border-radius: 4px;
    background: var(--bg-surface);
}
.pct-indicator { color: var(--text-muted); }
.weight-badge { color: var(--brand-primary-light); background: var(--brand-primary-glass); }
.act-score { font-size: 1rem; font-weight: 700; }

.progress-track {
    width: 100%; height: 5px;
    background: rgba(255,255,255,0.05);
    border-radius: 3px; display: flex; overflow: hidden;
}
.progress-complete { height: 100%; background: var(--status-complete); transition: width 0.6s ease-out; }
.progress-wip { height: 100%; background: var(--status-wip); transition: width 0.6s ease-out; }

/* Text score colors */
.text-complete { color: var(--status-complete); }
.text-pct-5 { color: var(--pct-5); }
.text-pct-4 { color: var(--pct-4); }
.text-pct-3 { color: var(--pct-3); }
.text-pct-2 { color: var(--pct-2); }
.text-pct-1 { color: var(--pct-1); }

/* ═══════════════════════ FAB ═══════════════════════ */
.fab {
    position: absolute;
    bottom: 1.5rem; right: 1.5rem;
    width: 56px; height: 56px;
    border-radius: 16px; border: none;
    background: var(--brand-primary-glass);
    color: var(--brand-primary-light);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; box-shadow: var(--shadow-card);
    transition: transform 0.2s, background 0.2s;
    z-index: 30;
}
.fab:hover { transform: scale(1.05); background: rgba(59,130,246,0.25); }
.fab .material-icons { font-size: 26px; }

/* ═══════════════════════ TOWER CARDS (Data Screen) ═══════════════════════ */
.tower-cards {
    display: flex; flex-direction: column; gap: 1rem;
}

.tower-card {
    background: rgba(29, 36, 48, 0.5);
    border: 1px solid var(--border-glass);
    border-radius: 16px; padding: 1.5rem;
    cursor: pointer;
    transition: transform 0.2s var(--easing), box-shadow 0.2s;
}
.tower-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-card); }

.tower-card-name { font-size: 1.35rem; font-weight: 600; margin-bottom: 1rem; }
.tower-card-stats {
    display: flex; justify-content: space-between; margin-bottom: 1rem;
}
.tower-stat-col { display: flex; flex-direction: column; }
.tower-stat-col.right { align-items: flex-end; }
.tower-stat-label {
    font-size: 0.6rem; font-weight: 600;
    letter-spacing: 0.1em; color: var(--text-muted); text-transform: uppercase;
}
.tower-stat-value { font-size: 1.4rem; font-weight: 700; }

.tower-progress {
    width: 100%; height: 4px;
    background: rgba(255,255,255,0.08);
    border-radius: 2px; overflow: hidden;
}
.tower-progress-fill {
    height: 100%; background: var(--status-complete);
    border-radius: 2px; transition: width 0.6s ease-out;
}

/* ═══════════════════════ TOWER SCREEN (Grouped) ═══════════════════════ */
.group-section { margin-bottom: 0.5rem; }
.group-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 0.6rem 0.25rem; cursor: pointer;
    border-radius: 8px; transition: background 0.2s;
}
.group-header:hover { background: rgba(255,255,255,0.03); }
.group-header-left {
    font-size: 0.7rem; font-weight: 700;
    letter-spacing: 0.12em; text-transform: uppercase;
}
.group-header-right {
    display: flex; align-items: center; gap: 0.4rem;
    font-size: 0.75rem; color: var(--text-secondary);
}
.group-header-right .material-icons { font-size: 20px; }

.group-body { display: flex; flex-direction: column; gap: 0.25rem; }
.group-body.collapsed { display: none; }

/* Tower screen activity item — more compact than Home cards */
.tower-act-item {
    display: flex; align-items: center; gap: 0.6rem;
    background: rgba(29, 36, 48, 0.35);
    border: 1px solid var(--border-glass);
    border-radius: 10px;
    padding: 0.65rem 0.8rem;
    cursor: pointer;
    transition: background 0.15s;
}
.tower-act-item:hover { background: rgba(29, 36, 48, 0.6); }
.tower-act-info { flex: 1; min-width: 0; }
.tower-act-name {
    font-size: 0.85rem; font-weight: 500;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tower-act-contractor {
    font-size: 0.65rem; color: var(--text-secondary);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tower-act-stats { display: flex; align-items: center; gap: 0.35rem; flex-shrink: 0; }
.status-dot-group { display: flex; align-items: center; gap: 2px; }
.status-dot {
    width: 6px; height: 6px; border-radius: 50%;
}
.status-dot-count {
    font-size: 0.6rem; color: var(--text-secondary);
}

/* ═══════════════════════ ACTIVITY SCREEN ═══════════════════════ */
.activity-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;  /* let inner grid scroll */
    padding-top: 0.5rem;
}

.legend-bar {
    display: flex; justify-content: center; gap: 0.8rem; flex-wrap: wrap;
    padding: 0 1rem 0.5rem 1rem; flex-shrink: 0;
}
.legend-item { display: flex; align-items: center; gap: 0.35rem; font-size: 0.7rem; color: var(--text-secondary); }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; }

.stats-row {
    display: flex; justify-content: center; gap: 1.5rem;
    padding: 0.25rem 1rem 1rem 1rem; flex-shrink: 0;
}
.stat-chip { display: flex; flex-direction: column; align-items: center; }
.stat-val { font-size: 1.15rem; font-weight: 700; }
.stat-lbl { font-size: 0.65rem; color: var(--text-secondary); }

.grid-header {
    display: flex; padding: 0 1rem 0.4rem 1rem; gap: 3px; flex-shrink: 0;
}
.grid-header > div {
    flex: 1; text-align: center;
    font-size: 0.6rem; font-weight: 700; color: var(--text-secondary);
}
.grid-header-fl { flex: 0 0 36px !important; }

.grid-scroll-area {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0 1rem 2rem 1rem;
    display: flex; flex-direction: column; gap: 3px;
}

.grid-row { display: flex; gap: 3px; }

.grid-cell {
    height: 42px;
    background: rgba(255,255,255,0.04);
    border-radius: 7px;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.7rem; font-weight: 600;
}
.grid-cell-fl { flex: 0 0 36px; color: var(--text-secondary); }
.grid-cell-data { flex: 1; transition: background-color 0.15s; }

/* Cell colors */
.cell-complete { background: var(--status-complete); color: #022c22; }
.cell-wip { background: var(--status-wip); color: #451a03; }
.cell-empty { background: rgba(239, 68, 68, 0.15); color: #7f1d1d; }
.pct-cell-5 { background: var(--pct-5); color: #022c22; }
.pct-cell-4 { background: var(--pct-4); color: #14532d; }
.pct-cell-3 { background: var(--pct-3); color: #422006; }
.pct-cell-2 { background: var(--pct-2); color: #431407; }
.pct-cell-1 { background: var(--pct-1); color: #450a0a; }

/* ═══════════════════════ FILTER POPUPS ═══════════════════════ */
.popup-backdrop { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 45; }
.popup-menu {
    position: fixed; top: 80px; right: 16px;
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-highlight);
    border-radius: 12px; box-shadow: var(--shadow-glass);
    z-index: 50; padding: 0.5rem 0;
    min-width: 200px; max-height: 50vh; overflow-y: auto;
    animation: popIn 0.2s var(--easing);
}
@keyframes popIn { from { opacity: 0; transform: scale(0.95) translateY(-8px); } to { opacity: 1; transform: none; } }

.dropdown-item {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.65rem 1rem; font-size: 0.85rem;
    cursor: pointer; transition: background 0.15s;
}
.dropdown-item:hover { background: rgba(255,255,255,0.05); }
.popup-divider { border: none; border-top: 1px solid var(--border-glass); margin: 0.4rem 0; }
.popup-actions { padding: 0.6rem 1rem; display: flex; justify-content: flex-end; }
.btn-primary {
    background: var(--brand-primary); color: white; border: none;
    padding: 0.45rem 1.2rem; border-radius: 20px;
    font-family: inherit; font-weight: 600; font-size: 0.8rem;
    cursor: pointer; transition: background 0.2s;
}
.btn-primary:active { background: var(--brand-primary-light); }

.hidden { display: none !important; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Scrollbar */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.25); }
