/* ============================================================
   Calc Engine — Calculator Styles
   Supports: light theme (default) + dark theme
   ============================================================ */

:root {
  --ce-accent:       #c9963a;
  --ce-accent-hover: #b07e28;
  --ce-accent-pale:  #fdf4e3;
  --ce-ink:          #1a1714;
  --ce-muted:        #6b6355;
  --ce-border:       #ddd5c4;
  --ce-bg:           #faf8f4;
  --ce-surface:      #ffffff;
  --ce-cream:        #f2ede3;
  --ce-positive:     #2d7a3a;
  --ce-negative:     #b84c1e;
  --ce-warning:      #b07e28;
  --ce-radius:       8px;
  --ce-font:         'DM Sans', system-ui, -apple-system, sans-serif;
  --ce-font-mono:    'Courier New', monospace;
  --ce-shadow:       0 2px 12px rgba(0,0,0,.08);
  --ce-chart-bg:     #f9f7f3;
}

/* ── Dark theme ── */
.ce-theme-dark {
  --ce-accent:       #f0d090;
  --ce-accent-hover: #ffd96a;
  --ce-accent-pale:  #2a2218;
  --ce-ink:          #f0ebe4;
  --ce-muted:        #a09080;
  --ce-border:       #3a3530;
  --ce-bg:           #1a1714;
  --ce-surface:      #221f1b;
  --ce-cream:        #252119;
  --ce-shadow:       0 2px 12px rgba(0,0,0,.3);
  --ce-chart-bg:     #1e1c18;
}

/* ── Base wrapper ── */
.ce-calculator {
  font-family: var(--ce-font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ce-ink);
  background: var(--ce-bg);
  border-radius: var(--ce-radius);
  box-shadow: var(--ce-shadow);
  border: 1px solid var(--ce-border);
  overflow: hidden;
  max-width: 100%;
  margin: 24px 0;
}

.ce-wrapper { display: flex; flex-direction: column; }

/* ── Loading state ── */
.ce-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px 24px;
  color: var(--ce-muted);
  font-size: .9rem;
}
.ce-loading-spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--ce-border);
  border-top-color: var(--ce-accent);
  border-radius: 50%;
  animation: ce-spin .7s linear infinite;
}
@keyframes ce-spin { to { transform: rotate(360deg); } }

/* ── Header ── */
.ce-header {
  background: var(--ce-cream);
  border-bottom: 1px solid var(--ce-border);
  padding: 20px 24px 18px;
}
.ce-header-icon { font-size: 1.5rem; margin-right: 8px; vertical-align: middle; }
.ce-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--ce-ink);
  margin: 0 0 6px;
  display: inline;
}
.ce-description {
  font-size: .88rem;
  color: var(--ce-muted);
  margin: 6px 0 0;
  line-height: 1.55;
}

/* ── Body ── */
.ce-body {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
}
.ce-layout-split {
  grid-template-columns: 1fr 1fr;
}
@media (max-width: 640px) {
  .ce-layout-split { grid-template-columns: 1fr; }
}

/* ── Inputs Panel ── */
.ce-inputs-panel {
  padding: 24px;
  border-right: 1px solid var(--ce-border);
}
.ce-layout-split .ce-inputs-panel { border-right: 1px solid var(--ce-border); }
.ce-body:not(.ce-layout-split) .ce-inputs-panel { border-right: none; border-bottom: 1px solid var(--ce-border); }

/* ── Groups ── */
.ce-group { margin-bottom: 20px; }
.ce-group:last-child { margin-bottom: 0; }
.ce-group-label {
  font-size: .8rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ce-muted);
  margin: 0 0 14px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--ce-border);
}

/* ── Field ── */
.ce-field { margin-bottom: 18px; }
.ce-field:last-of-type { margin-bottom: 0; }

.ce-label {
  display: block;
  font-size: .88rem;
  font-weight: 600;
  color: var(--ce-ink);
  margin-bottom: 7px;
  cursor: default;
}
.ce-field-desc {
  font-size: .8rem;
  color: var(--ce-muted);
  margin: -2px 0 7px;
  line-height: 1.4;
}
.ce-tooltip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px; height: 16px;
  background: var(--ce-muted);
  color: #fff;
  border-radius: 50%;
  font-size: .68rem;
  font-weight: 700;
  cursor: help;
  margin-left: 5px;
  vertical-align: middle;
}

