/* ============================================================
   Socium FormulaJS — Function Tester
   Tokens mirrored from the Socium website design system
   (app/assets/css/tokens.css in socium-corporate-website)
   ============================================================ */

:root {
  --socium-energy: #006aff;
  --inspiring-night: #142141;
  --player-green: #bdff00;
  --sunset-orange: #ff8b26;

  --night-deep: #00172d;
  --night-navy: #0d0e40;
  --energy-hover: #0573e8;

  --white: #ffffff;
  --paper: #f8f6fb;
  --mist: #d6cee4;
  --fog: #b8c0d0;
  --steel: #6e7891;
  --slate: #2a3550;
  --ink: #0b1226;

  --bg: var(--white);
  --bg-muted: #f4f6fb;
  --fg-1: var(--inspiring-night);
  --fg-2: #3a4566;
  --fg-3: var(--steel);
  --border: #e2e6ef;
  --border-strong: #c9d0de;
  --accent: var(--socium-energy);
  --accent-fg: var(--white);
  --success: var(--player-green);
  --success-ink: #2d4a00;
  --warning: var(--sunset-orange);
  --danger: #e5484d;
  --info: var(--socium-energy);

  --font-display: 'Lexend', system-ui, -apple-system, Segoe UI, sans-serif;
  --font-body: 'DM Sans', system-ui, -apple-system, Segoe UI, sans-serif;
  --font-mono: ui-monospace, 'JetBrains Mono', SFMono-Regular, Menlo, monospace;

  --radius-xs: 3px;
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-xl: 10px;
  --radius-pill: 999px;

  --shadow-sm: 0 2px 4px rgba(20, 33, 65, 0.03);
  --shadow-md: 0 4px 12px rgba(20, 33, 65, 0.04);
  --shadow-lg: 0 8px 24px rgba(20, 33, 65, 0.05);

  --ease-out: cubic-bezier(0.22, 0.61, 0.36, 1);
  --dur-fast: 120ms;
  --dur-base: 220ms;

  --header-height: 71px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: var(--font-body);
  font-size: 16px;
  color: var(--fg-1);
  background: var(--bg-muted);
}

h1,
h2,
h3,
h4 {
  font-family: var(--font-display);
  color: var(--fg-1);
  margin: 0;
  font-weight: 600;
}

code,
pre,
kbd {
  font-family: var(--font-mono);
}

/* ---------- Layout ---------- */

.app-header {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 20px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  display: block;
  height: 30px;
  width: auto;
}

.brand-sub {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 13px;
  color: var(--fg-3);
  border-left: 1px solid var(--border-strong);
  padding-left: 12px;
}

.eyebrow-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  background: rgba(0, 106, 255, 0.08);
  color: var(--socium-energy);
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.header-meta {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--fg-3);
}

.app-shell {
  display: grid;
  grid-template-columns: 320px 1fr;
  min-height: calc(100vh - var(--header-height));
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
}

/* ---------- Sidebar ---------- */

.sidebar {
  background: var(--white);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - var(--header-height));
  position: sticky;
  top: var(--header-height);
}

.sidebar-controls {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sidebar-count {
  font-size: 12px;
  color: var(--fg-3);
  padding: 0 2px;
}

.function-list {
  overflow-y: auto;
  flex: 1;
  padding: 8px;
}

.category-group {
  margin-bottom: 4px;
}

.category-label {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-3);
  padding: 10px 10px 6px;
}

.function-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--fg-1);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
}

.function-item:hover {
  background: var(--bg-muted);
}

.function-item.active {
  background: rgba(0, 106, 255, 0.08);
  border-color: rgba(0, 106, 255, 0.25);
  color: var(--socium-energy);
  font-weight: 600;
}

.function-item .arity {
  font-size: 11px;
  color: var(--fg-3);
}

.function-item.active .arity {
  color: var(--socium-energy);
  opacity: 0.7;
}

.empty-list {
  padding: 24px 12px;
  text-align: center;
  color: var(--fg-3);
  font-size: 13px;
}

/* ---------- Main panel ---------- */

.main {
  padding: 28px 32px 60px;
  max-width: 920px;
  width: 100%;
}

.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  margin-bottom: 20px;
}

.function-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.function-name {
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 700;
  color: var(--fg-1);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  background: var(--bg-muted);
  color: var(--fg-3);
  border: 1px solid var(--border);
}

.function-description {
  color: var(--fg-2);
  font-size: 14.5px;
  line-height: 1.55;
  margin: 10px 0 16px;
}

.warning-banner {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-family: var(--font-body);
  font-size: 13px;
  line-height: 1.5;
  color: #8a4b0f;
  background: rgba(255, 139, 38, 0.1);
  border: 1px solid rgba(255, 139, 38, 0.4);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 16px;
}

.syntax-line {
  font-family: var(--font-mono);
  font-size: 13.5px;
  background: var(--bg-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--fg-1);
  overflow-x: auto;
  white-space: pre;
}

.syntax-line .opt {
  color: var(--fg-3);
}

.section-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--fg-3);
  margin: 20px 0 12px;
}

