/* MDH v4 — premium dark UI, faster & safer UI actions */
:root{
  --bg:#070813;
  --panel:rgba(255,255,255,.035);
  --panel2:rgba(255,255,255,.05);
  --stroke:rgba(255,255,255,.12);
  --stroke2:rgba(255,255,255,.08);
  --text:#eef0ff;
  --muted:rgba(238,240,255,.68);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}
*{box-sizing:border-box}
html,body{height:100%}
body{margin:0;background:var(--bg);color:var(--text);font-family:system-ui,Segoe UI,Roboto,Arial;min-height:100vh;overflow:hidden}
.app{height:100%;display:grid;grid-template-columns:320px 1fr}
.sidebar{padding:16px;border-right:1px solid var(--stroke);background:var(--panel);overflow:auto}
.brand{display:flex;gap:10px;align-items:center;padding:12px;border:1px solid var(--stroke);border-radius:18px;background:rgba(255,255,255,.03)}
.logo{width:36px;height:36px;border-radius:12px;border:1px solid var(--stroke);background:linear-gradient(135deg,rgba(107,123,255,.35),rgba(51,230,255,.20))}
.brand h1{margin:0;font-size:14px}
.brand p{margin:2px 0 0;font-size:11px;opacity:.7}
.section-title{margin:14px 6px 8px;font-size:11px;opacity:.65;text-transform:uppercase;letter-spacing:.8px}

.navHeader{
  margin:10px 8px 2px;
  font-size:11px;
  letter-spacing:.8px;
  text-transform:uppercase;
  opacity:.55;
}
.nav{display:flex;flex-direction:column;gap:8px}
.nav button{border:1px solid var(--stroke);background:rgba(255,255,255,.03);color:var(--text);border-radius:14px;padding:10px 12px;cursor:pointer;display:flex;justify-content:space-between;align-items:center;gap:10px;min-height:44px;transition:background .15s ease,border-color .15s ease,transform .05s ease;}
.nav button:active{transform:scale(.995)}
.nav button:focus{outline:none}
.nav button:focus-visible{box-shadow:0 0 0 2px rgba(51,230,255,.22);}

.nav button.active{background:linear-gradient(135deg,rgba(107,123,255,.18),rgba(51,230,255,.10));border-color:rgba(107,123,255,.45)}
.nav button:hover{background:rgba(255,255,255,.06)}
.meta{font-size:11px;opacity:.7;font-family:var(--mono)}
.card{border:1px solid var(--stroke);background:var(--panel2);border-radius:18px;overflow:hidden}
.card .head{padding:12px 14px;display:flex;justify-content:space-between;align-items:center;border-bottom:1px solid var(--stroke2);background:rgba(0,0,0,.15);gap:12px}
.card .head h3{margin:0;font-size:13px}
.card .head .sub{font-size:11px;opacity:.7;font-family:var(--mono)}
.card .body{padding:12px 14px}
.hint{font-size:11px;opacity:.72;line-height:1.45}
.main{display:flex;flex-direction:column;min-width:0;min-height:0;height:100%}
.topbar{padding:14px 16px;border-bottom:1px solid var(--stroke);background:rgba(0,0,0,.18);display:flex;justify-content:space-between;align-items:center;gap:12px}
.crumb{font-size:12px;opacity:.7}
.title{display:flex;align-items:center;gap:10px}
.title h2{margin:0;font-size:18px}
.badge{font-size:11px;padding:4px 8px;border-radius:999px;border:1px solid var(--stroke);opacity:.85;font-family:var(--mono)}
.actions{display:flex;align-items:center;gap:8px;flex-wrap:wrap;justify-content:flex-end}
.search{display:flex;gap:8px;align-items:center;padding:8px 10px;border:1px solid var(--stroke);border-radius:14px;background:rgba(255,255,255,.03);width:min(360px,100%)}
.search input{border:none;background:transparent;outline:none;color:var(--text);width:100%;font-size:12px}
.btn{border:1px solid var(--stroke);background:rgba(255,255,255,.03);color:var(--text);border-radius:12px;padding:9px 10px;cursor:pointer;font-size:12px}
.btn:hover{background:rgba(255,255,255,.06)}
.btn.primary{background:linear-gradient(135deg,rgba(107,123,255,.22),rgba(51,230,255,.12));border-color:rgba(107,123,255,.55)}
.btn.danger{background:rgba(255,95,122,.10);border-color:rgba(255,95,122,.45)}
.btn.ghost{background:transparent}
.content{padding:16px;overflow:auto;min-width:0;flex:1;min-height:0;overscroll-behavior:contain;scrollbar-gutter:stable;}

