:root {
    --bg: #08111f;
    --surface: #101c2f;
    --surface-2: #16243a;
    --text: #eef4ff;
    --muted: #9fb0c7;
    --line: #2b3d56;
    --primary: #60a5fa;
    --primary-strong: #2563eb;
    --danger: #ef4444;

    /* Solid reference colors used for lines, borders, and readable text. */
    --green: #16a34a;
    --yellow: #d97706;
    --red: #dc2626;
    --neutral: #64748b;
    --target-green: #22c55e;

    /* Translucent RAG fills for softer dashboards. */
    --rag-green-bg: rgba(22, 163, 74, .30);
    --rag-yellow-bg: rgba(217, 119, 6, .30);
    --rag-red-bg: rgba(220, 38, 38, .30);
    --rag-neutral-bg: rgba(100, 116, 139, .28);
    --rag-green-line: rgba(34, 197, 94, .70);
    --rag-yellow-line: rgba(245, 158, 11, .72);
    --rag-red-line: rgba(248, 113, 113, .72);
    --rag-neutral-line: rgba(148, 163, 184, .62);
    --rag-green-fg: #dcfce7;
    --rag-yellow-fg: #fef3c7;
    --rag-red-fg: #fee2e2;
    --rag-neutral-fg: #e2e8f0;
}
body.theme-light {
    --bg: #f4f7fb;
    --surface: #ffffff;
    --surface-2: #eef3f9;
    --text: #111827;
    --muted: #526070;
    --line: #d6dee9;
    --primary: #2563eb;
    --primary-strong: #1d4ed8;
    --danger: #b91c1c;

    --green: #15803d;
    --yellow: #b45309;
    --red: #b91c1c;
    --neutral: #475569;
    --target-green: #16a34a;

    --rag-green-bg: rgba(22, 163, 74, .18);
    --rag-yellow-bg: rgba(217, 119, 6, .20);
    --rag-red-bg: rgba(220, 38, 38, .18);
    --rag-neutral-bg: rgba(100, 116, 139, .16);
    --rag-green-line: rgba(21, 128, 61, .56);
    --rag-yellow-line: rgba(180, 83, 9, .58);
    --rag-red-line: rgba(185, 28, 28, .56);
    --rag-neutral-line: rgba(71, 85, 105, .45);
    --rag-green-fg: #14532d;
    --rag-yellow-fg: #78350f;
    --rag-red-fg: #7f1d1d;
    --rag-neutral-fg: #334155;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: linear-gradient(135deg, rgba(16, 28, 47, .96), rgba(8, 17, 31, .96));
    border-bottom: 1px solid rgba(96, 165, 250, .18);
    box-shadow: 0 12px 35px rgba(0, 0, 0, .24);
    backdrop-filter: blur(14px);
}
body.theme-light .topbar {
    background: linear-gradient(135deg, rgba(255, 255, 255, .96), rgba(238, 243, 249, .96));
    border-bottom-color: rgba(37, 99, 235, .14);
    box-shadow: 0 10px 28px rgba(15, 23, 42, .08);
}
.topbar-inner {
    width: 100%;
    max-width: 1320px;
    margin: 0 auto;
    padding: 12px 24px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
}
.topbar-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    width: 100%;
    min-width: 0;
}
.topbar-menu {
    display: none;
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 22px;
    background: linear-gradient(180deg, var(--surface), var(--surface-2));
    box-shadow: 0 22px 55px rgba(0,0,0,.30);
    max-height: calc(100vh - 86px);
    overflow-y: auto;
}
body.theme-light .topbar-menu {
    background: linear-gradient(180deg, #ffffff, #eef3f9);
    box-shadow: 0 18px 42px rgba(15,23,42,.12);
}
.topbar-menu.is-open { display: flex; }
.brand { display: inline-flex; align-items: center; gap: 11px; color: var(--text); font-weight: 850; white-space: nowrap; text-decoration: none; }
.brand:hover { text-decoration: none; }
.brand-mark {
    width: 42px;
    height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 42px;
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 10px 24px rgba(15, 23, 42, .28);
}
.brand-mark-image {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
    border-radius: inherit;
}
.brand-copy { display: flex; flex-direction: column; line-height: 1.05; min-width: 0; }
.brand-title { font-size: 16px; letter-spacing: -.02em; overflow: hidden; text-overflow: ellipsis; }
.brand-subtitle { margin-top: 4px; color: var(--muted); font-size: 11px; font-weight: 750; text-transform: uppercase; letter-spacing: .13em; }
.main-nav {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    align-items: start;
    gap: 12px;
    flex: 1;
    min-width: 0;
}
.nav-cluster {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    border: 1px solid rgba(159, 176, 199, .16);
    border-radius: 18px;
    background: rgba(255, 255, 255, .035);
    min-width: 0;
}
body.theme-light .nav-cluster { background: rgba(37, 99, 235, .035); border-color: rgba(37, 99, 235, .10); }
.nav-section-label {
    color: var(--muted);
    font-size: 11px;
    font-weight: 850;
    letter-spacing: .12em;
    text-transform: uppercase;
    padding: 0 4px 3px;
}
.main-nav a, .user-box a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    color: var(--text);
    background: rgba(255,255,255,.045);
    border: 1px solid transparent;
    padding: 12px 13px;
    border-radius: 14px;
    font-size: 14px;
    font-weight: 780;
    transition: background .16s ease, color .16s ease, transform .16s ease, box-shadow .16s ease, border-color .16s ease;
}
body.theme-light .main-nav a, body.theme-light .user-box a { background: rgba(37,99,235,.045); }
.main-nav a:hover, .user-box a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; transform: translateY(-1px); border-color: var(--line); }
.main-nav a.active {
    background: linear-gradient(135deg, var(--primary-strong), var(--primary));
    color: #fff;
    box-shadow: 0 10px 22px rgba(37, 99, 235, .28);
}
.user-box {
    display: flex;
    gap: 10px;
    align-items: center;
    color: var(--muted);
    margin-left: 0;
    padding: 10px;
    border: 1px solid rgba(159, 176, 199, .16);
    border-radius: 18px;
    background: rgba(255, 255, 255, .035);
    white-space: nowrap;
}
body.theme-light .user-box { background: rgba(255,255,255,.75); border-color: rgba(37, 99, 235, .10); }
.user-avatar {
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    color: #fff;
    background: linear-gradient(135deg, #64748b, #334155);
    font-size: 13px;
    font-weight: 900;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.05; max-width: none; flex: 1; min-width: 0; }
.user-meta strong { color: var(--text); font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.user-meta small { color: var(--muted); font-size: 11px; margin-top: 3px; }
.logout-link { background: rgba(239, 68, 68, .12) !important; color: #fecaca !important; text-align: center; }
body.theme-light .logout-link { color: var(--danger) !important; background: rgba(185, 28, 28, .08) !important; }
.hamburger {
    display: inline-flex;
    width: 48px;
    height: 44px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface-2);
    color: var(--text);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 5px;
    flex: 0 0 auto;
}
.hamburger:hover { filter: brightness(1.08); }
.hamburger span { display: block; width: 21px; height: 2px; background: currentColor; border-radius: 999px; transition: transform .16s ease, opacity .16s ease; }
.hamburger[aria-expanded="true"] span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hamburger[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.hamburger[aria-expanded="true"] span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }
.container { max-width: 1280px; margin: 0 auto; padding: 26px; }
.footer { color: var(--muted); text-align: center; padding: 24px; border-top: 1px solid var(--line); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 18px; box-shadow: 0 12px 35px rgba(0,0,0,.18); margin-bottom: 18px; }
.page-title-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; margin-bottom: 18px; }
h1, h2, h3 { margin-top: 0; }
.muted { color: var(--muted); }
.actions, .form-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); padding: 9px 13px; border-radius: 12px; cursor: pointer; font-weight: 650; text-decoration: none; }
.btn:hover { text-decoration: none; filter: brightness(1.08); }
.btn.primary { background: var(--primary-strong); border-color: var(--primary-strong); color: white; }
.btn.danger { background: rgba(239, 68, 68, .18); border-color: var(--danger); color: #fecaca; }
body.theme-light .btn.danger { color: var(--danger); }
.btn.small { padding: 5px 9px; font-size: 13px; }
.toolbar { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; }
.grow { flex: 1; min-width: 220px; }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 650; }
.field span, label span { font-size: 13px; color: var(--muted); font-weight: 700; }
input, select, textarea { width: 100%; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); border-radius: 10px; padding: 10px 11px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); border-color: transparent; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-stack { display: flex; flex-direction: column; gap: 14px; }
.full { grid-column: 1 / -1; }
.grid.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.phase-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.phase-fieldset { border: 1px solid var(--line); border-radius: 16px; padding: 16px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.phase-fieldset legend { color: var(--primary); font-weight: 800; padding: 0 6px; }
.table-scroll { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { padding: 12px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.data-table th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.data-table tr:hover td { background: rgba(96,165,250,.06); }
.data-table.compact th, .data-table.compact td { padding: 8px; font-size: 14px; }
.task-editor input, .task-editor select { min-width: 95px; padding: 7px; }
.empty { text-align: center; color: var(--muted); padding: 26px !important; }
.pagination { display: flex; gap: 8px; justify-content: center; margin: 18px 0; }
.pagination a, .pagination span { padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--text); }
.pagination .current { background: var(--primary-strong); color: white; }
.flash { border-radius: 14px; padding: 12px 14px; margin-bottom: 16px; background: rgba(22,163,74,.14); border: 1px solid rgba(22,163,74,.5); }
.flash.error { background: rgba(220,38,38,.14); border-color: rgba(220,38,38,.5); }
.login-card { max-width: 430px; margin: 70px auto; }
.metric-row { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.metric-box { border-radius: 16px; padding: 14px; border: 1px solid var(--line); background: var(--surface-2); }
.metric-box span { display: block; color: var(--muted); font-size: 13px; }
.metric-box strong { display: block; margin-top: 5px; font-size: 25px; }
.pill { display: inline-flex; min-width: 52px; justify-content: center; border-radius: 999px; padding: 5px 9px; font-weight: 800; font-size: 13px; border: 1px solid transparent; backdrop-filter: blur(8px); }
.metric-green { background: var(--rag-green-bg) !important; border-color: var(--rag-green-line) !important; color: var(--rag-green-fg) !important; }
.metric-yellow { background: var(--rag-yellow-bg) !important; border-color: var(--rag-yellow-line) !important; color: var(--rag-yellow-fg) !important; }
.metric-red { background: var(--rag-red-bg) !important; border-color: var(--rag-red-line) !important; color: var(--rag-red-fg) !important; }
.metric-neutral { background: var(--rag-neutral-bg) !important; border-color: var(--rag-neutral-line) !important; color: var(--rag-neutral-fg) !important; }
.metric-box.metric-green, .metric-box.metric-yellow, .metric-box.metric-red, .metric-box.metric-neutral { box-shadow: inset 0 1px 0 rgba(255,255,255,.10), 0 12px 28px rgba(0,0,0,.16); }
.danger-zone { border-color: rgba(239,68,68,.7); }
.inline-form { display: inline; }
.check-field { display: flex; gap: 8px; align-items: center; }
.check-field input { width: auto; }
.checkbox-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; }
.checkbox-grid input { width: auto; }
.note { margin: 0; }
.chart-card { overflow-x: auto; }
.scatter { width: 100%; min-width: 760px; height: auto; }
.plot-bg { fill: var(--surface-2); stroke: var(--line); }
.axis, .grid, .target, .leader { stroke: var(--line); stroke-width: 1; }
.grid { opacity: .42; }
.target { stroke: var(--target-green); stroke-width: 2.5; stroke-dasharray: 5 5; }
.leader { stroke: var(--muted); stroke-width: 1; opacity: .9; }
.dot { stroke: rgba(255,255,255,.86); stroke-width: 2; }
.dot.metric-green { fill: var(--rag-green-bg) !important; stroke: var(--rag-green-line) !important; }
.dot.metric-yellow { fill: var(--rag-yellow-bg) !important; stroke: var(--rag-yellow-line) !important; }
.dot.metric-red { fill: var(--rag-red-bg) !important; stroke: var(--rag-red-line) !important; }
.dot.metric-neutral { fill: var(--rag-neutral-bg) !important; stroke: var(--rag-neutral-line) !important; }
.tick, .axis-label, .label-text { fill: var(--muted); font-size: 12px; text-anchor: middle; }
.label-text { fill: var(--text); font-weight: 800; }
.label-bg { fill: var(--surface); stroke: var(--line); opacity: .95; }
.y { text-anchor: end; }
.y-label { text-anchor: middle; }
@media (max-width: 1100px) {
    .topbar-inner { padding: 12px 16px; }
    .main-nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .page-title-row { flex-direction: column; align-items: stretch; }
    .form-grid, .grid.two, .phase-grid, .metric-row { grid-template-columns: 1fr; }
    .phase-fieldset { grid-template-columns: 1fr; }
    .container { padding: 16px; }
}
@media (max-width: 520px) {
    .brand-title { font-size: 14px; }
    .brand-subtitle { display: none; }
    .brand-mark { width: 38px; height: 38px; border-radius: 13px; }
    .user-box { flex-wrap: wrap; }
    .logout-link { width: 100%; text-align: center; }
}

/* Mobile-width protection and responsive list tables */
html, body {
    max-width: 100%;
    overflow-x: hidden;
}
.container, .topbar-inner, .card, .toolbar, .page-title-row, .topbar-row, .topbar-menu {
    min-width: 0;
}
.container {
    width: 100%;
}
.card {
    overflow-wrap: anywhere;
}
.table-scroll {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.data-table {
    max-width: 100%;
}
.data-table td, .data-table th {
    overflow-wrap: anywhere;
    word-break: normal;
}

@media (max-width: 760px) {
    .main-nav { grid-template-columns: 1fr; }
    .toolbar.card {
        display: grid;
        grid-template-columns: 1fr;
        align-items: stretch;
    }
    .toolbar .btn,
    .page-title-row .btn,
    .actions .btn,
    .form-actions .btn {
        width: 100%;
    }
    .actions,
    .form-actions {
        width: 100%;
        display: grid;
        grid-template-columns: 1fr;
    }
    .pagination {
        flex-wrap: wrap;
    }

    /* Lists become stacked cards on phones instead of forcing horizontal overflow. */
    .data-table:not(.task-editor),
    .data-table:not(.task-editor) thead,
    .data-table:not(.task-editor) tbody,
    .data-table:not(.task-editor) tr,
    .data-table:not(.task-editor) th,
    .data-table:not(.task-editor) td {
        display: block;
        width: 100%;
    }
    .data-table:not(.task-editor) thead {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
        border: 0;
    }
    .data-table:not(.task-editor) tbody {
        display: grid;
        gap: 12px;
    }
    .data-table:not(.task-editor) tr {
        border: 1px solid var(--line);
        border-radius: 16px;
        padding: 10px;
        background: var(--surface-2);
        box-shadow: 0 8px 20px rgba(0,0,0,.12);
    }
    body.theme-light .data-table:not(.task-editor) tr {
        background: #ffffff;
    }
    .data-table:not(.task-editor) tr:hover td {
        background: transparent;
    }
    .data-table:not(.task-editor) td {
        display: grid;
        grid-template-columns: minmax(92px, 38%) minmax(0, 1fr);
        gap: 10px;
        align-items: center;
        padding: 10px 4px;
        border-bottom: 1px solid rgba(159,176,199,.18);
        text-align: right;
    }
    .data-table:not(.task-editor) td:last-child {
        border-bottom: 0;
    }
    .data-table:not(.task-editor) td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: 11px;
        font-weight: 850;
        letter-spacing: .06em;
        text-transform: uppercase;
        text-align: left;
        overflow-wrap: normal;
    }
    .data-table:not(.task-editor) td.empty {
        display: block;
        text-align: center;
        border-bottom: 0;
    }
    .data-table:not(.task-editor) td.empty::before {
        display: none;
        content: '';
    }
    .data-table:not(.task-editor) td .pill,
    .data-table:not(.task-editor) td .btn {
        justify-self: end;
    }
    .data-table:not(.task-editor) td a {
        overflow-wrap: anywhere;
    }

    /* The task editor is intentionally kept as a horizontal editing grid. */
    .task-editor {
        min-width: 980px;
    }
    .scatter {
        min-width: 620px;
    }
}

@media (max-width: 480px) {
    .container { padding: 12px; }
    .card { padding: 14px; border-radius: 16px; }
    .data-table:not(.task-editor) td {
        grid-template-columns: 1fr;
        text-align: left;
        gap: 4px;
    }
    .data-table:not(.task-editor) td .pill,
    .data-table:not(.task-editor) td .btn {
        justify-self: start;
    }
}

/* Mobile overflow hardening: keep every view inside the viewport. */
html {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}
body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}
.topbar,
.footer,
.container,
.card,
.toolbar,
.page-title-row,
.topbar-inner,
.topbar-row,
.topbar-menu,
.main-nav,
.nav-cluster,
.user-box,
.form-grid,
.grid,
.phase-grid,
.metric-row,
.actions,
.form-actions {
    max-width: 100%;
    min-width: 0;
}
.container {
    width: 100%;
    overflow-x: clip;
}
.card {
    width: 100%;
    overflow-x: hidden;
}
.table-scroll,
.chart-card {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
}
input,
select,
textarea,
button,
.btn,
a,
span,
strong,
small,
td,
th,
p,
h1,
h2,
h3 {
    min-width: 0;
    max-width: 100%;
}
input,
select,
textarea {
    min-width: 0;
}
.btn,
.pill {
    white-space: normal;
}
.brand {
    min-width: 0;
    overflow: hidden;
}
.brand-copy {
    min-width: 0;
    max-width: calc(100vw - 112px);
}
.brand-title,
.brand-subtitle,
.user-meta strong,
.user-meta small {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.data-table {
    min-width: 0;
}
.data-table td > *,
.data-table th > * {
    max-width: 100%;
    min-width: 0;
}
.data-table a,
.data-table span,
.data-table td {
    overflow-wrap: anywhere;
    word-break: break-word;
}
.scatter {
    min-width: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    display: block;
}

@media (max-width: 900px) {
    .topbar-inner {
        padding-left: 12px;
        padding-right: 12px;
    }
    .container {
        padding-left: 12px;
        padding-right: 12px;
    }
    .page-title-row,
    .toolbar,
    .actions,
    .form-actions,
    .user-box {
        display: grid;
        grid-template-columns: 1fr;
        align-items: stretch;
    }
    .toolbar label,
    .toolbar .field,
    .actions .btn,
    .form-actions .btn,
    .toolbar .btn,
    .user-box a {
        width: 100%;
    }
    .grow {
        min-width: 0;
        width: 100%;
    }

    /* Use cards earlier than phone width. This prevents iPhone/Android landscape overflow too. */
    .data-table:not(.task-editor),
    .data-table:not(.task-editor) thead,
    .data-table:not(.task-editor) tbody,
    .data-table:not(.task-editor) tr,
    .data-table:not(.task-editor) th,
    .data-table:not(.task-editor) td {
        display: block;
        width: 100%;
        min-width: 0;
        max-width: 100%;
    }
    .data-table:not(.task-editor) thead {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
        border: 0;
    }
    .data-table:not(.task-editor) tbody {
        display: grid;
        gap: 12px;
    }
    .data-table:not(.task-editor) tr {
        border: 1px solid var(--line);
        border-radius: 16px;
        padding: 10px;
        background: var(--surface-2);
        overflow: hidden;
    }
    body.theme-light .data-table:not(.task-editor) tr {
        background: #ffffff;
    }
    .data-table:not(.task-editor) td {
        display: grid;
        grid-template-columns: minmax(0, 34%) minmax(0, 1fr);
        gap: 8px;
        align-items: start;
        padding: 10px 4px;
        border-bottom: 1px solid rgba(159,176,199,.18);
        text-align: left;
        overflow: hidden;
    }
    .data-table:not(.task-editor) td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: 11px;
        font-weight: 850;
        letter-spacing: .06em;
        text-transform: uppercase;
        text-align: left;
        overflow-wrap: anywhere;
    }
    .data-table:not(.task-editor) td:last-child {
        border-bottom: 0;
    }
    .data-table:not(.task-editor) td.empty {
        display: block;
        text-align: center;
        border-bottom: 0;
    }
    .data-table:not(.task-editor) td.empty::before {
        display: none;
    }
    .data-table:not(.task-editor) td .pill,
    .data-table:not(.task-editor) td .btn {
        justify-self: start;
    }

    /* Editing tasks has many fields; keep only this grid scrollable inside its card. */
    .task-editor {
        width: max-content;
        min-width: 980px;
        max-width: none;
    }
}

@media (max-width: 520px) {
    .topbar-inner,
    .container {
        padding-left: 10px;
        padding-right: 10px;
    }
    .card {
        padding: 12px;
    }
    h1 { font-size: 1.55rem; }
    h2 { font-size: 1.25rem; }
    .metric-box strong { font-size: 21px; }
    .data-table:not(.task-editor) td {
        grid-template-columns: 1fr;
        gap: 5px;
    }
    .data-table:not(.task-editor) td::before {
        margin-bottom: 1px;
    }
    .pagination {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .pagination a,
    .pagination span {
        text-align: center;
    }
}

/* True mobile card rendering for list/detail tables.
   JavaScript clones server-rendered table rows into these cards.
   This avoids mobile browsers keeping wide table layout constraints. */
.mobile-card-list {
    display: none;
}

@media (max-width: 900px) {
    table.data-table.mobile-card-source:not(.task-editor) {
        display: none !important;
    }
    .table-scroll.has-mobile-cards {
        overflow-x: visible !important;
    }
    .mobile-card-list {
        display: grid;
        grid-template-columns: 1fr;
        gap: 12px;
        width: 100%;
        max-width: 100%;
        min-width: 0;
        overflow: visible;
    }
    .mobile-card {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        overflow: hidden;
        border: 1px solid var(--line);
        border-radius: 16px;
        background: var(--surface-2);
        padding: 10px 12px;
        box-shadow: 0 8px 18px rgba(0, 0, 0, .12);
    }
    body.theme-light .mobile-card {
        background: #fff;
        box-shadow: 0 8px 18px rgba(15, 23, 42, .07);
    }
    .mobile-card-empty {
        color: var(--muted);
        text-align: center;
        padding: 18px 12px;
    }
    .mobile-card-field {
        display: grid;
        grid-template-columns: minmax(82px, 34%) minmax(0, 1fr);
        gap: 8px;
        width: 100%;
        max-width: 100%;
        min-width: 0;
        align-items: start;
        padding: 9px 0;
        border-bottom: 1px solid rgba(159, 176, 199, .18);
    }
    .mobile-card-field:last-child {
        border-bottom: 0;
    }
    .mobile-card-label {
        color: var(--muted);
        font-size: 11px;
        font-weight: 850;
        letter-spacing: .06em;
        text-transform: uppercase;
        line-height: 1.25;
        min-width: 0;
        overflow-wrap: anywhere;
    }
    .mobile-card-value {
        min-width: 0;
        max-width: 100%;
        overflow-wrap: anywhere;
        word-break: break-word;
        line-height: 1.35;
    }
    .mobile-card-value > * {
        max-width: 100%;
        min-width: 0;
    }
    .mobile-card-value a,
    .mobile-card-value span,
    .mobile-card-value strong,
    .mobile-card-value small,
    .mobile-card-value form {
        max-width: 100%;
        min-width: 0;
        overflow-wrap: anywhere;
        word-break: break-word;
    }
    .mobile-card-value .pill {
        min-width: 0;
        white-space: normal;
    }
    .mobile-card-value .btn {
        width: auto;
        max-width: 100%;
        white-space: normal;
    }
    .mobile-card-value .actions,
    .mobile-card-value .form-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        width: 100%;
    }
}

@media (max-width: 520px) {
    .mobile-card {
        padding: 10px;
    }
    .mobile-card-field {
        grid-template-columns: 1fr;
        gap: 4px;
    }
    .mobile-card-label {
        font-size: 10px;
    }
    .mobile-card-value .btn,
    .mobile-card-value button {
        width: 100%;
    }
}

/* Historical reporting charts */
.chart-card { overflow-x: hidden; }
.scatter, .trend { width: 100% !important; min-width: 0 !important; max-width: 100% !important; height: auto; display: block; }
.limit { stroke-width: 2; stroke-dasharray: 7 6; }
.limit-min { stroke: var(--red); }
.limit-max { stroke: var(--yellow); }
.limit-label { fill: var(--muted); font-size: 11px; font-weight: 800; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-top: 10px; color: var(--muted); font-size: 13px; }
.chart-legend span { display: inline-flex; gap: 6px; align-items: center; }
.legend-line { width: 24px; height: 0; border-top: 3px dashed var(--muted); display: inline-block; }
.legend-line.min { border-color: var(--red); }
.legend-line.max { border-color: var(--yellow); }
.legend-line.target { border-color: var(--target-green); }
.legend-dot { width: 10px; height: 10px; border-radius: 999px; display: inline-block; }
.legend-dot.cpi, .trend-dot.cpi { background: var(--primary); fill: var(--primary); }
.legend-dot.spi, .trend-dot.spi { background: #a855f7; fill: #a855f7; }
.trend-line { fill: none; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.trend-line.cpi { stroke: var(--primary); }
.trend-line.spi { stroke: #a855f7; }
.trend-dot { stroke: white; stroke-width: 2; }
.tick.month { font-size: 10px; }
@media (max-width: 600px) { .tick.month, .limit-label { font-size: 9px; } .chart-legend { font-size: 12px; } }

/* Historical reporting drill-down and domain graph tabs */
.snapshot-date-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    padding: 6px 10px;
    font-weight: 850;
    background: rgba(96, 165, 250, .10);
    border: 1px solid rgba(96, 165, 250, .20);
}
.snapshot-date-link:hover {
    text-decoration: none;
    background: rgba(96, 165, 250, .20);
}
.snapshot-date-link.is-selected {
    color: #fff;
    background: linear-gradient(135deg, var(--primary-strong), var(--primary));
    border-color: var(--primary-strong);
}
.data-table tr.snapshot-selected td {
    background: rgba(96, 165, 250, .10);
}
.chart-header-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 12px;
}
.view-tabs {
    display: inline-flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    flex: 0 0 auto;
}
@media (max-width: 760px) {
    .chart-header-row {
        flex-direction: column;
        align-items: stretch;
    }
    .view-tabs {
        display: grid;
        grid-template-columns: 1fr;
        width: 100%;
    }
    .view-tabs .btn {
        width: 100%;
    }
}

/* Project detail graph tabs */
.view-tabs .btn.primary {
    background: linear-gradient(135deg, var(--primary-strong), var(--primary));
    border-color: var(--primary-strong);
    color: #fff;
    box-shadow: 0 8px 18px rgba(37, 99, 235, .24);
}
.chart-card .view-tabs {
    align-self: flex-start;
}
@media (max-width: 760px) {
    .chart-card .view-tabs {
        align-self: stretch;
    }
}

/* Selected-project report settings */
.selected-project-config {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
    margin-top: 6px;
}
.section-heading-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
}
.project-picker {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 10px;
    max-height: 520px;
    overflow: auto;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: rgba(148, 163, 184, .06);
}
.project-picker-item {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px 10px;
    align-items: start;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--card);
    cursor: pointer;
}
.project-picker-item:hover {
    border-color: var(--primary);
}
.project-picker-item input {
    margin-top: 3px;
}
.project-picker-main,
.project-picker-meta {
    min-width: 0;
    overflow-wrap: anywhere;
}
.project-picker-meta {
    grid-column: 2;
    color: var(--muted);
    font-size: 12px;
}
@media (max-width: 760px) {
    .section-heading-row {
        flex-direction: column;
        align-items: stretch;
    }
    .project-picker {
        grid-template-columns: 1fr;
        max-height: none;
        overflow: visible;
    }
}