/* ---------- Fields ---------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.field__label {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 500;
  color: var(--fg-1);
  display: flex;
  align-items: center;
  gap: 8px;
}

.field__optional {
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  color: var(--fg-3);
  letter-spacing: 0.04em;
}

.field__help {
  font-size: 12.5px;
  color: var(--fg-3);
  line-height: 1.4;
}

.field__input,
.field__select,
.field__textarea {
  font-family: var(--font-mono);
  font-size: 14px;
  background: var(--white);
  color: var(--fg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  outline: none;
  width: 100%;
  transition: all var(--dur-base) var(--ease-out);
}

.field__textarea {
  font-family: var(--font-mono);
  resize: vertical;
  min-height: 72px;
}

.field__input:focus,
.field__select:focus,
.field__textarea:focus {
  border-color: var(--socium-energy);
  box-shadow: 0 0 0 3px rgba(0, 106, 255, 0.14);
}

.arg-row {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.arg-row .field {
  flex: 1;
}

.remove-arg {
  margin-top: 2px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-3);
  border-radius: var(--radius-sm);
  width: 38px;
  height: 38px;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  transition: all var(--dur-fast) var(--ease-out);
}

.remove-arg:hover {
  border-color: var(--danger);
  color: var(--danger);
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-display);
  font-weight: 600;
  border: 0;
  cursor: pointer;
  border-radius: var(--radius-md);
  padding: 11px 20px;
  font-size: 14px;
  transition: all var(--dur-base) var(--ease-out);
}

.btn--primary {
  background: var(--socium-energy);
  color: var(--white);
  box-shadow: 0 4px 15px rgba(0, 106, 255, 0.25);
}

.btn--primary:hover {
  background: var(--energy-hover);
  transform: translateY(-1px);
  box-shadow: 0 8px 22px rgba(0, 106, 255, 0.35);
}

.btn--ghost {
  background: transparent;
  color: var(--fg-1);
  border: 1.5px solid var(--border-strong);
  padding: 9.5px 18px;
}

.btn--ghost:hover {
  border-color: var(--socium-energy);
  color: var(--socium-energy);
}

.btn--sm {
  padding: 7px 12px;
  font-size: 12.5px;
}

.btn-row {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 4px;
}

/* ---------- Result panel ---------- */

.result-card {
  border: 1px solid var(--border);
}

.result-card.is-success {
  border-color: rgba(189, 255, 0, 0.55);
  background: linear-gradient(180deg, rgba(189, 255, 0, 0.06), transparent 40%);
}

.result-card.is-error {
  border-color: rgba(229, 72, 77, 0.4);
  background: linear-gradient(180deg, rgba(229, 72, 77, 0.05), transparent 40%);
}

.result-meta {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  font-size: 12px;
  color: var(--fg-3);
  font-family: var(--font-mono);
}

.result-meta strong {
  color: var(--fg-2);
  font-weight: 600;
}

.result-call {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--fg-3);
  margin-bottom: 10px;
  word-break: break-all;
}

.result-value {
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 600;
  color: var(--fg-1);
  word-break: break-word;
  white-space: pre-wrap;
}

.result-card.is-error .result-value {
  color: var(--danger);
}

.result-card.is-success .result-value {
  color: var(--success-ink);
}

.result-placeholder {
  color: var(--fg-3);
  font-size: 13.5px;
}

/* ---------- Formula editor (syntax highlighting overlay) ---------- */

.formula-editor {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--white);
  transition: border-color var(--dur-base) var(--ease-out), box-shadow var(--dur-base) var(--ease-out);
}

.formula-editor:focus-within {
  border-color: var(--socium-energy);
  box-shadow: 0 0 0 3px rgba(0, 106, 255, 0.14);
}

.formula-highlight,
.formula-input {
  margin: 0;
  padding: 12px 14px;
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 140px;
  max-height: 360px;
}

.formula-highlight {
  color: var(--fg-1);
  overflow: auto;
  pointer-events: none;
}

.formula-highlight code {
  font-family: inherit;
}

.formula-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  resize: vertical;
  border: 0;
  outline: none;
  background: transparent;
  color: transparent;
  caret-color: var(--fg-1);
  overflow: auto;
}

.formula-input::placeholder {
  color: var(--fg-3);
}

.tok-fn {
  color: var(--socium-energy);
  font-weight: 600;
}

.tok-keyword {
  color: var(--inspiring-night);
  font-weight: 600;
}

.tok-string {
  color: #1a7f37;
}

.tok-number {
  color: #0e7490;
}

.tok-punct {
  color: var(--fg-3);
}

.tok-error,
.tok-fn.tok-error {
  color: var(--danger);
  text-decoration: underline wavy var(--danger);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 3px;
}

.syntax-status {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--fg-3);
  margin-top: 8px;
}

.syntax-status.has-errors {
  color: var(--danger);
}

.syntax-status.is-valid {
  color: var(--success-ink);
}

/* ---------- Console ---------- */

.console-examples {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.chip {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--bg-muted);
  border: 1px solid var(--border);
  color: var(--fg-2);
  border-radius: var(--radius-pill);
  padding: 6px 12px;
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease-out);
}

.chip:hover {
  border-color: var(--socium-energy);
  color: var(--socium-energy);
}

/* ---------- History ---------- */

.history-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.history-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--white);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 12.5px;
  transition: all var(--dur-fast) var(--ease-out);
}

.history-row:hover {
  border-color: var(--border-strong);
  background: var(--bg-muted);
}

.history-row .h-expr {
  color: var(--fg-1);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-row .h-result {
  color: var(--fg-3);
  flex-shrink: 0;
}

.history-row.is-error .h-result {
  color: var(--danger);
}

.no-history {
  color: var(--fg-3);
  font-size: 13px;
}

/* ---------- Scrollbars (Webkit) ---------- */

.function-list::-webkit-scrollbar {
  width: 8px;
}

.function-list::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-pill);
}
