/* ===== layout wrapper for the new server-rendered pages ===== */
.page-wrap {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
}

/* ===== top navigation ===== */
.topnav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 14px 24px;
    background: var(--glass-bg);
    backdrop-filter: blur(16px) saturate(140%);
    border-bottom: 1px solid var(--glass-border);
    flex-wrap: wrap;
    position: sticky;
    top: 0;
    z-index: 100;
}
.topnav-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: var(--text-primary);
}
.topnav-brand img { width: 40px; height: 40px; border-radius: 10px; object-fit: cover; }
.topnav-brand strong {
    font-family: var(--font-display);
    font-size: 1.1rem;
    display: block;
    background: linear-gradient(to right, var(--text-primary), var(--accent-color));
    -webkit-background-clip: text; background-clip: text; color: transparent;
}
.topnav-brand span { font-size: .72rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .4px; }
.topnav-links { display: flex; gap: 8px; flex-wrap: wrap; }
.topnav-links a {
    display: inline-flex; align-items: center; gap: 8px; padding: 10px 16px; border-radius: var(--radius-md);
    color: var(--text-secondary); text-decoration: none; font-size: .88rem; font-weight: 500; transition: all .2s;
}
.topnav-links a:hover { background: var(--overlay-1); color: var(--text-primary); }
.topnav-user { display: flex; align-items: center; gap: 12px; }
.topnav-user-info { display: flex; flex-direction: column; text-align: right; }
.topnav-user-info strong { font-size: .88rem; }
.topnav-user-info span { font-size: .72rem; color: var(--text-secondary); }

/* ===== flash messages ===== */
.flash {
    display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-radius: var(--radius-md);
    margin-bottom: 20px; font-size: .9rem; border: 1px solid var(--card-border);
}
.flash-success { background: rgba(31,138,112,.1); border-color: rgba(31,138,112,.35); color: var(--success-color); }
.flash-error { background: rgba(179,39,58,.1); border-color: rgba(179,39,58,.35); color: var(--danger-color); }
.flash-warning { background: rgba(192,122,30,.1); border-color: rgba(192,122,30,.35); color: var(--warning-color); }
.flash-info { background: rgba(199,154,75,.1); border-color: rgba(199,154,75,.35); color: var(--accent-color); }

/* ===== data table (projects list, users list) ===== */
.data-table-wrap {
    background: var(--glass-bg); border: 1px solid var(--glass-border); border-radius: var(--radius-lg);
    overflow: hidden; box-shadow: var(--glass-shadow);
}
.data-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.data-table th {
    text-align: left; padding: 14px 16px; background: var(--card-bg); color: var(--text-light);
    font-weight: 600; border-bottom: 2px solid var(--card-border); white-space: nowrap;
}
.data-table td { padding: 14px 16px; border-bottom: 1px solid var(--card-border); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: rgba(30,58,95,.04); }
.data-table a.row-link { color: var(--text-primary); font-weight: 600; text-decoration: none; }
.data-table a.row-link:hover { color: var(--primary-color); }

/* ===== badges ===== */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 20px; font-size: .76rem; font-weight: 600; }
.badge-admin { background: rgba(199,154,75,.15); color: var(--accent-color); }
.badge-manager { background: rgba(30,58,95,.15); color: var(--primary-color); }
.badge-active { background: rgba(31,138,112,.15); color: var(--success-color); }
.badge-inactive { background: rgba(179,39,58,.15); color: var(--danger-color); }
.badge-possible { background: rgba(31,138,112,.15); color: var(--success-color); }
.badge-conditional { background: rgba(192,122,30,.15); color: var(--warning-color); }
.badge-not-possible { background: rgba(179,39,58,.15); color: var(--danger-color); }
.badge-pending { background: var(--overlay-2); color: var(--text-secondary); }

/* ===== page header row ===== */
.page-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-header h1 { font-family: var(--font-display); font-size: 1.6rem; }
.page-header p { color: var(--text-secondary); font-size: .9rem; margin-top: 4px; }

/* ===== auth pages (login / install) ===== */
.centered-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-box {
    background: var(--glass-bg); backdrop-filter: blur(24px) saturate(150%); border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg); box-shadow: var(--glass-shadow); padding: 40px; max-width: 420px; width: 100%;
}
.auth-box h3 { color: var(--accent-color); margin-bottom: 8px; font-size: 1.35rem; display: flex; align-items: center; gap: 10px; }
.auth-box .muted { color: var(--text-secondary); font-size: .85rem; margin-bottom: 20px; }
.auth-box form .form-group { margin-bottom: 14px; }
.form-error { color: var(--danger-color); font-size: .85rem; margin-top: 8px; }

/* ===== project tabs (server-rendered, link-based) ===== */
.project-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 20px; border-bottom: 1px solid var(--card-border); padding-bottom: 0; }
.project-tabs a {
    padding: 12px 18px; text-decoration: none; color: var(--text-secondary); font-size: .9rem; font-weight: 600;
    border-bottom: 3px solid transparent; transition: all .2s;
}
.project-tabs a:hover { color: var(--text-primary); }
.project-tabs a.active { color: var(--accent-color); border-bottom-color: var(--accent-color); }

.dept-pill-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.dept-pill {
    padding: 8px 14px; border-radius: 20px; font-size: .82rem; text-decoration: none; border: 1px solid var(--card-border);
    color: var(--text-secondary); display: inline-flex; align-items: center; gap: 6px; transition: all .2s;
}
.dept-pill:hover { border-color: var(--primary-color); color: var(--text-primary); }
.dept-pill.active { background: rgba(199,154,75,.12); border-color: var(--accent-color); color: var(--accent-color); font-weight: 600; }
.dept-pill.mine::after { content: '\f4fe'; font-family: 'Font Awesome 6 Free'; font-weight: 900; margin-left: 4px; color: var(--success-color); }
.dept-pill.filled { border-color: var(--success-color); }

.readonly-note {
    display: flex; align-items: center; gap: 8px; padding: 10px 14px; background: var(--overlay-1);
    border-radius: var(--radius-sm); color: var(--text-secondary); font-size: .82rem; margin-bottom: 16px;
}

.comment-form textarea { min-height: 100px; }
.small-link { font-size: .8rem; color: var(--text-secondary); text-decoration: none; }
.small-link:hover { color: var(--danger-color); }