/* Settings project report picker controls */
.project-picker-filter-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}
.project-picker-filter-row .grow {
    flex: 1 1 320px;
}
.project-picker-panel h3 {
    margin: 10px 0 6px;
}
.selected-projects-bottom {
    border-color: var(--primary);
    background: rgba(37, 99, 235, .08);
}
.small-text {
    font-size: 13px;
}

.selected-projects-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px;
    margin-top: 14px;
}
.selected-projects-header h3 {
    margin-bottom: 4px;
}
.actions-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}
@media (max-width: 760px) {
    .selected-projects-header,
    .actions-row {
        align-items: stretch;
        flex-direction: column;
    }
}

@media (max-width: 760px) {
    .project-picker-filter-row {
        align-items: stretch;
    }
    .project-picker-filter-row .btn,
    .project-picker-filter-row .field {
        width: 100%;
    }
}


.task-order-cell {
    min-width: 52px;
    text-align: center;
}
.task-order-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 28px;
    border-radius: 999px;
    border: 1px solid var(--line);
    color: var(--muted);
    background: var(--surface-2);
    font-weight: 800;
    font-size: 12px;
}
.task-actions {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
    min-width: 220px;
}
.btn.mini {
    padding: 5px 8px;
    border-radius: 9px;
    font-size: 12px;
    line-height: 1.1;
}
.btn.mini:disabled {
    opacity: .42;
    cursor: not-allowed;
}
.task-row-focus td {
    background: rgba(96, 165, 250, .16) !important;
    transition: background .25s ease;
}
.task-editor input[name="task_id[]"] {
    min-width: 120px;
}


