/**
 * FleetCalc Pro - Calculator Keypad CSS
 * Features:
 * - Rectangular keys with bevel 3D tactile contours
 * - Distinct light vs dark key palettes
 * - High-legibility enlarged fonts for scientific keys
 * - Clean unit tags with removed input spinners
 * - Function Runner & Variable Inspector modal styling
 * - Intelligent rich tooltips & info cards with formulas, expanded descriptions, business importance, and line-by-line variable dictionaries
 */

.keypad-wrapper {
  padding: 16px 18px 22px 18px;
  background: #131720;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Zone Container */
.key-zone {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.zone-title {
  font-size: 8pt;
  font-weight: 800;
  letter-spacing: 1.2px;
  color: #7b889d;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 6px;
  padding-left: 2px;
}

.zone-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #232c3d;
}

/* Grid Layouts */
.keys-grid {
  display: grid;
  gap: 6px;
}

.grid-cols-8 {
  grid-template-columns: repeat(8, 1fr);
}

.grid-cols-6 {
  grid-template-columns: repeat(6, 1fr);
}

.grid-cols-5 {
  grid-template-columns: repeat(5, 1fr);
}

/* Base Rectangular Key Geometry */
.btn-calc {
  position: relative;
  height: 42px;
  border-radius: 4px;
  font-family: var(--font-ui);
  font-size: 10pt;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
  border: none;
  outline: none;
  transition: transform 0.05s ease, filter 0.15s ease, box-shadow 0.1s ease;
  user-select: none;
  -webkit-user-select: none;
}

.btn-calc:active {
  transform: translateY(2px);
  filter: brightness(0.9);
}

/* Enlarged typography specifically for Scientific keys for optimal legibility */
#zoneScientific .btn-calc {
  height: 48px;
  font-size: 13.5pt;
  font-weight: 800;
  letter-spacing: 0.3px;
  color: #f8fafc;
}

#zoneScientific .btn-calc[data-key="memlist"] {
  font-size: 9.5pt;
  font-weight: 800;
  letter-spacing: 0px;
}

#zoneFleet .btn-calc {
  font-size: 11pt;
  font-weight: 800;
}

#zoneAdvanced .btn-calc {
  font-size: 11pt;
  font-weight: 800;
}

