/* ========================================================================
   GPS Responsive CSS — Mobile/Tablet UI Pass
   Loaded AFTER sidebar.css in index_app.html
   ======================================================================== */

/* -----------------------------------------------------------------------
   0. Z-INDEX HIERARCHY (global — not in media query)
   Page content:         1–10
   Sidebar (desktop):    50    (in sidebar.css)
   Sidebar backdrop:     190   (in sidebar.css)
   Sidebar (mobile):     200   (in sidebar.css)
   Modal backdrop:       300
   Modal content:        400
   Toasts:               500
   ----------------------------------------------------------------------- */

/* Modal z-index standardization */
#materialModal,
#adjModal,
#rescheduleModal,
#calendarSettingsModal,
#scheduleJobModal,
#downtimeModal,
#urgentScheduleModal,
#sjDefectModal,
#sjDetailModal,
#invoiceDetailModal,
#itemMasterDetailModal,
#poMasterSchedulerJobDetailWrap,
#poMasterSchedulerCalendarWrap {
  z-index: 400 !important;
}

#adjModalBackdrop {
  z-index: 300 !important;
}

/* Toast above everything */
.glr-toast {
  z-index: 500 !important;
}

/* Sidebar modal guard handled in sidebar.css */

/* =======================================================================
   LAYOUT RESTRUCTURE — Odoo-style flat full-width layout
   Overrides Tailwind pill/card classes on page-level containers.
   Does NOT affect: modals, KPI cards, login card.
   ======================================================================= */

/* --- Global overflow guard --- */
/* NOTE: html,body overflow-x:hidden breaks iOS Safari touch events.
   Scope to main content wrapper only. */
#appMain {
  overflow-x: hidden;
}

/* --- Remove gray background + centering from "form" pages --- */
/* NOTE: display must NOT use !important — it would override Tailwind's
   .hidden { display: none !important } and break tab switching. */
#page-po,
#page-design,
#page-item-master,
#page-sampling,
#page-clients,
#page-materials,
#page-employees,
#page-machines,
#page-pricing {
  background: var(--glorion-black, #0e0e0e) !important;
  padding: 12px !important;
  min-height: auto !important;
  display: block;
  align-items: initial !important;
  justify-content: initial !important;
}

/* --- Page-wrap: full width --- */
.page-wrap {
  max-width: none !important;
}

/* --- Neutralize card/pill wrappers on page sections ---
   Pattern found: bg-white rounded-2xl shadow p-5/p-6 border
   We target by page ID > descendant so modals/KPI are untouched. */

/* "Form" pages: single large card wrapper */
#page-po > .page-wrap > .bg-white.rounded-2xl,
#page-design > .page-wrap > .bg-white.rounded-2xl,
#page-item-master > .page-wrap > .bg-white.rounded-2xl,
#page-clients > .page-wrap > .bg-white.rounded-2xl,
#page-materials > .page-wrap > .bg-white.rounded-2xl,
#page-employees > .page-wrap > .bg-white.rounded-2xl,
#page-machines > .page-wrap > .bg-white.rounded-2xl,
#page-pricing > .page-wrap > .bg-white.rounded-2xl {
  border-radius: 0 !important;
  box-shadow: none !important;
  border: none !important;
  border-bottom: 1px solid var(--glorion-border, #2a2a2b) !important;
  padding: 16px !important;
}

/* Sampling page: multiple cards inside page-wrap */
#page-sampling > .page-wrap > .bg-white.rounded-2xl,
#page-sampling > .page-wrap > .rounded-2xl.shadow-sm,
#page-sampling .grid > .bg-white.rounded-2xl {
  border-radius: 8px !important;
  box-shadow: none !important;
  border: 1px solid var(--glorion-border, #2a2a2b) !important;
}

/* "Section card" pages: multiple cards stacked */
#page-prod > .bg-white.rounded-2xl,
#page-prod > .grid > .bg-white.rounded-2xl,
#page-qc > .bg-white.rounded-2xl,
#page-sj > .bg-white.rounded-2xl,
#page-invoice > .bg-white.rounded-2xl,
#page-po-master > .bg-white.rounded-2xl,
#page-logs > .bg-white.rounded-2xl {
  border-radius: 0 !important;
  box-shadow: none !important;
  border-bottom: 1px solid var(--glorion-border, #2a2a2b) !important;
  border-left: none !important;
  border-right: none !important;
  border-top: none !important;
}

/* Scheduler: lane subtitle under machine name */
.machine-lane {
  font-size: 11px;
  color: #8b949e;
}

/* =======================================================================
   SCHEDULER DARK MODE
   Forces #page-scheduler and all its children to dark theme.
   ======================================================================= */

/* Page background */
#page-scheduler {
  background: var(--glorion-black, #0e0e0e) !important;
}

