/*
 * The tracker's own pieces, on top of app.css (which is the Control Panel's stylesheet, the same
 * palette as the Sankari sign-in page).
 *
 * Status colours are one fixed vocabulary for items, decisions, readiness cells and blockers,
 * checked with the colour-blindness validator (adjacent ΔE ≥ 9 for every vision type). A colour
 * is never the only signal: every swatch sits beside its label or count.
 */
:root {
    --s-done: #2f8a5b;
    --s-prog: #3f76c0;
    --s-wait: #d9962b;
    --s-none: #d8c8c0;
    --s-defer: #9b8f87;
    --s-late: #a0522d;
}

.empty { text-align: center; padding: 26px 16px; color: var(--muted); border: 1px dashed var(--border); border-radius: 10px; background: #fcfbfa; }
.empty b { display: block; color: var(--text-2); margin-bottom: 4px; }

.sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; background: var(--s-none); }
.s-done.sw, .seg-bar > .s-done, .stack > .s-done { background: var(--s-done); }
.s-prog.sw, .seg-bar > .s-prog { background: var(--s-prog); }
.s-wait.sw, .seg-bar > .s-wait, .stack > .s-open { background: var(--s-wait); }
.s-none.sw, .seg-bar > .s-none { background: var(--s-none); }
.s-defer.sw, .seg-bar > .s-defer { background: var(--s-defer); }
.s-late.sw, .stack > .s-late { background: var(--s-late); }

