/* ==============================================================================
   ClassKit Global - Function Machine Rules Studio Stylesheet
   Pure Vanilla CSS | A4 210mm x 297mm Vector Print Engine
   Input-Output Algebraic Transformations & Pattern Analysis (CCSS 4.OA.C.5)
   Strict Rule 4 Compliance: Under 600 lines
   ============================================================================== */

:root {
  --fm-border-thick: 2px solid #0F172A;
  --fm-border-thin: 1px solid #CBD5E1;
  --fm-green: #16A34A;
  --fm-green-bg: rgba(22, 163, 74, 0.12);
}

/* ------------------------------------------------------------------------------
   1. Left Control Panel Options & Form Elements
   ------------------------------------------------------------------------------ */
.form-group-wb { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.form-label-wb { font-size: 12px; font-weight: 800; color: var(--text-main, #0F172A); }
.form-input-wb {
  height: 38px; padding: 0 12px; border: 1.5px solid var(--border-medium, #CBD5E1);
  border-radius: var(--radius-sm, 6px); font-size: 13px; font-weight: 700;
  color: var(--text-main, #0F172A); outline: none; background: #FFFFFF;
  box-sizing: border-box; transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.form-input-wb:focus { border-color: var(--primary, #4F46E5); box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12); }
.form-row-checkboxes { display: flex; flex-direction: column; gap: 8px; }
.checkbox-label-wb { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--text-main, #1E293B); cursor: pointer; user-select: none; }
.checkbox-label-wb input[type="checkbox"] { accent-color: var(--primary, #4F46E5); width: 16px; height: 16px; cursor: pointer; }

.option-label-sub { font-size: 11.5px; font-weight: 700; color: var(--text-muted, #64748B); margin-bottom: 6px; letter-spacing: -0.2px; }
.segmented-control { display: flex; gap: 4px; background: #EDF2F7; padding: 4px; border-radius: 8px; }
.seg-btn {
  flex: 1; padding: 8px 4px; font-size: 11.5px; font-weight: 700; color: #64748B;
  background: transparent; border: none; border-radius: 6px; cursor: pointer;
  transition: all 0.15s ease; text-align: center; user-select: none; white-space: nowrap;
}
.seg-btn:hover { color: #0F172A; }
.seg-btn.active { background: #FFFFFF; color: #0F172A; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); }
.layout-hint-text { font-size: 11.5px; color: #64748B; line-height: 1.4; margin-top: 8px; padding: 4px 6px; }

.btn-secondary-action {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px;
  font-size: 13px; font-weight: 700; background: #FFFFFF; color: #334155; border: 1px solid #CBD5E1;
  cursor: pointer; transition: all 0.15s ease;
}
.btn-secondary-action:hover { background: #F8FAFC; border-color: #94A3B8; color: #0F172A; }

.btn-sidebar-generate {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; padding: 12px;
  border-radius: 10px; font-size: 13.5px; font-weight: 800; background: #F1F5F9; border: 1.5px solid #CBD5E1;
  color: #1E293B; cursor: pointer; transition: all 0.18s ease;
}
.btn-sidebar-generate:hover { background: #E2E8F0; border-color: #94A3B8; color: #0F172A; transform: translateY(-1px); }

/* ------------------------------------------------------------------------------
   2. A4 Printable Sheet Engine (Portrait 210mm x 297mm)
   ------------------------------------------------------------------------------ */
.print-pages-container {
  display: flex;
  flex-direction: column;
  gap: 24px;
  align-items: center;
}

.function-sheet {
  width: 210mm;
  height: 297mm;
  min-height: 297mm;
  max-height: 297mm;
  box-sizing: border-box;
  padding: 10mm 14mm 8mm 14mm;
  background: #FFFFFF;
  color: #0F172A;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
  box-shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.1);
  border-radius: 2px;
}

/* Standardized Worksheet Header Block (No Badges, Top-Right Metadata) */
.sheet-header-block {
  display: flex;
  flex-direction: column;
  gap: 2mm;
  border-bottom: 2px solid #0F172A;
  padding-bottom: 2mm;
  margin-bottom: 3mm;
}

.sheet-meta-row {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 6mm;
  font-size: 8.5pt;
  font-weight: 700;
  color: #334155;
}

.sheet-name-field {
  display: inline-block;
  min-width: 26mm;
  border-bottom: 1.5px solid #0F172A;
}

.sheet-answer-tag {
  font-size: 9pt;
  font-weight: 900;
  color: #166534;
  background: #DCFCE7;
  padding: 1mm 3mm;
  border-radius: 4px;
  letter-spacing: 0.5px;
}

.sheet-main-title {
  font-size: 16pt;
  font-weight: 900;
  color: #0F172A;
  margin: 0;
  line-height: 1.2;
}

/* ------------------------------------------------------------------------------
   3. Directive Mission Banner
   ------------------------------------------------------------------------------ */
.function-hero-banner {
  background: #EEF2FF;
  border: 1.5px solid #C7D2FE;
  border-radius: 7px;
  padding: 2.2mm 4mm;
  margin-bottom: 2.5mm;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-sizing: border-box;
}

.function-directive-text {
  font-size: 8.2pt;
  color: #334155;
  line-height: 1.4;
  flex: 1;
}

.function-directive-text strong {
  color: #0F172A;
}

.function-answer-banner {
  width: 100%;
  background: #F0FDF4;
  border: 1.5px solid #86EFAC;
  border-radius: 7px;
  padding: 2.2mm 4mm;
  margin-bottom: 2.5mm;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-sizing: border-box;
}

.ans-banner-text {
  font-size: 8.5pt;
  color: #166534;
  font-weight: 700;
}

/* ------------------------------------------------------------------------------
   4. Machines Grid Layout (Fixed 4 Machines, 2x2 Spacious Layout)
   ------------------------------------------------------------------------------ */
.machines-grid-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  min-height: 0;
  overflow: hidden;
}

.machines-grid-4 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 3.5mm;
  flex: 1;
  min-height: 0;
}

/* ------------------------------------------------------------------------------
   5. Individual Machine Card & Input-Output Table
   ------------------------------------------------------------------------------ */
.machine-card {
  background: #FFFFFF;
  border: 1.8px solid #0F172A;
  border-radius: 8px;
  padding: 2.5mm 3.5mm;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: 0 2px 5px rgba(15, 23, 42, 0.05);
  box-sizing: border-box;
}

.machine-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #E2E8F0;
  padding-bottom: 1.2mm;
  margin-bottom: 1.5mm;
}

.machine-card-title {
  font-size: 9.5pt;
  font-weight: 900;
  color: #0F172A;
}

.machine-card-badge {
  font-size: 7.2pt;
  font-weight: 800;
  padding: 0.5mm 2.2mm;
  border-radius: 3px;
  background: #F1F5F9;
  color: #475569;
}

.machine-icon-svg {
  width: 100%;
  height: 16mm;
  display: block;
  margin: 1mm auto;
}

/* In-Out Table */
.in-out-table-wrap {
  width: 100%;
  margin: 1.5mm 0;
}

.in-out-table {
  width: 100%;
  border-collapse: collapse;
  text-align: center;
  background: #FFFFFF;
}

.in-out-table th,
.in-out-table td {
  border: 1.2px solid #0F172A;
  padding: 1.2mm 1mm;
  font-size: 9pt;
  font-weight: 800;
}

.in-out-table th {
  background: #F8FAFC;
  color: #334155;
  font-size: 8pt;
  font-weight: 900;
}

.in-out-table td.cell-filled {
  color: #0F172A;
}

.in-out-table td.cell-blank {
  background: #FAFAF9;
  color: transparent;
  min-width: 12mm;
}

.is-answer-key-page .in-out-table td.cell-blank {
  background: #DCFCE7 !important;
  color: #166534 !important;
  font-weight: 900;
}

/* Rule Response Footer inside Card */
.machine-rule-prompt {
  display: flex;
  align-items: center;
  gap: 2mm;
  font-size: 8.5pt;
  font-weight: 800;
  color: #0F172A;
  margin-top: 1.5mm;
  padding-top: 1.5mm;
  border-top: 1px dashed #CBD5E1;
}

.rule-blank-box {
  flex: 1;
  height: 6mm;
  border-bottom: 1.8px solid #0F172A;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9.5pt;
  font-weight: 900;
  color: #0F172A;
}

.is-answer-key-page .rule-blank-box {
  color: #166534;
  background: #DCFCE7;
  border-radius: 3px;
  border-bottom: none;
}

/* ------------------------------------------------------------------------------
   6. Footer Meta Information
   ------------------------------------------------------------------------------ */
.sheet-footer-block {
  border-top: 1px solid #E2E8F0;
  padding-top: 2mm;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 7.2pt;
  color: #94A3B8;
}

.footer-meta-brand {
  font-weight: 700;
  color: #64748B;
}

.footer-brand-tag {
  font-weight: 800;
  color: #4F46E5;
}

/* ------------------------------------------------------------------------------
   7. Native Print Optimization (@media print)
   ------------------------------------------------------------------------------ */
@media print {
  @page {
    size: A4 portrait;
    margin: 0;
  }

  html, body {
    margin: 0 !important;
    padding: 0 !important;
    background: #FFFFFF !important;
  }

  .top-navbar,
  .studio-header,
  .studio-sidebar,
  .pro-modal-backdrop,
  footer {
    display: none !important;
  }

  .studio-body {
    display: block !important;
    height: auto !important;
    overflow: visible !important;
  }

  .studio-viewport {
    background: transparent !important;
    padding: 0 !important;
    overflow: visible !important;
    display: block !important;
  }

  .a4-wrapper {
    transform: none !important;
  }

  .print-pages-container {
    gap: 0 !important;
  }

  .function-sheet {
    box-shadow: none !important;
    border-radius: 0 !important;
    margin: 0 !important;
    page-break-after: always !important;
    break-after: page !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .function-sheet:last-child {
    page-break-after: avoid !important;
    break-after: avoid !important;
  }
}
