﻿/*--------------------------------------------------------------
# Engineering Calculator page
# Builds on the shared primitives in style.css:
#   .calc-card / .calc-grid / .calc-field / .input-unit-wrap /
#   .search-button / .reset-button / .result-unit-toggle / .unit-tab /
#   .calc-error / .presets-panel / .presets-header / .presets-title /
#   .file-count / .option-rows / .option-row / .option-row-label /
#   .icon-tab-grid / .icon-tab / .action-row
# This file only contains calculator-specific styling: the tool tab
# strip, scientific keypad, matrix textarea, resistor preview, graph
# canvas wrapper, GPA rows, etc.
--------------------------------------------------------------*/
.calculator-section { padding: 60px 0; }

/* ── Tool picker — full-width tab strip (NOT inside a .option-row, so no
   sidebar label crowds the buttons). Wraps to two rows on narrow widths. */
.calc-tool-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 4px 0 26px;
  padding-bottom: 22px;
  border-bottom: 1px solid #eef0f2;
}
.calc-tool-btn {
  flex: 1 1 0;
  min-width: 96px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 10px;
  background: #f8fafd;
  border: 1.5px solid #e4eaf1;
  border-radius: 10px;
  font-family: "Open Sans", sans-serif;
  font-size: 13px;
  font-weight: 600;
  color: #6c757d;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.05s;
  white-space: nowrap;
}
.calc-tool-btn i {
  font-size: 22px;
  color: #6c757d;
  transition: color 0.15s;
}
.calc-tool-btn:hover {
  border-color: #0563bb;
  color: #0563bb;
  background: #e8f0fb;
}
.calc-tool-btn:hover i { color: #0563bb; }
.calc-tool-btn.active {
  border-color: #0563bb;
  background: #0563bb;
  color: #fff;
  box-shadow: 0 4px 14px rgba(5, 99, 187, 0.18);
}
.calc-tool-btn.active i { color: #fff; }
.calc-tool-btn:active { transform: translateY(1px); }

/* Each tool panel is hidden until its tab is selected */
.calc-tool[hidden] { display: none; }

/* Help/intro text above each tool */
.tool-blurb {
  font-size: 14px;
  color: #6c757d;
  margin: 4px 0 22px;
  line-height: 1.6;
}
.tool-blurb code {
  background: #f1f4f8;
  border: 1px solid #e4eaf1;
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 13px;
  color: #0563bb;
}

.field-help-inline {
  font-weight: 400;
  color: #adb5bd;
  font-size: 12px;
  margin-left: 6px;
}

kbd {
  background: #f1f4f8;
  border: 1px solid #d0dae8;
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 12px;
  font-family: "Open Sans", sans-serif;
  color: #45505b;
}

/* ── Scientific keypad ──────────────────────────────────────────────────── */
.calc-keypad {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin: 18px 0 6px;
}
.calc-keypad button {
  background: #f8fafd;
  border: 1px solid #e4eaf1;
  border-radius: 8px;
  padding: 10px 6px;
  font-size: 14px;
  font-weight: 600;
  color: #0563bb;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, transform 0.05s;
}
.calc-keypad button:hover { background: #0563bb; color: #fff; }
.calc-keypad button:active { transform: scale(0.97); }

.sci-modes { margin: 14px 0 6px; }

/* History panel */
.sci-history { margin-top: 24px; }
.sci-history-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.sci-history-list li {
  padding: 12px 28px;
  border-bottom: 1px solid #eef0f2;
  font-family: "Open Sans", sans-serif;
  font-size: 14px;
  color: #45505b;
  cursor: pointer;
  transition: background 0.12s;
}
.sci-history-list li:last-child { border-bottom: none; }
.sci-history-list li:hover { background: #f8fafd; }
.sci-history-list .hist-expr {
  color: #6c757d;
  font-size: 13px;
  margin-bottom: 4px;
}
.sci-history-list .hist-result {
  color: #0563bb;
  font-weight: 600;
  word-break: break-word;
}

/* ── Matrix tool ────────────────────────────────────────────────────────── */
.mat-textarea {
  border: 1px solid #ced4da;
  border-radius: 6px;
  padding: 10px 14px;
  font-family: "Courier New", monospace;
  font-size: 14px;
  color: #45505b;
  background: #fff;
  resize: vertical;
  transition: border-color 0.18s, box-shadow 0.18s;
}
.mat-textarea:focus {
  outline: none;
  border-color: #0563bb;
  box-shadow: 0 0 0 3px rgba(5, 99, 187, 0.12);
}

.mat-grid { margin-bottom: 18px; }

.mat-ops { margin-bottom: 6px; }
.mat-op-grid {
  /* Wrap onto multiple rows when 8 cells get cramped — keeps each label
     readable instead of squashing the icons. */
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
}

.mat-output { margin-top: 24px; }
.mat-output-body {
  margin: 0;
  padding: 22px 28px 26px;
  font-family: "Courier New", monospace;
  font-size: 15px;
  color: #45505b;
  background: #f8fafd;
  border-radius: 0 0 8px 8px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── Physics tool ───────────────────────────────────────────────────────── */
.phys-formula-grid {
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
}
.phys-formula-name {
  text-align: center;
  font-family: "Poppins", sans-serif;
  font-size: 16px;
  font-weight: 600;
  color: #0563bb;
  margin: 18px 0 14px;
  letter-spacing: 0.3px;
}
.phys-formula-name .equation {
  display: inline-block;
  background: #e8f0fb;
  border: 1px solid #d0dae8;
  border-radius: 6px;
  padding: 6px 16px;
  margin-left: 10px;
  font-family: "Courier New", monospace;
  color: #0563bb;
}
.phys-fields { margin-bottom: 18px; }

.phys-output { margin-top: 24px; }
.phys-output-body {
  padding: 22px 28px 26px;
  font-size: 15px;
  color: #45505b;
}
.phys-output-body .solved-var {
  font-weight: 700;
  color: #0563bb;
  font-size: 18px;
}
.phys-output-body .solved-eq {
  margin-top: 10px;
  font-family: "Courier New", monospace;
  background: #f8fafd;
  border: 1px solid #e4eaf1;
  border-radius: 6px;
  padding: 12px 16px;
  word-break: break-word;
}

/* ── Resistor color code ────────────────────────────────────────────────── */
.res-modes { margin-bottom: 18px; }
.res-bands {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 10px;
  margin: 18px 0 22px;
}
.res-band-col {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.res-band-col label {
  font-size: 12px;
  font-weight: 700;
  color: #6c757d;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  text-align: center;
}
.res-band-col select {
  border: 1px solid #ced4da;
  border-radius: 6px;
  padding: 8px 10px;
  background: #fff;
  font-size: 13px;
  color: #45505b;
  cursor: pointer;
}
.res-band-col select:focus {
  outline: none;
  border-color: #0563bb;
  box-shadow: 0 0 0 3px rgba(5, 99, 187, 0.12);
}

/* Visual resistor preview — colored stripes on a beige body */
.res-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 80px;
  margin: 6px 0 18px;
  background: linear-gradient(180deg, #f3e3c2 0%, #e9d4ad 50%, #f3e3c2 100%);
  border-radius: 40px 40px 40px 40px / 40px;
  position: relative;
  overflow: hidden;
}
.res-preview::before,
.res-preview::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 60px;
  height: 4px;
  background: #b8b8b8;
  transform: translateY(-50%);
}
.res-preview::before { left: -45px; box-shadow: -2px 0 0 #999; }
.res-preview::after  { right: -45px; box-shadow: 2px 0 0 #999; }
.res-stripe {
  width: 9px;
  height: 60px;
  margin: 0 5px;
  border-radius: 2px;
}

.res-output { margin-top: 24px; }
.res-output-body {
  padding: 22px 28px 26px;
  text-align: center;
}
.res-value {
  font-family: "Poppins", sans-serif;
  font-size: 28px;
  font-weight: 700;
  color: #0563bb;
}
.res-tol {
  margin-top: 8px;
  font-size: 14px;
  color: #6c757d;
}

/* ── Base / Bits tool ───────────────────────────────────────────────────── */
.base-grid { margin-bottom: 16px; }

.bitwise-title {
  font-family: "Poppins", sans-serif;
  font-size: 16px;
  font-weight: 600;
  color: #45505b;
  margin: 24px 0 14px;
}

.bit-output {
  margin-top: 22px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}
.bit-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  background: #f8fafd;
  border: 1px solid #e4eaf1;
  border-radius: 6px;
  font-family: "Courier New", monospace;
  font-size: 13px;
}
.bit-row .bit-op {
  font-weight: 700;
  color: #0563bb;
  text-transform: uppercase;
  font-family: "Open Sans", sans-serif;
  font-size: 12px;
  letter-spacing: 0.4px;
}
.bit-row .bit-val { color: #45505b; word-break: break-all; text-align: right; }

/* ── Graph (desmos-lite) ────────────────────────────────────────────────── */
.graph-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 22px;
  align-items: start;
}
.graph-side {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}
.graph-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.graph-row {
  display: grid;
  grid-template-columns: 18px 1fr 28px 28px;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  background: #f8fafd;
  border: 1px solid #e4eaf1;
  border-radius: 8px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.graph-row:focus-within {
  border-color: #0563bb;
  box-shadow: 0 0 0 3px rgba(5, 99, 187, 0.12);
}
.graph-row.is-error { border-color: #dc3545; }
.graph-color-swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(0,0,0,0.08);
  cursor: pointer;
  transition: transform 0.1s;
}
.graph-color-swatch:hover { transform: scale(1.2); }
.graph-row .graph-prefix {
  display: inline-flex;
  align-items: center;
  font-family: "Courier New", monospace;
  color: #6c757d;
  font-size: 14px;
  margin-right: 2px;
}
.graph-input {
  border: none;
  outline: none;
  background: transparent;
  font-family: "Courier New", monospace;
  font-size: 14px;
  color: #45505b;
  width: 100%;
  padding: 4px 0;
}
.graph-input::placeholder { color: #adb5bd; }
.graph-toggle, .graph-remove {
  background: transparent;
  border: 1px solid #e4eaf1;
  border-radius: 6px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #6c757d;
  font-size: 16px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.graph-toggle:hover { background: #e8f0fb; color: #0563bb; border-color: #0563bb; }
.graph-toggle.is-off { color: #adb5bd; background: #f1f4f8; }
.graph-remove:hover { background: #fff3f3; color: #dc3545; border-color: #dc3545; }

.graph-add-btn {
  align-self: flex-start;
  margin: 0;
  padding: 7px 16px;
  font-size: 13px;
}

.graph-controls {
  background: #f8fafd;
  border: 1px solid #e4eaf1;
  border-radius: 8px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.graph-control-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.graph-control-row label {
  font-size: 11px;
  font-weight: 700;
  color: #6c757d;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.graph-range-pair {
  display: flex;
  align-items: center;
  gap: 6px;
}
.graph-range-pair input {
  flex: 1;
  min-width: 0;
  border: 1px solid #ced4da;
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 13px;
  color: #45505b;
}
.graph-range-pair input:focus {
  outline: none;
  border-color: #0563bb;
  box-shadow: 0 0 0 3px rgba(5, 99, 187, 0.12);
}
.graph-range-pair span {
  font-size: 12px;
  color: #adb5bd;
}
.graph-buttons {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.graph-buttons .graph-apply-btn,
.graph-buttons .graph-reset-btn {
  margin: 0;
  padding: 7px 14px;
  font-size: 13px;
  flex: 1;
}

.graph-trace {
  background: #0563bb;
  color: #fff;
  padding: 10px 14px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-family: "Courier New", monospace;
  font-size: 13px;
}
.graph-trace-label {
  font-family: "Open Sans", sans-serif;
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  opacity: 0.85;
}
.graph-trace-coords { font-weight: 600; }

.graph-canvas-wrap {
  background: #fff;
  border: 1px solid #e4eaf1;
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  min-width: 0;
}
#graph-canvas {
  display: block;
  width: 100%;
  height: auto;
  cursor: grab;
  touch-action: none;
}
#graph-canvas.is-panning { cursor: grabbing; }

@media (max-width: 992px) {
  .graph-layout {
    grid-template-columns: 1fr;
  }
}

/* ── Statistics ─────────────────────────────────────────────────────────── */
.stats-modes { margin: 14px 0 0; }
.stats-output { margin-top: 24px; }
.stats-output-body {
  padding: 22px 28px 26px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px 22px;
}
.stat-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat-item .stat-label {
  font-size: 12px;
  font-weight: 700;
  color: #6c757d;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.stat-item .stat-val {
  font-family: "Poppins", sans-serif;
  font-size: 18px;
  color: #0563bb;
  font-weight: 600;
  word-break: break-word;
}
.stats-eq {
  grid-column: 1 / -1;
  font-family: "Courier New", monospace;
  background: #f1f4f8;
  border: 1px solid #e4eaf1;
  border-radius: 6px;
  padding: 12px 16px;
  font-size: 14px;
  color: #45505b;
  margin-top: 4px;
}

/* ── GPA ────────────────────────────────────────────────────────────────── */
.gpa-rows {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}
.gpa-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr auto;
  gap: 10px;
  align-items: center;
}
.gpa-row input[type="text"],
.gpa-row input[type="number"] {
  border: 1px solid #ced4da;
  border-radius: 6px;
  padding: 9px 12px;
  font-size: 14px;
  color: #45505b;
}
.gpa-row input:focus {
  outline: none;
  border-color: #0563bb;
  box-shadow: 0 0 0 3px rgba(5, 99, 187, 0.12);
}
.gpa-remove {
  background: transparent;
  border: 1px solid #d0dae8;
  border-radius: 6px;
  width: 36px;
  height: 36px;
  color: #adb5bd;
  cursor: pointer;
  font-size: 16px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.gpa-remove:hover {
  background: #fff3f3;
  color: #dc3545;
  border-color: #dc3545;
}

.gpa-output { margin-top: 22px; }
.gpa-output-body {
  padding: 22px 28px 26px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px 22px;
}

.gpa-divider {
  border: 0;
  border-top: 1px solid #eef0f2;
  margin: 36px 0 22px;
}
.gpa-need-title {
  font-family: "Poppins", sans-serif;
  font-size: 17px;
  font-weight: 600;
  color: #45505b;
  margin: 0 0 6px;
}
.gpa-need-output {
  margin-top: 14px;
  padding: 16px 22px;
  background: #f8fafd;
  border: 1px solid #e4eaf1;
  border-left: 4px solid #0563bb;
  border-radius: 6px;
  font-size: 15px;
  color: #45505b;
  text-align: center;
}
.gpa-need-output.is-impossible {
  background: #fff3f3;
  border-left-color: #dc3545;
  color: #dc3545;
}
.gpa-need-output.is-easy {
  background: #f1f9f3;
  border-left-color: #2c9c4a;
  color: #2c9c4a;
}
.gpa-need-output strong {
  font-size: 22px;
  font-weight: 700;
  font-family: "Poppins", sans-serif;
}

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 992px) {
  .mat-grid {
    grid-template-columns: 1fr;
  }
  .calc-tool-btn {
    /* Two rows of four (or three of three) on tablet — let flex-wrap handle it. */
    flex: 1 1 calc(25% - 8px);
  }
}

@media (max-width: 768px) {
  .calculator-section { padding: 36px 0; }

  /* Tool strip: 3-up. Padding tightens so eight buttons in two rows of
     three (+ trailing two) still feel deliberate, not packed. */
  .calc-tool-btn {
    flex: 1 1 calc(33.3% - 8px);
    font-size: 12px;
    padding: 10px 6px;
  }
  .calc-tool-btn i { font-size: 18px; }

  .calc-keypad {
    grid-template-columns: repeat(4, 1fr);
  }
  .calc-keypad button {
    padding: 9px 4px;
    font-size: 13px;
  }

  /* Sub-pickers (matrix-op + physics-formula): tighten so labels don't
     truncate. The auto-fit grid already handles column count. */
  .mat-op-grid .icon-tab,
  .phys-formula-grid .icon-tab {
    padding: 9px 4px;
    font-size: 11px;
  }
  .mat-op-grid .icon-tab i,
  .phys-formula-grid .icon-tab i {
    font-size: 18px;
  }

  /* GPA: course full-width on top, grade + credits + remove below. */
  .gpa-row {
    grid-template-columns: 1fr 90px auto;
    gap: 8px;
  }
  .gpa-row .gpa-course {
    grid-column: 1 / -1;
  }
  .gpa-output-body {
    padding: 18px 18px 22px;
  }

  /* Resistor bands always wrap to two-up on phone width. */
  .res-bands {
    grid-template-columns: repeat(2, 1fr);
  }
  .res-output-body {
    padding: 18px 18px 22px;
  }
  .res-value { font-size: 24px; }

  /* Stats grid stacks tighter and the result body shrinks padding. */
  .stats-output-body { padding: 18px 18px 22px; }

  /* Matrix output gets a horizontal scroll instead of overflowing the card. */
  .mat-output-body {
    padding: 16px 18px 20px;
    font-size: 13px;
    overflow-x: auto;
  }

  /* Physics fields: stack the equation/blurb text neatly. */
  .phys-formula-name {
    font-size: 14px;
    flex-direction: column;
    display: flex;
    align-items: center;
    gap: 6px;
  }
  .phys-formula-name .equation {
    margin-left: 0;
    font-size: 13px;
    padding: 5px 12px;
  }
  .phys-output-body { padding: 18px 18px 22px; }

  /* Bit-output rows shrink to single column (already auto-fit, but clamp
     the label/val text size). */
  .bit-row { font-size: 12px; padding: 8px 10px; }

  /* Long inline code in tool blurbs shouldn't blow out the page. */
  .tool-blurb code { word-break: break-word; }

  /* Graph: tighter side panel so the canvas isn't a postage stamp. */
  .graph-row { padding: 6px 8px; gap: 6px; grid-template-columns: 16px 1fr 26px 26px; }
  .graph-toggle, .graph-remove { width: 26px; height: 26px; font-size: 14px; }
  .graph-input { font-size: 13px; }
  .graph-controls { padding: 10px 12px; }
  .graph-trace { font-size: 12px; padding: 8px 12px; }
}

@media (max-width: 480px) {
  .calc-keypad {
    grid-template-columns: repeat(3, 1fr);
  }
  .calc-tool-btn {
    flex: 1 1 calc(50% - 8px);
  }
  .mat-op-grid .icon-tab,
  .phys-formula-grid .icon-tab {
    font-size: 10.5px;
  }
  /* GPA: drop the credit field to its own narrow row so the grade input
     gets readable width on tiny phones. */
  .gpa-row {
    grid-template-columns: 1fr auto;
  }
  .gpa-row .gpa-credits {
    grid-column: 1 / 2;
  }
  /* GPA need: the three % inputs stack to one column. */
  .gpa-need-output { font-size: 14px; }
  .gpa-need-output strong { font-size: 18px; }

  /* Search/Reset action buttons stretch full width so they're tappable. */
  .action-row {
    flex-direction: column;
    align-items: stretch;
  }
  .action-row .search-button,
  .action-row .reset-button {
    width: 100%;
    margin: 0;
  }

  /* Final-grade-needed block — keep all three % fields in a single column
     so labels stay readable. The .calc-grid already collapses at 768px,
     this just trims padding. */
  .gpa-divider { margin: 28px 0 18px; }
}