.kpi{display:grid;grid-template-columns:repeat(4,minmax(170px,1fr));gap:10px}
.tile{border:1px solid rgba(255,255,255,.10);background:rgba(255,255,255,.03);border-radius:16px;padding:10px;min-height:76px;display:flex;flex-direction:column;justify-content:space-between}
.tile .label{font-size:11px;opacity:.72}
.tile .val{font-size:22px;font-weight:700}
.tile .mini{font-size:11px;opacity:.58;font-family:var(--mono)}
.tablewrap{overflow:auto;border-radius:14px;border:1px solid rgba(255,255,255,.10)}
table{width:100%;border-collapse:separate;border-spacing:0;min-width:1100px}
thead th{position:sticky;top:0;background:rgba(10,10,22,.94);border-bottom:1px solid rgba(255,255,255,.10);font-size:11px;padding:10px;text-align:left;white-space:nowrap}
tbody td{border-bottom:1px solid rgba(255,255,255,.06);padding:9px 10px;font-size:12px;white-space:nowrap;max-width:420px;overflow:hidden;text-overflow:ellipsis}
tbody tr:hover td{background:rgba(255,255,255,.03)}
.pill{display:inline-flex;align-items:center;gap:6px;padding:4px 8px;border-radius:999px;border:1px solid var(--stroke);background:rgba(255,255,255,.03);font-size:11px;font-family:var(--mono)}
.pill.good{border-color:rgba(41,211,145,.45);background:rgba(41,211,145,.10)}
.pill.warn{border-color:rgba(255,204,102,.50);background:rgba(255,204,102,.10)}
.pill.bad{border-color:rgba(255,95,122,.50);background:rgba(255,95,122,.10)}
.t-actions{display:flex;gap:6px;justify-content:flex-end}
.iconbtn{width:30px;height:30px;border-radius:10px;border:1px solid var(--stroke);background:rgba(255,255,255,.03);cursor:pointer;display:grid;place-items:center}
.iconbtn:hover{background:rgba(255,255,255,.07)}
.mono{font-family:var(--mono)}
.chip{border:1px solid var(--stroke);background:rgba(255,255,255,.03);border-radius:999px;padding:6px 10px;font-size:11px;opacity:.85;white-space:nowrap;}
hr.sep{border:none;border-top:1px solid rgba(255,255,255,.08);margin:12px 0}
.filters{display:flex;gap:8px;align-items:center;flex-wrap:wrap}
select.filter, input.filter{border:1px solid rgba(255,255,255,.12);background:rgba(255,255,255,.03);color:var(--text);border-radius:12px;padding:9px 10px;font-size:12px;outline:none}
.modal{position:fixed;inset:0;background:rgba(0,0,0,.58);display:none;align-items:center;justify-content:center;padding:18px;z-index:50}
.modal.open{display:flex}
.dialog{width:min(1200px,100%);max-height:92vh;overflow:auto;border-radius:20px;border:1px solid rgba(255,255,255,.14);background:rgba(10,10,22,.96)}
.authDialog{width:min(680px,100%);max-height:86vh}
.dhead{padding:12px 14px;display:flex;justify-content:space-between;align-items:center;border-bottom:1px solid rgba(255,255,255,.10);position:sticky;top:0;background:rgba(10,10,22,.96);gap:10px}
.dhead h4{margin:0;font-size:13px}
.dbody{padding:12px 14px}
.form{display:grid;grid-template-columns:repeat(3,minmax(260px,1fr));gap:10px}
.field{border:1px solid var(--stroke);background:rgba(255,255,255,.03);border-radius:14px;padding:10px;display:flex;flex-direction:column;gap:6px}
.field label{font-size:11px;opacity:.75;display:flex;justify-content:space-between;gap:8px}
.field .help{font-size:10px;opacity:.6;line-height:1.35}
input,select,textarea{width:100%;border:1px solid rgba(255,255,255,.10);background:rgba(0,0,0,.20);color:var(--text);border-radius:10px;padding:9px 10px;outline:none;font-size:12px}
textarea{min-height:120px;resize:vertical}
.footerbar{padding:12px 14px;border-top:1px solid rgba(255,255,255,.10);display:flex;gap:10px;align-items:center;justify-content:flex-end;position:sticky;bottom:0;background:rgba(0,0,0,.14)}
.small{font-size:11px;opacity:.75}
.toggle{display:flex;gap:8px;align-items:center}
.switch{width:44px;height:24px;border-radius:999px;border:1px solid var(--stroke);background:rgba(255,255,255,.03);position:relative;cursor:pointer}
.switch::after{content:'';position:absolute;top:3px;left:3px;width:18px;height:18px;border-radius:999px;background:rgba(255,255,255,.78);transition:.15s}
.switch.on{background:rgba(107,123,255,.18);border-color:rgba(107,123,255,.55)}
.switch.on::after{left:22px;background:rgba(255,255,255,.92)}
.toast{position:fixed;right:16px;bottom:16px;display:flex;flex-direction:column;gap:8px;z-index:60}
.toast .t{border:1px solid rgba(255,255,255,.12);background:rgba(10,10,22,.92);padding:10px 12px;border-radius:14px;max-width:360px;font-size:12px}
.toast .t.good{border-color:rgba(41,211,145,.35)}
.toast .t.bad{border-color:rgba(255,95,122,.35)}
@media(max-width:1050px){.app{grid-template-columns:1fr}.sidebar{display:none}.kpi{grid-template-columns:repeat(2,minmax(160px,1fr))}.form{grid-template-columns:1fr}table{min-width:920px}}