/* Header card + calendar grid card + PO monitor panel */
#page-scheduler .scheduler-header,
#page-scheduler .bg-white.rounded-2xl.shadow,
#page-scheduler > div > .grid > div > .bg-white,
#page-scheduler .bg-white {
  background: var(--glorion-surface, #161617) !important;
  border: 1px solid var(--glorion-border, #2a2a2b) !important;
  border-radius: 8px !important;
  box-shadow: none !important;
}

/* PO Monitor aside */
#page-scheduler aside,
#poMonitorPanel {
  background: var(--glorion-surface, #161617) !important;
  border: 1px solid var(--glorion-border, #2a2a2b) !important;
}

/* Headings and primary text */
#page-scheduler h2,
#page-scheduler .text-xl,
#page-scheduler .text-gray-800,
#page-scheduler .text-slate-700,
#page-scheduler .font-semibold:not([class*="text-red"]):not([class*="text-amber"]):not([class*="text-emerald"]):not([class*="text-blue"]):not([class*="text-orange"]):not([class*="text-purple"]):not([class*="text-green"]) {
  color: var(--glorion-text-bright, #f5f5f5) !important;
}

/* Secondary / muted text */
#page-scheduler .text-gray-500,
#page-scheduler .text-gray-600,
#page-scheduler .text-slate-500,
#page-scheduler .text-slate-600,
#page-scheduler .text-slate-400 {
  color: var(--glorion-text-secondary, #a0a0a0) !important;
}

/* Lighter muted text */
#page-scheduler .text-slate-300 {
  color: #555 !important;
}

/* Toolbar buttons */
#page-scheduler .scheduler-toolbar button,
#page-scheduler button.rounded-lg {
  background: var(--glorion-surface-2, #1e1e1f) !important;
  border-color: var(--glorion-border, #2a2a2b) !important;
  color: var(--glorion-text-primary, #e0e0e0) !important;
}
#page-scheduler .scheduler-toolbar button:hover,
#page-scheduler button.rounded-lg:hover {
  background: var(--glorion-border, #2a2a2b) !important;
}

/* Calendar & date picker inputs */
#page-scheduler input[type="date"],
#page-scheduler input[type="text"],
#page-scheduler select {
  background: var(--glorion-surface-2, #1e1e1f) !important;
  border-color: var(--glorion-border, #2a2a2b) !important;
  color: var(--glorion-text-primary, #e0e0e0) !important;
}

/* Calendar settings, PO Monitor search */
#poMasterSchedulerMonitorSearch {
  background: var(--glorion-surface-2, #1e1e1f) !important;
  border-color: var(--glorion-border, #2a2a2b) !important;
  color: var(--glorion-text-primary, #e0e0e0) !important;
}

/* PO Monitor tab buttons */
#page-scheduler .inline-flex.rounded-lg {
  border-color: var(--glorion-border, #2a2a2b) !important;
  background: var(--glorion-surface, #161617) !important;
}

/* PO Monitor line rows */
#page-scheduler .po-line-row {
  border-color: var(--glorion-border, #2a2a2b) !important;
}
#page-scheduler .po-line-row:hover {
  background: rgba(255,255,255,0.03) !important;
}
#page-scheduler .po-line-row .text-gray-800 {
  color: var(--glorion-text-bright, #f5f5f5) !important;
}
#page-scheduler .po-line-row .text-gray-600,
#page-scheduler .po-line-row .text-gray-500 {
  color: var(--glorion-text-secondary, #a0a0a0) !important;
}

/* PO Monitor list container border */
#poMasterSchedulerMonitorList {
  border-color: var(--glorion-border, #2a2a2b) !important;
}

/* ---- Calendar Grid Table ---- */
#poMasterSchedulerGrid table {
  border-color: var(--glorion-border, #2a2a2b) !important;
}

/* Thead */
#poMasterSchedulerGrid thead,
#poMasterSchedulerGrid thead th,
#poMasterSchedulerGrid .bg-slate-50 {
  background: var(--glorion-surface-2, #1e1e1f) !important;
  color: var(--glorion-text-secondary, #a0a0a0) !important;
}

/* Machine name sticky column */
#poMasterSchedulerGrid td.sticky,
#poMasterSchedulerGrid th.sticky {
  background: var(--glorion-surface, #161617) !important;
  border-color: var(--glorion-border, #2a2a2b) !important;
  color: var(--glorion-text-bright, #f5f5f5) !important;
}
#poMasterSchedulerGrid td.sticky .text-slate-500,
#poMasterSchedulerGrid td.sticky .text-slate-600 {
  color: var(--glorion-text-secondary, #a0a0a0) !important;
}

/* All table cell borders */
#poMasterSchedulerGrid td,
#poMasterSchedulerGrid th {
  border-color: var(--glorion-border, #2a2a2b) !important;
}

/* Slot cells — base dark background */
#poMasterSchedulerGrid td.align-top {
  background-color: var(--glorion-surface, #161617);
}

/* Slot cell text */
#poMasterSchedulerGrid td .text-slate-600,
#poMasterSchedulerGrid td .text-slate-700 {
  color: var(--glorion-text-secondary, #a0a0a0) !important;
}
#poMasterSchedulerGrid td .text-slate-400 {
  color: #555 !important;
}

/* "Slot Detail" button inside cells */
#poMasterSchedulerGrid td button[data-slot-detail-id] {
  background: var(--glorion-surface-2, #1e1e1f) !important;
  border-color: var(--glorion-border, #2a2a2b) !important;
  color: var(--glorion-text-secondary, #a0a0a0) !important;
}
#poMasterSchedulerGrid td button[data-slot-detail-id]:hover {
  background: var(--glorion-border, #2a2a2b) !important;
}

/* Downtime cell */
#poMasterSchedulerGrid .bg-slate-300 {
  background: #2a2a2b !important;
  color: var(--glorion-text-secondary, #a0a0a0) !important;
}

/* OFF/LIBUR cells */
#poMasterSchedulerGrid .bg-red-50 {
  background: rgba(220, 38, 38, 0.08) !important;
}
#poMasterSchedulerGrid .bg-slate-50 {
  background: var(--glorion-surface-2, #1e1e1f) !important;
}

/* Load tone: color only on badge/pill, not on cell background (removed cell tints) */

/* Downtime resolve button */
#poMasterSchedulerGrid button.bg-white {
  background: var(--glorion-surface-2, #1e1e1f) !important;
  color: var(--glorion-text-primary, #e0e0e0) !important;
}

/* Machine downtime button in machine column */
#poMasterSchedulerGrid button.bg-slate-100 {
  background: var(--glorion-surface-2, #1e1e1f) !important;
  color: var(--glorion-text-secondary, #a0a0a0) !important;
}
#poMasterSchedulerGrid button.bg-slate-100:hover {
  background: rgba(245, 158, 11, 0.15) !important;
}

/* Engine warnings banner */
#engineWarningsBanner {
  background: rgba(245, 158, 11, 0.1) !important;
  border-color: rgba(245, 158, 11, 0.25) !important;
}

/* ---- Scheduler-specific special buttons ---- */
/* Calendar button */
#scheduleCalendarBtn {
  background: rgba(56, 189, 248, 0.1) !important;
  border-color: rgba(56, 189, 248, 0.3) !important;
  color: #7dd3fc !important;
}
/* PO Lines toggle */
#poMonitorToggleBtn {
  background: rgba(99, 102, 241, 0.1) !important;
  border-color: rgba(99, 102, 241, 0.3) !important;
  color: #a5b4fc !important;
}

/* View toggle buttons (Produksi / QC) */
#page-scheduler .scheduler-view-toggle .svt-btn {
  background: var(--glorion-surface-2, #1e1e1f) !important;
  color: var(--glorion-text-secondary, #a0a0a0) !important;
  border-color: var(--glorion-border, #2a2a2b) !important;
}
#page-scheduler .scheduler-view-toggle .svt-btn.active {
  background: var(--glorion-border, #2a2a2b) !important;
  color: var(--glorion-text-bright, #f5f5f5) !important;
}

/* Hover on slot cells */
#poMasterSchedulerGrid td.cursor-pointer:hover {
  filter: brightness(1.15);
}

/* Dashboard: keep KPI cards, flatten other sections */
#page-dash > .bg-white.rounded-2xl:not([id^="kpi"]) {
  border-radius: 8px !important;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05) !important;
}

/* --- Section dividers instead of cards --- */
#page-prod > .bg-white + .bg-white,
#page-qc > .bg-white + .bg-white {
  margin-top: 0 !important;
}

/* --- Typography consistency --- */
.page-wrap h1,
#page-prod h1,
#page-qc h1,
#page-dash h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--glorion-text-bright, #f5f5f5);
  line-height: 1.3;
}

/* --- Form overflow prevention --- */
@media (max-width: 767px) {
  /* Thread (benang) rows: stack on mobile */
  .grid.grid-cols-12 {
    grid-template-columns: 1fr 1fr !important;
    gap: 8px !important;
  }

  .grid.grid-cols-12 > .col-span-4,
  .grid.grid-cols-12 > .col-span-6 {
    grid-column: span 1 !important;
  }

  .grid.grid-cols-12 > .col-span-2 {
    grid-column: span 2 !important;
  }

  /* Sampling file reference: stack flex row */
  #page-sampling .flex.items-center.gap-3 {
    flex-wrap: wrap;
  }

  #page-sampling .flex.items-center.gap-3 > span {
    word-wrap: break-word;
    overflow-wrap: break-word;
  }

  /* Prevent any element from causing horizontal scroll */
  img {
    max-width: 100%;
    height: auto;
  }

  /* "Form" pages: tighter padding on mobile */
  #page-po,
  #page-design,
  #page-item-master,
  #page-sampling {
    padding: 0 !important;
  }

  #page-po > .page-wrap > .bg-white,
  #page-design > .page-wrap > .bg-white,
  #page-item-master > .page-wrap > .bg-white {
    padding: 12px !important;
  }

  /* Dashboard header: stack title + refresh on mobile */
  #page-dash > .flex.items-center.justify-between {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 8px;
  }
}

/* -----------------------------------------------------------------------
   1. TOUCH QUALITY (global — benefits all touch devices)
   ----------------------------------------------------------------------- */

button,
.btn,
a.btn,
input[type="button"],
input[type="submit"],
[role="button"],
.nav-item,
.clickable {
  touch-action: manipulation;
}

/* Tap feedback on interactive elements */
.scheduler-slot:active,
.prod-row:active,
.po-master-row:active {
  opacity: 0.7;
  transition: opacity 0.1s;
}

/* Tap feedback on clickable non-button elements (touch devices) */
@media (hover: none) {
  tr[onclick]:active,
  [data-clickable]:active,
  #qcListBody tr:active {
    opacity: 0.7;
    transition: opacity 0.1s;
  }
}

