:root{--navy:#142e49;--blue:#235e91;--orange:#e87722;--bg:#eef2f7;--card:#fff;--line:#dce4ed;--text:#17324d;--mute:#5d728a;--red:#c0392b}
*{box-sizing:border-box}
[hidden]{display:none!important}
body{margin:0;font:14px/1.45 "Segoe UI",system-ui,sans-serif;background:var(--bg);color:var(--text)}
header{display:flex;align-items:center;gap:16px;padding:10px 20px;background:#fff;border-bottom:3px solid var(--orange)}
header img{height:44px}
h1{margin:0;font-size:20px;color:var(--navy)}
h2{margin:0 0 12px;font-size:16px}
small{color:var(--mute)}
.who{margin-left:auto;display:flex;gap:10px;align-items:center;flex-wrap:wrap;justify-content:flex-end}
nav{display:flex;flex-wrap:wrap;gap:2px;padding:0 20px;background:var(--navy)}
nav a{color:#dbe7f3;text-decoration:none;padding:11px 14px;border-bottom:3px solid transparent}
nav a.active{color:#fff;border-color:var(--orange);font-weight:600}
main{max-width:1800px;margin:auto;padding:14px}
.card{background:var(--card);border-radius:10px;padding:14px 16px;margin-bottom:12px;box-shadow:0 1px 3px #0000000f}
.grid2{display:grid;grid-template-columns:repeat(auto-fit,minmax(320px,1fr));gap:12px;margin-bottom:12px}
.grid2 .card{margin:0}
button{background:var(--blue);color:#fff;border:1px solid var(--blue);border-radius:6px;padding:7px 14px;cursor:pointer;font:inherit}
button:disabled{opacity:.5;cursor:default}
.ghost{background:#fff;color:var(--blue)}
.toggle{display:none}
input,select,textarea{font:inherit;color:inherit;padding:6px 9px;border:1px solid #bac9d8;border-radius:6px;background:#fff;max-width:100%}
textarea{width:100%;min-height:70px}
label{display:grid;gap:4px}
label.inline{display:inline-flex;align-items:center;gap:6px}
.stack{display:grid;gap:10px;justify-items:start}
.stack label{width:min(340px,100%)}
.filters{display:flex;flex-wrap:wrap;gap:8px;align-items:center}
.filters input[type=search]{flex:1;min-width:260px}
.filters input[type=number]{width:84px}
.filters select{max-width:220px}
.scroll{overflow:auto}
.note,.empty{color:var(--mute)}
.badge{background:var(--red);color:#fff;border-radius:10px;font-size:12px;padding:1px 8px}
.badge:empty{display:none}
#msg{position:fixed;right:16px;bottom:16px;max-width:min(560px,92vw);margin:0;padding:11px 16px;border-radius:8px;z-index:20;box-shadow:0 3px 14px #0004}
#msg.ok{background:#ddf3e4}
#msg.error{background:#fde2dd}
.error{color:#9c2a12}

/* tổng quan */
.kpis{display:grid;grid-template-columns:repeat(auto-fit,minmax(170px,1fr));gap:10px;margin-bottom:12px}
.kpi{background:#fff;border-radius:10px;padding:12px 14px;text-decoration:none;color:inherit;border-top:3px solid var(--blue);box-shadow:0 1px 3px #0000000f}
.kpi span{display:block;color:var(--mute)}
.kpi strong{display:block;font-size:28px;line-height:1.25}
.kpi.warn{border-color:var(--orange);background:#fff6ee}
.kpi.bad{border-color:var(--red);background:#fff1ef}
.kpi.good{border-color:#2e8b57}
.warnlist{list-style:none;margin:0;padding:0;max-height:330px;overflow:auto}
.warnlist li{display:grid;grid-template-columns:150px 130px 1fr 150px;gap:10px;padding:8px 6px;border-bottom:1px solid var(--line);cursor:pointer;align-items:start}
.warnlist li:hover{background:#f5f9fd}
.cols{display:grid;grid-template-columns:repeat(14,1fr);gap:6px;align-items:end;height:170px}
.cols a{display:grid;grid-template-rows:18px 1fr 18px;height:100%;text-align:center;text-decoration:none;color:inherit;font-size:12px}
.cols i{align-self:end;background:var(--blue);border-radius:4px 4px 0 0;min-height:2px}
.cols a.soon i{background:var(--orange)}
.bar{display:grid;grid-template-columns:160px 1fr 40px;gap:8px;align-items:center;margin:5px 0}
.bar span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.bar i{background:#eaf0f6;border-radius:4px;height:10px}
.bar b{display:block;height:10px;background:var(--blue);border-radius:4px}
.bar em{font-style:normal;text-align:right}

/* bảng */
table{width:100%;border-collapse:collapse}
th,td{text-align:left;vertical-align:top;padding:8px 9px;border-bottom:1px solid var(--line)}
th{background:#eaf0f6;font-weight:600;white-space:nowrap}
tr[data-person],tr[data-open]{cursor:pointer}
tr[data-person]:hover td,tr[data-open]:hover td{background:#f5f9fd}
.r{text-align:right}
.nowrap{white-space:nowrap}
.chips{display:flex;flex-wrap:wrap;gap:6px;margin-bottom:10px}
.chips button{background:#fff;color:var(--text);border-color:#bac9d8;border-radius:16px;padding:5px 13px}
.chips button.active{background:var(--navy);color:#fff;border-color:var(--navy)}
.chips b{margin-left:6px}
.listhead{display:flex;justify-content:space-between;gap:10px;flex-wrap:wrap;align-items:center;margin-bottom:6px}
.pager{display:flex;gap:6px;align-items:center}
.tablewrap{overflow:auto;max-height:calc(100vh - 120px);background:#fff;border-radius:10px;box-shadow:0 1px 3px #0000000f}
#grid{min-width:1480px;border-collapse:separate;border-spacing:0;font-size:13px}
#grid th,#grid td{padding:7px 6px}
#grid th{position:sticky;top:0;z-index:3;cursor:pointer;user-select:none}
#grid th.sorted::after{content:" ▲";font-size:10px}
#grid th.sorted.desc::after{content:" ▼"}
#grid td{background:#fff}
#grid th:first-child,#grid td:first-child{position:sticky;left:0;z-index:2;box-shadow:inset 4px 0 0 transparent}
#grid th:first-child{z-index:4}
#grid tr.urgent td{background:#fff6ec}
#grid tr.urgent td:first-child{box-shadow:inset 4px 0 0 var(--orange)}
#grid tr.overdue td,#grid tr.fail td{background:#fff0ee}
#grid tr.overdue td:first-child,#grid tr.fail td:first-child{box-shadow:inset 4px 0 0 var(--red)}
#grid tr.expired td,#grid tr.skip td{color:#7b8a9a}
.c-code{width:118px;min-width:118px;max-width:118px}.c-title{min-width:250px;max-width:340px}.c-buyer{min-width:150px;max-width:210px}
@media(min-width:1100px){#grid th:nth-child(2),#grid td:nth-child(2){position:sticky;left:118px;z-index:2;box-shadow:4px 0 6px -4px #0003}#grid th:nth-child(2){z-index:4}}
.c-title a{color:var(--text);font-weight:600;text-decoration:none;cursor:pointer;display:-webkit-box;-webkit-line-clamp:3;-webkit-box-orient:vertical;overflow:hidden}
.c-title a:hover{color:var(--blue)}
.clamp{display:-webkit-box;-webkit-line-clamp:3;-webkit-box-orient:vertical;overflow:hidden}
.code{font-family:Consolas,monospace;font-weight:700;background:none;border:0;color:var(--blue);padding:0;cursor:copy}
.c-staff input{width:122px}
.c-staff input.set{border-color:var(--blue);background:#eef6fd;font-weight:600}
.c-status select{width:128px;padding-left:4px;padding-right:2px}
.tag{display:inline-block;font-size:12px;padding:1px 8px;border-radius:10px;background:#e8eef5;white-space:nowrap}
.tag.urgent{background:var(--orange);color:#fff;font-weight:700}
.tag.overdue,.tag.fail{background:var(--red);color:#fff;font-weight:700}
.tag.open{background:#ddf3e4;color:#17663a}
.tag.done{background:#dcecfb;color:#1c4f80}

dialog{width:min(860px,96vw);max-height:92vh;border:0;border-radius:12px;padding:20px;color:inherit}
dialog::backdrop{background:#0008}
.dhead{display:flex;gap:12px;justify-content:space-between;align-items:start}
dl{display:grid;grid-template-columns:170px 1fr;gap:4px 12px}
dt{color:var(--mute)}dd{margin:0;overflow-wrap:anywhere}
.form{display:grid;grid-template-columns:1fr 1fr;gap:10px;align-items:end}
.form .wide{grid-column:1/-1}
.hist{list-style:none;padding:0;margin:0 0 10px;max-height:260px;overflow:auto}
.hist li{padding:7px 0;border-bottom:1px solid var(--line);overflow-wrap:anywhere;display:flex;gap:10px;justify-content:space-between}
.secret{background:#ffead6;padding:10px 12px;border-radius:8px;overflow-wrap:anywhere}
body.login{min-height:100vh;display:grid;place-items:center;padding:16px}
body.login form{width:min(360px,100%);display:grid;gap:12px}
body.login img{height:60px;justify-self:center}
body.login h1{text-align:center}
body.login button{padding:11px 14px}

@media(max-width:760px){
  header{flex-wrap:wrap;padding:8px 12px}nav{padding:0 4px}nav a{padding:9px 8px}main{padding:8px}
  .form,dl{grid-template-columns:1fr}
  .filters>*{flex:1 1 45%;min-width:0}.filters input[type=search]{flex-basis:100%;min-width:0}.filters select{max-width:none}
  .filters label.inline input:not([type=checkbox]){flex:1;width:0;min-width:0}.filters label.check{flex-basis:100%}
  .filters:not(.more)>:not(input[type=search]):not(.toggle){display:none}.filters .toggle{display:block;flex-basis:100%}
  .warnlist li{grid-template-columns:1fr 1fr}.warnlist li span:nth-child(3){grid-column:1/-1}
  .cols{gap:2px;font-size:10px}.cols a{font-size:10px}
  .bar{grid-template-columns:120px 1fr 36px}
  /* mỗi gói thầu thành một thẻ */
  .tablewrap{max-height:none;background:none;box-shadow:none}
  #grid{min-width:0;display:block}
  #grid thead{display:none}
  #grid tbody{display:block}
  #grid tr{display:grid;grid-template-columns:1fr 1fr;border-radius:10px;overflow:hidden;margin-bottom:10px;box-shadow:0 1px 4px #0002}
  #grid td{display:block;position:static!important;border:0;padding:5px 10px;min-width:0;max-width:none;width:auto}
  #grid td::before{content:attr(data-label);display:block;font-size:11px;color:var(--mute)}
  #grid td.c-code,#grid td.c-title,#grid td.c-buyer{grid-column:1/-1}
  .c-staff input,.c-status select{width:100%}
}
