/* Units page upgrades (units-plus.js) */
body.read-only-user .admin-only,
body.partner-view .admin-only {
    display: none !important;
}

/* column visibility (column chooser) */
#units-table.up-hide-project .up-c-project,
#units-table.up-hide-unit .up-c-unit,
#units-table.up-hide-owners .up-c-owners,
#units-table.up-hide-op .up-c-op,
#units-table.up-hide-cost .up-c-cost,
#units-table.up-hide-disc .up-c-disc,
#units-table.up-hide-mv .up-c-mv,
#units-table.up-hide-gain .up-c-gain,
#units-table.up-hide-status .up-c-status,
#units-table.up-hide-nextpay .up-c-nextpay,
#units-table.up-hide-progress .up-c-progress,
#units-table.up-hide-remaining .up-c-remaining,
#units-table.up-hide-handover .up-c-handover,
#units-table.up-hide-psf .up-c-psf {
    display: none;
}
#units-table tbody tr.up-hidden {
    display: none !important;
}

.up-colmenu {
    position: absolute;
    z-index: 3000;
    width: 250px;
    max-height: 70vh;
    overflow: auto;
    padding: 0.75rem;
    background: var(--bg-surface, #fff);
    color: var(--text-primary, #1e293b);
    border: 1px solid var(--border-medium, #cbd5e1);
    border-radius: 10px;
    box-shadow: var(--shadow-lg, 0 10px 15px rgba(0, 0, 0, 0.15));
}
.up-colmenu label {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    padding: 0.3rem 0;
    font-size: 0.85rem;
    cursor: pointer;
}
.up-colmenu-title {
    font-weight: 600;
    margin-bottom: 0.4rem;
}
.up-colmenu-title small {
    font-weight: 400;
    color: var(--text-muted, #64748b);
}
.up-colmenu button {
    margin-top: 0.5rem;
}

/* flags and tags */
.up-flag {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    margin-top: 0.2rem;
    padding: 0.05rem 0.4rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
    white-space: nowrap;
}
.up-flag-red {
    background: rgba(239, 68, 68, 0.14);
    color: #dc2626;
}
.up-flag-amber {
    background: rgba(245, 158, 11, 0.16);
    color: #b45309;
}
.up-tag {
    display: inline-block;
    margin-top: 0.2rem;
    padding: 0.05rem 0.4rem;
    border-radius: 6px;
    font-size: 0.68rem;
    background: rgba(34, 197, 94, 0.14);
    color: #15803d;
    white-space: nowrap;
}
.up-tag-resale {
    background: rgba(99, 102, 241, 0.14);
    color: #4338ca;
}
.up-warn-ico {
    color: #d97706;
    font-size: 0.8em;
}
.up-stale {
    color: #dc2626;
}
.up-muted {
    color: var(--text-muted, #94a3b8);
}
.up-urg-red {
    color: #dc2626;
}
.up-urg-amber {
    color: #b45309;
}
.up-urg-green {
    color: #15803d;
}
td.up-urg-red strong,
td.up-urg-amber strong,
td.up-urg-green strong {
    color: inherit;
}
td.up-c-nextpay {
    border-left: 3px solid transparent;
}
td.up-c-nextpay.up-urg-red {
    border-left-color: #ef4444;
}
td.up-c-nextpay.up-urg-amber {
    border-left-color: #f59e0b;
}
td.up-c-nextpay.up-urg-green {
    border-left-color: #22c55e;
}

/* paid / built bars */
.up-bar {
    position: relative;
    height: 16px;
    min-width: 96px;
    margin: 2px 0;
    border-radius: 8px;
    background: rgba(100, 116, 139, 0.18);
    overflow: hidden;
}
.up-bar > i {
    position: absolute;
    inset: 0 auto 0 0;
    background: linear-gradient(90deg, #6366f1, #818cf8);
}
.up-bar-build > i {
    background: linear-gradient(90deg, #16a34a, #4ade80);
}
.up-bar > span {
    position: relative;
    display: block;
    padding: 0 6px;
    font-size: 0.68rem;
    line-height: 16px;
    font-weight: 600;
    color: var(--text-primary, #1e293b);
    text-shadow: 0 0 3px var(--bg-surface, #fff);
}

/* summary row + legend */
#units-table tfoot .up-sumrow td {
    position: sticky;
    bottom: 0;
    background: var(--bg-surface-hover, #f1f5f9);
    border-top: 2px solid var(--border-medium, #cbd5e1);
    font-size: 0.85rem;
}
.up-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
}
.up-legend-title {
    font-weight: 600;
    margin-right: 0.25rem;
}
.up-chip {
    border: 1px solid var(--border-medium, #cbd5e1);
    background: var(--bg-surface, #fff);
    color: var(--text-primary, #1e293b);
    border-radius: 999px;
    padding: 0.15rem 0.6rem;
    font-size: 0.75rem;
    cursor: pointer;
}
.up-chip.active {
    background: #6366f1;
    border-color: #6366f1;
    color: #fff;
}
.up-chip b {
    margin-left: 0.25rem;
}

/* cards view */
.up-card {
    padding: 0;
    overflow: hidden;
}
.up-card-img {
    position: relative;
    height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-size: cover;
    background-position: center;
}
.up-card-initials {
    font-size: 2.2rem;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.85);
    letter-spacing: 2px;
}
.up-card-status {
    position: absolute;
    top: 8px;
    left: 8px;
}
.up-card-cam {
    position: absolute;
    top: 8px;
    right: 8px;
    border: 0;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    background: rgba(0, 0, 0, 0.45);
    color: #fff;
    cursor: pointer;
}
.up-card .unit-card-body {
    padding: 0.9rem;
}
.up-card .unit-card-header {
    margin-bottom: 0.5rem;
}

/* modals */
.up-info-btn {
    padding: 0.5rem 0.7rem;
}
.up-mv-wrap {
    max-height: 52vh;
    overflow: auto;
    margin-top: 0.75rem;
}
.up-mv-in {
    width: 150px;
}
.up-sim-inputs {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}
.up-sim-inputs label {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.8rem;
    font-weight: 600;
}
.up-sim-inputs small {
    font-weight: 400;
    color: var(--text-muted, #64748b);
}
.up-sim-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1rem;
    align-items: start;
}
.up-sim-total td {
    border-top: 2px solid var(--border-medium, #cbd5e1);
}
.up-kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}
.up-kpis > div {
    padding: 0.6rem 0.8rem;
    border-radius: 10px;
    background: var(--bg-surface-hover, #f1f5f9);
}
.up-kpis small {
    display: block;
    color: var(--text-muted, #64748b);
    font-size: 0.72rem;
}
.up-kpis b {
    font-size: 1.1rem;
}
.up-inc-form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 0.5rem;
    align-items: end;
}
.up-inc-form label {
    display: flex;
    flex-direction: column;
    font-size: 0.75rem;
    gap: 0.2rem;
}
.up-docgrp {
    margin-bottom: 0.6rem;
}
.up-docgrp-title {
    font-weight: 600;
    font-size: 0.85rem;
}
.up-count {
    color: var(--text-muted, #64748b);
    font-weight: 400;
}
.up-doc {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    padding: 0.25rem 0 0.25rem 0.5rem;
    font-size: 0.82rem;
}
.up-doc-name {
    flex: 1 1 200px;
    word-break: break-all;
}
.up-doc-exp {
    display: inline-flex;
    gap: 0.3rem;
    align-items: center;
    font-size: 0.72rem;
}
.up-detail-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: 1rem;
}

@media (max-width: 700px) {
    .up-bar {
        min-width: 80px;
    }
    .up-card-img {
        height: 96px;
    }
}