/* Modal body scroll containment */
.modal-body,
.modal-content,
[id$="Panel"],
[id$="DetailBody"],
[class*="modal"] .content {
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

/* -----------------------------------------------------------------------
   2. TABLET (max-width: 1279px)
   ----------------------------------------------------------------------- */

@media (max-width: 1279px) {
  /* --- Forms: stack vertically --- */
  .form-grid-2,
  .form-grid-3 {
    grid-template-columns: 1fr !important;
  }

  /* --- Buttons: touch-friendly sizing --- */
  button:not(.nav-item):not(.sidebar-toggle):not(.hamburger-btn):not(.sidebar-logout),
  .btn, a.btn,
  input[type="button"],
  input[type="submit"],
  select {
    min-height: 44px;
  }

  /* Small icon buttons: exempt from 44px touch minimum */
  [data-delete-photo],
  .samp-ref-actions a,
  .samp-ref-actions button,
  .samp-ref-actions a svg,
  .samp-ref-actions button svg {
    min-height: auto !important;
    min-width: auto !important;
  }

  /* Sampling design card buttons: keep compact, already touch-friendly via padding */
  .samp-card-stack button,
  .samp-card-stack button svg,
  .samp-variant-tabs button,
  .samp-result-group button,
  .samp-card-stack label,
  #samplingBriefActions button,
  #samplingPaletteSection button,
  .mobile-schedule-fab,
  .mobile-sched-tab,
  .mobile-schedule-sheet-content button {
    min-height: auto !important;
    min-width: auto !important;
  }

  /* Icon-only buttons (except sampling ref actions which stay compact) */
  button:not(.nav-item):not(.sidebar-toggle):not(.hamburger-btn):not(.sidebar-logout):not(.kcm-icon-action-btn):not(.kcm-icon-btn):not(.kcm-section-action):not([class*="ql-"]) svg:only-child {
    min-width: 44px;
    min-height: 44px;
  }
  .samp-ref-actions svg {
    min-width: auto !important;
    min-height: auto !important;
    width: 12px;
    height: 12px;
  }

  /* --- Tables: scroll wrappers --- */
  .table-wrap,
  .table-scroll-x {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .table-wrap > table,
  .table-scroll-x > table {
    min-width: 600px;
  }

  /* --- KPI cards responsive grid --- */
  #page-dash .grid.grid-cols-2 {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  }

  /* --- Chart containers --- */
  #page-dash .grid.grid-cols-1.md\:grid-cols-2 {
    grid-template-columns: 1fr;
  }

  /* --- Modals: near full-screen on tablet --- */
  #materialModal > div,
  #adjModal > div,
  #rescheduleModal > div,
  #calendarSettingsModal > div,
  #scheduleJobModal > div,
  #downtimeModal > div,
  #urgentScheduleModal > div,
  #sjDefectModal > div,
  #sjDetailModal > div,
  #invoiceDetailModal > div,
  #itemMasterDetailModal > div:not(#itemMasterDetailOverlay) {
    max-width: 95vw;
    max-height: 90vh;
    overflow-y: auto;
  }

  /* --- Scheduler: horizontal scroll + sticky machine column --- */
  #poMasterSchedulerGrid {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  #poMasterSchedulerGrid table th:first-child,
  #poMasterSchedulerGrid table td:first-child,
  #poMasterSchedulerGrid .sticky-col {
    position: sticky;
    left: 0;
    z-index: 5;
    background: var(--glorion-surface, #161617);
  }

  /* PO Line Monitor: full-width when stacked on tablet */
  #page-scheduler aside {
    width: 100% !important;
  }

  /* Scheduler toolbar: wrap and space out */
  .scheduler-toolbar {
    flex-wrap: wrap;
    gap: 8px;
  }

  .scheduler-toolbar button {
    min-height: 40px;
    padding-left: 12px;
    padding-right: 12px;
  }

  /* --- QC Scheduler View: tablet --- */
  .scheduler-view-toggle {
    gap: 4px;
  }
  .svt-btn {
    min-height: 40px;
    padding: 6px 20px;
    font-size: 14px;
  }
  .qc-priority-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* --- Production: touch-friendly --- */
  #page-prod .grid.grid-cols-1.md\:grid-cols-5 {
    grid-template-columns: 1fr !important;
  }

  #prodSearch {
    width: 100% !important;
  }

  /* Production form: show on mobile/tablet */
  #page-prod .md\:col-span-3,
  #page-prod .md\:col-span-2 {
    grid-column: span 1;
  }

  /* --- QC: stack vertically --- */
  #page-qc .grid.grid-cols-1.lg\:grid-cols-3 {
    grid-template-columns: 1fr !important;
  }

  #page-qc .lg\:col-span-1,
  #page-qc .lg\:col-span-2 {
    grid-column: span 1;
  }

  /* QC form grid: stack */
  #page-qc .grid.grid-cols-1.md\:grid-cols-4 {
    grid-template-columns: 1fr 1fr !important;
  }

  /* QC backlog rows: tappable height + tap feel */
  #qcListBody tr {
    min-height: 48px;
    cursor: pointer;
    transition: background 0.15s;
  }

  #qcListBody td {
    padding-top: 10px;
    padding-bottom: 10px;
  }

  /* --- PO Line Monitor: slide-in overlay on tablet/mobile --- */
  #poMonitorPanel {
    position: fixed !important;
    right: 0;
    top: 0;
    bottom: 0;
    width: 320px !important;
    max-width: 85vw;
    transform: translateX(100%);
    transition: transform 220ms ease;
    z-index: 150;
    border-radius: 0 !important;
    overflow-y: auto;
    box-shadow: -4px 0 24px rgba(0,0,0,0.15);
  }

  #poMonitorPanel.po-monitor-open {
    transform: translateX(0);
  }

  #poMonitorBackdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 140;
    opacity: 0;
    pointer-events: none;
    transition: opacity 220ms ease;
  }

  #poMonitorBackdrop.visible {
    opacity: 1;
    pointer-events: auto;
  }
}

/* -----------------------------------------------------------------------
   3. MOBILE (max-width: 767px)
   ----------------------------------------------------------------------- */