@media (max-width: 768px) {
    .page-wrap { padding: 14px; }
    .topnav { padding: 12px 14px; }
    .topnav-links { width: 100%; order: 3; }
    .data-table { font-size: .8rem; }
    .data-table th, .data-table td { padding: 10px 8px; }
}

/* ===== Progress bars ===== */
.progress-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 110px;
}
.progress-track {
    flex: 1;
    height: 8px;
    background: var(--overlay-2, rgba(0,0,0,.08));
    border-radius: 99px;
    overflow: hidden;
    min-width: 60px;
}
.progress-fill {
    height: 100%;
    border-radius: 99px;
    transition: width .3s ease;
}
.progress-full { background: var(--success-color, #1f8a70); }
.progress-mid  { background: var(--warning-color, #c07a1e); }
.progress-low  { background: var(--primary-color, #1e3a5f); }
.progress-text {
    font-size: .75rem;
    color: var(--text-secondary);
    white-space: nowrap;
    font-weight: 600;
}

/* ===== Filter bar ===== */
.filter-bar {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    padding: 14px 16px;
    margin-bottom: 18px;
    box-shadow: var(--glass-shadow);
}
.filter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}
.filter-field {
    position: relative;
}
.filter-field select,
.filter-field input[type="date"],
.filter-field input[type="search"] {
    padding: 10px 12px;
    border: 1px solid var(--card-border);
    border-radius: var(--radius-md);
    background: var(--input-bg, #fff);
    color: var(--text-primary);
    font-size: .88rem;
    min-height: 40px;
}
.filter-search {
    flex: 1;
    min-width: 180px;
}
.filter-search i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    font-size: .85rem;
    pointer-events: none;
}
.filter-search input {
    width: 100%;
    padding-left: 34px;
}
.filter-result-count {
    margin-top: 10px;
    font-size: .82rem;
    color: var(--text-secondary);
}

/* ===== Dashboard ===== */
.dash-kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 14px;
    margin-bottom: 22px;
}
.dash-kpi {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 18px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--glass-shadow);
}
.dash-kpi-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}
.dash-kpi-value {
    font-size: 1.55rem;
    font-weight: 700;
    line-height: 1.1;
}
.dash-kpi-label {
    font-size: .78rem;
    color: var(--text-secondary);
    margin-top: 2px;
}
.dash-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}
.dash-panel {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    padding: 18px;
    box-shadow: var(--glass-shadow);
}
.dash-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
    gap: 10px;
}
.dash-panel-header h3 {
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 8px;
}
.dash-empty {
    text-align: center;
    color: var(--text-secondary);
    padding: 24px 12px;
    font-size: .9rem;
}
.dept-coverage-list { display: flex; flex-direction: column; gap: 10px; }
.dept-coverage-row {
    display: flex;
    align-items: center;
    gap: 12px;
}
.dept-coverage-name {
    width: 160px;
    flex-shrink: 0;
    font-size: .82rem;
    display: flex;
    align-items: center;
    gap: 6px;
}
.dept-coverage-bar {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
}
.dept-coverage-bar .progress-track { flex: 1; }

