// ==========================================================================
// GoodBooks Production — Production Entry Screen
// Light theme
// ==========================================================================

$bg-page:        #F4F6FB;
$bg-panel:       #FFFFFF;
$bg-elevated:    #F7F8FC;
$bg-input:       #FFFFFF;

$border:         #DCE1EE;
$border-soft:    #E7EAF3;

$text-primary:   #1B2338;
$text-secondary: #5B6480;
$text-muted:     #8891A8;

$blue:           #3B66D6;
$blue-soft:      rgba(59, 102, 214, 0.10);

$green:          #1E9E5C;
$green-soft:     rgba(30, 158, 92, 0.10);

$red:            #E14545;
$red-soft:       rgba(225, 69, 69, 0.10);

$amber:          #C6862A;
$amber-soft:     rgba(198, 134, 42, 0.12);

$purple:         #7038B5;
$purple-soft:    rgba(112, 56, 181, 0.10);

$radius-sm: 4px;
$radius-md: 8px;
$radius-lg: 12px;

$font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Inter, Arial, sans-serif;
$font-mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;

.FormOverView {
  box-sizing: border-box;
  width: 100%;
  overflow-x: hidden;
  background: $bg-page;

  * , *::before, *::after { box-sizing: border-box; }
}

.pe-shell {
  width: 100%;
  color: $text-primary;
  font-family: $font-ui;
  position: relative;
}

.pe-muted { color: $text-muted; font-size: 12px; }
.pe-link { color: $blue; font-weight: 600; cursor: pointer; }
.pe-link-btn {
  background: none; border: none; color: $blue; font-size: 12.5px; font-weight: 600;
  cursor: pointer; padding: 0;
  &:hover { text-decoration: underline; }
}

// ---- Toasts ---------------------------------------------------------------
.pe-toast-stack {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 380px;
}

.pe-toast {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  border-radius: $radius-md;
  font-size: 12.5px;
  line-height: 1.4;
  box-shadow: 0 8px 24px rgba(20, 30, 60, 0.10);
  background: $bg-elevated;
  border: 1px solid $border;
  color: $text-primary;
  animation: pe-toast-in 0.18s ease;

  &--warning { border-color: $amber; background: $amber-soft; }
  &--info    { border-color: $blue; background: $blue-soft; }
  &--success { border-color: $green; background: $green-soft; }

  &__close {
    background: none; border: none; color: inherit; cursor: pointer; font-size: 16px; line-height: 1;
    flex-shrink: 0;
  }
}

@keyframes pe-toast-in {
  from { opacity: 0; transform: translateX(12px); }
  to { opacity: 1; transform: translateX(0); }
}

// ---- Header -----------------------------------------------------------------
.pe-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid $border;

  &__title { display: flex; align-items: center; gap: 10px; }
  &__brand { font-weight: 800; letter-spacing: 0.04em; color: $text-primary; font-size: 15px; }
  &__sep { color: $border; }
  &__page { font-weight: 700; font-size: 16px; color: $text-primary; }
  &__actions { display: flex; gap: 10px; }
}

// ---- Buttons ------------------------------------------------------------------
.btn {
  border-radius: $radius-md;
  font-size: 13px;
  font-weight: 600;
  padding: 9px 18px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: filter 0.15s ease, background 0.15s ease;

  &--sm { padding: 5px 12px; font-size: 12px; }

  &--ghost {
    background: $bg-elevated;
    border-color: $border;
    color: $text-primary;
    &:hover { filter: brightness(0.97); }
  }

  &--primary {
    background: $green;
    border-color: $green;
    color: #FFFFFF;
    &:hover { filter: brightness(1.08); }
  }
}

// ---- Filter bar -----------------------------------------------------------------
.pe-filterbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 24px;
  padding: 16px 24px;
  border-bottom: 1px solid $border;
  background: $bg-panel;
}