/* --- THEME 1: DARK KEYS (Scientific, Fleet & Calculus) --- */
.btn-calc.key-dark {
  background: linear-gradient(180deg, #242a36 0%, #151922 100%);
  color: #e4e8ef;
  border-top: 1px solid #3c4658;
  border-bottom: 2px solid #080a0e;
  border-left: 1px solid #28303f;
  border-right: 1px solid #28303f;
  box-shadow: 0 3px 0 #090c10, 0 4px 6px rgba(0, 0, 0, 0.5);
}

.btn-calc.key-dark:hover {
  background: linear-gradient(180deg, #2d3545 0%, #1a202c 100%);
  color: #ffffff;
  border-top-color: var(--key-cyan);
}

.btn-calc.key-dark.accent-cyan {
  color: #00e5ff;
}

.btn-calc.key-dark.accent-amber {
  color: #ffab40;
}

/* --- THEME 2: LIGHT KEYS (Numeric & Base Commands) --- */
.btn-calc.key-light {
  background: linear-gradient(180deg, #f0f3f8 0%, #d2d7e2 100%);
  color: #12161f;
  border-top: 1px solid #ffffff;
  border-bottom: 2px solid #788194;
  border-left: 1px solid #c2c8d4;
  border-right: 1px solid #c2c8d4;
  box-shadow: 0 3px 0 #6e778a, 0 4px 6px rgba(0, 0, 0, 0.4);
  font-size: 12pt;
  font-weight: 800;
}

.btn-calc.key-light:hover {
  background: linear-gradient(180deg, #ffffff 0%, #e0e5ee 100%);
  border-top-color: #ff9100;
}

/* --- THEME 3: SPECIAL ACTION KEYS --- */
.btn-calc.key-exe {
  background: linear-gradient(180deg, #ff8f00 0%, #e65100 100%);
  color: #ffffff;
  border-top: 1px solid #ffb74d;
  border-bottom: 2px solid #8c2500;
  border-left: 1px solid #ff9800;
  border-right: 1px solid #ff9800;
  box-shadow: 0 3px 0 #731e00, 0 4px 8px rgba(230, 81, 0, 0.4);
  font-size: 16pt;
  font-weight: 900;
  letter-spacing: 0.5px;
}

.btn-calc.key-exe:hover {
  background: linear-gradient(180deg, #ffa000 0%, #ef6c00 100%);
}

.btn-calc.key-clear {
  background: linear-gradient(180deg, #c62828 0%, #8e0000 100%);
  color: #ffffff;
  border-top: 1px solid #ef5350;
  border-bottom: 2px solid #4a0000;
  border-left: 1px solid #b71c1c;
  border-right: 1px solid #b71c1c;
  box-shadow: 0 3px 0 #3d0000, 0 4px 6px rgba(198, 40, 40, 0.4);
}

.btn-calc.key-clear:hover {
  background: linear-gradient(180deg, #d32f2f 0%, #a00000 100%);
}

/* Sub-labels printed on top edge of keys */
.key-label {
  pointer-events: none;
}

/* ========================================================
   ENHANCED INTELLIGENT TOOLTIP / FUNCTION DETAILS POPOVER
   ======================================================== */
.tooltip-popover {
  position: fixed;
  background: #141923;
  color: #f0f3f8;
  border: 1px solid #2d384c;
  border-left: 4px solid #ff6d00;
  border-radius: 8px;
  padding: 14px 18px;
  font-size: 9pt;
  line-height: 1.45;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.85), 0 0 0 1px rgba(255, 255, 255, 0.05);
  pointer-events: auto;
  z-index: 10000;
  width: 520px;
  max-width: calc(100vw - 32px);
  display: none;
  animation: fadeInTooltip 0.15s ease-out;
}

@keyframes fadeInTooltip {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.tooltip-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  border-bottom: 1px solid #232d3d;
  padding-bottom: 6px;
}

.tooltip-acronym-badge {
  background: #ff6d00;
  color: #ffffff;
  font-weight: 900;
  font-size: 8.5pt;
  padding: 2px 8px;
  border-radius: 4px;
  letter-spacing: 0.5px;
}

.tooltip-title {
  font-weight: 800;
  font-size: 10.5pt;
  color: #ffffff;
  flex: 1;
}

.tooltip-close-btn {
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 16pt;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s ease;
}

.tooltip-close-btn:hover {
  color: #ff6d00;
}

.tooltip-formula-wrapper {
  margin: 6px 0 10px 0;
}

.tooltip-formula {
  font-family: var(--font-lcd);
  font-size: 10pt;
  color: #00e5ff;
  background: #090d13;
  padding: 6px 10px;
  border-radius: 4px;
  border: 1px solid #1c2738;
  display: block;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.35;
}

.tooltip-section-label {
  font-size: 7.5pt;
  text-transform: uppercase;
  font-weight: 800;
  letter-spacing: 1px;
  color: #ff9100;
  margin-top: 8px;
  margin-bottom: 3px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.tooltip-desc {
  color: #cbd5e1;
  margin-bottom: 8px;
  text-align: justify;
}

.tooltip-importance {
  color: #94a3b8;
  background: rgba(255, 109, 0, 0.08);
  border-left: 2px solid #ff9100;
  padding: 6px 10px;
  border-radius: 0 4px 4px 0;
  margin-bottom: 10px;
  font-size: 8.5pt;
}

.tooltip-variables-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: #0d121a;
  border: 1px solid #1f2838;
  border-radius: 5px;
  padding: 8px 10px;
  margin-top: 4px;
}

.tooltip-var-item {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 8.5pt;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.07);
  padding-bottom: 3px;
}

.tooltip-var-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.tooltip-var-code {
  font-family: var(--font-lcd);
  font-weight: 800;
  color: #00e5ff;
  background: #141b25;
  padding: 1px 5px;
  border-radius: 3px;
  white-space: nowrap;
}

.tooltip-var-desc {
  color: #e2e8f0;
}

/* Interactive Modal Dialogs */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
  z-index: 9999;
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.2s ease, visibility 0.2s;
}

.modal-overlay.active {
  visibility: visible;
  opacity: 1;
}

.modal-content {
  background: #161b24;
  border: 2px solid #2f3a4e;
  border-radius: 10px;
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.9);
}

.modal-header {
  background: #1c2330;
  border-bottom: 2px solid #ff6d00;
  padding: 14px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  font-size: 12pt;
  font-weight: 800;
  color: #ffffff;
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-close-btn {
  background: none;
  border: none;
  color: #a0aec0;
  font-size: 16pt;
  cursor: pointer;
  line-height: 1;
}

.modal-close-btn:hover {
  color: #ff6d00;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  font-size: 9.5pt;
  color: #e2e8f0;
}

.modal-footer {
  background: #141820;
  border-top: 1px solid #242c3d;
  padding: 12px 20px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Form Styles inside Modals */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-group.full-width {
  grid-column: span 2;
}

.form-label {
  font-size: 8.5pt;
  font-weight: 700;
  color: #b0bac9;
}

.input-with-unit {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.input-with-unit .form-input {
  width: 100%;
  padding-right: 80px !important;
  box-sizing: border-box;
}

.input-unit-tag {
  position: absolute;
  right: 12px;
  font-family: var(--font-lcd);
  font-weight: 800;
  color: #ff9100;
  pointer-events: none;
  font-size: 8.5pt;
  text-transform: uppercase;
  background: rgba(15, 19, 26, 0.9);
  padding: 2px 6px;
  border-radius: 3px;
  letter-spacing: 0.5px;
  border: 1px solid rgba(255, 145, 0, 0.25);
  white-space: nowrap;
}

/* Remove default increment/decrement spin buttons from number inputs across all browsers */
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
  -webkit-appearance: none !important;
  display: none !important;
  margin: 0 !important;
}

input[type=number] {
  -moz-appearance: textfield !important;
  appearance: textfield !important;
}

.form-input {
  background: #0f131a;
  border: 1px solid #2e384d;
  color: #ffffff;
  padding: 8px 12px;
  border-radius: 4px;
  font-size: 9.5pt;
  font-family: var(--font-lcd);
  outline: none;
}

.form-input:focus {
  border-color: #ff6d00;
  box-shadow: 0 0 0 1px #ff6d00;
}

/* Memory Modal Interactive Controls & Banner */
.mem-modal-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  background: #0d1117;
  border: 1px solid #1f293d;
  border-left: 4px solid #ff9100;
  border-radius: 6px;
  padding: 10px 14px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.mem-screen-value-card {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mem-toolbar-label {
  font-size: 8.5pt;
  font-weight: 700;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.mem-toolbar-val {
  font-family: var(--font-lcd);
  font-size: 14pt;
  font-weight: 800;
  color: #00e5ff;
  background: #05080c;
  border: 1px solid #1a2332;
  border-radius: 4px;
  padding: 4px 10px;
  letter-spacing: 1px;
}

.mem-actions-toolbar {
  display: flex;
  gap: 8px;
}

.mem-mode-btn {
  font-size: 8.5pt;
  padding: 6px 12px;
  border-radius: 4px;
  border: 1px solid #2a374d;
  background: #141b26;
  color: #94a3b8;
  cursor: pointer;
  transition: all 0.15s ease;
}

.mem-mode-btn:hover {
  background: #1e293b;
  color: #ffffff;
}

.mem-mode-btn.active {
  background: rgba(255, 145, 0, 0.15);
  border-color: #ff9100;
  color: #ff9100;
  font-weight: 800;
  box-shadow: 0 0 10px rgba(255, 145, 0, 0.25);
}

.mem-mode-btn.active.recall-active {
  background: rgba(0, 229, 255, 0.15);
  border-color: #00e5ff;
  color: #00e5ff;
  box-shadow: 0 0 10px rgba(0, 229, 255, 0.25);
}

.mem-help-text {
  font-size: 8.5pt;
  color: #cbd5e1;
  background: rgba(15, 23, 42, 0.6);
  padding: 6px 10px;
  border-radius: 4px;
  margin-bottom: 12px;
  border: 1px dashed rgba(255, 255, 255, 0.1);
}

/* Memory Grid M00-M99 */
.memories-grid-container {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  max-height: 400px;
  overflow-y: auto;
  padding-right: 6px;
}

.memory-cell {
  background: #11151c;
  border: 1px solid #283344;
  border-radius: 4px;
  padding: 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: all 0.15s ease;
  user-select: none;
}

.memory-cell:hover {
  background: #1c2230;
  border-color: #00e5ff;
  transform: translateY(-1px);
}

.memory-cell.memory-saved-pulse {
  animation: memSavedPulse 0.6s ease-out;
  border-color: #69f0ae !important;
  background: rgba(105, 240, 174, 0.15) !important;
}

@keyframes memSavedPulse {
  0% { transform: scale(1.05); background: rgba(105, 240, 174, 0.4); border-color: #69f0ae; }
  100% { transform: scale(1); }
}

.memory-cell-id {
  font-weight: 800;
  font-size: 8pt;
  color: #ff9100;
}

.memory-cell-val {
  font-family: var(--font-lcd);
  font-size: 9.5pt;
  color: #00e5ff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Matrix Table Editor */
.matrix-editor-table {
  border-collapse: collapse;
  margin: 10px 0;
  max-height: 380px;
  overflow: auto;
  display: block;
}

.matrix-editor-table input {
  width: 52px;
  background: #0d1117;
  color: #00e5ff;
  border: 1px solid #283244;
  padding: 4px 6px;
  font-family: var(--font-lcd);
  font-size: 9pt;
  text-align: right;
}

/* Function Runner Modal Dynamic Box */
.fn-runner-box {
  background: #0e121a;
  border: 1px solid #252f40;
  border-radius: 6px;
  padding: 14px;
  margin-bottom: 14px;
}

.fn-runner-formula {
  font-family: var(--font-lcd);
  color: #00e5ff;
  background: #06090e;
  padding: 8px 12px;
  border-radius: 4px;
  border: 1px solid #1a2332;
  margin: 8px 0;
  word-break: break-all;
}

/* Mobile Media Queries */
@media (max-width: 768px) {
  .keypad-wrapper {
    padding: 10px 10px 16px 10px;
    gap: 10px;
  }

  .grid-cols-8 {
    grid-template-columns: repeat(4, 1fr);
  }

  .grid-cols-6 {
    grid-template-columns: repeat(3, 1fr);
  }

  .grid-cols-5 {
    grid-template-columns: repeat(5, 1fr);
  }

  .btn-calc {
    height: 38px;
    font-size: 8.5pt;
  }

  #zoneScientific .btn-calc {
    font-size: 10pt;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-group.full-width {
    grid-column: span 1;
  }

  .memories-grid-container {
    grid-template-columns: repeat(2, 1fr);
  }

  .tooltip-popover {
    width: calc(100vw - 24px);
    max-width: calc(100vw - 24px);
    left: 12px !important;
    max-height: 80vh;
    overflow-y: auto;
  }
}

@media (hover: none) and (pointer: coarse) {
  /* Prevent sticky hover pseudo-classes on touchscreens */
  .btn-calc:hover {
    transform: none;
  }
}

/* Currency Selector Grid & Cards */
.currency-grid-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 8px;
  max-height: 420px;
  overflow-y: auto;
  padding: 2px;
}

.currency-card {
  background: #0e121a;
  border: 1px solid #232d3d;
  border-radius: 6px;
  padding: 8px 12px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: all 0.15s ease;
}

.currency-card:hover {
  background: #162030;
  border-color: #00e5ff;
  transform: translateY(-1px);
}

.currency-card.active {
  border-color: #69f0ae;
  background: rgba(105, 240, 174, 0.1);
}

.currency-country-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
}

.currency-country-name {
  font-size: 8.5pt;
  font-weight: 600;
  color: #f1f5f9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.currency-name-label {
  font-size: 7.5pt;
  color: #94a3b8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.currency-code-badge {
  background: #1e293b;
  color: #69f0ae;
  font-family: var(--font-lcd, monospace);
  font-size: 8.5pt;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 4px;
  border: 1px solid rgba(105, 240, 174, 0.3);
  margin-left: 8px;
  flex-shrink: 0;
}