/* ===== Dashboard v4.6 (denser, less empty space, more “executive” view) ===== */
body{
  background:
    radial-gradient(1200px 700px at 20% -10%, rgba(107,123,255,.22), transparent 55%),
    radial-gradient(900px 700px at 90% 10%, rgba(51,230,255,.12), transparent 55%),
    radial-gradient(900px 700px at 40% 110%, rgba(255,79,216,.08), transparent 55%),
    var(--bg);
}

.navLeft{display:flex;align-items:center;gap:10px;min-width:0}
.navIcon{width:22px;display:inline-grid;place-items:center}
.navTitle{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.count{
  min-width:26px;
  height:22px;
  padding:0 8px;
  border-radius:999px;
  border:1px solid rgba(255,255,255,.12);
  background:rgba(255,255,255,.03);
  display:inline-flex;
  align-items:center;
  justify-content:center;
  font-size:11px;
  opacity:.92;
  white-space:nowrap;
}


.dash{display:flex;flex-direction:column;gap:12px}
.dashHeader{
  display:flex;align-items:flex-start;justify-content:space-between;gap:12px;
  padding:14px 16px;border:1px solid var(--stroke);border-radius:18px;
  background:rgba(255,255,255,.03);
}
.dashTitle{font-weight:850;font-size:16px}
.dashSub{font-size:11px;opacity:.7;margin-top:2px}
.dashPills{display:flex;gap:8px;align-items:center;flex-wrap:wrap;justify-content:flex-end}

.dashHero{display:grid;grid-template-columns:repeat(4,minmax(200px,1fr));gap:10px}
@media(max-width:1200px){.dashHero{grid-template-columns:repeat(2,minmax(180px,1fr))}}
@media(max-width:520px){.dashHero{grid-template-columns:1fr}}

.dashGrid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:12px;align-items:start}
.dashCard{height:100%}
.dashWide{grid-column:1 / -1}
@media(max-width:1200px){.dashGrid{grid-template-columns:1fr}.dashWide{grid-column:auto}}