.pe-field {
  display: flex;
  flex-direction: column;
  gap: 6px;

  label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: $text-muted;
    text-transform: uppercase;
  }

  &__static { font-size: 13px; font-weight: 600; color: $text-primary; }
  &--options { min-width: 220px; }
}

.pe-select, .pe-input {
  background: $bg-input;
  border: 1px solid $border;
  border-radius: $radius-sm;
  color: $text-primary;
  font-size: 13px;
  padding: 7px 10px;
  font-family: $font-ui;

  &:focus { outline: none; border-color: $blue; box-shadow: 0 0 0 3px $blue-soft; }

  &--big { font-size: 16px; font-weight: 700; padding: 10px 12px; }
  &--qty { width: 80px; }
}

.pe-toggle {
  display: flex;
  border: 1px solid $border;
  border-radius: $radius-md;
  overflow: hidden;

  &__opt {
    background: $bg-input;
    border: none;
    color: $text-secondary;
    font-size: 12.5px;
    font-weight: 600;
    padding: 8px 14px;
    cursor: pointer;

    &.active { background: $amber-soft; color: $amber; }
  }

  &__now { font-weight: 500; opacity: 0.8; font-size: 11px; }
}

.pe-options { display: flex; gap: 16px; padding-top: 4px; }

.pe-checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: $text-secondary;
  cursor: pointer;
}

.pe-radio {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: $text-secondary;
  cursor: pointer;
}

// ---- Tabs -----------------------------------------------------------------------
.pe-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 24px;
  border-bottom: 1px solid $border;
  background: $bg-panel;

  &__item {
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: $text-secondary;
    font-size: 13px;
    font-weight: 600;
    padding: 14px 16px;
    cursor: pointer;

    &.active { color: $blue; border-bottom-color: $blue; }
    &:hover:not(.active) { color: $text-primary; }
  }

  &__conflict {
    margin-left: auto;
    background: $red-soft;
    color: $red;
    border: 1px solid $red;
    border-radius: 999px;
    padding: 5px 12px;
    font-size: 11.5px;
    font-weight: 700;
    cursor: pointer;
  }
}

.pe-tabpanel { padding: 20px 24px; }

.pe-tabpanel__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0 4px;
  gap: 16px;
  flex-wrap: wrap;
}

.pe-footer-actions { display: flex; gap: 10px; }
.pe-footer-hint { font-size: 12px; }

// ---- Mode A: WO Accordion ---------------------------------------------------------
.pe-wo-card {
  background: $bg-panel;
  border: 1px solid $border;
  border-radius: $radius-lg;
  margin-bottom: 14px;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(20, 30, 60, 0.04);
}

.pe-wo-card__head {
  display: grid;
  grid-template-columns: 140px 1fr 180px 100px 100px 24px;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  cursor: pointer;

  &:hover { background: $bg-elevated; }
}

.pe-wo-card__name { font-weight: 700; font-size: 14px; }
.pe-wo-card__sub { font-size: 11.5px; color: $text-muted; margin-top: 2px; }

.pe-progressbar {
  height: 6px;
  border-radius: 999px;
  background: $border-soft;
  overflow: hidden;
  margin-bottom: 4px;

  &__fill { height: 100%; background: $blue; border-radius: 999px; }
}

.pe-wo-card__qty { text-align: right; }
.pe-qty { font-size: 15px; font-weight: 700; }
.pe-qty--done { color: $green; }

.pe-caret {
  background: none; border: none; color: $text-muted; font-size: 16px; cursor: pointer;
  transition: transform 0.15s ease;
  &.open { transform: rotate(180deg); }
}

.pe-stage-table {
  border-top: 1px solid $border;
}

.pe-stage-table__head, .pe-stage-table__row {
  display: grid;
  grid-template-columns: 60px 160px 140px 130px 1fr 1fr 1fr 1fr 90px;
  gap: 10px;
  align-items: center;
  padding: 10px 20px;
}