@media (max-width: 767px) {
  /* --- iOS zoom prevention (iOS zooms on inputs with font < 16px) --- */
  input,
  select,
  textarea {
    font-size: 16px !important;
  }

  /* --- Typography minimums --- */
  body {
    font-size: 14px;
  }

  table td, table th {
    font-size: 13px;
  }

  h1, .text-xl {
    font-size: 18px !important;
  }

  h2, .text-lg {
    font-size: 16px !important;
  }

  /* --- Forms: full-width stacking --- */
  .form-grid-2,
  .form-grid-3 {
    grid-template-columns: 1fr !important;
    gap: 12px;
  }

  /* All form inputs: minimum height for touch */
  input[type="text"],
  input[type="number"],
  input[type="date"],
  input[type="email"],
  input[type="password"],
  input[type="search"],
  input[type="tel"],
  input[type="url"],
  select,
  textarea {
    min-height: 44px;
    font-size: 16px !important;
  }

  /* --- KPI cards: 2-column on small mobile, 1-column on tiny --- */
  #page-dash .grid.grid-cols-2 {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }

  /* --- Dashboard: compact --- */
  #page-dash {
    padding: 8px !important;
    gap: 8px !important;
  }

  #page-dash .rounded-2xl {
    border-radius: 12px !important;
  }

  #page-dash .p-4 {
    padding: 10px !important;
  }

  /* Chart containers: full-width, fixed height */
  #page-dash canvas {
    max-height: 250px;
  }

  /* Alerts section: top priority on mobile */
  #dashAlerts {
    order: -1;
  }

  /* --- Modals: full-screen on mobile --- */
  #materialModal,
  #adjModal,
  #rescheduleModal,
  #calendarSettingsModal,
  #scheduleJobModal,
  #downtimeModal,
  #urgentScheduleModal,
  #sjDefectModal,
  #sjDetailModal,
  #invoiceDetailModal,
  #itemMasterDetailModal {
    align-items: stretch !important;
    padding: 0 !important;
  }

  #materialModal > div,
  #adjModal > div,
  #rescheduleModal > div,
  #calendarSettingsModal > div,
  #scheduleJobModal > div,
  #downtimeModal > div,
  #urgentScheduleModal > div,
  #sjDefectModal > div,
  #sjDetailModal > div,
  #invoiceDetailModal > div,
  #itemMasterDetailModal > div:not(#itemMasterDetailOverlay) {
    max-width: 100vw !important;
    max-height: 100dvh !important;
    width: 100vw !important;
    height: 100dvh !important;
    margin: 0 !important;
    border-radius: 0 !important;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Modal close buttons: easy to tap */
  [id$="Modal"] button[aria-label="Close"],
  [id$="modal"] button[aria-label="Close"],
  [id$="Wrap"] button[aria-label="Close"] {
    min-width: 44px;
    min-height: 44px;
  }

  /* --- Scheduler: slot detail as bottom sheet --- */
  #poMasterSchedulerJobDetailWrap {
    align-items: flex-end !important;
  }

  #poMasterSchedulerJobDetailPanel,
  #poMasterSchedulerJobDetailWrap > .relative {
    max-width: 100vw !important;
    width: 100vw !important;
    max-height: 70vh !important;
    margin: 0 !important;
    border-radius: 12px 12px 0 0 !important;
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding-bottom: env(safe-area-inset-bottom);
  }

  /* Bottom sheet drag handle */
  #poMasterSchedulerJobDetailPanel::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    background: var(--glorion-border-light, #333334);
    border-radius: 2px;
    margin: 10px auto 6px;
  }

  /* Scheduler grid: smaller font for compact view */
  #poMasterSchedulerGrid {
    font-size: 11px;
  }

  /* Scheduler week nav buttons: large and tappable */
  .scheduler-toolbar button {
    min-height: 44px;
    min-width: 44px;
    font-size: 13px;
  }

  /* --- QC Scheduler View: mobile --- */
  .svt-btn {
    min-height: 44px;
    min-width: 44px;
    padding: 8px 16px;
    font-size: 14px;
  }
  .qc-panel {
    border-radius: 8px;
  }
  .qc-panel-header {
    padding: 10px 12px;
    font-size: 13px;
  }
  .qc-priority-table {
    font-size: 12px;
  }
  .qc-priority-table thead th {
    padding: 6px 8px;
    font-size: 10px;
  }
  .qc-priority-row td {
    padding: 8px;
  }
  /* Hide lower-priority columns on mobile */
  .qc-priority-table th:nth-child(5),
  .qc-priority-table td:nth-child(5),
  .qc-priority-table th:nth-child(7),
  .qc-priority-table td:nth-child(7) {
    display: none;
  }
  .qc-board-col {
    width: 140px;
  }
  .qc-board-scroll {
    padding: 8px;
  }

  /* --- Production: large inputs for operators --- */
  #f_qty,
  #f_dqty,
  #f_fabricDefectQty {
    font-size: 24px !important;
    font-weight: 700;
    text-align: center;
    min-height: 56px;
  }

  /* Shift selector: tall and full-width */
  #f_shift {
    min-height: 56px;
    font-size: 15px !important;
    font-weight: 600;
  }

  /* Machine selector: large */
  #f_mesin {
    min-height: 48px;
    font-size: 16px !important;
  }

  /* Save button: prominent, full-width */
  #f_save {
    width: 100% !important;
    min-height: 52px !important;
    font-size: 16px !important;
    font-weight: 700;
  }

  /* Production: show mobile cards, hide desktop table */
  #page-prod .hidden.md\:block {
    display: none !important;
  }

  #prodCards {
    display: grid !important;
    gap: 8px !important;
  }

  /* Mobile production cards */
  .prod-mobile-card {
    background: var(--glorion-surface, #1e1e1f);
    border: 1px solid var(--glorion-border, #2a2a2b);
    border-radius: 12px;
    padding: 12px;
    cursor: pointer;
    transition: background 0.15s;
    -webkit-tap-highlight-color: transparent;
  }
  .prod-mobile-card:active {
    background: var(--glorion-surface-2, #252526);
  }
  .prod-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 4px;
  }
  .prod-card-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--glorion-text-primary, #e0e0e0);
    line-height: 1.3;
  }
  .prod-card-badge {
    flex-shrink: 0;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 10px;
  }
  .prod-card-sub {
    font-size: 11px;
    color: var(--glorion-text-secondary, #a0a0a0);
    margin-bottom: 6px;
  }
  .prod-card-pool {
    font-size: 10px;
    font-weight: 600;
    color: #06b6d4;
    background: #06b6d415;
    display: inline-block;
    padding: 1px 8px;
    border-radius: 8px;
    margin-bottom: 6px;
  }
  .prod-card-progress {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
  }
  .prod-card-progress-text {
    font-size: 11px;
    color: var(--glorion-text-secondary, #a0a0a0);
    white-space: nowrap;
  }
  .prod-card-progress-bar {
    flex: 1;
    height: 5px;
    border-radius: 3px;
    background: var(--glorion-border, #2a2a2b);
    overflow: hidden;
  }
  .prod-card-progress-bar > div {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s;
  }
  .prod-card-progress-pct {
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
  }
  .prod-card-footer {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--glorion-text-secondary, #a0a0a0);
  }
  .prod-card-footer strong {
    color: var(--glorion-text-primary, #e0e0e0);
  }

  /* Mobile form enhancements */
  #f_qty, #f_dqty, #f_fabricDefectQty {
    font-size: 20px !important;
    font-weight: 700 !important;
    text-align: center !important;
    min-height: 52px !important;
  }

  /* Segment selector: bigger touch targets on mobile */
  #segmentSelectorBody > div {
    min-height: 44px;
    padding: 10px 12px !important;
    font-size: 13px !important;
  }

  /* Pool claim section: full width on mobile */
  #poolClaimSection {
    margin: 8px 0 !important;
  }

  /* --- QC: touch-optimized --- */
  #qcInspectedInput,
  #qcScrapInput {
    font-size: 22px !important;
    font-weight: 700;
    text-align: center;
    min-height: 52px;
  }

  /* QC form grid: single column */
  #page-qc .grid.grid-cols-1.md\:grid-cols-4 {
    grid-template-columns: 1fr !important;
  }

  /* QC save button: prominent */
  #qcSaveBtn {
    width: 100% !important;
    min-height: 52px !important;
    font-size: 16px !important;
    font-weight: 700;
  }

  /* QC passed preview: large for quick reading */
  #qcPassedPreview {
    font-size: 20px !important;
    font-weight: 700;
    text-align: center;
  }

  /* --- Sampling: responsive images --- */
  #page-sampling img {
    max-width: 100%;
    height: auto;
  }

  /* File upload buttons: touch-friendly */
  #page-sampling input[type="file"] {
    min-height: 44px;
  }

  /* --- SJ & Invoice: table scroll + modal fullscreen --- */
  #page-sj .table-wrap,
  #page-invoice .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Print buttons: de-emphasize on mobile */
  #page-sj .print-btn,
  #page-invoice .print-btn,
  button[onclick*="print"] {
    font-size: 12px;
    padding: 6px 10px;
    min-height: 36px;
  }

  /* --- Page padding: tighter on mobile --- */
  .page-pad {
    padding-left: 8px !important;
    padding-right: 8px !important;
  }

  /* --- Topbar: compact --- */
  #mobileMenuBar {
    padding: 6px 10px;
    gap: 8px;
  }

  /* Production planning box: single column */
  #planningBox .grid.grid-cols-1.md\:grid-cols-3 {
    grid-template-columns: 1fr !important;
  }

  /* Hide lower-priority table columns on mobile */
  .hide-mobile {
    display: none !important;
  }

  /* --- Dashboard: KPI value prominence --- */
  #page-dash .dash-val {
    font-size: 22px !important;
  }

  /* Dashboard chart containers: overflow control */
  #page-dash .grid canvas {
    width: 100% !important;
    overflow: hidden;
  }

  /* Dashboard refresh button: full-width on mobile */
  #dashRefreshBtn {
    width: 100%;
    min-height: 44px;
  }

  /* --- Sampling: promote button full-width --- */
  #samplingPromoteBtn,
  #samplingSaveBtn,
  #samplingApproveBtn {
    width: 100% !important;
    min-height: 44px;
  }

  /* Sampling history cards: scroll containment */
  #samplingHistoryCards {
    max-height: 60vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* --- Safe area insets for iPhone notch/home bar --- */
  .sidebar {
    padding-top: env(safe-area-inset-top);
  }

  #mobileMenuBar {
    padding-top: max(6px, env(safe-area-inset-top));
  }

  #appMain {
    padding-bottom: env(safe-area-inset-bottom);
  }

  /* --- Invoice: mobile table optimization --- */
  #page-invoice .inv-hide-mobile {
    display: none !important;
  }

  /* Invoice tables: compact but readable */
  #page-invoice table {
    font-size: 12px;
  }

  /* Invoice line editor: ensure scroll + readable inputs */
  #invoiceLineEditor {
    padding: 12px 8px !important;
  }
  #invoiceLineEditor .overflow-x-auto {
    -webkit-overflow-scrolling: touch;
  }
  #invoiceLineEditor table {
    min-width: 500px;
  }
  #invoiceLineEditor input[type="text"],
  #invoiceLineEditor input[type="number"] {
    font-size: 13px !important;
    min-height: 36px;
    padding: 4px 6px;
  }

  /* Item name: readable width, allow wrapping */
  .inv-item-name {
    min-width: 140px;
    font-size: 12px !important;
  }

  /* Invoice form grid: 2-column on mobile */
  #page-invoice .grid.grid-cols-1.md\:grid-cols-4 {
    grid-template-columns: 1fr 1fr !important;
    gap: 8px;
  }

  /* --- PO Input: wider form on mobile --- */
  #page-po {
    padding: 2px !important;
  }
  #page-po > .page-wrap {
    padding: 0 !important;
  }
  #page-po > .page-wrap > .bg-white,
  #page-po .bg-gray-50.rounded-2xl {
    padding: 8px !important;
    border-radius: 8px !important;
  }
  #page-po .bg-gray-50.rounded-2xl .p-4 {
    padding: 8px !important;
  }
  #page-po table {
    font-size: 12px;
  }
  #page-po table td,
  #page-po table th {
    padding: 6px 8px;
  }

  /* PO line rows: reflow 12-col grid to 2-col on mobile */
  #page-po .line-row {
    grid-template-columns: 1fr 1fr !important;
    gap: 8px !important;
  }
  #page-po .line-row > div {
    grid-column: span 1 !important;
  }
  /* Item search: full width */
  #page-po .line-row > div:first-of-type {
    grid-column: 1 / -1 !important;
  }
  /* Checkboxes row + Hapus button: full width */
  #page-po .line-row > div:nth-last-of-type(1),
  #page-po .line-row > div:nth-last-of-type(2) {
    grid-column: 1 / -1 !important;
  }
  /* One-off button: pill shape */
  #page-po .oneoff-btn {
    padding: 4px 14px !important;
    min-height: auto !important;
    white-space: nowrap;
    border-radius: 999px !important;
    font-size: 11px !important;
  }
  /* PO line inputs: prevent overflow on mobile */
  #page-po .line-row input,
  #page-po .line-row select {
    width: 100% !important;
    box-sizing: border-box !important;
    max-width: 100% !important;
    overflow: hidden;
  }
  /* PO line grid container: contain children */
  #page-po .line-row {
    overflow: hidden;
  }
  /* One-off form: full width */
  #page-po .oneoff-form {
    grid-column: 1 / -1 !important;
  }
  #page-po .oneoff-form .grid {
    grid-template-columns: 1fr 1fr !important;
  }
  #page-po .oneoff-form .grid > div {
    grid-column: span 1 !important;
  }

  /* --- Finance: tables scrollable, forms wrap --- */
  #page-finance table {
    font-size: 12px;
  }
  #page-finance .flex.gap-2,
  #page-finance .flex.gap-3 {
    flex-wrap: wrap;
  }
  #page-finance input[type="text"],
  #page-finance input[type="number"] {
    min-width: 80px;
  }

  /* --- Master Data: compact tables --- */
  #page-item-master table,
  #page-po-master table,
  #page-materials table,
  #page-clients table,
  #page-suppliers table,
  #page-machines table,
  #page-employees table {
    font-size: 12px;
  }
  #page-item-master table td,
  #page-item-master table th,
  #page-po-master table td,
  #page-po-master table th,
  #page-materials table td,
  #page-materials table th,
  #page-clients table td,
  #page-clients table th,
  #page-suppliers table td,
  #page-suppliers table th {
    padding: 6px 8px;
  }

  /* --- Payroll: compact tables + touch-friendly selects --- */
  #page-payroll table {
    font-size: 12px;
  }
  #page-payroll table td,
  #page-payroll table th {
    padding: 6px 8px;
  }
  #page-payroll select {
    min-height: 36px;
    font-size: 13px !important;
  }

  /* --- Global: ensure all table containers scroll horizontally --- */
  .overflow-x-auto {
    -webkit-overflow-scrolling: touch;
  }
}