.barRow{display:flex;flex-direction:column;gap:6px;margin-bottom:10px}
.barTop{display:flex;align-items:center;justify-content:space-between;gap:10px}
.barLabel{font-size:12px;opacity:.88}
.barVal{font-size:12px;opacity:.9}
.barTrack{
  height:10px;border-radius:999px;
  border:1px solid rgba(255,255,255,.10);
  background:rgba(0,0,0,.18);
  overflow:hidden;
}
.barFill{
  height:100%;
  background:linear-gradient(90deg, rgba(107,123,255,.55), rgba(51,230,255,.35));
  width:0%;
}
.barNote{font-size:11px;opacity:.65;line-height:1.3}
.dashHint{margin-top:6px;font-size:11px;opacity:.72;line-height:1.45}

.dashActions{display:flex;gap:8px;flex-wrap:wrap;margin-top:10px}
.auditList{display:flex;flex-direction:column;gap:8px}
.auditItem{
  border:1px solid rgba(255,255,255,.10);
  background:rgba(255,255,255,.02);
  border-radius:14px;
  padding:10px;
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:10px;
}
.auditTop{display:flex;flex-direction:column;gap:4px;min-width:0}
.auditTitle{font-weight:750;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:760px}
.auditMeta{font-size:11px;opacity:.65}
.auditActions{display:flex;gap:8px;align-items:center;flex-shrink:0}

/* small polish */
.topbar{backdrop-filter: blur(10px)}
.sidebar{backdrop-filter: blur(10px)}

/* Countries hub */

.splitFill{height:100%;min-height:0}
.card.full{height:100%;display:flex;flex-direction:column;min-height:0}
.card.full .body{flex:1;min-height:0;overflow:auto}
.card.full .head{flex:0 0 auto}
.split{display:grid;grid-template-columns:360px 1fr;gap:12px;align-items:start}
@media (max-width: 1100px){
  .split{grid-template-columns:1fr}
}
.clist{display:flex;flex-direction:column;gap:8px}

.citem{width:100%;text-align:left;border:1px solid rgba(255,255,255,.10);background:rgba(255,255,255,.03);border-radius:14px;padding:10px;cursor:pointer;transition:background .15s ease,border-color .15s ease,transform .05s ease;}
.citem:active{transform:scale(.998)}
.citem:focus{outline:none}
.citem:focus-visible{box-shadow:0 0 0 2px rgba(51,230,255,.18);}

.citem:hover{background:rgba(255,255,255,.05)}
.citem.active{border-color:rgba(51,230,255,.45);box-shadow:0 0 0 1px rgba(51,230,255,.15) inset}
.citem .row{display:flex;align-items:center;justify-content:space-between;gap:10px}
.cname{font-weight:650}
.cnum{opacity:.78}
.csub{font-size:11px;opacity:.65;margin-top:4px;display:flex;gap:6px;flex-wrap:wrap;align-items:center}
.ctyHeader{display:flex;align-items:flex-start;justify-content:space-between;gap:12px}
.ctyTitle{font-size:18px;font-weight:800}
.ctyActions{display:flex;gap:8px;align-items:center;flex-wrap:wrap}
.grid2{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px}
@media (max-width: 1100px){
  .grid2{grid-template-columns:1fr}
}
.subcard{border:1px solid rgba(255,255,255,.10);background:rgba(255,255,255,.03);border-radius:16px;overflow:hidden}
.subhead{display:flex;align-items:flex-start;justify-content:space-between;gap:10px;padding:12px;border-bottom:1px solid rgba(255,255,255,.08)}
.subhead .h{font-weight:750}
.subhead .sub{font-size:11px;opacity:.65;margin-top:2px}
.subbody{padding:10px}
.mlist{display:flex;flex-direction:column;gap:8px}
.mrow{padding:8px;border:1px solid rgba(255,255,255,.08);border-radius:12px;background:rgba(255,255,255,.02)}
.m1{display:flex;gap:8px;align-items:center;font-size:11px}
.m2{margin-top:6px;font-weight:650}
.m3{margin-top:4px;font-size:11px;opacity:.7}