.chip.s-done { background: #e6f2eb; color: #22714a; }
.chip.s-prog { background: #e8eff9; color: #2f5f9e; }
.chip.s-wait { background: #fbf0dd; color: #8a5d14; }
.chip.s-none { background: #f3eeea; color: #6b5f57; }
.chip.s-defer { background: #efedeb; color: #6b625c; }
.chip.late { background: #f6e6dd; color: var(--s-late); }
.chip.p1 { background: var(--bad-bg); color: var(--bad); }
.chip.p2 { background: var(--warn-bg); color: var(--warn); }
.chip.p3 { background: var(--pill); color: var(--text-2); }
.chip.p4 { background: #f7f7f7; color: var(--muted); }
.chip.code { background: var(--ink); color: var(--cream); font-weight: 700; letter-spacing: .02em; direction: ltr; unicode-bidi: isolate; }
.chip.soft-code { background: var(--brown-50); color: var(--brown-700); direction: ltr; unicode-bidi: isolate; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* ------------------------------------------------------------------ KPI tiles */

.tiles { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 760px) { .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (min-width: 1240px) { .tiles { grid-template-columns: 1.7fr repeat(4, minmax(0, 1fr)); } }
.tile {
    background: #fff; border: 1px solid var(--border-soft); border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; color: inherit; min-width: 0;
}
a.tile:hover { text-decoration: none; border-color: var(--tan); }
.tile .k { color: var(--muted); font-size: 13px; }
.tile .v { font-size: 30px; font-weight: 800; line-height: 1.05; color: var(--ink); font-variant-numeric: tabular-nums; }
.tile .v small { font-size: 15px; font-weight: 600; color: var(--muted); }
.tile .s { font-size: 13px; color: var(--text-2); }
.tile.hero { flex-direction: row; align-items: center; gap: 22px; grid-column: 1 / -1; }
@media (min-width: 1240px) { .tile.hero { grid-column: auto; } }
@media (min-width: 760px) and (max-width: 1239px) { .tile.hero .streams { flex-direction: row; flex-wrap: wrap; gap: 10px 28px; } .tile.hero .streams > div { flex: 1 1 200px; } .tile.hero .streams > .k { flex-basis: 100%; } }
.tile.hero .streams { flex: 1; min-width: 0; }
.tile.warn .v { color: var(--warn); }
.tile.bad .v { color: var(--s-late); }

.ring {
    --p: 0; width: 96px; height: 96px; border-radius: 50%; flex: none; display: grid; place-items: center;
    background: conic-gradient(var(--s-done) calc(var(--p) * 1%), #efe9e3 0);
}
.ring::before { content: ""; grid-area: 1 / 1; width: 74px; height: 74px; border-radius: 50%; background: #fff; }
.ring b { grid-area: 1 / 1; font-size: 22px; font-weight: 800; color: var(--ink); z-index: 1; font-variant-numeric: tabular-nums; }
/* In Arabic the ring fills clockwise from the top towards the left, the way the text reads. */
html[dir="rtl"] .ring { transform: scaleX(-1); }
html[dir="rtl"] .ring b { transform: scaleX(-1); }

.streams { display: flex; flex-direction: column; gap: 9px; }
.streams .line { display: flex; justify-content: space-between; font-size: 13.5px; gap: 8px; margin-bottom: 4px; }
.streams .line span { color: var(--muted); font-size: 12.5px; }

/* ------------------------------------------------------------------ stacked bars (status by stream) */

.seg-rows { display: flex; flex-direction: column; gap: 14px; }
.seg-row .lab { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; margin-bottom: 6px; }
.seg-row .lab b { color: var(--ink); }
.seg-row .lab span { color: var(--muted); font-size: 13px; }
.seg-bar { display: flex; gap: 2px; height: 26px; border-radius: 6px; overflow: hidden; background: #f4f0ec; }
.seg-bar > i {
    display: flex; align-items: center; justify-content: center; min-width: 0; font-style: normal;
    font-size: 12px; font-weight: 700; color: #fff; transition: filter .15s; cursor: default;
}
.seg-bar > i.s-none { color: #5f544c; }
.seg-bar > i:hover { filter: brightness(.9); }
.seg-bar > i.narrow { font-size: 0; }
.seg-row.total .lab b { font-size: 15px; }
.seg-row.total .seg-bar { height: 32px; }

/* ------------------------------------------------------------------ horizontal bars (shares) */

.hbars { display: flex; flex-direction: column; gap: 10px; }
.hbar { display: grid; grid-template-columns: minmax(110px, 36%) minmax(0, 1fr) auto; gap: 10px; align-items: center; font-size: 13.5px; color: inherit; }
a.hbar:hover { text-decoration: none; }
a.hbar:hover .n { color: var(--brown); }
.hbar .n { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .track { height: 12px; background: #f4f0ec; border-radius: 4px; overflow: hidden; display: flex; gap: 2px; }
.hbar .track > i { display: block; height: 100%; background: var(--brown); }
.hbar .track > i:first-child { border-start-start-radius: 4px; border-end-start-radius: 4px; }
.hbar .track > i:last-child { border-start-end-radius: 4px; border-end-end-radius: 4px; }
.hbar .track > i.s-done { background: var(--s-done); }
.hbar .track > i.s-open { background: var(--s-wait); }
.hbar .val { font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; min-width: 34px; text-align: end; white-space: nowrap; }
.hbar .val small { color: var(--muted); font-weight: 500; }

/* ------------------------------------------------------------------ columns (weekly plan) */

.cols { display: flex; align-items: flex-end; gap: 8px; height: 200px; padding-top: 6px; border-bottom: 1px solid var(--border); }
.cols .col { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; color: inherit; }
.cols .col:hover { text-decoration: none; }
.cols .col .stack { display: flex; flex-direction: column-reverse; gap: 2px; border-radius: 4px 4px 0 0; overflow: hidden; }
.cols .col .stack > i { display: block; }
.cols .col .top { text-align: center; font-size: 12px; font-weight: 700; color: var(--ink); margin-bottom: 3px; font-variant-numeric: tabular-nums; }
.cols .col:hover .stack { filter: brightness(.92); }
.cols .col.current .top { color: var(--brown); }
.cols-x { display: flex; gap: 8px; }
.cols-x span { flex: 1 1 0; min-width: 0; text-align: center; font-size: 11.5px; color: var(--muted); padding-top: 5px; direction: ltr; overflow: hidden; }
.cols-x span.current { color: var(--brown); font-weight: 700; }

/* ------------------------------------------------------------------ package progress list */

.pk { display: grid; grid-template-columns: minmax(0, 1fr) 150px auto; gap: 4px 14px; align-items: center; padding: 11px 0; border-bottom: 1px solid var(--border-soft); color: inherit; }
.pk:last-child { border-bottom: 0; }
a.pk:hover { text-decoration: none; }
a.pk:hover .t { color: var(--brown); }
.pk .t { font-weight: 700; color: var(--ink); overflow-wrap: anywhere; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.pk .o { grid-column: 1; font-size: 13px; color: var(--muted); }
.pk .meter { grid-row: 1 / span 2; grid-column: 2; }
.pk .end { grid-row: 1 / span 2; grid-column: 3; text-align: end; font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums; white-space: nowrap; display: flex; flex-direction: column; gap: 3px; align-items: flex-end; }
@media (max-width: 640px) {
    .pk { grid-template-columns: minmax(0, 1fr) auto; }
    .pk .meter { grid-row: auto; grid-column: 1 / -1; }
    .pk .end { grid-row: 1; grid-column: 2; }
}
.bar > i.s-done { background: var(--s-done); }
.bar.lg { height: 10px; }

/* ------------------------------------------------------------------ sections */

.section-title { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.section-title h2 { font-size: 17px; }
.section-title .meta { color: var(--muted); font-size: 13px; }
.mt { margin-top: 16px; }
.mt-lg { margin-top: 24px; }

.table td.num, .table th.num { text-align: end; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .sub { display: block; color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.table tr.is-late td:first-child { box-shadow: inset -3px 0 0 var(--s-late); }
html[dir="ltr"] .table tr.is-late td:first-child { box-shadow: inset 3px 0 0 var(--s-late); }
.table select.status {
    height: 30px; border: 1px solid var(--border); border-radius: 6px; padding: 0 8px; font: inherit; font-size: 13px; background: #fff; color: var(--text); max-width: 140px;
}
.table select.status:focus { outline: none; border-color: var(--brown); }
.table td.nowrap { white-space: nowrap; }
.table.compact td { padding: 8px 10px; }
.table tfoot td { font-weight: 700; color: var(--ink); border-top: 1px solid var(--border); border-bottom: 0; }

/* ------------------------------------------------------------------ filters */

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filters select, .filters input {
    height: 38px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: #fff; padding: 0 10px; font: inherit; font-size: 14px; color: var(--text); max-width: 100%;
}
.filters input[type=search] { min-width: 200px; flex: 1; }
.filters select:focus, .filters input:focus { outline: none; border-color: var(--brown); box-shadow: 0 0 0 3px rgba(117, 89, 76, .12); }
.filters label.check { display: inline-flex; gap: 6px; align-items: center; font-size: 14px; color: var(--text-2); }
.band .filters select { background: var(--ink-2); color: var(--cream); border-color: var(--ink-line); }

/* ------------------------------------------------------------------ readiness matrix */

.matrix-wrap { overflow: auto; max-height: 78vh; border: 1px solid var(--border-soft); border-radius: 10px; background: #fff; }
table.matrix { border-collapse: separate; border-spacing: 0; font-size: 13px; min-width: 100%; }
.matrix th, .matrix td { border-bottom: 1px solid var(--border-soft); padding: 0; }
.matrix thead th { position: sticky; top: 0; z-index: 3; background: #fff; font-weight: 700; font-size: 12.5px; color: var(--text-2); padding: 10px 6px; vertical-align: bottom; min-width: 76px; text-align: center; box-shadow: inset 0 -1px 0 var(--border); }
.matrix thead th.step { text-align: start; min-width: 250px; inset-inline-start: 0; z-index: 4; }
.matrix tbody th { position: sticky; inset-inline-start: 0; z-index: 2; background: #fff; text-align: start; font-weight: 500; padding: 7px 10px; color: var(--ink); }
.matrix tbody th .no { color: var(--muted); font-variant-numeric: tabular-nums; margin-inline-end: 6px; font-size: 12px; }
.matrix tr.phase th, .matrix tr.phase td { background: var(--brown-50); font-weight: 700; color: var(--brown-700); padding: 8px 10px; }
.matrix tr.phase td { text-align: center; font-size: 12px; font-variant-numeric: tabular-nums; padding: 8px 4px; }
.matrix tr.sum th, .matrix tr.sum td { background: #faf8f5; padding: 8px 6px; text-align: center; font-weight: 700; color: var(--ink); }
.matrix tr.sum th { text-align: start; }
.matrix td.cell { text-align: center; }
.cellbox {
    display: flex; align-items: center; justify-content: center; height: 28px; margin: 3px; border-radius: 5px;
    font-weight: 700; font-size: 13px; color: #fff; position: relative;
}
.cellbox.s-done { background: var(--s-done); }
.cellbox.s-prog { background: var(--s-prog); }
.cellbox.s-wait { background: var(--s-wait); }
.cellbox.s-defer { background: var(--s-defer); }
.cellbox.s-none { background: #f1ebe6; color: #8b7f76; }
.cellbox.s-na { background: transparent; color: #c7beb6; }
.cellbox.s-blank { background: repeating-linear-gradient(135deg, #fbfaf9, #fbfaf9 4px, #f1eeea 4px, #f1eeea 8px); }
button.cellbox { border: 0; width: calc(100% - 6px); font: inherit; font-weight: 700; cursor: pointer; padding: 0; }
button.cellbox:hover, button.cellbox:focus-visible { outline: 2px solid var(--brown); outline-offset: 1px; }
.cellbox.saving { opacity: .5; }
.cell-menu {
    position: absolute; z-index: 60; background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow);
    padding: 6px; display: grid; gap: 2px; min-width: 170px;
}
.cell-menu[hidden] { display: none; }
.cell-menu button { display: flex; gap: 8px; align-items: center; border: 0; background: none; font: inherit; font-size: 14px; padding: 5px 8px; border-radius: 6px; cursor: pointer; text-align: start; color: var(--text); }
.cell-menu button:hover, .cell-menu button:focus-visible { background: var(--pill); outline: none; }
.cell-menu .cellbox { width: 24px; height: 20px; margin: 0; font-size: 11px; flex: none; }

/* ------------------------------------------------------------------ detail pages */

.prose { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.8; margin: 0; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px 20px; }
.kv > div { min-width: 0; }
.kv .k { color: var(--muted); font-size: 12.5px; display: block; margin-bottom: 3px; }
.kv .v { font-weight: 600; color: var(--ink); overflow-wrap: anywhere; }
.block-title { font-size: 13px; color: var(--muted); font-weight: 600; margin: 0 0 6px; }
.blocks > div + div { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border-soft); }

.multi { max-height: 260px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 4px 12px; background: #fff; }
.multi label { display: flex; gap: 8px; align-items: flex-start; padding: 5px 0; font-size: 14px; cursor: pointer; border-bottom: 1px solid var(--border-soft); }
.multi label:last-child { border-bottom: 0; }
.multi input { width: 17px; height: 17px; accent-color: var(--brown); margin-top: 3px; flex: none; }
.multi .grp { font-weight: 700; font-size: 13px; color: var(--brown-700); padding: 8px 0 2px; }
.multi label.hidden { display: none; }
.field input.multi-filter { height: 36px; margin-bottom: 6px; }
.check-line { display: flex; gap: 8px; align-items: center; font-size: 14px; cursor: pointer; }
.check-line input { width: 17px; height: 17px; accent-color: var(--brown); }
.field input[type=number] { width: 100%; height: 46px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: #fff; padding: 0 14px; font: inherit; outline: none; }
.field input[type=number]:focus { border-color: var(--brown); box-shadow: 0 0 0 3px rgba(117, 89, 76, .14); }
.row3 { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 760px) { .row3 { grid-template-columns: repeat(3, 1fr); } }

.lists-grid { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 1100px) { .lists-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.row-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border-soft); }
.row-form:last-child { border-bottom: 0; }
.row-form input[type=text], .row-form input[type=number], .row-form input[type=date], .row-form select {
    height: 34px; border: 1px solid var(--border); border-radius: 6px; padding: 0 9px; font: inherit; font-size: 13.5px; background: #fff; min-width: 0;
}
.row-form input[type=number] { width: 72px; }
.row-form input.wide { flex: 1 1 160px; }
.row-form input.mid { width: 140px; }
.row-form label.check { display: inline-flex; gap: 5px; align-items: center; font-size: 13px; color: var(--text-2); }
.row-form.new { background: #fcfaf8; border-radius: 8px; padding: 10px; border: 1px dashed var(--tan); margin-top: 10px; }
.row-form .companies { flex-basis: 100%; display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 13px; color: var(--text-2); }
.row-form .companies label { display: inline-flex; gap: 4px; align-items: center; }
.row-form.off input[type=text] { color: var(--muted); }

.admin-cards { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.admin-cards a { display: block; padding: 18px; border-radius: var(--radius); background: #fff; border: 1px solid var(--border-soft); box-shadow: var(--shadow); color: inherit; }
.admin-cards a:hover { text-decoration: none; border-color: var(--tan); }
.admin-cards b { display: block; font-size: 16px; color: var(--ink); margin-bottom: 4px; }
.admin-cards span { font-size: 13px; color: var(--muted); }

code.json { display: block; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12px; background: #faf8f5; border-radius: 6px; padding: 6px 8px; max-height: 140px; overflow: auto; direction: ltr; text-align: left; }

@media print {
    .filters, .btns, select.status, .no-print { display: none !important; }
    .matrix-wrap { max-height: none; overflow: visible; }
    .tile, .card { break-inside: avoid; }
}