/* -----------------------------------------------------------------------
   4. VERY SMALL SCREENS (max-width: 400px)
   ----------------------------------------------------------------------- */

@media (max-width: 400px) {
  /* KPI cards: single column */
  #page-dash .grid.grid-cols-2 {
    grid-template-columns: 1fr !important;
  }

  /* Even more compact padding */
  .page-pad {
    padding-left: 6px !important;
    padding-right: 6px !important;
  }
}

/* -----------------------------------------------------------------------
   5. DESKTOP-SPECIFIC (min-width: 1280px) — ensure no regressions
   ----------------------------------------------------------------------- */

@media (min-width: 1280px) {
  /* Hamburger + mobileMenuBar hidden on desktop (handled in sidebar.css + inline CSS) */

  /* Restore dashboard multi-column charts */
  #page-dash .grid.grid-cols-1.md\:grid-cols-2 {
    grid-template-columns: repeat(2, 1fr);
  }

  /* PO monitor toggle hidden on desktop (panel is always visible) */
  #poMonitorToggleBtn {
    display: none !important;
  }

  /* PO monitor backdrop hidden on desktop */
  #poMonitorBackdrop {
    display: none !important;
  }
}

/* =======================================================================
   6. KANBAN BOARD STYLES
   All classes prefixed kb- to avoid conflicts with existing GPS styles.
   ======================================================================= */

/* ── Kanban Typography ── */
.kb-toolbar,
.kb-column,
.kb-card,
.kb-col-header {
  font-family: 'Space Grotesk', var(--font-family, sans-serif);
}

