/* =====================================================================
   KIRAN OMS V4 — Phase 7.2
   Sticky Master Order command bar + Light/Dark theme system
   ===================================================================== */
:root{
  --mo-sticky-gap:8px;
  --mo-sticky-top:calc(var(--header-h,68px) + var(--mo-sticky-gap));
  --mo-sticky-shadow:0 10px 28px rgba(15,23,42,.12);
}

/* ---------------------------------------------------------------------
   MASTER ORDER — KEEP THE 2-ROW FILTER/ACTION BAR VISIBLE WHILE SCROLLING
   --------------------------------------------------------------------- */
#pg-orders .mo-filter-shell{
  position:sticky!important;
  top:var(--mo-sticky-top)!important;
  z-index:1080!important;
  margin-top:0!important;
  isolation:isolate;
  transition:box-shadow .18s ease,border-color .18s ease,background .18s ease;
}
#pg-orders .mo-filter-shell.mo-stuck{
  box-shadow:var(--mo-sticky-shadow)!important;
  border-color:#cbd8e8!important;
}
#pg-orders .mo-filter-shell::before{
  content:"";
  position:absolute;
  left:-4px;right:-4px;top:calc(-1 * var(--mo-sticky-gap));
  height:var(--mo-sticky-gap);
  background:var(--app-bg);
  pointer-events:none;
}
/* Dropdowns must open above the order table even while the toolbar is sticky. */
#pg-orders .mo-filter-shell .msel-panel{z-index:1400!important}
#pg-orders .mo-filter-shell .cd-panel{z-index:1400!important}

/* Give table jumps enough clearance so a target row never hides under the frozen bar. */
#pg-orders #ow,
#pg-orders #ar-tr{
  scroll-margin-top:calc(var(--header-h,68px) + 112px)!important;
}

/* Compact sticky shell on smaller screens. Keep the user's requested 2 rows. */
@media (max-width:1180px){
  #pg-orders .mo-filter-shell{top:calc(var(--header-h,62px) + 5px)!important}
}
@media (max-width:760px){
  :root{--mo-sticky-gap:4px}
  #pg-orders .mo-filter-shell{border-radius:9px!important}
}
@media print{
  #pg-orders .mo-filter-shell{position:static!important;box-shadow:none!important}
}

/* ---------------------------------------------------------------------
   THEME TOGGLE BUTTON
   --------------------------------------------------------------------- */