/* ── Input wrap ── */
.ce-input-wrap {
  display: flex;
  align-items: center;
  background: var(--ce-surface);
  border: 1.5px solid var(--ce-border);
  border-radius: 6px;
  overflow: hidden;
  transition: border-color .15s;
}
.ce-input-wrap:focus-within {
  border-color: var(--ce-accent);
  box-shadow: 0 0 0 3px rgba(201,150,58,.15);
}

/* Prefix / Suffix */
.ce-prefix, .ce-suffix {
  padding: 0 12px;
  font-size: .95rem;
  font-weight: 600;
  color: var(--ce-muted);
  background: var(--ce-cream);
  border-right: 1px solid var(--ce-border);
  height: 44px;
  display: flex;
  align-items: center;
  user-select: none;
  flex-shrink: 0;
}
.ce-suffix { border-right: none; border-left: 1px solid var(--ce-border); }

/* Number input */
.ce-input {
  flex: 1;
  border: none;
  outline: none;
  padding: 0 12px;
  height: 44px;
  font-size: 1rem;
  font-family: var(--ce-font);
  background: transparent;
  color: var(--ce-ink);
  width: 0; /* flex will grow it */
  min-width: 60px;
  -moz-appearance: textfield;
}
.ce-input::-webkit-outer-spin-button,
.ce-input::-webkit-inner-spin-button { -webkit-appearance: none; }

/* Select */
.ce-select {
  width: 100%;
  border: none;
  outline: none;
  padding: 0 36px 0 12px;
  height: 44px;
  font-size: .95rem;
  font-family: var(--ce-font);
  color: var(--ce-ink);
  background: var(--ce-surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b6355' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 12px center;
  appearance: none;
  cursor: pointer;
}
.ce-select:focus { outline: none; }

/* Toggle */
.ce-toggle-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
}
.ce-toggle-input { display: none; }
.ce-toggle-label {
  width: 48px; height: 26px;
  background: var(--ce-border);
  border-radius: 13px;
  cursor: pointer;
  position: relative;
  transition: background .2s;
  flex-shrink: 0;
}
.ce-toggle-label::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 20px; height: 20px;
  background: #fff;
  border-radius: 50%;
  transition: transform .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.ce-toggle-input:checked + .ce-toggle-label {
  background: var(--ce-accent);
}
.ce-toggle-input:checked + .ce-toggle-label::after {
  transform: translateX(22px);
}
.ce-toggle-text { font-size: .88rem; color: var(--ce-muted); }

/* Slider */
.ce-slider-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--ce-surface);
  border: 1.5px solid var(--ce-border);
  border-radius: 6px;
  padding: 8px 12px;
}
.ce-slider-row:focus-within {
  border-color: var(--ce-accent);
  box-shadow: 0 0 0 3px rgba(201,150,58,.15);
}
.ce-slider {
  flex: 1;
  height: 4px;
  appearance: none;
  background: var(--ce-border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
.ce-slider::-webkit-slider-thumb {
  appearance: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--ce-accent);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
  cursor: grab;
}
.ce-slider::-moz-range-thumb {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--ce-accent);
  border: 2px solid #fff;
  cursor: grab;
}
.ce-slider-value {
  width: 60px;
  border: 1px solid var(--ce-border);
  border-radius: 4px;
  padding: 4px 6px;
  font-size: .88rem;
  text-align: center;
  background: var(--ce-surface);
  color: var(--ce-ink);
  -moz-appearance: textfield;
}
.ce-slider-value::-webkit-outer-spin-button,
.ce-slider-value::-webkit-inner-spin-button { -webkit-appearance: none; }