.disabled-action,
.btn[aria-disabled="true"] {
    opacity: .48;
    cursor: help;
    filter: grayscale(.35);
}
.disabled-action:hover,
.btn[aria-disabled="true"]:hover {
    opacity: .64;
}

/* Clean aligned project action buttons */
.page-actions.project-action-panel {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    max-width: 760px;
}
.project-action-panel .action-group {
    display: contents;
}
.project-action-panel .action-group-label {
    display: none;
}
.project-action-panel .action-form {
    display: inline-flex;
    margin: 0;
}
.project-action-panel .action-btn,
.project-action-panel .action-form .btn {
    min-width: 154px;
    min-height: 40px;
    padding: 9px 12px;
    border-radius: 12px;
    white-space: nowrap;
}
.project-action-panel.compact-action-panel {
    max-width: 360px;
}
.project-action-panel.compact-action-panel .action-btn {
    min-width: 142px;
}

@media (max-width: 900px) {
    .page-title-row {
        flex-direction: column;
        align-items: stretch;
    }
    .page-actions.project-action-panel {
        width: 100%;
        max-width: none;
        justify-content: flex-start;
    }
}

@media (max-width: 560px) {
    .page-actions.project-action-panel {
        display: grid;
        grid-template-columns: 1fr;
    }
    .project-action-panel .action-form,
    .project-action-panel .action-btn,
    .project-action-panel .action-form .btn {
        width: 100%;
        min-width: 0;
    }
}