.theme-toggle{
  height:34px!important;
  min-width:88px;
  display:inline-flex!important;
  align-items:center;
  justify-content:center;
  gap:6px;
  border:1px solid var(--line)!important;
  border-radius:9px!important;
  padding:0 10px!important;
  background:var(--surface)!important;
  color:var(--text-2)!important;
  font-size:10.5px!important;
  font-weight:800!important;
  cursor:pointer;
  white-space:nowrap;
}
.theme-toggle:hover{border-color:#94a3b8!important;transform:translateY(-1px)}
.theme-toggle .theme-icon{font-size:14px;line-height:1}
@media (max-width:1180px){.theme-toggle{min-width:34px!important;width:34px!important;padding:0!important}.theme-toggle .theme-label{display:none}}

/* ---------------------------------------------------------------------
   DARK THEME — VARIABLE LAYER
   --------------------------------------------------------------------- */
html[data-theme="dark"]{
  color-scheme:dark;
  --app-bg:#0a1020;
  --surface:#111827;
  --surface-soft:#162033;
  --surface-raised:#172235;
  --text:#e6edf7;
  --text-2:#aab7ca;
  --text-3:#8190a6;
  --line:#273449;
  --line-strong:#34445b;
  --brand:#60a5fa;
  --brand-2:#3b82f6;
  --brand-soft:#172554;
  --success:#4ade80;
  --warning:#fbbf24;
  --danger:#f87171;
  --sidebar:#070d18;
  --sidebar-2:#101827;
  --sidebar-text:#d7e1ef;
  --sidebar-muted:#7f91aa;
  --sidebar-line:rgba(255,255,255,.08);
  --bg:var(--app-bg);
  --s1:var(--surface);
  --s2:var(--surface-soft);
  --s3:#1d2939;
  --bd:var(--line);
  --acc:var(--brand);
  --tx:var(--text);
  --mu:var(--text-2);
  --hdr-bg:var(--sidebar);
  --mo-sticky-shadow:0 12px 30px rgba(0,0,0,.34);
}

html[data-theme="dark"],
html[data-theme="dark"] body,
html[data-theme="dark"] main,
html[data-theme="dark"] .pg{background:var(--app-bg)!important;color:var(--text)!important}

html[data-theme="dark"] header.app-header{
  background:rgba(12,19,33,.97)!important;
  border-bottom-color:var(--line)!important;
  box-shadow:0 6px 24px rgba(0,0,0,.28)!important;
}
html[data-theme="dark"] header .logo{color:#f1f5f9!important}
html[data-theme="dark"] #app-page-title{color:#dbe7f6!important}
html[data-theme="dark"] .header-page-kicker,
html[data-theme="dark"] .brand-subtitle,
html[data-theme="dark"] header .header-current-date,
html[data-theme="dark"] header .header-last-work{color:var(--text-3)!important}
html[data-theme="dark"] header .header-current-date b{color:#d2dbea!important}
html[data-theme="dark"] .sidebar-toggle,
html[data-theme="dark"] .sys-pill,
html[data-theme="dark"] .header-icon-btn,
html[data-theme="dark"] .fit-control button,
html[data-theme="dark"] .theme-toggle{
  background:#111a2a!important;color:#b8c5d8!important;border-color:#2a3950!important;
}
html[data-theme="dark"] .lan-pill{background:#10251b!important;border-color:#214b34!important;color:#75d99a!important}
html[data-theme="dark"] .oms-pill{background:#2a161a!important;border-color:#5d2d35!important;color:#f39aa8!important}
html[data-theme="dark"] .header-kpi{background:#101827!important;border-color:#202d40!important;color:#7f8da3!important}
html[data-theme="dark"] .header-kpi b{color:#e2e8f0!important}

/* Sidebar remains deliberately dark in both themes, only flyouts need switching. */
html[data-theme="dark"] .nav-history-dropdown,
html[data-theme="dark"] .nav-admin-dropdown{background:#111827!important;border-color:#2b3a50!important}
html[data-theme="dark"] .nav-history-dropdown .tab,
html[data-theme="dark"] .nav-admin-dropdown .tab{background:#111827!important;color:#c5d1e2!important}
html[data-theme="dark"] .nav-history-dropdown .tab:hover,
html[data-theme="dark"] .nav-admin-dropdown .tab:hover{background:#17243a!important;color:#8ec0ff!important}

/* Inputs, dropdowns, forms */
html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea,
html[data-theme="dark"] .inp,
html[data-theme="dark"] .sel,
html[data-theme="dark"] .mo-sort-field{
  background:#101827!important;
  color:#e5edf7!important;
  border-color:#34445b!important;
}
html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder{color:#708099!important}
html[data-theme="dark"] option{background:#111827!important;color:#e5edf7!important}
html[data-theme="dark"] input:focus,
html[data-theme="dark"] select:focus,
html[data-theme="dark"] textarea:focus{border-color:#60a5fa!important;box-shadow:0 0 0 3px rgba(96,165,250,.14)!important}

/* Common surfaces */
html[data-theme="dark"] .filter-card,
html[data-theme="dark"] .stbl,
html[data-theme="dark"] .rpt-card,
html[data-theme="dark"] .card,
html[data-theme="dark"] .panel,
html[data-theme="dark"] .twrap,
html[data-theme="dark"] .mbox,
html[data-theme="dark"] .mhd,
html[data-theme="dark"] .mbody,
html[data-theme="dark"] .mft,
html[data-theme="dark"] .pgbar,
html[data-theme="dark"] .msel-panel,
html[data-theme="dark"] .cd-panel{
  background:var(--surface)!important;
  color:var(--text)!important;
  border-color:var(--line)!important;
}
html[data-theme="dark"] .filter-card-header,
html[data-theme="dark"] .mhd,
html[data-theme="dark"] .mft{border-color:var(--line)!important}

/* Master Order sticky shell */
html[data-theme="dark"] #pg-orders .mo-filter-shell{
  background:linear-gradient(180deg,#131d2e 0%,#101827 100%)!important;
  border-color:#2b3a50!important;
}
html[data-theme="dark"] #pg-orders .mo-filter-shell.mo-stuck{border-color:#3c5270!important}
html[data-theme="dark"] #pg-orders .mo-filter-row-1{border-bottom-color:#2a394f!important}
html[data-theme="dark"] #pg-orders .mo-sort-box{background:#101827!important;border-color:#324760!important}
html[data-theme="dark"] #pg-orders #xl-toggle-btn{background:#10251b!important;border-color:#2f6845!important;color:#8ee5ab!important}

/* Buttons / segmented controls */
html[data-theme="dark"] .btn,
html[data-theme="dark"] .qs-btn,
html[data-theme="dark"] .vb,
html[data-theme="dark"] .abt{
  background:#121c2c!important;
  color:#cbd6e5!important;
  border-color:#33445a!important;
}
html[data-theme="dark"] .btn:hover,
html[data-theme="dark"] .qs-btn:hover,
html[data-theme="dark"] .vb:hover,
html[data-theme="dark"] .abt:hover{background:#1a2940!important;color:#fff!important}
html[data-theme="dark"] .btn-acc,
html[data-theme="dark"] .vb.on{background:#2563eb!important;color:#fff!important;border-color:#3b82f6!important}

html[data-theme="dark"] .qs-bar{background:#0d2134!important;border-bottom-color:#234766!important}
html[data-theme="dark"] .xl-bar{background:#10241a!important;border-color:#285a3d!important}
html[data-theme="dark"] .qs-sep{background:#334155!important}

/* Tables */
html[data-theme="dark"] table.ot,
html[data-theme="dark"] .stbl table,
html[data-theme="dark"] #pg-dash .stbl,
html[data-theme="dark"] #pg-dash .stbl table{background:#111827!important;color:#e6edf7!important;border-color:#2a394f!important}
html[data-theme="dark"] table.ot thead th,
html[data-theme="dark"] .stbl th,
html[data-theme="dark"] #pg-dash .stbl th{
  background:#172235!important;color:#aebed2!important;border-color:#2b3a50!important;
}
html[data-theme="dark"] table.ot tbody td,
html[data-theme="dark"] .stbl td,
html[data-theme="dark"] #pg-dash .stbl td{
  color:#d9e3f0!important;border-color:#263449!important;background:#111827;
}
html[data-theme="dark"] table.ot tbody tr:hover td,
html[data-theme="dark"] .stbl tr:hover td,
html[data-theme="dark"] #pg-dash .stbl tbody tr:hover td{background:#17243a!important}
html[data-theme="dark"] table.ot tbody tr.s-Pending td{background:#2b171b!important;color:#f5afb8!important}
html[data-theme="dark"] table.ot tbody tr.s-In-Production td{background:#2c2413!important;color:#f4ce79!important}
html[data-theme="dark"] table.ot tbody tr.s-Cancelled td{background:#27171a!important;color:#f2a3ad!important}
html[data-theme="dark"] tr.row-selected td{background:#15345e!important;outline-color:#60a5fa!important}
html[data-theme="dark"] .ar-row td,
html[data-theme="dark"] #ow > table.ot > tbody > tr.ar-row > td:last-child{background:#122b4a!important;border-color:#315b83!important}
html[data-theme="dark"] .ar-inp{background:#0f1b2c!important;color:#e7eef7!important;border-color:#355779!important}

/* Multi-selects / popovers */
html[data-theme="dark"] .msel-panel,
html[data-theme="dark"] .cd-panel{box-shadow:0 16px 34px rgba(0,0,0,.45)!important}
html[data-theme="dark"] .msel-actions,
html[data-theme="dark"] .msel-search{background:#111827!important;border-color:#2b3a50!important;color:#dbe5f2!important}
html[data-theme="dark"] .msel-list label,
html[data-theme="dark"] .cd-item{color:#d6e0ed!important}
html[data-theme="dark"] .msel-list label:hover,
html[data-theme="dark"] .cd-item:hover{background:#1c2b42!important}

/* Phase 2 dashboard / Phase 6 production / Phase 7 stock generic surfaces */
html[data-theme="dark"] [class*="p2-"],
html[data-theme="dark"] [class*="p6-"],
html[data-theme="dark"] [class*="p7-"]{border-color:var(--line)}
html[data-theme="dark"] .p2-kpi-card,
html[data-theme="dark"] .p2-panel,
html[data-theme="dark"] .p2-activity-item,
html[data-theme="dark"] .p2-alert-item,
html[data-theme="dark"] .p6-metric,
html[data-theme="dark"] .p6-lane,
html[data-theme="dark"] .p6-order-card,
html[data-theme="dark"] .p6-workload-card,
html[data-theme="dark"] .p7-kpi-card,
html[data-theme="dark"] .p7-panel,
html[data-theme="dark"] .p7-ledger-card,
html[data-theme="dark"] .p7-reorder-card{
  background:#111827!important;color:#e5edf7!important;border-color:#29384c!important;
}
html[data-theme="dark"] .p2-panel-head,
html[data-theme="dark"] .p6-panel-head,
html[data-theme="dark"] .p7-panel-head{background:#141f31!important;border-color:#29384c!important;color:#dce6f3!important}

/* Sole/Box tables and report blocks */
html[data-theme="dark"] .sole-tbl th{background:#172235!important;color:#b8c6d8!important;border-color:#314157!important}
html[data-theme="dark"] .sole-tbl td{background:#111827!important;color:#dbe5f0!important;border-color:#263449!important}
html[data-theme="dark"] .sole-tbl tbody tr:hover td{background:#17243a!important}
html[data-theme="dark"] .sole-data-row.sole-row-prod td{background:#2a2415!important}
html[data-theme="dark"] .sole-data-row.sole-row-projected td{background:#11251c!important}
html[data-theme="dark"] .sole-data-row.sole-row-pending td{background:#21182f!important}
html[data-theme="dark"] .sole-data-row.sole-row-balance td{background:#172033!important}
html[data-theme="dark"] .sole-data-row.sole-row-need td{background:#2a171b!important}

/* Inline hard-coded light backgrounds commonly used across legacy panels. */
html[data-theme="dark"] .info-bar,
html[data-theme="dark"] [style*="background:#fff"],
html[data-theme="dark"] [style*="background: #fff"],
html[data-theme="dark"] [style*="background:#f8fafc"],
html[data-theme="dark"] [style*="background:var(--bg2"]{
  background:#111827!important;
  color:#dbe5f0!important;
  border-color:#2b3a50!important;
}

/* Keep semantic warning/success banners readable rather than flattening them. */
html[data-theme="dark"] .alert-bar{color:#f8e7b0!important}
html[data-theme="dark"] #backup-reminder{background:#342a12!important;border-color:#6d5420!important}

/* Scrollbars */
html[data-theme="dark"] *{scrollbar-color:#40516a #111827}
html[data-theme="dark"] ::-webkit-scrollbar{width:10px;height:10px}
html[data-theme="dark"] ::-webkit-scrollbar-track{background:#101827}
html[data-theme="dark"] ::-webkit-scrollbar-thumb{background:#40516a;border-radius:10px;border:2px solid #101827}