/* ── Calculate Button ── */
.ce-btn {
  width: 100%;
  margin-top: 20px;
  background: var(--ce-accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-family: var(--ce-font);
  font-size: .95rem;
  font-weight: 700;
  letter-spacing: .04em;
  padding: 13px 20px;
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.ce-theme-dark .ce-btn { color: var(--ce-ink); }
.ce-btn:hover { background: var(--ce-accent-hover); transform: translateY(-1px); }
.ce-btn:active { transform: translateY(0); }
.ce-btn-pulse { animation: ce-pulse .3s ease; }
@keyframes ce-pulse {
  0%   { transform: scale(1); }
  50%  { transform: scale(.97); }
  100% { transform: scale(1); }
}
.ce-btn-reset {
  background: transparent;
  border: 1.5px solid var(--ce-border);
  color: var(--ce-muted);
  font-size: .82rem;
  padding: 7px 14px;
  border-radius: 5px;
  cursor: pointer;
  margin-top: 10px;
  font-family: var(--ce-font);
  width: 100%;
  transition: border-color .15s;
}
.ce-btn-reset:hover { border-color: var(--ce-accent); color: var(--ce-accent); }

/* ── Results Panel ── */
.ce-results-panel {
  padding: 24px;
  background: var(--ce-cream);
}
.ce-results-title {
  font-size: .85rem;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--ce-muted);
  margin: 0 0 16px;
}

/* ── Output rows ── */
.ce-outputs { display: flex; flex-direction: column; gap: 2px; }

.ce-output-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 13px 16px;
  background: var(--ce-surface);
  border-radius: 6px;
  border: 1px solid var(--ce-border);
}

.ce-output-highlight {
  background: var(--ce-ink);
  border-color: var(--ce-ink);
  margin-top: 6px;
}
.ce-output-highlight .ce-output-label { color: var(--ce-muted); }
.ce-theme-dark .ce-output-highlight { background: var(--ce-accent-pale); }

.ce-output-label {
  font-size: .88rem;
  color: var(--ce-muted);
  font-weight: 500;
}
.ce-output-value {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--ce-ink);
  font-variant-numeric: tabular-nums;
  transition: color .2s;
}
.ce-output-highlight .ce-output-value {
  font-size: 1.5rem;
  color: var(--ce-accent);
}

/* Value animation */
.ce-updated {
  animation: ce-flash .35s ease;
}
@keyframes ce-flash {
  0%   { opacity: .4; transform: scale(.97); }
  100% { opacity: 1;  transform: scale(1); }
}

/* Colour states */
.ce-positive { color: var(--ce-positive) !important; }
.ce-negative { color: var(--ce-negative) !important; }
.ce-warning  { color: var(--ce-warning)  !important; }

/* ── Result note ── */
.ce-result-note {
  font-size: .85rem;
  color: var(--ce-muted);
  margin: 14px 0 0;
  padding: 10px 14px;
  background: var(--ce-accent-pale);
  border-left: 3px solid var(--ce-accent);
  border-radius: 0 5px 5px 0;
  display: none;
  line-height: 1.5;
}

/* ── Chart ── */
.ce-chart-wrap {
  margin-top: 20px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--ce-border);
}
.ce-chart {
  display: block;
  width: 100%;
  height: 200px;
  background: var(--ce-chart-bg);
}

/* ── Footer ── */
.ce-footer {
  padding: 12px 24px;
  border-top: 1px solid var(--ce-border);
  background: var(--ce-cream);
}
.ce-formula-note {
  font-size: .78rem;
  color: var(--ce-muted);
  margin: 0;
  font-family: var(--ce-font-mono);
}

/* ── Error state ── */
.ce-error {
  background: #fde8e0;
  border: 1px solid #f5c6b8;
  color: #b84c1e;
  padding: 12px 16px;
  border-radius: 6px;
  font-size: .9rem;
  margin: 8px 0;
}
.ce-error code {
  background: rgba(184,76,30,.1);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: var(--ce-font-mono);
}

/* ── Responsive ── */
@media (max-width: 480px) {
  .ce-header, .ce-inputs-panel, .ce-results-panel { padding: 16px; }
  .ce-output-value { font-size: 1.05rem; }
  .ce-output-highlight .ce-output-value { font-size: 1.3rem; }
}
