:root {
  --bg: #F6F7F9; --surface: #FFFFFF; --line: #E3E6EB; --line-2: #D5DAE1; --soft: #EEF1F5;
  --ink: #111827; --ink-2: #374151; --muted: #5B6472;
  --accent: #2952CC; --accent-ink: #1E3FA3; --accent-soft: #E6ECFB;
  --radius: 12px;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink); background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); font-size: 14px; line-height: 1.45; }
a { color: var(--accent); }
a:hover { color: var(--accent-ink); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

/* ---------- header ---------- */
.top { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.top-in { max-width: 1360px; margin: 0 auto; padding: 12px 24px; display: flex; align-items: center; gap: 20px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; text-decoration: none; color: var(--ink); }
.logo { width: 32px; height: 32px; border-radius: 8px; background: var(--accent); color: #fff; font-weight: 700; font-size: 13px; display: grid; place-items: center; }
.tabs { display: flex; gap: 4px; flex: 1; }
.tab { padding: 9px 16px; border-radius: 8px; color: #4B5563; font-weight: 500; text-decoration: none; }
.tab:hover { background: var(--soft); color: var(--ink); }
.tab[aria-current="page"] { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.top-actions { display: flex; gap: 8px; align-items: center; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--line-2); background: var(--surface); font-weight: 500; color: var(--ink); text-decoration: none; white-space: nowrap; }
.btn:hover { background: #F9FAFB; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-ink); }
.btn.danger { color: #B42318; border-color: #F1C4BF; }
.btn.danger:hover { background: #FEF3F2; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.icon { padding: 8px; min-width: 40px; }
.btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); }
.btn:disabled { opacity: .55; cursor: default; }

/* ---------- layout ---------- */
main { max-width: 1360px; margin: 0 auto; padding: 24px 24px 64px; display: flex; flex-direction: column; gap: 20px; }
.head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; }
h1 { margin: 0; font-size: 24px; font-weight: 700; }
.sub { margin: 4px 0 0; color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.pad { padding: 18px 20px; }
h2 { margin: 0 0 14px; font-size: 15px; font-weight: 600; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.muted { color: var(--muted); }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

/* ---------- KPIs + charts ---------- */
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; }
.kpi { padding: 16px 18px; }
.kpi .l { font-size: 13px; color: var(--muted); font-weight: 500; }
.kpi .v { font-size: 30px; font-weight: 700; margin-top: 4px; line-height: 1.15; }
.kpi .s { font-size: 13px; color: var(--muted); margin-top: 2px; }
button.kpi { text-align: left; font: inherit; cursor: pointer; }
button.kpi:hover { border-color: var(--line-2); box-shadow: 0 1px 3px rgba(17,24,39,.06); }
.bars { display: flex; flex-direction: column; gap: 9px; font-size: 13px; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 150px) 1fr 34px; align-items: center; gap: 10px; background: none; border: 0; padding: 2px 0; text-align: left; border-radius: 6px; }
.bar-row:hover .bar-fill { filter: brightness(0.9); }
.bar-row .n { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.bar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.bar-track { background: var(--soft); border-radius: 4px; height: 14px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; background: var(--accent); min-width: 3px; }
.cols { display: flex; align-items: flex-end; gap: 10px; height: 190px; border-bottom: 1px solid var(--line-2); padding: 0 4px; }
.col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px; height: 100%; min-width: 0; }
.col .n { font-size: 12px; font-weight: 600; }
.col .b { width: 100%; max-width: 56px; border-radius: 5px 5px 0 0; background: var(--accent); min-height: 2px; }
.col-labels { display: flex; gap: 10px; padding: 6px 4px 0; }
.col-labels div { flex: 1; text-align: center; font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 10px 4px; border-top: 1px solid var(--soft); background: none; border-left: 0; border-right: 0; border-bottom: 0; width: 100%; text-align: left; border-radius: 0; }
.list-row:hover { background: #F9FAFB; }
.list-row .d { width: 54px; font-size: 12px; color: var(--muted); flex-shrink: 0; }
.list-row .t { flex: 1; min-width: 0; }
.list-row .t b { display: block; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-row .t span { font-size: 12px; color: var(--muted); }

/* ---------- pills ---------- */
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.st-Delivered { background: #E3F4EC; color: #0F6B4B; }
.st-In-progress { background: #E6ECFB; color: #1E3FA3; }
.st-Waiting-approval { background: #EFE8FB; color: #5B32A3; }
.st-Pending { background: #FDF1DC; color: #8A5200; }
.st-Dropped { background: #F1F3F6; color: #4B5563; }
.st-Live { color: #0F6B4B; }
.st-In-build { color: #8A5200; }
.st-Retired { color: var(--muted); }
select.pill { border: 0; appearance: none; -webkit-appearance: none; padding: 5px 24px 5px 10px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23374151' fill='none' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 9px center; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 6px; background: #F1F3F6; color: var(--ink-2); font-size: 12px; font-weight: 500; white-space: nowrap; }
.ref { display: inline-flex; align-items: center; gap: 5px; padding: 3px 8px; border: 1px solid var(--line-2); border-radius: 6px; font-size: 12px; font-weight: 500;
  text-decoration: none; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; background: #fff; }
.ref svg.i { width: 12px; height: 12px; }
.refs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }

/* ---------- filters ---------- */
.filters { padding: 14px 16px; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.search { flex: 1 1 260px; display: flex; align-items: center; gap: 8px; border: 1px solid var(--line-2); border-radius: 8px; padding: 0 12px; height: 42px; background: #fff; }
.search input { border: 0; outline: 0; flex: 1; min-width: 0; background: transparent; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 8px 13px; border-radius: 999px; border: 1px solid var(--line-2); background: #fff; color: var(--ink-2); font-weight: 500; font-size: 13px; white-space: nowrap; }
.chip[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.sel { height: 42px; padding: 0 10px; border: 1px solid var(--line-2); border-radius: 8px; background: #fff; max-width: 100%; }

/* ---------- task table ---------- */
.table-wrap { overflow-x: auto; }
table.tasks { width: 100%; min-width: 1080px; border-collapse: collapse; }
.tasks th { background: #F9FAFB; text-align: left; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; padding: 11px 12px; white-space: nowrap; }
.tasks td { padding: 11px 12px; border-top: 1px solid var(--soft); vertical-align: top; }
.tasks tr.row { cursor: pointer; }
.tasks tr.row:hover td { background: #FAFBFC; }
.tasks tr.sel-row td { background: #F3F6FE; }
.tasks .ttl { font-weight: 500; }
.tasks .note { font-size: 12px; color: var(--muted); margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.cb { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }
.cards { display: none; }
.foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--soft); color: var(--muted); font-size: 13px; flex-wrap: wrap; }

.bulk { position: fixed; left: 50%; transform: translateX(-50%); bottom: 20px; z-index: 30; background: var(--ink); color: #fff; border-radius: 12px;
  padding: 10px 12px 10px 16px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: calc(100vw - 24px); }
.bulk select { height: 38px; border-radius: 8px; border: 0; padding: 0 8px; color: var(--ink); }
.bulk label { display: flex; gap: 6px; align-items: center; font-size: 13px; }
.bulk .btn { min-height: 38px; }

/* ---------- links ---------- */
.link-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.link-card { padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.link-card .t { font-size: 15px; font-weight: 600; line-height: 1.35; word-break: break-word; }
.link-card .u { font-size: 12px; color: var(--muted); word-break: break-all; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.link-card .acts { display: flex; gap: 6px; align-items: center; margin-top: auto; padding-top: 6px; flex-wrap: wrap; }
.link-card .acts .btn { min-height: 34px; padding: 5px 11px; font-size: 13px; }
.group-h { margin: 6px 0 -4px; font-size: 14px; font-weight: 600; color: var(--ink-2); }

/* ---------- dialogs ---------- */
dialog { border: 0; padding: 0; border-radius: 14px; width: min(600px, calc(100vw - 24px)); max-height: calc(100vh - 40px); box-shadow: 0 20px 50px rgba(0,0,0,.25); color: var(--ink); }
dialog::backdrop { background: rgba(17,24,39,.45); }
.dlg { display: flex; flex-direction: column; max-height: calc(100vh - 40px); }
.dlg-h { padding: 18px 22px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.dlg-h h2 { margin: 0; font-size: 18px; }
.dlg-b { padding: 18px 22px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.dlg-f { padding: 14px 22px; border-top: 1px solid var(--line); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.dlg-f .grow { flex: 1; }
.fld { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.fld input, .fld select, .fld textarea { font-weight: 400; font-size: 15px; min-height: 44px; padding: 8px 12px; border: 1px solid var(--line-2); border-radius: 8px; background: #fff; color: var(--ink); width: 100%; }
.fld textarea { min-height: 84px; resize: vertical; }
.fld .hint { font-weight: 400; color: var(--muted); font-size: 12px; }
.row2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { padding: 9px 12px; border-radius: 8px; border: 1px solid var(--line-2); background: #fff; font-size: 13px; font-weight: 500; color: var(--ink-2); }
.seg button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.people-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.pchip { display: inline-flex; align-items: center; gap: 4px; padding: 5px 6px 5px 11px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-ink); font-size: 13px; font-weight: 600; }
.pchip button { border: 0; background: none; color: inherit; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; padding: 0; }
.pchip button:hover { background: rgba(41,82,204,.15); }
.add-row { display: flex; gap: 8px; }
.add-row input { flex: 1; min-width: 0; }
.box { padding: 14px; background: #F9FAFB; border: 1px solid var(--line); border-radius: 10px; display: flex; flex-direction: column; gap: 10px; }
.ref-row { display: grid; grid-template-columns: 140px 1fr 40px; gap: 8px; }
.ref-row input { min-height: 40px; padding: 6px 10px; border: 1px solid var(--line-2); border-radius: 8px; font-size: 14px; min-width: 0; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; font-weight: 400; }
.check input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--accent); }
.err { background: #FEF3F2; color: #B42318; border: 1px solid #F1C4BF; border-radius: 8px; padding: 10px 12px; font-size: 13px; }
details.hist summary { cursor: pointer; font-weight: 600; font-size: 13px; color: var(--ink-2); padding: 4px 0; }
.hist-item { font-size: 13px; padding: 8px 0; border-top: 1px solid var(--soft); }
.hist-item .when { color: var(--muted); font-size: 12px; }
.person-row { display: flex; gap: 8px; align-items: center; padding: 8px 0; border-top: 1px solid var(--soft); flex-wrap: wrap; }
.person-row input { flex: 1 1 160px; min-height: 38px; padding: 6px 10px; border: 1px solid var(--line-2); border-radius: 8px; }
.person-row .btn { min-height: 38px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 14px 10px 16px; border-radius: 10px;
  display: flex; gap: 12px; align-items: center; z-index: 100; box-shadow: 0 8px 24px rgba(0,0,0,.25); max-width: calc(100vw - 24px); }
body:has(#bulk) .toast { bottom: 92px; }
.toast button { background: none; border: 0; color: #9DB4FF; font-weight: 600; padding: 6px; }
.loading { padding: 80px 20px; text-align: center; color: var(--muted); }

.bottom-nav { display: none; }
body.present .edit-only { display: none !important; }
.present-badge { display: none; }
body.present .present-badge { display: inline-flex; }

/* ---------- phone ---------- */
@media (max-width: 760px) {
  body { font-size: 15px; padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
  .top-in { padding: 10px 14px; gap: 10px; }
  .tabs, .top-actions .wide { display: none; }
  .brand { flex: 1; }
  main { padding: 16px 14px 32px; gap: 16px; }
  h1 { font-size: 21px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpis > :first-child { grid-column: span 2; }
  .kpi .v { font-size: 26px; }
  .grid2 { grid-template-columns: minmax(0, 1fr); }
  .filters { padding: 12px; }
  .filters .sel { flex: 1 1 140px; }
  .chips { flex-wrap: nowrap; overflow-x: auto; margin: 0 -12px; padding: 0 12px 2px; scrollbar-width: none; width: calc(100% + 24px); }
  .table-wrap { display: none; }
  .cards { display: flex; flex-direction: column; }
  .tcard { padding: 14px 16px; border-top: 1px solid var(--soft); display: flex; gap: 12px; cursor: pointer; }
  .tcard:first-child { border-top: 0; }
  .tcard.sel-row { background: #F3F6FE; }
  .tcard .body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
  .tcard .meta { font-size: 12px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
  .tcard .ttl { font-weight: 600; font-size: 15px; line-height: 1.35; }
  .tcard .who { font-size: 13px; color: var(--ink-2); }
  .tcard .line { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
  .bottom-nav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; background: #fff; border-top: 1px solid var(--line);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); justify-content: space-around; }
  .bottom-nav a, .bottom-nav button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 4px; min-height: 52px; font-size: 11px; font-weight: 600;
    color: var(--muted); text-decoration: none; background: none; border: 0; border-radius: 10px; }
  .bottom-nav [aria-current="page"] { color: var(--accent); }
  .bottom-nav .add { color: #fff; }
  .bottom-nav .add span.plus { width: 44px; height: 32px; border-radius: 10px; background: var(--accent); display: grid; place-items: center; }
  body.present .bottom-nav .add { display: none; }
  .bulk { bottom: calc(80px + env(safe-area-inset-bottom)); }
  .toast { bottom: calc(84px + env(safe-area-inset-bottom)); }
  body:has(#bulk) .toast { bottom: calc(150px + env(safe-area-inset-bottom)); }
  dialog { width: 100vw; max-width: 100vw; height: 100%; max-height: 100%; border-radius: 0; margin: 0; }
  .dlg { height: 100%; max-height: 100%; }
  .dlg-h, .dlg-b, .dlg-f { padding-left: 16px; padding-right: 16px; }
  .dlg-f { padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  .row2 { grid-template-columns: 1fr; }
  .ref-row { grid-template-columns: 1fr 40px; }
  .ref-row input:first-child { grid-column: span 2; }
  .link-grid { grid-template-columns: 1fr; }
}
@media (max-width: 1100px) and (min-width: 761px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
