/* Tabs + MateChi Intelligence Platform dashboard. Loaded after styles.css. */

body { display: flex; flex-direction: column; }
#tabbar {
  flex: 0 0 46px; display: flex; align-items: center; gap: 6px; padding: 0 14px;
  background: #0c1016; border-bottom: 1px solid var(--line); z-index: 30; min-width: 0;
}
.tb-brand { font-weight: 800; font-size: 13.5px; letter-spacing: .3px; margin-right: 14px; color: #cfe0ff; }
.tb-brand span { color: var(--muted); font-weight: 500; font-size: 11px; margin-left: 6px; }
#tabbar .tb {
  background: transparent; color: var(--muted); border: 1px solid transparent; border-radius: 8px;
  padding: 7px 14px; font-size: 13px; font-weight: 600; cursor: pointer;
}
#tabbar .tb:hover { color: var(--ink); }
#tabbar .tb.active { color: #06223f; background: var(--accent); border-color: var(--accent); }
.tb-link { text-decoration: none; }

#app { height: auto; min-height: 0; flex: 1 1 auto; }
#platform { flex: 1 1 auto; min-height: 0; display: flex; background: var(--bg); }
#platform[hidden] { display: none; }
body.platform-active #app { display: none; }

.plat-side { width: 232px; flex: none; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.plat-org { padding: 16px; border-bottom: 1px solid var(--line); }
.plat-org-name { font-weight: 700; font-size: 14px; }
.plat-org-plan { color: var(--ok); font-size: 11.5px; margin-top: 3px; }
.plat-nav { display: flex; flex-direction: column; padding: 8px; gap: 2px; }
.plat-nav button { text-align: left; background: transparent; color: var(--ink); border: 1px solid transparent; border-radius: 8px; padding: 9px 11px; font-size: 13px; cursor: pointer; }
.plat-nav button:hover { background: var(--panel-2); }
.plat-nav button.active { background: var(--panel-2); border-color: var(--accent); color: #cfe0ff; }
.plat-side-foot { margin-top: auto; padding: 14px 16px; color: var(--muted); font-size: 10.5px; border-top: 1px solid var(--line); }
.plat-main { flex: 1; min-width: 0; overflow-y: auto; overflow-x: hidden; padding: 22px 26px 60px; }

.plat-h { font-size: 18px; margin: 0 0 16px; }
.plat-h .plat-sub, .plat-sub { color: var(--muted); font-size: 12px; font-weight: 500; }
.muted { color: var(--muted); }
.agroup-label { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); margin: 22px 0 10px; }

.plat-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.plat-kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 11px; padding: 14px 15px; }
.plat-kpi.small { padding: 11px 13px; }
.pk-v { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; }
.plat-kpi.small .pk-v { font-size: 19px; }
.pk-k { color: var(--ink); font-size: 12.5px; margin-top: 4px; }
.pk-sub { color: var(--muted); font-size: 11px; margin-top: 2px; }

.plat-two { display: grid; grid-template-columns: 1.2fr 1fr; gap: 14px; margin-top: 18px; }
.plat-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.plat-card h3 { margin: 0 0 10px; font-size: 14px; }

