/* ===== Scientific Calculator ===== */

.cal-tool .row-layout {
  align-items: stretch;
}

.cal-panels > [class*='col-'] {
  display: flex;
  flex-direction: column;
}

.cal-panel,
.cal-side-panel {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
}

.cal-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.cal-panel-header > span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.cal-mode-switch {
  display: inline-flex;
  background: var(--bg-soft, #f1f5f9);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}

.cal-mode-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary, #64748b);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.cal-mode-btn.is-active {
  background: var(--accent, #2563eb);
  color: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.cal-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1 1 auto;
}

/* display */
.cal-display {
  background: var(--bg-soft, #f8fafc);
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 12px;
  padding: 12px 16px;
  text-align: right;
}

.cal-history {
  min-height: 18px;
  font-size: 13px;
  color: var(--text-secondary, #64748b);
  white-space: pre;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}

.cal-main {
  width: 100%;
  border: none;
  background: transparent;
  font-size: 34px;
  font-weight: 700;
  color: var(--text, #0f172a);
  text-align: right;
  outline: none;
  font-variant-numeric: tabular-nums;
  font-family: inherit;
}

/* keypad */
.cal-keypad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.cal-keypad[data-mode='basic'] {
  grid-template-columns: repeat(4, 1fr);
}

.cal-key {
  height: 52px;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 10px;
  background: var(--bg-card, #fff);
  color: var(--text, #0f172a);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.15s ease, background 0.15s ease;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  font-family: inherit;
}

.cal-key:hover {
  background: var(--bg-soft, #f1f5f9);
  transform: translateY(-1px);
}

.cal-key:active {
  transform: translateY(0);
  box-shadow: none;
}

.cal-key-num {
  background: var(--bg-card, #fff);
}

.cal-key-op,
.cal-key-eq {
  background: var(--accent-soft, #eff6ff);
  color: var(--accent, #2563eb);
  border-color: var(--accent-border, #bfdbfe);
}

.cal-key-eq {
  background: var(--accent, #2563eb);
  color: #fff;
  border-color: var(--accent, #2563eb);
}

.cal-key-clear {
  background: var(--danger-soft, #fef2f2);
  color: var(--danger, #dc2626);
  border-color: var(--danger-border, #fecaca);
}

.cal-key-fn {
  background: var(--bg-soft, #f1f5f9);
  font-size: 14px;
}

.cal-key-filler {
  visibility: hidden;
}

/* message */
.cal-message {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.5;
}

.cal-message.hidden {
  display: none;
}

.cal-msg-info {
  background: var(--info-soft, #eff6ff);
  color: var(--info, #2563eb);
  border: 1px solid var(--info-border, #bfdbfe);
}

.cal-msg-success {
  background: var(--success-soft, #f0fdf4);
  color: var(--success, #16a34a);
  border: 1px solid var(--success-border, #bbf7d0);
}

.cal-msg-error {
  background: var(--danger-soft, #fef2f2);
  color: var(--danger, #dc2626);
  border: 1px solid var(--danger-border, #fecaca);
}

.cal-message.is-fading {
  opacity: 0;
  transition: opacity 0.25s ease;
}

/* history list */
.cal-history-list {
  flex: 1 1 auto;
  min-height: 200px;
  max-height: 340px;
  overflow-y: auto;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 10px;
  background: var(--bg-card, #fff);
}

.cal-history-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 36px 16px;
  color: var(--text-secondary, #64748b);
  text-align: center;
}

.cal-history-empty i {
  font-size: 28px;
  opacity: 0.5;
}

.cal-history-empty p {
  margin: 0;
  font-size: 13px;
}

.cal-history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border-soft, #f1f5f9);
  cursor: pointer;
  transition: background 0.15s ease;
}

.cal-history-item:last-child {
  border-bottom: none;
}

.cal-history-item:hover {
  background: var(--bg-soft, #f8fafc);
}

.cal-history-eq {
  font-size: 13px;
  color: var(--text-secondary, #475569);
  word-break: break-all;
}

.cal-history-res {
  font-size: 13px;
  font-weight: 700;
  color: var(--text, #0f172a);
  white-space: nowrap;
}

.cal-history-item:hover .cal-history-res {
  color: var(--accent, #2563eb);
}

/* toolbar */
.cal-output-actions {
  margin-left: auto;
}

.cal-meta-stack {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.cal-meta {
  font-size: 12px;
  color: var(--text-secondary, #64748b);
}

/* shortcuts */
.cal-shortcuts {
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 10px;
  padding: 0 14px;
  background: var(--bg-card, #fff);
}

.cal-shortcuts summary {
  cursor: pointer;
  padding: 10px 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text, #0f172a);
  display: flex;
  align-items: center;
  gap: 8px;
  list-style: none;
}

.cal-shortcuts summary::-webkit-details-marker {
  display: none;
}

.cal-shortcuts summary::after {
  content: '\f282';
  font-family: 'bootstrap-icons';
  margin-left: auto;
  font-size: 11px;
  color: var(--text-secondary, #64748b);
  transition: transform 0.2s ease;
}

.cal-shortcuts[open] summary::after {
  transform: rotate(180deg);
}

.cal-shortcuts-body {
  padding: 4px 0 12px;
  font-size: 12.5px;
  line-height: 2;
  color: var(--text-secondary, #475569);
}

.cal-shortcuts-body code {
  background: var(--bg-soft, #f1f5f9);
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 12px;
  color: var(--text, #0f172a);
}

/* note */
.cal-note {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 12px 14px;
  background: var(--info-soft, #eff6ff);
  border: 1px solid var(--info-border, #bfdbfe);
  border-radius: 10px;
  color: var(--info, #1d4ed8);
  font-size: 12.5px;
  line-height: 1.6;
}

/* responsive */
@media (max-width: 767px) {
  .cal-key {
    height: 48px;
  }

  .cal-main {
    font-size: 28px;
  }

  .cal-history-list {
    min-height: 140px;
    max-height: 220px;
  }
}

@media (max-width: 420px) {
  .cal-keypad {
    gap: 6px;
  }

  .cal-key {
    height: 44px;
    font-size: 14px;
  }

  .cal-key-fn {
    font-size: 13px;
  }
}