/* --- Toolbar --- */
.kb-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--glorion-black, #0e0e0e);
  color: var(--glorion-text-primary, #e0e0e0);
  flex-wrap: wrap;
  flex-shrink: 0;
  z-index: 10;
}

.kb-board-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 18px;
  font-weight: 700;
  color: var(--glorion-text-bright, #f5f5f5);
  white-space: nowrap;
  letter-spacing: -0.02em;
}



.kb-toolbar-sep {
  flex: 1;
}

.kb-filter-group {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.kb-filter-label {
  font-size: 11px;
  color: var(--glorion-text-secondary, #a0a0a0);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-right: 4px;
}

.kb-filter-btn {
  padding: 4px 10px;
  border-radius: 4px;
  border: 1px solid var(--glorion-border, #2a2a2b);
  background: transparent;
  color: var(--glorion-text-primary, #e0e0e0);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  min-height: 28px;
}

.kb-filter-btn:hover {
  background: var(--glorion-border, #2a2a2b);
  color: var(--glorion-text-bright, #f5f5f5);
}

.kb-filter-btn.active {
  background: var(--glorion-gold, #C39B5A);
  border-color: var(--glorion-gold, #C39B5A);
  color: #fff;
}

.kb-total-badge {
  font-size: 12px;
  color: var(--glorion-text-secondary, #a0a0a0);
  white-space: nowrap;
}

/* --- Board (horizontal scroll container) --- */
.kb-board {
  display: flex;
  align-items: flex-start;
  gap: 0;
  overflow-x: auto;
  background: var(--glorion-black, #0e0e0e);
  scrollbar-width: thin;
  scrollbar-color: var(--glorion-border-light, #333334) transparent;
  padding: 8px 0 8px 8px;
}

.kb-board::-webkit-scrollbar {
  height: 8px;
}

.kb-board::-webkit-scrollbar-thumb {
  background: var(--glorion-border-light, #333334);
  border-radius: 4px;
}

/* --- Column --- */
.kb-column {
  min-width: 260px;
  max-width: 280px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--glorion-surface, #161617);
  border: none;
  border-radius: 10px;
  margin-right: 8px;
}

.kb-col-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--glorion-surface, #161617);
  border-bottom: 2px solid var(--stage-color, #94a3b8);
  border-radius: 10px 10px 0 0;
  position: sticky;
  top: 0;
  z-index: 2;
  box-shadow: 0 0 20px -10px var(--stage-color, rgba(195,155,90,0.5));
}

.kb-col-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.kb-col-name {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 10px;
  font-weight: 700;
  color: var(--stage-color, var(--glorion-gold, #C39B5A));
  text-transform: uppercase;
  letter-spacing: 0.1em;
  flex: 1;
}

.kb-col-count {
  background: var(--glorion-surface-2, #1e1e1f);
  color: var(--glorion-text-secondary, #a0a0a0);
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 10px;
}

.col-add-btn {
  padding: 6px 12px;
  font-size: 12px;
  color: var(--glorion-gold, #C39B5A);
  cursor: pointer;
  text-align: center;
  border-bottom: 1px solid var(--glorion-border, #2a2a2b);
  transition: background 0.15s;
}

.col-add-btn:hover {
  background: rgba(195,155,90,0.1);
}

/* --- Column card area --- */
.kb-col-cards {
  padding: 8px;
  padding-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-radius: 0 0 10px 10px;
}

.kb-col-cards.drag-over {
  background: rgba(91,141,239,0.08);
  outline: 2px dashed var(--glorion-blue, #5B8DEF);
  outline-offset: -2px;
  border-radius: 8px;
}

/* Disable transitions during drag for performance */
.kb-board--dragging .kb-card-cover img,
.kb-board--dragging .kb-card-progress-bar {
  transition: none;
}

/* Drop position indicator */
.kb-drop-indicator {
  height: 3px;
  background: var(--glorion-gold, #C39B5A);
  border-radius: 2px;
  margin: 2px 0;
  box-shadow: 0 0 8px var(--glorion-gold-dim, rgba(195,155,90,0.3));
}

/* Touch drag ghost — styled via inline styles in JS */

/* Column highlight when dragging over */
.kb-column.drop-target {
  border-color: var(--glorion-blue, #5B8DEF);
}
.kb-column.drop-target .kb-col-dot {
  box-shadow: 0 0 8px currentColor;
}

.kb-col-empty {
  padding: 20px;
  text-align: center;
  color: var(--glorion-text-muted, #6b6b6b);
  font-size: 12px;
  font-style: italic;
}

/* --- Card --- */
.kb-card {
  background: linear-gradient(135deg, var(--glorion-surface-2, #1e1e1f) 0%, var(--glorion-surface, #161617) 50%, rgba(195,155,90,0.05) 100%);
  backdrop-filter: blur(12px);
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.05);
  border-left: 4px solid var(--stage-color, var(--glorion-gold, #C39B5A));
  padding: 0;
  cursor: grab;
  transition: transform 200ms ease, box-shadow 200ms ease, opacity 150ms;
  position: relative;
  overflow: hidden;
}

.kb-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 4px;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.08), transparent);
  pointer-events: none;
  z-index: 2;
}

.kb-card::after {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: linear-gradient(45deg, transparent 0%, rgba(195,155,90,0.03) 45%, rgba(255,255,255,0.02) 50%, rgba(195,155,90,0.03) 55%, transparent 100%);
  pointer-events: none;
  transition: transform 500ms ease;
  z-index: 1;
}

.kb-card:hover::after {
  transform: translate(10%, 10%);
}

.kb-card:hover {
  transform: scale(1.02);
  box-shadow: 0 8px 30px rgba(0,0,0,0.3), inset 0 0 0 1px rgba(255,255,255,0.06);
}

.kb-card.dragging {
  opacity: 0.35;
  cursor: grabbing;
  transition: none;
}

.kb-card.subkon {
  border-left: 3px solid var(--glorion-gold, #C39B5A);
}

.kb-card.manual-card {
  border-left: 3px solid #f97316;
  background: rgba(249,115,22,0.08);
}

/* Card cover image */
.kb-card-cover {
  margin: 0;
  aspect-ratio: 16 / 9;
  height: auto;
  overflow: hidden;
  background: var(--glorion-surface-2, #1e1e1f);
  border-bottom: 1px solid rgba(255,255,255,0.03);
}

.kb-card-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.75;
  transition: opacity 300ms;
  cursor: pointer;
}

.kb-card:hover .kb-card-cover img {
  opacity: 0.85;
}

.kb-card.has-cover .kb-card-body {
  padding-top: 8px;
}

.kb-card-body {
  padding: 12px 14px;
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Card sections */
.kb-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 6px;
  margin-bottom: 4px;
}

.kb-card-po {
  font-size: 11px;
  font-weight: 600;
  color: var(--glorion-blue, #5B8DEF);
  word-break: break-all;
}

.kb-card-client {
  font-size: 10px;
  color: var(--glorion-text-secondary, #a0a0a0);
}

.kb-card-deadline {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 4px;
  white-space: nowrap;
  flex-shrink: 0;
}

.kb-card-deadline.ok {
  background: rgba(93,202,165,0.12);
  color: var(--glorion-teal, #5DCAA5);
}

.kb-card-deadline.soon {
  background: rgba(195,155,90,0.12);
  color: var(--glorion-gold, #C39B5A);
}

.kb-card-deadline.late {
  background: rgba(229,115,115,0.12);
  color: var(--glorion-red, #E57373);
}

.kb-card-design {
  font-size: 13px;
  font-weight: 600;
  color: var(--glorion-text-bright, #f5f5f5);
  line-height: 1.3;
  margin-bottom: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.kb-card-qty {
  font-size: 11px;
  color: var(--glorion-text-secondary, #a0a0a0);
  margin-bottom: 4px;
}

/* Thread stitching progress bar */
.kb-card-progress {
  height: 2px;
  background-image: linear-gradient(to right, var(--glorion-border-light, #333335) 50%, transparent 50%);
  background-size: 8px 1px;
  background-repeat: repeat-x;
  border-radius: 1px;
  margin: 8px 0 4px;
  position: relative;
  overflow: visible;
}

.kb-card-progress-bar {
  height: 100%;
  background: var(--glorion-gold, #C39B5A);
  border-radius: 1px;
  transition: width 0.3s ease;
  box-shadow: 0 0 10px var(--glorion-gold-dim, rgba(195,155,90,0.4));
  position: relative;
}

/* Thread needle dot at progress tip */
.kb-card-progress-bar::after {
  content: '';
  position: absolute;
  right: -4px;
  top: -3px;
  width: 8px;
  height: 8px;
  background: #fff;
  border: 2px solid var(--glorion-gold, #C39B5A);
  border-radius: 50%;
}

.kb-card-progress-label {
  position: relative;
  top: auto;
  right: auto;
  font-size: 9px;
  font-weight: 700;
  color: var(--glorion-text-secondary, #9A8E7A);
  text-transform: uppercase;
  margin-top: 4px;
}

/* Item code above title */
.kb-card-code {
  font-size: 9px;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--glorion-text-hint, #5A5650);
  letter-spacing: 0.12em;
  font-family: 'Space Grotesk', sans-serif;
}

/* Status chips row */
.kb-card-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 2px;
}
.kb-status-chip {
  font-size: 9px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 2px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  font-family: 'Space Grotesk', sans-serif;
}
.kb-status-chip.chip-late {
  background: var(--glorion-red-dim, rgba(160,64,64,0.2));
  color: var(--glorion-red-light, #E08080);
  border: 1px solid rgba(160,64,64,0.3);
}
.kb-status-chip.chip-soon {
  background: var(--glorion-gold-dim, rgba(195,155,90,0.15));
  color: var(--glorion-gold-light, #E8C98A);
  border: 1px solid rgba(195,155,90,0.25);
}
.kb-status-chip.chip-ok {
  background: var(--glorion-teal-dim, rgba(46,125,106,0.2));
  color: var(--glorion-teal-light, #5DCAA5);
  border: 1px solid rgba(46,125,106,0.3);
}
.kb-status-chip.chip-prod {
  background: rgba(16,185,129,0.1);
  color: #34d399;
  border: 1px solid rgba(16,185,129,0.2);
}
.kb-status-chip.chip-subkon {
  background: var(--glorion-gold-dim, rgba(195,155,90,0.15));
  color: var(--glorion-gold-light, #E8C98A);
  border: 1px solid rgba(195,155,90,0.25);
}
.kb-status-chip.chip-done {
  background: rgba(6,182,212,0.1);
  color: #22d3ee;
  border: 1px solid rgba(6,182,212,0.2);
}

/* Card footer */
.kb-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
}

.kb-card-machine {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
}

.kb-card-machine.assigned {
  background: rgba(91,141,239,0.15);
  color: var(--glorion-blue, #5B8DEF);
}

.kb-card-machine.unassigned {
  background: var(--glorion-surface-2, #1e1e1f);
  color: var(--glorion-text-secondary, #a0a0a0);
}

.kb-card-machine.external {
  background: rgba(195,155,90,0.15);
  color: var(--glorion-gold, #C39B5A);
}

.kb-card-attach {
  font-size: 10px;
  font-weight: 500;
  color: var(--glorion-text-secondary, #a0a0a0);
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--glorion-surface-2, #1e1e1f);
}

.kb-card-detail-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  color: var(--glorion-text-secondary, #a0a0a0);
  padding: 2px 4px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
  min-height: auto;
}

.kb-card-detail-btn:hover {
  color: var(--glorion-gold, #C39B5A);
  background: rgba(195,155,90,0.1);
}

/* Delete countdown on done cards */
.kb-card-delete-countdown {
  position: absolute;
  top: 4px;
  right: 4px;
  font-size: 10px;
  color: var(--glorion-red, #E57373);
  background: rgba(229,115,115,0.12);
  padding: 1px 5px;
  border-radius: 4px;
}

/* --- Toast (fallback) --- */
.kb-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--glorion-surface, #161617);
  color: #fff;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  z-index: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}

.kb-toast.show {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

.kb-toast.success { background: #059669; }
.kb-toast.warning { background: #d97706; }
.kb-toast.error { background: #dc2626; }

/* --- Quick modal (add card) --- */
.kanban-quick-modal {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
}

.kqm-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
}

.kqm-box {
  position: relative;
  background: var(--glorion-surface, #161617);
  border: 1px solid var(--glorion-border, #2a2a2b);
  border-radius: 12px;
  padding: 24px;
  width: 360px;
  max-width: 90vw;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  transform: scale(0.95);
  opacity: 0;
  transition: transform 0.15s, opacity 0.15s;
}

.kqm-box.open {
  transform: scale(1);
  opacity: 1;
}

.kqm-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--glorion-text-bright, #f5f5f5);
  margin-bottom: 16px;
}

.kqm-input {
  display: block;
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--glorion-border, #2a2a2b);
  border-radius: 6px;
  font-size: 14px;
  margin-bottom: 10px;
  color: var(--glorion-text-primary, #e0e0e0);
  background: var(--glorion-surface-2, #1e1e1f);
  box-sizing: border-box;
}

.kqm-input:focus {
  outline: none;
  border-color: var(--glorion-gold, #C39B5A);
  box-shadow: 0 0 0 2px rgba(195,155,90,0.2);
}

.kqm-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
}

.kqm-btn-cancel {
  padding: 8px 16px;
  border: 1px solid var(--glorion-border, #2a2a2b);
  border-radius: 6px;
  background: var(--glorion-surface-2, #1e1e1f);
  color: var(--glorion-text-secondary, #a0a0a0);
  font-size: 13px;
  cursor: pointer;
}

.kqm-btn-save {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  background: var(--glorion-gold, #C39B5A);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.kqm-btn-save:hover {
  background: var(--glorion-gold-hover, #D4AC6B);
}

/* --- Detail panel (slide-in) --- */
.kanban-detail-panel {
  position: fixed;
  right: 0;
  top: 0;
  bottom: 0;
  width: 360px;
  max-width: 90vw;
  background: var(--glorion-surface, #161617);
  border-left: 1px solid var(--glorion-border, #2a2a2b);
  box-shadow: -4px 0 24px rgba(0,0,0,0.4);
  z-index: 200;
  transform: translateX(100%);
  transition: transform 0.2s ease;
  overflow-y: auto;
  padding: 20px;
}

.kanban-detail-panel.open {
  transform: translateX(0);
}

.kd-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 16px;
}

.kd-design {
  font-size: 18px;
  font-weight: 700;
  color: var(--glorion-text-bright, #f5f5f5);
  line-height: 1.3;
}

.kd-client {
  font-size: 13px;
  color: var(--glorion-text-secondary, #a0a0a0);
  margin-top: 2px;
}

.kd-po {
  font-size: 12px;
  color: var(--glorion-blue, #5B8DEF);
  font-weight: 600;
  margin-top: 4px;
}

.kd-close {
  background: none;
  border: none;
  font-size: 18px;
  color: var(--glorion-text-secondary, #a0a0a0);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  min-height: auto;
}

.kd-close:hover {
  color: var(--glorion-text-primary, #e0e0e0);
  background: var(--glorion-surface-2, #1e1e1f);
}

.kd-cover {
  margin: -20px -20px 16px;
  height: 160px;
  overflow: hidden;
}

.kd-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Upload row */
.kd-upload-row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.kd-upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border: 1px dashed var(--glorion-border-light, #333334);
  border-radius: 6px;
  font-size: 12px;
  color: var(--glorion-text-secondary, #a0a0a0);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.kd-upload-btn:hover {
  border-color: var(--glorion-gold, #C39B5A);
  background: rgba(195,155,90,0.1);
  color: var(--glorion-gold, #C39B5A);
}

/* Files */
.kd-files-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--glorion-text-secondary, #a0a0a0);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.kd-file-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--glorion-border, #2a2a2b);
}

.kd-file-badge {
  font-size: 9px;
  font-weight: 700;
  color: #fff;
  padding: 2px 6px;
  border-radius: 3px;
  text-transform: uppercase;
  flex-shrink: 0;
}

.kd-file-name {
  flex: 1;
  font-size: 13px;
  color: var(--glorion-text-primary, #e0e0e0);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.kd-file-dl {
  font-size: 16px;
  color: var(--glorion-blue, #5B8DEF);
  text-decoration: none;
  padding: 4px;
}

.kd-file-dl:hover {
  color: var(--glorion-gold, #C39B5A);
}

.kd-files-empty {
  font-size: 12px;
  color: var(--glorion-text-muted, #6b6b6b);
  font-style: italic;
  padding: 8px 0;
}

/* Info rows */
.kd-info {
  margin: 16px 0;
  border: 1px solid var(--glorion-border, #2a2a2b);
  border-radius: 8px;
  overflow: hidden;
}

.kd-info-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 12px;
  font-size: 13px;
  border-bottom: 1px solid var(--glorion-border, #2a2a2b);
}

.kd-info-row:last-child {
  border-bottom: none;
}

.kd-info-row span:first-child {
  color: var(--glorion-text-secondary, #a0a0a0);
}

.kd-info-row span:last-child {
  font-weight: 600;
  color: var(--glorion-text-bright, #f5f5f5);
}

.kd-notes {
  font-size: 13px;
  color: var(--glorion-text-secondary, #a0a0a0);
  background: var(--glorion-surface-2, #1e1e1f);
  padding: 10px 12px;
  border-radius: 6px;
  line-height: 1.5;
  white-space: pre-wrap;
}

/* --- Auto-progression banner --- */
.kanban-advance-banner {
  position: fixed;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--glorion-surface, #161617);
  border: 1px solid var(--glorion-gold, #C39B5A);
  color: var(--glorion-gold-light, #E8D5B0);
  padding: 10px 20px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 500;
  z-index: 600;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  animation: kbBannerIn 0.3s ease;
  max-width: 90vw;
}

@keyframes kbBannerIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-20px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.kb-banner-icon {
  font-size: 16px;
}

.kb-banner-msg {
  flex: 1;
}

.kb-banner-dismiss {
  background: none;
  border: none;
  color: rgba(255,255,255,0.7);
  font-size: 14px;
  cursor: pointer;
  padding: 2px;
  min-height: auto;
}

.kb-banner-dismiss:hover {
  color: #fff;
}

/* --- Kanban page container --- */

#page-kanban {
  background: transparent !important;
  padding: 0 !important;
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  overflow-y: auto;
  min-height: 0;
}

#kanban-root {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* --- Kanban responsive --- */
@media (max-width: 767px) {
  .kb-toolbar {
    padding: 8px 12px;
    gap: 8px;
  }

  .kb-board-title {
    font-size: 14px;
  }

  .kb-filter-group {
    width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
    flex-wrap: nowrap;
  }
  .kb-filter-group::-webkit-scrollbar {
    display: none;
  }

  .kb-board {
    padding: 6px 0 6px 6px;
    -webkit-overflow-scrolling: touch;
  }

  .kb-column {
    min-width: 260px;
    max-width: 260px;
  }

  .kb-filter-btn {
    min-height: 36px;
    padding: 5px 12px;
    font-size: 11px;
    flex-shrink: 0;
  }

  .kanban-detail-panel {
    width: 100vw;
    max-width: 100vw;
  }

  .kqm-box {
    width: 100%;
    max-width: 100vw;
    border-radius: 12px 12px 0 0;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    margin: 0;
  }

  /* Compact cards — mobile */
  .kb-card {
    padding: 8px 10px;
  }
  .kb-card-cover {
    display: none;
  }
  .kb-card-design {
    font-size: 12px;
    -webkit-line-clamp: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
  }
  .kb-card-header {
    margin-bottom: 2px;
  }
  .kb-card-po {
    font-size: 9px;
  }
  .kb-card-client {
    font-size: 9px;
  }
  .kb-card-qty {
    font-size: 9px;
    margin-bottom: 2px;
  }
  .kb-card-deadline {
    font-size: 8px;
    padding: 1px 5px;
  }
  .kb-card-footer {
    margin-top: 3px;
  }
  .kb-card-machine {
    font-size: 8px;
    padding: 1px 5px;
  }
  .kb-card-attach {
    font-size: 9px;
  }
  .kb-card-progress {
    height: 3px;
    margin: 4px 0;
  }
  .kb-card-detail-btn {
    display: none;
  }
}

/* --- Kanban tablet --- */
@media (min-width: 768px) and (max-width: 1024px) {
  .kb-column {
    min-width: 240px;
    max-width: 250px;
  }

  .kb-filter-btn {
    min-height: 36px;
    padding: 5px 12px;
  }

  .kb-card {
    padding: 9px 11px;
  }

  .kb-card-design {
    font-size: 12px;
  }

  .kb-card-po {
    font-size: 10px;
  }
}

/* -----------------------------------------------------------------------
   Item Master lock — active PO items
   ----------------------------------------------------------------------- */
.field-locked {
  background: var(--glorion-surface-2, #1e1e1f);
  color: var(--glorion-text-muted, #6b6b6b);
  cursor: not-allowed;
  pointer-events: none;
  opacity: 0.6;
}
.item-lock-banner {
  background: rgba(195,155,90,0.1);
  border: 1px solid var(--glorion-gold, #C39B5A);
  border-radius: 6px;
  padding: 10px 14px;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--glorion-gold-light, #E8D5B0);
}

/* -----------------------------------------------------------------------
   Staff role — hide pricing/financial data
   ----------------------------------------------------------------------- */
body.role-staff .harga-field,
body.role-staff .price-field,
body.role-staff [data-owner-only] {
  display: none !important;
}

/* -----------------------------------------------------------------------
   5. MOBILE SCHEDULE FAB + BOTTOM SHEET
   ----------------------------------------------------------------------- */

/* FAB: hidden by default, shown on mobile */
.mobile-schedule-fab {
  display: none;
  position: fixed;
  bottom: 24px;
  right: 16px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #d4a853;
  color: #0c0e14;
  font-size: 28px;
  font-weight: bold;
  border: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  z-index: 100;
  cursor: pointer;
  min-height: auto !important;
  min-width: auto !important;
  align-items: center;
  justify-content: center;
}

/* Bottom sheet */
.mobile-schedule-sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 998;
}

.mobile-schedule-sheet-content {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #111420;
  border-top: 1px solid #262c3d;
  border-radius: 16px 16px 0 0;
  padding: 20px 16px;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 999;
  max-height: 80vh;
  overflow-y: auto;
}

/* Bottom sheet tabs */
.mobile-sched-tab {
  background: #252b3a;
  color: #9a97a2;
}

.mobile-sched-tab.active {
  background: #d4a853 !important;
  color: #0c0e14 !important;
  border-color: #d4a853 !important;
}

@media (max-width: 767px) {
  #page-scheduler:not(.hidden) .mobile-schedule-fab {
    display: flex;
  }
}