.feed-row { display: flex; gap: 9px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 12.5px; }
.feed-row:last-child { border-bottom: none; }
.feed-dot { width: 8px; height: 8px; border-radius: 2px; background: #9b7c31; margin-top: 5px; flex: none; }
.feed-msg { color: var(--muted); margin-top: 2px; }

.rec { display: flex; gap: 10px; padding: 10px 12px; border-radius: 10px; margin-bottom: 8px; background: var(--panel-2); border: 1px solid var(--line); }
.rec-sev { font-size: 9.5px; text-transform: uppercase; letter-spacing: .5px; font-weight: 800; padding: 3px 7px; border-radius: 20px; height: fit-content; }
.rec-high .rec-sev { background: rgba(231,76,60,.18); color: #ff9b8e; }
.rec-med .rec-sev { background: rgba(241,196,15,.16); color: #f1c40f; }
.rec-low .rec-sev { background: rgba(46,204,113,.15); color: #6fe0a0; }
.rec-title { font-weight: 600; font-size: 13px; }
.rec-body { color: var(--muted); font-size: 12px; margin-top: 3px; }

.agrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(248px, 1fr)); gap: 11px; }
.acard { text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 13px 14px; cursor: pointer; color: var(--ink); transition: border-color .12s, transform .05s; }
.acard:hover { border-color: var(--accent); }
.acard:active { transform: scale(.99); }
.acard.static { cursor: default; }
.acard.static:hover { border-color: var(--line); }
.acard-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.astatus { font-size: 9.5px; font-weight: 800; letter-spacing: .5px; padding: 3px 7px; border-radius: 20px; }
.astatus.connected { background: rgba(74,163,255,.16); color: #a9d3ff; }
.astatus.scenario { background: rgba(241,196,15,.13); color: #f6dc75; }
.astatus.live { background: rgba(46,204,113,.16); color: #6fe0a0; }
.astatus.enabled { background: rgba(74,163,255,.14); color: #8fc0ff; }
.aruns { color: var(--muted); font-size: 11px; }
.aname { font-weight: 700; font-size: 13.5px; }
.adesc { color: var(--muted); font-size: 12px; margin: 5px 0 10px; line-height: 1.4; }
.akpi { display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--line); padding-top: 8px; font-size: 12px; }
.akpi span { color: var(--muted); }
.akpi b { color: var(--accent); }

.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.metric { background: var(--panel); border: 1px solid var(--line); border-radius: 11px; padding: 12px 13px; }
.metric-head { display: flex; justify-content: space-between; font-size: 12.5px; }
.metric-head b { font-variant-numeric: tabular-nums; }
.metric .good { color: var(--ok); }
.spark { display: flex; align-items: flex-end; gap: 3px; height: 34px; margin-top: 9px; }
.spark .bar { flex: 1; background: linear-gradient(180deg, var(--accent), #2b6db5); border-radius: 2px; opacity: .85; }

.thread-brief p { margin: 0; line-height: 1.55; }
.thread-map { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 11px; }
.thread-node {
  display: grid; grid-template-columns: 42px 1fr; gap: 12px; align-items: start;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 15px;
}
.thread-index {
  width: 34px; height: 34px; display: grid; place-items: center;
  background: rgba(74,163,255,.12); color: #8fc0ff; border: 1px solid rgba(74,163,255,.28);
  border-radius: 9px; font-weight: 800; font-size: 12px; font-variant-numeric: tabular-nums;
}
.thread-name { font-weight: 750; font-size: 13.5px; }
.thread-owner { color: #8fc0ff; font-size: 11.5px; margin-top: 3px; }
.thread-detail { color: var(--muted); font-size: 12px; line-height: 1.45; margin-top: 7px; }

.proj-list { display: flex; flex-direction: column; gap: 10px; }
.proj { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 13px 15px; }
.proj-head { display: flex; justify-content: space-between; align-items: flex-start; }
.proj-name { font-weight: 700; font-size: 14px; }
.proj-status { font-size: 11px; color: #8fc0ff; background: rgba(74,163,255,.12); padding: 4px 9px; border-radius: 20px; white-space: nowrap; }
.proj-bar { height: 6px; background: var(--panel-2); border-radius: 4px; margin: 10px 0; overflow: hidden; }
.proj-bar span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), #2ecc71); }
.proj-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.proj-agents { display: flex; gap: 5px; flex-wrap: wrap; }
.chip { font-size: 10.5px; color: var(--ink); background: var(--panel-2); border: 1px solid var(--line); border-radius: 14px; padding: 3px 8px; cursor: pointer; }
.chip:hover { border-color: var(--accent); }

#agent-drawer { position: fixed; inset: 0; z-index: 80; display: none; }
#agent-drawer.open { display: block; }
.ad-scrim { position: absolute; inset: 0; background: rgba(0,0,0,.5); }
.ad-panel { position: absolute; top: 0; right: 0; bottom: 0; width: min(560px, 94vw); background: var(--panel); border-left: 1px solid var(--line); box-shadow: var(--shadow); padding: 18px 20px; overflow-y: auto; }
.ad-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.ad-head h3 { margin: 8px 0 2px; font-size: 17px; }
.ad-close { background: var(--panel-2); border: 1px solid var(--line); color: var(--ink); width: 30px; height: 30px; border-radius: 8px; cursor: pointer; flex: none; }
.ad-desc { color: var(--muted); font-size: 13px; line-height: 1.5; margin: 12px 0; }
.ad-q { display: flex; gap: 8px; margin-bottom: 10px; }
.ad-q input { flex: 1; background: var(--panel-2); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; font-size: 13px; }
.ad-q button, .ad-run { background: var(--accent); border: 1px solid var(--accent); color: #06223f; font-weight: 700; padding: 9px 14px; border-radius: 8px; cursor: pointer; font-size: 13px; }
.ad-run { width: 100%; margin-bottom: 14px; }
.ad-out { min-height: 60px; }
.ad-card { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 13px 14px; }
.ad-card-h { font-weight: 700; font-size: 13.5px; margin-bottom: 10px; }
.ad-stat { font-weight: 700; font-size: 13px; padding: 7px 10px; border-radius: 8px; margin-bottom: 10px; }
.ad-stat.ok { background: rgba(46,204,113,.14); color: #6fe0a0; }
.ad-stat.warn { background: rgba(241,196,15,.14); color: #f1c40f; }
.ad-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.ad-table th, .ad-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.ad-table th { color: var(--muted); font-size: 11px; text-transform: uppercase; }
.v-pass, .v-included, .v-ok { color: #6fe0a0; font-weight: 700; }
.v-fail, .v-critical, .v-error { color: #ff9b8e; font-weight: 700; }
.v-review, .v-high, .v-warning { color: #f1c40f; font-weight: 700; }
.ad-note { color: var(--muted); font-size: 11.5px; margin-top: 10px; }
.cite { border-left: 2px solid var(--accent); padding: 6px 0 6px 11px; margin: 9px 0; }
.cite-src { color: #8fc0ff; font-size: 11px; font-weight: 600; }
.cite-ex { color: var(--ink); font-size: 12px; margin-top: 3px; }

@media (max-width: 860px) {
  /* The tab bar is fixed at the very top; the configurator's drawer-toolbar sits just below it,
     and the stage/panels are offset to clear both. */
  #tabbar { position: fixed; top: 0; left: 0; right: 0; height: 44px; z-index: 60; justify-content: flex-start; gap: 4px; overflow-x: auto; overscroll-behavior-x: contain; padding: 0 8px; scrollbar-width: none; }
  #tabbar::-webkit-scrollbar { display: none; }
  .tb-brand { display: none; }
  #tabbar .tb { padding: 7px 11px; flex: 0 0 auto; white-space: nowrap; }
  #mtopbar { top: 44px; }                       /* below the tab bar */
  body.platform-active #mtopbar { display: none; }
  #stage { top: 96px; }                          /* 44 tab bar + 52 mobile toolbar */
  #panel-left, #panel-right { top: 96px; }
  #backdrop { top: 96px; }
  #platform { position: fixed; inset: 44px 0 0 0; }  /* below the tab bar */

  .plat-side { width: 72px; }
  .plat-org, .plat-side-foot { display: none; }
  .plat-nav button { font-size: 9.5px; line-height: 1.15; padding: 9px 6px; text-align: center; }
  .plat-main { padding: 16px 12px 50px; }
  .plat-h .plat-sub { display: none; }
  .plat-kpis { grid-template-columns: repeat(2, 1fr); }
  .plat-two { grid-template-columns: 1fr; }
  .ctrl-bar { gap: 8px 10px; padding: 10px 11px; }
  .ctrl-bar label { font-size: 11px; }
  .ctrl-bar select, .ctrl-bar input { padding: 6px 7px; font-size: 12px; }
  /* Make the View (Chart / 3D twin) toggle stand out on phones */
  #fd-view { border-color: var(--accent); }
  .ctrl-bar label:has(#fd-view) { order: -1; flex: 1 0 100%; font-weight: 700; color: var(--ink); }
}

@media (max-width: 560px) {
  #tabbar { gap: 2px; overflow-x: hidden; padding-inline: 6px; }
  #tabbar .tb { flex: 1 1 0; min-width: 0; padding-inline: 3px; font-size: 12px; text-align: center; }
}

/* Control bars for Factory Designer + Procurement */
.ctrl-bar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 11px; padding: 12px 14px; margin-bottom: 16px; }
.ctrl-bar label { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 7px; }
.ctrl-bar label.chk { color: var(--ink); }
.ctrl-bar select, .ctrl-bar input { background: var(--panel-2); color: var(--ink); border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px; font-size: 12.5px; }
.ctrl-bar input[type=checkbox] { accent-color: var(--accent); }
.ctrl-bar > button.m-btn {
  background: var(--panel-2); color: var(--ink); border: 1px solid var(--line);
  border-radius: 7px; padding: 7px 10px; font: inherit; font-size: 12px; cursor: pointer;
}
.ctrl-bar > button.m-btn:hover { border-color: var(--accent); }
.ctrl-bar > button.m-btn:disabled { opacity: .48; cursor: not-allowed; border-color: var(--line); }
.acard.sel { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

/* Station utilization chart */
.stations { display: flex; align-items: flex-end; gap: 3px; background: var(--panel); border: 1px solid var(--line); border-radius: 11px; padding: 14px 12px; overflow-x: auto; }
.stn { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 22px; }
.stn-n { font-size: 9px; color: var(--muted); }
.stn-bar { width: 16px; height: 120px; display: flex; align-items: flex-end; background: var(--panel-2); border-radius: 3px; overflow: hidden; }
.stn-bar span { width: 100%; background: linear-gradient(180deg, var(--accent), #2b6db5); }
.stn-bar span.hot { background: linear-gradient(180deg, #f1c40f, #c79a08); }
.stn-bar span.bn { background: linear-gradient(180deg, #e74c3c, #b03224); }
.stn-u { font-size: 8.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.stn { cursor: pointer; }
.stn:hover .stn-bar { outline: 1px solid var(--accent); }
.stn .px { color: var(--accent); font-weight: 700; margin-left: 1px; }

/* Provenance banner + editable figures */
.prov { background: rgba(241,196,15,.08); border: 1px solid rgba(241,196,15,.35); color: var(--ink); font-size: 12px; border-radius: 9px; padding: 9px 12px; margin: 0 0 14px; }
.prov b { color: #f1c40f; }
.scenario-boundary { display: flex; align-items: center; gap: 16px; margin: 0 0 18px; padding: 13px 14px; border: 1px solid rgba(241,196,15,.58); border-left-width: 4px; border-radius: 10px; background: rgba(241,196,15,.085); }
.scenario-boundary > div { display: grid; gap: 2px; min-width: 0; }
.scenario-boundary strong { color: #f8df78; font-size: 12px; letter-spacing: .25px; }
.scenario-boundary span { color: #c5cfdb; font-size: 11.5px; line-height: 1.45; }
.scenario-boundary a { flex: none; color: #b8dbff; font-size: 11px; font-weight: 700; }

@media (max-width: 620px) {
  .scenario-boundary { align-items: flex-start; flex-direction: column; gap: 8px; }
}
.edit-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-bottom: 14px; }
.ef { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 11.5px; color: var(--muted); }
.ef span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ef input { width: 64px; background: var(--panel-2); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: 5px 7px; font-size: 12px; }
.cost-in { width: 78px; background: var(--panel-2); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; font-size: 12px; font-variant-numeric: tabular-nums; }
.cost-in:focus { border-color: var(--accent); outline: none; }

/* Factory layout authoring */
.layout-tools {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; margin-bottom: 10px;
}
.layout-tools label { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.layout-tools input, .layout-tools select, .layout-row input {
  background: var(--panel-2); color: var(--ink); border: 1px solid var(--line);
  border-radius: 7px; padding: 6px 8px; font-size: 12px; min-width: 0;
}
.layout-tools input { width: min(340px, 52vw); }
.layout-table {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  overflow-x: auto; margin-bottom: 14px;
}
.layout-head, .layout-row {
  display: grid; grid-template-columns: 34px minmax(180px, 1.4fr) minmax(120px, .8fr) 72px 58px 70px 70px 142px;
  gap: 6px; align-items: center; min-width: 880px; padding: 7px 10px;
}
.layout-head {
  color: var(--muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: .45px;
  border-bottom: 1px solid var(--line);
}
.layout-row { border-bottom: 1px solid var(--line); }
.layout-row:last-child { border-bottom: none; }
.layout-row > span:first-child { color: var(--muted); font-variant-numeric: tabular-nums; }
.layout-actions { display: flex; gap: 4px; }
.layout-actions button {
  background: var(--panel-2); color: var(--ink); border: 1px solid var(--line);
  border-radius: 6px; padding: 5px 7px; font-size: 11px; cursor: pointer;
}
.layout-actions button:hover { border-color: var(--accent); }

/* Factory 3D twin */
.twin-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.twin-wrap { display: grid; grid-template-columns: 1fr 280px; gap: 12px; height: 72vh; min-height: 460px; }
.twin-canvas { background: #0c1016; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; position: relative; }
.twin-canvas canvas { display: block; }
.twin-data { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; overflow-y: auto; }
.twin-data .ad-card-h { font-weight: 700; font-size: 14px; margin-bottom: 10px; }
.twin-kpi { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 12.5px; }
.twin-kpi span { color: var(--muted); }
.twin-kpi b { font-variant-numeric: tabular-nums; }
.twin-machine { font-size: 12px; color: #9cc0ff; background: rgba(74,111,255,.1); border: 1px solid rgba(91,140,255,.3); border-radius: 7px; padding: 6px 9px; margin-bottom: 10px; }
@media (max-width: 860px) {
  .twin-wrap { grid-template-columns: 1fr; height: auto; }
  .twin-canvas { height: 52vh; }
}

/* SKU report table */
.ad-table.sku td, .ad-table.sku th { padding: 5px 9px; }
.ad-table.sku tr.total td { border-top: 2px solid var(--line); border-bottom: none; padding-top: 8px; }
.ad-table.sku tr:hover td { background: var(--panel-2); }