.pe-stage-table__head {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: $text-muted;
  background: $bg-elevated;
}

.pe-stage-table__row {
  border-top: 1px solid $border-soft;
  transition: background 0.15s ease;

  &.is-conflict { background: $red-soft; }
  &.is-subcontract { background: rgba(112, 56, 181, 0.05); }

  &--rework {
    background: $amber-soft;
    grid-template-columns: 60px 160px 140px 130px 1fr 1fr 1fr;
  }
}

.pe-stage-badge {
  width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: $text-primary;
  background: $bg-input; border: 1px solid $border;

  &.status-done    { background: $green-soft; border-color: $green; color: $green; }
  &.status-active   { background: $blue-soft; border-color: $blue; color: $blue; }
  &.status-pending  { background: $bg-elevated; border-color: $border; color: $text-muted; }
  &.status-rework   { background: $amber-soft; border-color: $amber; color: $amber; }
}

.pe-stage-process__name { font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.pe-lock-icon { font-size: 11px; opacity: 0.8; }

.pe-cell-input {
  width: 100%;
  background: $bg-input;
  border: 1px solid $border;
  border-radius: $radius-sm;
  color: $text-primary;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 9px;
  font-family: $font-mono;

  &:focus { outline: none; border-color: $blue; box-shadow: 0 0 0 3px $blue-soft; }

  &.is-propagated { border-style: dashed; border-color: $blue; color: $blue; }
  &.is-conflict   { border-color: $red; color: $red; background: $red-soft; }
  &.is-locked, &:disabled { opacity: 0.5; cursor: not-allowed; background: $bg-elevated; }

  &--jit { font-size: 12.5px; padding: 5px 7px; }
}

.pe-total { margin-top: 3px; }

.pe-sc-summary { display: flex; gap: 10px; align-items: center; }
.pe-sc-chip {
  background: $purple-soft;
  border: 1px solid $purple;
  color: $purple;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 600;

  strong { color: $text-primary; }
}

// ---- Inline stoppage form (Mode A) -----------------------------------------------
.pe-stoppage-form {
  padding: 12px 20px 14px 90px;
  background: $bg-elevated;
  border-top: 1px dashed $border;

  &__row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
  }

  &__list {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 10px;
  }
}

.pe-stoppage-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: $bg-input;
  border: 1px solid $border;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 11.5px;
}

.pe-icon-btn {
  background: none;
  border: none;
  color: $text-muted;
  cursor: pointer;
  font-size: 13px;
  padding: 2px;
  &:hover { color: $red; }
}

.pe-add-row-btn {
  background: none;
  border: 1px dashed $border;
  color: $text-secondary;
  border-radius: $radius-sm;
  font-size: 12px;
  padding: 6px 12px;
  cursor: pointer;
  margin-top: 4px;

  &:hover { border-color: $blue; color: $blue; }
}

// ---- Mode B: JIT Grid ------------------------------------------------------------
.pe-jit-wrap { overflow-x: auto; border: 1px solid $border; border-radius: $radius-lg; }

.pe-jit-table {
  border-collapse: collapse;
  width: 100%;

  th, td {
    border: 1px solid $border-soft;
    padding: 8px 10px;
    text-align: left;
    font-size: 12px;
  }

  thead th {
    background: $bg-elevated;
    font-weight: 700;
    color: $text-secondary;
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 1;
  }

  &__corner { background: $bg-panel !important; }
  &__routing { text-align: center; color: $blue; font-size: 11px; }
  &__wo {
    min-width: 200px;
    background: $bg-panel;
    position: sticky;
    left: 0;
    z-index: 1;
  }

  &__cell { min-width: 90px; text-align: center; }
}

.pe-jit-stagename { font-weight: 400; color: $text-muted; font-size: 10px; }

.pe-jit-dash { color: $border; font-size: 16px; }

.pe-jit-sc {
  font-size: 10.5px;
  color: $purple;
  font-weight: 600;
  line-height: 1.4;
}