/* ===== Mobile 5M table → stacked cards ===== */
@media (max-width: 768px) {
    .dash-grid { grid-template-columns: 1fr; }
    .dept-coverage-name { width: 120px; font-size: .75rem; }
    .filter-row { flex-direction: column; align-items: stretch; }
    .filter-field select,
    .filter-field input[type="date"] { width: 100%; }

    /* Transform sixm-table into stacked cards */
    .sixm-table thead { display: none; }
    .sixm-table,
    .sixm-table tbody,
    .sixm-table tr,
    .sixm-table td {
        display: block;
        width: 100%;
    }
    .sixm-table tr.category-row {
        background: transparent;
        margin-top: 16px;
    }
    .sixm-table tr.category-row td {
        background: var(--primary-color, #1e3a5f);
        color: #fff;
        font-weight: 700;
        border-radius: 10px 10px 0 0;
        padding: 12px 14px;
        border: none;
        font-size: .95rem;
    }
    .sixm-table tr:not(.category-row) {
        background: var(--glass-bg, #fff);
        border: 1px solid var(--card-border);
        border-top: none;
        border-radius: 0 0 10px 10px;
        margin-bottom: 12px;
        padding: 12px;
        box-shadow: 0 2px 8px rgba(0,0,0,.04);
    }
    .sixm-table tr:not(.category-row) td {
        border: none;
        padding: 6px 0;
    }
    .sixm-table tr:not(.category-row) td:first-child {
        font-size: .78rem;
        color: var(--text-secondary);
        padding-bottom: 8px;
    }
    .sixm-table tr:not(.category-row) td:nth-child(2)::before {
        content: 'Findings / Requests / Limitations';
        display: block;
        font-size: .75rem;
        font-weight: 600;
        color: var(--text-secondary);
        margin-bottom: 4px;
    }
    .sixm-table tr:not(.category-row) td:nth-child(3)::before {
        content: 'Related Actions';
        display: block;
        font-size: .75rem;
        font-weight: 600;
        color: var(--text-secondary);
        margin-bottom: 4px;
        margin-top: 8px;
    }
    .sixm-table .table-textarea {
        min-height: 80px;
        width: 100%;
    }
    .table-container {
        overflow: visible;
    }
}

/* ===== Multi-select dropdown with tags ===== */
.ms-wrap { position: relative; }
.ms-trigger {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    min-height: 44px; padding: 10px 14px; border: 1px solid var(--card-border);
    border-radius: var(--radius-md); background: var(--input-bg); cursor: pointer;
    color: var(--text-primary); font-size: .9rem;
}
.ms-trigger:hover { border-color: var(--primary-color); }
.ms-trigger i.chev { transition: transform .2s; color: var(--text-secondary); }
.ms-wrap.open .ms-trigger i.chev { transform: rotate(180deg); }
.ms-dropdown {
    display: none; position: absolute; z-index: 50; left: 0; right: 0; top: calc(100% + 4px);
    max-height: 220px; overflow-y: auto; background: var(--card-bg); border: 1px solid var(--card-border);
    border-radius: var(--radius-md); box-shadow: var(--shadow-md); padding: 6px;
}
.ms-wrap.open .ms-dropdown { display: block; }
.ms-option {
    display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--radius-sm);
    cursor: pointer; font-size: .88rem; color: var(--text-primary);
}
.ms-option:hover { background: var(--overlay-1); }
.ms-option input { accent-color: var(--primary-color); }
.ms-tags { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; min-height: 8px; }
.ms-tag {
    display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px 6px 14px;
    background: rgba(0, 61, 166, 0.12); border: 1px solid rgba(0, 61, 166, 0.25);
    color: var(--primary-color); border-radius: 999px; font-size: .82rem; font-weight: 600;
}
html[data-theme="light"] .ms-tag { background: rgba(0, 61, 166, 0.08); }
.ms-tag button {
    background: none; border: none; color: var(--danger-color); cursor: pointer;
    width: 22px; height: 22px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
    font-size: .75rem;
}
.ms-tag button:hover { background: rgba(239, 61, 77, 0.15); }

/* Full-width stacked fields */
.form-stack { display: flex; flex-direction: column; gap: 18px; margin-top: 24px; }
.form-stack .form-group { width: 100%; }
.form-stack .form-textarea { width: 100%; min-height: 120px; }

/* Status badges */
.badge-ongoing { background: rgba(0, 188, 255, 0.15); color: var(--info-color, #00BCFF); }
.badge-done { background: rgba(4, 167, 92, 0.15); color: var(--success-color); }

/* Theme toggle button */
.theme-toggle-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--card-border);
    background: var(--overlay-1); color: var(--accent-color); cursor: pointer;
    transition: all .2s; font-size: 1rem;
}
.theme-toggle-btn:hover { background: var(--overlay-2); transform: scale(1.06); }

/* Soften any remaining sharp corners */
.btn, .form-input, .form-select, .form-textarea, .section, .data-table-wrap,
.auth-box, .conclusion-card, .uploaded-file-item, .dept-note-textarea,
.table-textarea, .sig-input {
    border-radius: var(--radius-md) !important;
}
.section { border-radius: var(--radius-lg) !important; }

/* ===== Badge dots ===== */
.badge-dot {
    width: 7px; height: 7px; border-radius: 50%; display: inline-block;
    background: currentColor; opacity: .9; flex-shrink: 0;
}
.badge-possible .badge-dot, .badge-done .badge-dot { background: #22C55E; }
.badge-conditional .badge-dot, .badge-ongoing .badge-dot { background: #F59E0B; }
.badge-not-possible .badge-dot { background: #EF4444; }
.badge-pending .badge-dot { background: #94A3B8; }
.badge-ongoing .badge-dot { background: #3B82F6; }

/* ===== User avatars ===== */
.user-avatar {
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 50%; font-weight: 700; color: #fff; flex-shrink: 0;
    background: linear-gradient(135deg, #1E3A8A, #3B82F6);
    letter-spacing: .02em; user-select: none;
}
.user-avatar-sm { width: 28px; height: 28px; font-size: .68rem; }
.user-avatar-md { width: 36px; height: 36px; font-size: .78rem; }
.user-avatar-lg { width: 48px; height: 48px; font-size: .95rem; }
.owner-cell { display: flex; align-items: center; gap: 8px; }

/* ===== Notifications ===== */
.notif-wrap { position: relative; }
.notif-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--card-border);
    background: var(--overlay-1); color: var(--text-primary); cursor: pointer;
    transition: all .2s; font-size: 1rem; position: relative;
}
.notif-btn:hover { background: var(--overlay-2); }
.notif-badge {
    position: absolute; top: 4px; right: 4px; min-width: 16px; height: 16px;
    background: #EF4444; color: #fff; font-size: .65rem; font-weight: 700;
    border-radius: 99px; display: flex; align-items: center; justify-content: center;
    padding: 0 4px; border: 2px solid var(--card-bg);
}
.notif-dropdown {
    display: none; position: absolute; top: calc(100% + 8px); right: 0; width: 320px;
    background: var(--card-bg); border: 1px solid var(--card-border); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg); z-index: 200; overflow: hidden;
}
.notif-dropdown.open { display: block; animation: fadeIn .2s; }
.notif-header {
    padding: 12px 16px; font-weight: 700; font-size: .88rem;
    border-bottom: 1px solid var(--card-border); color: var(--text-primary);
}
.notif-empty { padding: 20px 16px; text-align: center; color: var(--text-secondary); font-size: .85rem; }
.notif-item {
    display: flex; align-items: flex-start; gap: 10px; padding: 12px 16px;
    text-decoration: none; color: var(--text-primary); font-size: .85rem;
    border-bottom: 1px solid var(--card-border); transition: background .15s;
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--overlay-1); }
.notif-item i { color: var(--primary-color); margin-top: 2px; width: 16px; text-align: center; }

/* ===== Home KPI strip ===== */
.home-kpis {
    display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px;
}
.home-kpi {
    display: flex; align-items: center; gap: 14px; padding: 18px 20px;
    background: var(--glass-bg); border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg); box-shadow: var(--glass-shadow);
    text-decoration: none; color: var(--text-primary); transition: all .25s;
}
.home-kpi:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.home-kpi-icon {
    width: 48px; height: 48px; border-radius: 12px; display: flex;
    align-items: center; justify-content: center; font-size: 1.25rem; flex-shrink: 0;
}
.kpi-total .home-kpi-icon { background: rgba(30,58,138,.12); color: #1E3A8A; }
.kpi-done .home-kpi-icon { background: rgba(34,197,94,.12); color: #22C55E; }
.kpi-progress .home-kpi-icon { background: rgba(59,130,246,.12); color: #3B82F6; }
.kpi-overdue .home-kpi-icon { background: rgba(239,68,68,.12); color: #EF4444; }
html[data-theme="dark"] .kpi-total .home-kpi-icon { background: rgba(59,130,246,.18); color: #60A5FA; }
.home-kpi-value { font-size: 1.6rem; font-weight: 800; line-height: 1.1; }
.home-kpi-label { font-size: .8rem; color: var(--text-secondary); margin-top: 2px; font-weight: 500; }

/* ===== Project cards ===== */
.project-cards {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px;
}
.project-card {
    display: flex; flex-direction: column; gap: 10px; padding: 18px;
    background: var(--glass-bg); border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg); box-shadow: var(--glass-shadow);
    text-decoration: none; color: var(--text-primary); transition: all .25s;
}
.project-card:hover {
    transform: translateY(-4px); box-shadow: var(--shadow-md);
    border-color: rgba(59,130,246,.35);
}
.project-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.project-card-title { font-weight: 700; font-size: 1.02rem; line-height: 1.35; flex: 1; }
.project-card-number { font-size: .8rem; color: var(--text-secondary); font-weight: 500; }
.project-card-progress { margin: 4px 0; }
.project-card-meta {
    display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
}
.project-card-owner { display: flex; align-items: center; gap: 8px; font-size: .82rem; color: var(--text-secondary); }
.project-card-right { display: flex; gap: 6px; flex-wrap: wrap; }
.project-card-footer {
    display: flex; justify-content: space-between; gap: 10px; font-size: .75rem;
    color: var(--text-secondary); padding-top: 8px; border-top: 1px solid var(--card-border);
}
.project-card-footer i { margin-right: 4px; opacity: .7; }

.progress-wrap-lg .progress-track { height: 10px; min-width: 80px; }
.progress-wrap-lg .progress-text { font-size: .8rem; min-width: 36px; }

/* View toggle */
.filter-footer {
    display: flex; align-items: center; justify-content: space-between; margin-top: 10px; gap: 12px;
}
.view-toggle {
    display: inline-flex; border: 1px solid var(--card-border); border-radius: var(--radius-md); overflow: hidden;
}
.view-btn {
    padding: 7px 12px; color: var(--text-secondary); text-decoration: none; background: transparent;
    transition: all .15s; font-size: .9rem;
}
.view-btn.active, .view-btn:hover { background: var(--overlay-2); color: var(--primary-color); }
.view-btn + .view-btn { border-left: 1px solid var(--card-border); }

/* Needs action panel */
.needs-action-panel {
    background: var(--glass-bg); border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg); padding: 16px 18px; margin-bottom: 18px;
    box-shadow: var(--glass-shadow);
}
.needs-action-list {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px;
}
.needs-action-item {
    padding: 12px 14px; border-radius: var(--radius-md); border: 1px solid var(--card-border);
    background: var(--input-bg); text-decoration: none; color: var(--text-primary); transition: all .2s;
}
.needs-action-item:hover { border-color: var(--primary-color); background: var(--overlay-1); }
.needs-action-title { font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
.needs-action-meta { display: flex; align-items: center; gap: 10px; font-size: .75rem; color: var(--text-secondary); }

.empty-state {
    grid-column: 1 / -1; text-align: center; padding: 60px 20px; color: var(--text-secondary);
}
.empty-state i { font-size: 2.5rem; margin-bottom: 12px; opacity: .4; display: block; }
.empty-state p { margin-bottom: 16px; }

/* ===== Charts ===== */
.chart-wrap { position: relative; height: 240px; width: 100%; }

/* Latest list */
.latest-list { display: flex; flex-direction: column; gap: 8px; }
.latest-item {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 12px; border-radius: var(--radius-md); border: 1px solid var(--card-border);
    text-decoration: none; color: var(--text-primary); transition: background .15s;
}
.latest-item:hover { background: var(--overlay-1); }
.latest-item-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.latest-item-main strong { font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.latest-item-main span { font-size: .75rem; color: var(--text-secondary); }
.latest-item-side { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

/* Activity timeline */
.activity-timeline { display: flex; flex-direction: column; gap: 0; }
.activity-item {
    display: flex; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--card-border);
}
.activity-item:last-child { border-bottom: none; }
.activity-body { flex: 1; min-width: 0; }
.activity-line { font-size: .88rem; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.activity-details { font-size: .8rem; color: var(--text-secondary); margin-top: 4px; }
.activity-time { font-size: .72rem; color: var(--text-secondary); margin-top: 4px; opacity: .8; }

/* ===== Project timeline ===== */
.project-timeline {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 0; margin: 20px 0 28px; padding: 20px 12px;
    background: var(--glass-bg); border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg); overflow-x: auto;
}
.tl-step {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 8px;
    position: relative; min-width: 90px; text-align: center;
}
.tl-step:not(:last-child)::after {
    content: ''; position: absolute; top: 16px; left: calc(50% + 18px); right: calc(-50% + 18px);
    height: 3px; background: var(--card-border); border-radius: 2px; z-index: 0;
}
.tl-step.done:not(:last-child)::after { background: #22C55E; }
.tl-step.active:not(:last-child)::after { background: linear-gradient(90deg, #22C55E, var(--card-border)); }
.tl-dot {
    width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center;
    justify-content: center; font-size: .85rem; z-index: 1; border: 2px solid var(--card-border);
    background: var(--card-bg); color: var(--text-secondary); transition: all .25s;
}
.tl-step.done .tl-dot { background: #22C55E; border-color: #22C55E; color: #fff; }
.tl-step.active .tl-dot { background: #3B82F6; border-color: #3B82F6; color: #fff; box-shadow: 0 0 0 4px rgba(59,130,246,.2); }
.tl-label { font-size: .75rem; font-weight: 600; color: var(--text-secondary); }
.tl-step.done .tl-label, .tl-step.active .tl-label { color: var(--text-primary); }
.tl-sub { font-size: .68rem; color: var(--text-secondary); opacity: .8; }

/* ===== Login page ===== */
.login-body { position: relative; min-height: 100vh; overflow: hidden; }
.login-bg { position: fixed; inset: 0; z-index: 0; pointer-events: none; }
.login-orb {
    position: absolute; border-radius: 50%; filter: blur(80px); opacity: .45;
}
.login-orb-1 {
    width: 420px; height: 420px; background: #1E3A8A; top: -80px; left: -80px;
    animation: orbFloat 12s ease-in-out infinite;
}
.login-orb-2 {
    width: 360px; height: 360px; background: #3B82F6; bottom: -60px; right: -40px;
    animation: orbFloat 14s ease-in-out infinite reverse;
}
.login-orb-3 {
    width: 240px; height: 240px; background: #22C55E; top: 40%; left: 50%;
    opacity: .2; animation: orbFloat 10s ease-in-out infinite;
}
@keyframes orbFloat {
    0%, 100% { transform: translate(0, 0); }
    50% { transform: translate(30px, -20px); }
}
.login-page { position: relative; z-index: 1; }
.login-card { animation: loginIn .5s ease; }
@keyframes loginIn {
    from { opacity: 0; transform: translateY(16px) scale(.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
.login-brand {
    display: flex; align-items: center; gap: 14px; margin-bottom: 22px;
}
.login-brand img { width: 56px; height: 56px; border-radius: 14px; object-fit: cover; }
.login-brand h2 { font-size: 1.2rem; font-weight: 800; margin: 0; }
.login-brand p { font-size: .78rem; color: var(--text-secondary); margin: 0; }
.login-options {
    display: flex; align-items: center; justify-content: space-between;
    margin: 8px 0 4px; font-size: .82rem;
}
.remember-me { display: flex; align-items: center; gap: 6px; color: var(--text-secondary); cursor: pointer; }
.remember-me input { accent-color: var(--primary-color); }
.forgot-hint { color: var(--primary-color); cursor: help; opacity: .8; }
.login-submit { width: 100%; justify-content: center; margin-top: 12px; padding: 14px; font-size: 1rem; }
.login-footer {
    text-align: center; margin-top: 18px; font-size: .75rem; color: var(--text-secondary); opacity: .7;
}

/* Info summary cards on project page */
.info-summary-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 20px;
}
.info-summary-card {
    padding: 14px 16px; border-radius: var(--radius-md); border: 1px solid var(--card-border);
    background: var(--input-bg);
}
.info-summary-card .label { font-size: .72rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .4px; margin-bottom: 4px; }
.info-summary-card .value { font-size: .95rem; font-weight: 600; }

@media (max-width: 900px) {
    .home-kpis { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
    .home-kpis { grid-template-columns: 1fr; }
    .project-timeline { padding: 16px 8px; }
    .tl-step { min-width: 70px; }
    .tl-label { font-size: .68rem; }
}

/* ===== Score pills ===== */
.score-pill {
    display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
    min-width: 64px; padding: 8px 12px; border-radius: 14px; border: 2px solid transparent;
    font-weight: 800;
}
.score-pill .score-num { font-size: 1.35rem; line-height: 1.1; }
.score-pill .score-label { font-size: .7rem; font-weight: 600; letter-spacing: .5px; opacity: .9; }
.score-pill-lg { min-width: 100px; padding: 16px 20px; border-radius: 18px; }
.score-pill-lg .score-num { font-size: 2.2rem; }
.score-pill-lg .score-label { font-size: .85rem; margin-top: 4px; }
.score-high { background: rgba(34,197,94,.15); color: #16A34A; border-color: rgba(34,197,94,.35); }
.score-mid { background: rgba(245,158,11,.15); color: #D97706; border-color: rgba(245,158,11,.35); }
.score-low { background: rgba(239,68,68,.15); color: #DC2626; border-color: rgba(239,68,68,.35); }
.score-none { background: var(--overlay-1); color: var(--text-secondary); border-color: var(--card-border); }

.badge-priority-low { background: rgba(34,197,94,.15); color: #22C55E; }
.badge-priority-medium { background: rgba(59,130,246,.15); color: #3B82F6; }
.badge-priority-high { background: rgba(245,158,11,.15); color: #F59E0B; }
.badge-priority-critical { background: rgba(239,68,68,.15); color: #EF4444; }
.badge-risk-low { background: rgba(34,197,94,.15); color: #22C55E; }
.badge-risk-medium { background: rgba(245,158,11,.15); color: #F59E0B; }
.badge-risk-high { background: rgba(239,68,68,.15); color: #EF4444; }

/* Executive summary strip */
.exec-summary {
    display: grid; grid-template-columns: auto 1fr auto; gap: 20px; align-items: center;
    padding: 18px 20px; margin-bottom: 20px;
    background: var(--glass-bg); border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg); box-shadow: var(--glass-shadow);
}
.exec-meta-grid {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 20px;
}
.exec-meta-item .label {
    display: block; font-size: .7rem; text-transform: uppercase; letter-spacing: .4px;
    color: var(--text-secondary); margin-bottom: 4px;
}
.exec-meta-item .value { font-size: .95rem; font-weight: 600; }
.exec-radar { width: 180px; height: 180px; }

.mgmt-report-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px;
}

/* File preview */
.file-preview-thumb {
    display: block; border-radius: var(--radius-sm); overflow: hidden;
    margin-bottom: 10px; border: 1px solid var(--card-border); max-height: 140px;
}
.file-preview-thumb img { width: 100%; height: 140px; object-fit: cover; display: block; }

/* Risks */
.risk-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.risk-card {
    padding: 14px 16px; border-radius: var(--radius-md); border: 1px solid var(--card-border);
    background: var(--input-bg); border-left: 4px solid #94A3B8;
}
.risk-card.severity-high { border-left-color: #EF4444; }
.risk-card.severity-medium { border-left-color: #F59E0B; }
.risk-card.severity-low { border-left-color: #22C55E; }
.risk-card-top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; margin-bottom: 6px; }
.risk-desc { font-size: .85rem; color: var(--text-secondary); margin: 6px 0 10px; }
.risk-meta { display: flex; flex-wrap: wrap; gap: 10px; font-size: .78rem; color: var(--text-secondary); margin-bottom: 10px; }
.risk-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Gantt simple */
.gantt-wrap { overflow-x: auto; }
.gantt-row {
    display: grid; grid-template-columns: 200px 1fr; gap: 12px; align-items: center;
    padding: 8px 0; border-bottom: 1px solid var(--card-border); font-size: .85rem;
}
.gantt-bar-track {
    position: relative; height: 22px; background: var(--overlay-1); border-radius: 6px; min-width: 400px;
}
.gantt-bar {
    position: absolute; top: 2px; height: 18px; border-radius: 5px; font-size: .65rem;
    color: #fff; display: flex; align-items: center; padding: 0 6px; white-space: nowrap;
    overflow: hidden; background: #3B82F6;
}
.gantt-bar.done { background: #22C55E; }
.gantt-bar.overdue { background: #EF4444; }

@media (max-width: 900px) {
    .exec-summary { grid-template-columns: 1fr; }
    .exec-radar { width: 100%; max-width: 220px; margin: 0 auto; }
    .exec-meta-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ===== RBAC badges ===== */
.badge-approver { background: rgba(139,92,246,.15); color: #8B5CF6; }
.badge-viewer { background: rgba(148,163,184,.2); color: #64748B; }

/* ===== Workflow admin ===== */
.wf-layout { display: grid; grid-template-columns: 280px 1fr; gap: 20px; align-items: start; }
.wf-sidebar {
    background: var(--glass-bg); border: 1px solid var(--glass-border); border-radius: var(--radius-lg);
    padding: 16px; box-shadow: var(--glass-shadow); position: sticky; top: 80px;
}
.wf-sidebar h3 { font-size: 1rem; margin-bottom: 12px; }
.wf-tpl-list { list-style: none; margin: 0 0 16px; padding: 0; }
.wf-tpl-list a {
    display: flex; flex-direction: column; gap: 4px; padding: 10px 12px; border-radius: var(--radius-md);
    text-decoration: none; color: var(--text-primary); margin-bottom: 4px; border: 1px solid transparent;
}
.wf-tpl-list a:hover { background: var(--overlay-1); }
.wf-tpl-list a.active { background: rgba(59,130,246,.1); border-color: rgba(59,130,246,.3); }
.wf-tpl-list .muted { font-size: .72rem; color: var(--text-secondary); }
.wf-new-tpl { border-top: 1px solid var(--card-border); padding-top: 14px; }
.wf-stage-row {
    display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px;
    border: 1px solid var(--card-border); border-radius: var(--radius-md); margin-bottom: 8px;
    background: var(--input-bg);
}
.wf-stage-color { width: 12px; height: 32px; border-radius: 4px; flex-shrink: 0; }
.wf-gate { font-size: .78rem; color: var(--text-secondary); display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.wf-stage-add { border-style: dashed; }

/* ===== Project workflow panel ===== */
.wf-project-panel {
    background: var(--glass-bg); border: 1px solid var(--glass-border); border-radius: var(--radius-lg);
    padding: 18px 20px; margin-bottom: 20px; box-shadow: var(--glass-shadow);
}
.wf-project-header {
    display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 16px;
}
.wf-project-header h3 { font-size: 1.05rem; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.wf-tpl-name {
    font-size: .78rem; font-weight: 600; padding: 3px 10px; border-radius: 99px;
    background: rgba(59,130,246,.12); color: #3B82F6;
}
.wf-project-header p { font-size: .85rem; color: var(--text-secondary); margin-top: 4px; }
.wf-project-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.wf-stage-track {
    display: flex; align-items: flex-start; gap: 0; overflow-x: auto; padding: 8px 0 12px;
}
.wf-stage-node {
    display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 90px; text-align: center;
}
.wf-stage-dot {
    width: 32px; height: 32px; border-radius: 50%; border: 2px solid var(--card-border);
    background: var(--card-bg); display: flex; align-items: center; justify-content: center;
    font-size: .75rem; font-weight: 700; color: var(--text-secondary); z-index: 1;
}
.wf-stage-node.done .wf-stage-dot { color: #fff; }
.wf-stage-node.current .wf-stage-dot { color: #fff; box-shadow: 0 0 0 4px rgba(59,130,246,.2); }
.wf-stage-label { font-size: .75rem; font-weight: 600; max-width: 100px; }
.wf-stage-node.todo .wf-stage-label { color: var(--text-secondary); }
.wf-stage-meta { font-size: .7rem; min-height: 14px; }
.wf-stage-line {
    flex: 1; min-width: 24px; height: 3px; background: var(--card-border); margin-top: 14px; border-radius: 2px;
}
.wf-stage-line.done { background: #22C55E; }
.wf-assign-form {
    display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 12px;
    padding-top: 12px; border-top: 1px solid var(--card-border);
}
.wf-log-details { margin-top: 12px; font-size: .85rem; }
.wf-log-details summary { cursor: pointer; color: var(--text-secondary); font-weight: 600; }
.wf-log-list { list-style: none; margin: 10px 0 0; padding: 0; }
.wf-log-list li { padding: 8px 0; border-bottom: 1px solid var(--card-border); }
.wf-log-list .muted { font-size: .78rem; color: var(--text-secondary); }

@media (max-width: 900px) {
    .wf-layout { grid-template-columns: 1fr; }
    .wf-sidebar { position: static; }
}

.notif-header { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.notif-item.notif-unread { background: rgba(59,130,246,.08); font-weight: 600; }
.notif-item.notif-unread::before {
    content: ''; width: 8px; height: 8px; border-radius: 50%; background: #3B82F6; flex-shrink: 0; margin-top: 6px;
}
.dept-pill.assigned-dept { border-color: rgba(59,130,246,.4); }

/* ============================================================
   MOBILE UX v8 — hamburger, bottom nav, touch targets, safe-area
   ============================================================ */

/* ---- Hamburger button (hidden on desktop) ---- */
.nav-burger {
    display: none;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: 1px solid var(--card-border);
    background: var(--overlay-1);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 1.15rem;
    flex-shrink: 0;
    transition: background .2s;
    -webkit-tap-highlight-color: transparent;
}
.nav-burger:active { background: var(--overlay-2); }

/* ---- Mobile slide-out drawer ---- */
.mobile-drawer-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 900;
    opacity: 0;
    transition: opacity .25s ease;
    -webkit-tap-highlight-color: transparent;
}
.mobile-drawer-overlay.open { display: block; opacity: 1; }

.mobile-drawer {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(320px, 86vw);
    background: var(--card-bg);
    border-right: 1px solid var(--card-border);
    z-index: 910;
    transform: translateX(-105%);
    transition: transform .28s cubic-bezier(.32,.72,0,1);
    display: flex;
    flex-direction: column;
    padding: calc(16px + env(safe-area-inset-top, 0px)) 0 calc(16px + env(safe-area-inset-bottom, 0px));
    box-shadow: 8px 0 32px rgba(0,0,0,.18);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.mobile-drawer.open { transform: translateX(0); }

.mobile-drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px 16px;
    border-bottom: 1px solid var(--card-border);
    gap: 12px;
}
.mobile-drawer-head .brand-text strong {
    display: block;
    font-size: 1rem;
    font-weight: 800;
}
.mobile-drawer-head .brand-text span {
    font-size: .72rem;
    color: var(--text-secondary);
}
.mobile-drawer-close {
    width: 40px; height: 40px; border-radius: 10px;
    border: 1px solid var(--card-border); background: var(--overlay-1);
    color: var(--text-primary); cursor: pointer; font-size: 1.1rem;
    display: flex; align-items: center; justify-content: center;
}

.mobile-drawer-user {
    display: flex; align-items: center; gap: 12px;
    padding: 16px; border-bottom: 1px solid var(--card-border);
}
.mobile-drawer-user strong { display: block; font-size: .92rem; }
.mobile-drawer-user span { font-size: .75rem; color: var(--text-secondary); }

.mobile-drawer-links {
    display: flex; flex-direction: column; padding: 12px 10px; gap: 4px; flex: 1;
}
.mobile-drawer-links a {
    display: flex; align-items: center; gap: 14px;
    padding: 14px 16px; border-radius: 12px;
    color: var(--text-primary); text-decoration: none;
    font-size: .95rem; font-weight: 600;
    transition: background .15s;
    min-height: 48px;
}
.mobile-drawer-links a i {
    width: 22px; text-align: center; color: var(--primary-color); font-size: 1.05rem;
}
.mobile-drawer-links a:active,
.mobile-drawer-links a:hover { background: var(--overlay-1); }

.mobile-drawer-footer {
    padding: 12px 16px; border-top: 1px solid var(--card-border);
    display: flex; flex-direction: column; gap: 8px;
}
.mobile-drawer-footer .btn { width: 100%; justify-content: center; min-height: 48px; }

/* ---- Bottom tab bar ---- */
.bottom-tab-bar {
    display: none;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 80;
    background: var(--glass-bg);
    backdrop-filter: blur(20px) saturate(160%);
    -webkit-backdrop-filter: blur(20px) saturate(160%);
    border-top: 1px solid var(--glass-border);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -4px 24px rgba(0,0,0,.08);
}
.bottom-tab-item {
    flex: 1;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; padding: 8px 4px;
    color: var(--text-secondary); text-decoration: none;
    font-size: .65rem; font-weight: 600;
    border-radius: 10px;
    min-height: 52px;
    -webkit-tap-highlight-color: transparent;
    transition: color .15s, background .15s;
}
.bottom-tab-item i { font-size: 1.2rem; }
.bottom-tab-item.active {
    color: var(--accent-color, #c79a4b);
    background: rgba(199,154,75,.1);
}
.bottom-tab-item:active { background: var(--overlay-1); }

/* Body padding when bottom bar is visible */
body.has-bottom-nav { padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px)); }

/* ---- Sticky mobile form actions ---- */
.mobile-sticky-actions {
    display: none;
    position: sticky;
    bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    z-index: 40;
    margin-top: 20px;
    padding: 12px;
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    gap: 10px;
}
.mobile-sticky-actions .btn {
    flex: 1;
    justify-content: center;
    min-height: 48px;
    font-size: 1rem;
}

/* ---- Touch-friendly form controls ---- */
@media (max-width: 768px) {
    .form-input,
    .form-select,
    .form-textarea,
    .table-textarea,
    .sig-input {
        min-height: 48px !important;
        font-size: 16px !important; /* prevents iOS zoom on focus */
        padding: 12px 14px !important;
    }
    .form-textarea,
    .table-textarea {
        min-height: 100px !important;
    }
    .btn {
        min-height: 48px;
        padding: 12px 18px;
        font-size: .95rem;
    }
    .btn-sm, .btn[style*="padding:6px"], .btn[style*="padding:8px"] {
        min-height: 40px;
        padding: 10px 14px !important;
    }
    .option-item {
        min-height: 48px;
        padding: 10px 12px;
    }
    .option-label {
        font-size: .92rem;
        padding: 4px 0;
    }

    /* Topnav mobile */
    .nav-burger { display: inline-flex; }
    .topnav-links { display: none !important; }
    .topnav-user-info { display: none; }
    .topnav-user .btn { display: none; } /* logout moves to drawer */
    .topnav {
        padding: 10px 12px;
        padding-top: calc(10px + env(safe-area-inset-top, 0px));
        gap: 10px;
        position: sticky;
        top: 0;
        z-index: 100;
    }
    .topnav-brand img { width: 36px; height: 36px; }
    .topnav-brand strong { font-size: .95rem; }
    .topnav-brand span { display: none; }
    .topnav-user { gap: 8px; margin-left: auto; }

    /* Notification dropdown full-width on mobile */
    .notif-dropdown {
        position: fixed;
        top: auto;
        left: 12px;
        right: 12px;
        width: auto;
        max-height: 60vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: var(--radius-lg);
    }

    /* Bottom tab bar */
    .bottom-tab-bar { display: flex; }
    body.has-bottom-nav { padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px)); }

    /* Sticky save buttons */
    .mobile-sticky-actions { display: flex; }

    /* Project tabs → horizontal scroll chips */
    .project-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        gap: 4px;
        margin-left: -14px;
        margin-right: -14px;
        padding: 0 14px 8px;
        border-bottom: 1px solid var(--card-border);
    }
    .project-tabs::-webkit-scrollbar { display: none; }
    .project-tabs a {
        white-space: nowrap;
        padding: 12px 14px;
        font-size: .82rem;
        border-bottom-width: 3px;
        flex-shrink: 0;
    }

    /* Dept pills scroll */
    .dept-pill-list {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding-bottom: 6px;
        margin-left: -4px;
        margin-right: -4px;
        padding-left: 4px;
        padding-right: 4px;
    }
    .dept-pill-list::-webkit-scrollbar { display: none; }
    .dept-pill {
        flex-shrink: 0;
        padding: 10px 14px;
        min-height: 40px;
    }

    /* Page header stack */
    .page-header {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }
    .page-header .btn,
    .page-header > div:last-child {
        width: 100%;
    }
    .page-header > div:last-child {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }
    .page-header > div:last-child .btn {
        flex: 1;
        justify-content: center;
        min-width: 120px;
    }
    .page-header h1 { font-size: 1.35rem; }

    /* Data tables horizontal scroll with sticky first col hint */
    .data-table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin-left: -14px;
        margin-right: -14px;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }
    .data-table {
        min-width: 640px;
        font-size: .82rem;
    }

    /* Cards denser */
    .project-cards {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    .project-card {
        padding: 16px;
        border-radius: 14px;
    }
    .project-card:active {
        transform: scale(.98);
    }

    /* KPI grid */
    .home-kpis {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    .home-kpi {
        padding: 14px;
    }
    .home-kpi-value { font-size: 1.35rem; }
    .dash-kpis {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    .dash-kpi { padding: 14px; gap: 10px; }
    .dash-kpi-icon { width: 40px; height: 40px; font-size: 1rem; }
    .dash-kpi-value { font-size: 1.3rem; }

    /* Filter bar stack */
    .filter-bar { padding: 12px; }
    .filter-row {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }
    .filter-field select,
    .filter-field input[type="date"],
    .filter-field input[type="search"] {
        width: 100%;
        min-height: 48px;
        font-size: 16px;
    }
    .filter-search { min-width: 0; }

    /* Gantt mobile */
    .gantt-row {
        grid-template-columns: 1fr;
        gap: 6px;
    }
    .gantt-bar-track { min-width: 280px; }

    /* Timeline compact */
    .project-timeline {
        padding: 14px 6px;
        gap: 0;
    }
    .tl-step { min-width: 64px; }
    .tl-dot { width: 28px; height: 28px; font-size: .75rem; }
    .tl-label { font-size: .65rem; }

    /* Exec summary */
    .exec-summary {
        grid-template-columns: 1fr;
        gap: 14px;
        padding: 14px;
    }
    .exec-meta-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .exec-radar { width: 100%; max-width: 200px; margin: 0 auto; height: 160px; }

    /* Form grids single column */
    .form-grid {
        grid-template-columns: 1fr !important;
        gap: 14px;
    }

    /* Signature items stack */
    .signature-item {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }
    .signature-item .form-input,
    .signature-item .sig-input {
        max-width: none !important;
        width: 100%;
    }

    /* Uploaded files */
    .uploaded-files {
        grid-template-columns: 1fr !important;
    }

    /* Risk cards */
    .risk-list {
        grid-template-columns: 1fr;
    }

    /* Multiselect */
    .ms-trigger { min-height: 48px; }
    .ms-option { padding: 14px 12px; min-height: 48px; }

    /* Workflow admin */
    .wf-stage-row {
        flex-wrap: wrap;
        gap: 8px;
    }
    .wf-stage-row .form-input,
    .wf-stage-row .form-select {
        max-width: none !important;
        flex: 1 1 120px;
    }

    /* Auth boxes */
    .auth-box {
        padding: 28px 20px;
        margin: 12px;
    }
    .centered-page {
        padding: 12px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    }

    /* Section padding */
    .section {
        padding: 16px !important;
    }
    .page-wrap {
        padding: 12px;
        padding-bottom: 24px;
    }

    /* Info summary */
    .info-summary-grid {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    /* Needs action */
    .needs-action-list {
        grid-template-columns: 1fr;
    }

    /* Comment items */
    .comment-item {
        padding: 14px !important;
    }

    /* Hide desktop-only export row overflow */
    .export-actions,
    .project-actions-row {
        flex-wrap: wrap;
        gap: 8px;
    }
    .export-actions .btn,
    .project-actions-row .btn {
        flex: 1 1 auto;
        justify-content: center;
        min-width: calc(50% - 8px);
    }
}

@media (max-width: 480px) {
    .home-kpis { grid-template-columns: 1fr 1fr; }
    .dash-kpis { grid-template-columns: 1fr 1fr; }
    .info-summary-grid { grid-template-columns: 1fr; }
    .topnav-brand strong { font-size: .88rem; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .page-header h1 { font-size: 1.2rem; }
    .score-pill-lg .score-num { font-size: 1.8rem; }
}

/* Landscape phones */
@media (max-width: 900px) and (orientation: landscape) {
    .bottom-tab-bar { padding-bottom: env(safe-area-inset-bottom, 0px); }
    .mobile-drawer { width: min(280px, 70vw); }
}

/* Reduce motion preference */
@media (prefers-reduced-motion: reduce) {
    .mobile-drawer,
    .mobile-drawer-overlay,
    .project-card {
        transition: none !important;
    }
}

/* Touch device: remove hover transform jank */
@media (hover: none) {
    .project-card:hover,
    .home-kpi:hover {
        transform: none;
    }
    .project-card:active {
        transform: scale(.985);
        opacity: .95;
    }
}

/* ============================================================
   RTL + Persian typography (v9)
   ============================================================ */
html[dir="rtl"] body,
html[lang="fa"] body {
    font-family: 'Vazirmatn', 'Inter', system-ui, sans-serif;
}
html[dir="rtl"] {
    direction: rtl;
}
html[dir="rtl"] .topnav-user-info { text-align: left; }
html[dir="rtl"] .topnav-brand { flex-direction: row; }
html[dir="rtl"] .notif-dropdown {
    right: auto;
    left: 0;
}
html[dir="rtl"] .mobile-drawer {
    left: auto;
    right: 0;
    transform: translateX(105%);
    border-right: none;
    border-left: 1px solid var(--card-border);
    box-shadow: -8px 0 32px rgba(0,0,0,.18);
}
html[dir="rtl"] .mobile-drawer.open { transform: translateX(0); }
html[dir="rtl"] .filter-search i { left: auto; right: 12px; }
html[dir="rtl"] .filter-search input { padding-left: 12px; padding-right: 34px; }
html[dir="rtl"] .data-table th,
html[dir="rtl"] .data-table td { text-align: right; }
html[dir="rtl"] .progress-wrap { flex-direction: row-reverse; }
html[dir="rtl"] .ms-trigger { flex-direction: row-reverse; }
html[dir="rtl"] .gantt-row { direction: ltr; } /* keep gantt LTR for dates */
html[dir="rtl"] .project-timeline { direction: ltr; }
html[dir="rtl"] .tl-step { direction: rtl; }
html[dir="rtl"] .flash { flex-direction: row; }
html[dir="rtl"] .home-kpi,
html[dir="rtl"] .dash-kpi { flex-direction: row; }
html[dir="rtl"] .activity-item { flex-direction: row; }
html[dir="rtl"] .login-options { flex-direction: row; }
html[dir="rtl"] .form-label i { margin-left: 6px; margin-right: 0; }
html[dir="rtl"] .btn i { margin-left: 6px; }

/* PWA standalone: safe top padding when status bar overlays */
@media all and (display-mode: standalone) {
    .topnav {
        padding-top: calc(10px + env(safe-area-inset-top, 0px));
    }
}