/* Master Lists (pick from existing) */
.masterRow{display:flex;gap:8px;align-items:center}
.masterRow select{flex:1}


/* Smart Entry */
.entryWrap{display:flex;flex-direction:column;gap:12px}
.entryBar{display:flex;align-items:center;gap:8px;flex-wrap:wrap}
.sepV{width:1px;height:28px;background:rgba(255,255,255,.14);margin:0 2px}
.entrySplit{grid-template-columns: 1.25fr .75fr}
.entryKpi{grid-template-columns:repeat(2,minmax(0,1fr))}
.ctyRowActions{display:flex;gap:8px;align-items:center}

@media (max-width: 980px){
  .entrySplit{grid-template-columns: 1fr}
  .entryBar input{min-width: 100% !important}
  .entryBar select{min-width: 100% !important}
}


/* Segmented control (Table / Cards) */
.seg{display:inline-flex;border:1px solid rgba(255,255,255,.12);border-radius:999px;overflow:hidden;background:rgba(255,255,255,.03)}
.segBtn{border:none;background:transparent;color:rgba(255,255,255,.75);padding:6px 10px;font-size:12px;cursor:pointer;transition:background .15s ease,color .15s ease}
.segBtn:hover{background:rgba(255,255,255,.06)}
.segBtn.active{background:rgba(51,230,255,.16);color:#fff}


/* Cards view for lists */
.cardsGrid{display:grid;grid-template-columns:repeat(auto-fill,minmax(280px,1fr));gap:12px}
.rcard{border:1px solid rgba(255,255,255,.10);background:rgba(255,255,255,.03);border-radius:16px;padding:12px;display:flex;flex-direction:column;gap:10px;min-height:160px}
.rcTop{display:flex;justify-content:space-between;align-items:flex-start;gap:10px}
.rcTitle{font-weight:780;line-height:1.25;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:100%}
.rcStatus{flex:0 0 auto}
.rcMeta{font-size:11px;opacity:.72;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.rcKeys{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:10px}
.kv .k{font-size:10px;opacity:.65}
.kv .v{font-size:12px;margin-top:2px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.rcBottom{display:flex;justify-content:space-between;align-items:center;gap:10px;margin-top:auto}
.rcUpdated{font-size:11px;opacity:.6}
.rcActions{display:flex;gap:8px;align-items:center}


/* Admin */
.tabs{display:flex;gap:8px;align-items:center;flex-wrap:wrap;margin-bottom:12px}
.tab{border:1px solid rgba(255,255,255,.10);background:rgba(255,255,255,.03);color:rgba(255,255,255,.82);padding:8px 12px;border-radius:999px;cursor:pointer;transition:background .15s ease,border-color .15s ease}
.tab:hover{background:rgba(255,255,255,.05)}
.tab.active{border-color:rgba(51,230,255,.45);background:rgba(51,230,255,.14);color:#fff}
.adminGrid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px}
@media (max-width: 1100px){
  .adminGrid{grid-template-columns:1fr}
}
.formRow label{display:block;font-size:11px;opacity:.65;margin-bottom:6px}


/* Busy pill */
#busy{border-color:rgba(51,230,255,.25);background:rgba(51,230,255,.10);animation:mdhPulse 1.2s ease-in-out infinite}
@keyframes mdhPulse{0%{opacity:.55}50%{opacity:1}100%{opacity:.55}}


/* Scrollbars */
*::-webkit-scrollbar{width:10px;height:10px}
*::-webkit-scrollbar-thumb{background:rgba(255,255,255,.10);border-radius:999px;border:2px solid rgba(0,0,0,0)}
*::-webkit-scrollbar-thumb:hover{background:rgba(255,255,255,.16)}
*::-webkit-scrollbar-track{background:rgba(0,0,0,0)}

@media (max-width: 860px){
  .app{grid-template-columns:1fr}
  .sidebar{position:sticky;top:0;z-index:5}
}


/* ===== Right Drawer (Inspector / AI Copilot) ===== */
.drawer{
  position:fixed;
  inset:0;
  z-index:55;
  display:none;
}
.drawer.open{display:block}
.drawerBackdrop{
  position:absolute;
  inset:0;
  background:rgba(0,0,0,.38);
}
.drawerPanel{
  position:absolute;
  top:0;
  right:0;
  height:100%;
  width:min(520px, 92vw);
  border-left:1px solid rgba(255,255,255,.14);
  background:rgba(10,10,22,.98);
  display:flex;
  flex-direction:column;
}
.drawerPanel .dbody{overflow:auto;min-height:0;flex:1}


/* ===== Plant PFD ===== */
.plantHeader{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:12px;
  padding:12px 14px;
  border:1px solid rgba(255,255,255,.10);
  border-radius:18px;
  background:rgba(255,255,255,.03);
  margin-bottom:12px;
}
.plantTitle{font-weight:850;font-size:16px}
.plantSub{font-size:11px;opacity:.7;margin-top:2px}

.lineCards{display:grid;grid-template-columns:repeat(auto-fit,minmax(220px,1fr));gap:10px;margin-bottom:12px}
.lcard{
  border:1px solid rgba(255,255,255,.10);
  background:rgba(255,255,255,.03);
  border-radius:16px;
  padding:10px 12px;
  cursor:pointer;
  transition:background .15s ease,border-color .15s ease,transform .05s ease;
}
.lcard:hover{background:rgba(255,255,255,.05)}
.lcard:active{transform:scale(.998)}
.lcard.active{border-color:rgba(51,230,255,.45);box-shadow:0 0 0 1px rgba(51,230,255,.15) inset}
.l1{display:flex;justify-content:space-between;align-items:center;gap:10px}
.lname{font-weight:780}
.lmeta{margin-top:6px;display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}

.pfdWrap{border:1px solid rgba(255,255,255,.10);border-radius:18px;background:rgba(255,255,255,.02);overflow:hidden}
.pfdHead{padding:10px 12px;border-bottom:1px solid rgba(255,255,255,.08);display:flex;justify-content:space-between;align-items:center;gap:10px}
.pfdBody{padding:10px;overflow:auto;min-height:420px;max-height:70vh}
.pfdSvg{min-width:760px;min-height:420px}

.pfdNode{cursor:pointer}
.pfdNode rect{fill:rgba(255,255,255,.04);stroke:rgba(255,255,255,.18);stroke-width:1.2}
.pfdNode:hover rect{fill:rgba(255,255,255,.06);stroke:rgba(51,230,255,.35)}
.pfdNode text{fill:rgba(255,255,255,.92);font-size:12px}

.pfdEdge{cursor:pointer}
.pfdEdge line{stroke:rgba(255,255,255,.28);stroke-width:2}
.pfdEdge:hover line{stroke:rgba(51,230,255,.55)}
.pfdEdge text{fill:rgba(255,255,255,.72);font-size:11px}


/* ===== Skeleton / Loading cards ===== */
.skeleton{
  position:relative;
  overflow:hidden;
  border:1px solid rgba(255,255,255,.10);
  background:rgba(255,255,255,.03);
  border-radius:16px;
  padding:12px;
  min-height:86px;
}
.skeleton::after{
  content:'';
  position:absolute;
  top:0;left:-40%;
  height:100%;width:40%;
  background:linear-gradient(90deg, transparent, rgba(255,255,255,.10), transparent);
  animation:mdhShimmer 1.05s ease-in-out infinite;
}
@keyframes mdhShimmer{0%{left:-40%}100%{left:120%}}

.aiActions{display:flex;gap:8px;flex-wrap:wrap}
.aiResultGrid{display:grid;grid-template-columns:1fr;gap:10px}
.aiCard{border:1px solid rgba(255,255,255,.10);background:rgba(255,255,255,.03);border-radius:16px;overflow:hidden}
.aiCard .head{padding:10px 12px;border-bottom:1px solid rgba(255,255,255,.08);display:flex;justify-content:space-between;align-items:center;gap:10px}
.aiCard .body{padding:10px 12px}