.pe-avail {
  margin-top: 3px;
  font-size: 10.5px;

  &.low { color: $amber; }
  &.blocked { color: $red; }
}

// ---- Mode C: Process View ---------------------------------------------------------
.pe-process-bar {
  display: flex;
  align-items: center;
  gap: 24px;
  margin-bottom: 16px;
  flex-wrap: wrap;

  &__wc { font-size: 13px; color: $text-secondary; }
  &__hint { font-size: 12px; }
}

.pe-flat-table {
  width: 100%;
  border-collapse: collapse;

  th {
    text-align: left;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.06em;
    color: $text-muted;
    padding: 8px 10px;
    border-bottom: 1px solid $border;
  }

  td {
    padding: 8px 10px;
    border-bottom: 1px solid $border-soft;
    font-size: 12.5px;
  }
}

.pe-avail-num {
  font-weight: 700;
  &.ok { color: $green; }
  &.blocked { color: $red; }
}

.pe-suggestion-row td { padding: 0; border-bottom: none; }

.pe-suggestion-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: $blue-soft;
  border: 1px dashed $blue;
  border-radius: $radius-md;
  padding: 10px 14px;
  margin: 4px 0 10px;

  &__text { font-size: 12px; color: $text-primary; }
  &__actions { display: flex; gap: 8px; flex-shrink: 0; }
}

// ---- Supervisor Entry ------------------------------------------------------------
.pe-sup-panel {
  background: $bg-panel;
  border: 1px solid $border;
  border-radius: $radius-lg;
  padding: 18px 20px;
  margin-bottom: 16px;
  box-shadow: 0 1px 2px rgba(20, 30, 60, 0.04);
}

.pe-sup-panel__head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;

  .pe-select--wo { min-width: 160px; }
}

.pe-badge {
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 11px;
  font-weight: 700;

  &--purple { background: $purple-soft; color: $purple; border: 1px solid $purple; }
}

.pe-sup-panel__timing {
  display: flex;
  gap: 20px;
  margin-bottom: 14px;
}

.pe-sup-panel__grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 18px;
}

.pe-sup-panel__section {
  margin-bottom: 14px;

  &:last-child { margin-bottom: 0; }
}

.pe-section-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: $text-muted;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.pe-reconcile-flag {
  color: $amber;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: none;
  letter-spacing: normal;
}

.pe-qlog-row, .pe-slog-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

// ---- Stage Detail Lightbox (§9) ---------------------------------------------------
.pe-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(27, 35, 56, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1500;
}

.pe-modal {
  width: 480px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  background: $bg-panel;
  border: 1px solid $border;
  border-radius: 14px;
  padding: 24px;
  position: relative;
  box-shadow: 0 20px 60px rgba(20, 30, 60, 0.18);

  &__close {
    position: absolute; top: 16px; right: 16px;
    background: none; border: none; color: $text-muted; font-size: 20px; cursor: pointer;
    &:hover { color: $text-primary; }
  }

  &__header { margin-bottom: 18px; }
  &__title { font-size: 16px; font-weight: 700; margin: 0 0 4px; }
  &__subtitle { font-size: 12px; color: $text-muted; }

  &__grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 16px;
  }

  &__section { margin-bottom: 16px; }

  &__actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 8px;
  }
}

.pe-input--good { border-color: $green; }
.pe-input--rejected { border-color: $red; }
.pe-input--rework { border-color: $amber; }

// ---- Responsive -------------------------------------------------------------------
@media (max-width: 900px) {
  .pe-wo-card__head { grid-template-columns: 1fr; gap: 8px; }
  .pe-stage-table__head, .pe-stage-table__row { grid-template-columns: repeat(3, 1fr); }
  .pe-sup-panel__grid { grid-template-columns: repeat(2, 1fr); }
  .pe-modal__grid { grid-template-columns: repeat(2, 1fr); }
}