:root {
  --redis-red: #ff4438;
  --redis-red-dark: #d9312a;
  --ink: #1b1f1d;
  --muted: #66706b;
  --cream: #f6f1eb;
  --mint: #dff3e8;
  --mint-dark: #236b50;
  --line: #d8d8d3;
  --white: #fff;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  color: var(--ink);
  background: #ede9e4;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  margin: 0;
}

button,
input,
select {
  font: inherit;
}

.page {
  width: min(900px, calc(100% - 36px));
  margin: 0 auto;
  padding: 34px 0 48px;
}

.calculator-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 0 4px 24px;
}

.calculator-header p {
  margin: 0 0 7px;
  color: var(--redis-red-dark);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.calculator-header h1 {
  margin: 0;
  font-size: clamp(2.25rem, 5vw, 3.75rem);
  font-weight: 650;
  letter-spacing: -0.045em;
  line-height: 1;
}

.header-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 7px;
}

.header-actions span {
  color: var(--muted);
  font-size: 0.82rem;
}

.header-actions a {
  color: var(--redis-red-dark);
  font-size: 0.78rem;
  font-weight: 700;
  text-underline-offset: 3px;
}

#calculator-form {
  display: grid;
  grid-template-columns: 420px minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid #cfcac4;
  border-top: 6px solid var(--redis-red);
  border-radius: 12px;
  background: var(--white);
  box-shadow: 0 12px 30px rgba(39, 31, 26, 0.08);
}

.setup,
.estimate {
  min-width: 0;
  padding: 28px;
}

.setup {
  border-right: 1px solid var(--line);
  background: var(--cream);
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 22px;
}

.section-heading h2 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.section-heading p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
}

.reset-button {
  padding: 4px 0 4px 10px;
  border: 0;
  color: var(--redis-red-dark);
  background: transparent;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.preset-row {
  display: grid;
  grid-template-columns: 1fr 1.45fr;
  gap: 7px 10px;
  margin-bottom: 18px;
  padding: 13px;
  border: 1px solid #e0b4ae;
  border-left: 4px solid var(--redis-red);
  background: #fff8f6;
}

.preset-row label {
  align-self: center;
  font-size: 0.86rem;
  font-weight: 700;
}

.preset-row select {
  width: 100%;
  height: 36px;
  padding: 6px 8px;
  border: 1px solid #c7b9b5;
  border-radius: 4px;
  color: var(--ink);
  background: var(--white);
}

.preset-row p {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.45;
}

.preset-row .preset-sources {
  padding-top: 7px;
  border-top: 1px solid #ead4d0;
  font-size: 0.72rem;
}

.preset-sources a {
  color: var(--redis-red-dark);
  text-underline-offset: 2px;
}

.setup-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 13px;
}

.setup-group {
  min-width: 0;
  margin: 0;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.72);
}

.model-group,
.memory-group {
  grid-column: 1 / -1;
}

.setup-group legend {
  padding: 0 5px;
  color: #4a514d;
  font-size: 0.84rem;
  font-weight: 700;
}

.model-group > label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.8rem;
}

.model-group select {
  width: 100%;
  height: 40px;
  padding: 7px 10px;
  border: 1px solid #bbbdb9;
  border-radius: 4px;
  color: var(--ink);
  background: var(--white);
}

.model-price {
  display: flex;
  gap: 17px;
  margin-top: 7px;
  color: var(--muted);
  font-size: 0.76rem;
}

.model-price b {
  color: var(--ink);
}

.field-row {
  margin-bottom: 12px;
}

.field-row:last-child {
  margin-bottom: 0;
}

.field-row > label {
  display: block;
  margin-bottom: 5px;
  color: #4d5551;
  font-size: 0.81rem;
  font-weight: 600;
  line-height: 1.25;
}

.field-row > div:not(.range-row) {
  display: flex;
  align-items: center;
}

.field-row input[type="number"] {
  width: 100%;
  min-width: 0;
  height: 38px;
  padding: 7px 8px;
  border: 1px solid #bbbdb9;
  border-radius: 4px;
  color: var(--ink);
  background: var(--white);
}

.field-row small {
  margin-left: 6px;
  color: var(--muted);
  font-size: 0.7rem;
  white-space: nowrap;
}

select:focus,
input:focus {
  border-color: var(--redis-red-dark) !important;
  outline: 3px solid rgba(255, 68, 56, 0.14);
}

.range-row {
  display: flex;
  min-height: 38px;
  gap: 9px;
  align-items: center;
}

input[type="range"] {
  width: 100%;
  height: 5px;
  appearance: none;
  border-radius: 5px;
  background: #c7c7c3;
}

input[type="range"]::-webkit-slider-thumb {
  width: 17px;
  height: 17px;
  appearance: none;
  border: 3px solid var(--white);
  border-radius: 50%;
  background: var(--redis-red);
  box-shadow: 0 0 0 1px var(--redis-red-dark);
}

input[type="range"]::-moz-range-thumb {
  width: 11px;
  height: 11px;
  border: 3px solid var(--white);
  border-radius: 50%;
  background: var(--redis-red);
  box-shadow: 0 0 0 1px var(--redis-red-dark);
}

.range-row output {
  flex: 0 0 42px;
  color: var(--redis-red-dark);
  font-size: 0.82rem;
  font-weight: 700;
  text-align: right;
}

.memory-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.choice-group > span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.79rem;
  font-weight: 700;
}

.choice-group label {
  display: block;
  margin: 7px 0;
  font-size: 0.82rem;
  line-height: 1.25;
}

.choice-group input {
  margin: 0 5px 0 0;
  accent-color: var(--redis-red);
  vertical-align: -1px;
}

.retention-field {
  grid-column: 1 / -1;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.retention-field label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.79rem;
  font-weight: 700;
}

.retention-field > div {
  display: flex;
  align-items: center;
}

.retention-field input {
  width: 90px;
  height: 36px;
  padding: 6px 8px;
  border: 1px solid #bbbdb9;
  border-radius: 4px;
  color: var(--ink);
  background: var(--white);
}

.retention-field small {
  margin-left: 7px;
  color: var(--muted);
  font-size: 0.72rem;
}

.strategy-strip {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  overflow: hidden;
  margin: 15px 0 0;
  border: 1px solid var(--line);
  background: var(--line);
}

.strategy-strip > div {
  padding: 9px 10px;
  background: var(--white);
}

.strategy-strip dt {
  color: var(--muted);
  font-size: 0.72rem;
}

.strategy-strip dd {
  margin: 3px 0 0;
  font-size: 0.9rem;
  font-weight: 700;
}

.cost-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
  margin: 0 0 25px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--white);
}

.cost-summary > div {
  min-width: 0;
  padding: 16px;
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
}

.cost-summary > div:first-child {
  border-top: 0;
  border-left: 0;
  background: #fff8f7;
}

.cost-summary > div:nth-child(2) {
  border-top: 0;
  border-left: 1px solid var(--line);
  background: #fbfbfa;
}

.cost-summary > div:nth-child(3) {
  border-left: 0;
  background: #fbfbfa;
}

.cost-summary > div:nth-child(4) {
  background: #fbfbfa;
}

.cost-summary dt {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.3;
}

.cost-summary dd {
  overflow: hidden;
  margin: 0;
  color: var(--ink);
  font-size: 1.08rem;
  font-weight: 750;
  letter-spacing: -0.02em;
  text-overflow: ellipsis;
}

.cost-summary .total {
  display: block;
  grid-column: auto;
  padding: 16px;
  background: #fff8f7;
}

.cost-summary .total dt {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 0.76rem;
}

.cost-summary .total dd {
  color: var(--redis-red-dark);
  font-size: 1.45rem;
}

.cost-summary dt small {
  display: block;
  margin-top: 2px;
  color: var(--redis-red-dark);
  font-size: 0.64rem;
  font-weight: 750;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.result-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 28px;
}

.result-column h3 {
  margin: 0 0 8px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--redis-red);
  font-size: 0.9rem;
  font-weight: 750;
}

.result-column h3:not(:first-child) {
  margin-top: 25px;
}

.customer-paid {
  float: right;
  padding: 3px 6px;
  border-radius: 3px;
  color: var(--redis-red-dark);
  background: #fff0ee;
  font-size: 0.65rem;
  font-weight: 750;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.section-explainer {
  min-height: 34px;
  margin: -1px 0 8px;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.4;
}

.calculation-note {
  margin: 4px 0 14px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--redis-red);
  border-radius: 4px;
  background: #fbfbfa;
}

.calculation-note strong {
  display: block;
  margin-bottom: 4px;
  font-size: 0.78rem;
}

.calculation-note p {
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.5;
}

.token-ratios {
  margin: 0 0 14px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--white);
}

.token-ratios-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.token-ratios-heading > strong {
  font-size: 0.78rem;
}

.source-token-formula {
  margin-bottom: 9px;
  padding: 8px 0 9px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.source-token-formula span,
.source-token-formula code,
.source-token-formula b {
  display: block;
}

.source-token-formula span {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.7rem;
}

.source-token-formula code {
  padding: 0;
  color: var(--ink);
  background: transparent;
  font-size: 0.68rem;
  line-height: 1.45;
}

.source-token-formula b {
  margin-top: 5px;
  color: var(--redis-red-dark);
  font-size: 0.76rem;
}

#source-token-total::before {
  content: "= ";
}

.token-ratios dl {
  display: grid;
  gap: 5px;
  margin: 0;
}

.token-ratios dl > div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.token-ratios dt {
  color: var(--muted);
  font-size: 0.72rem;
}

.token-ratios dd {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.72rem;
  text-align: right;
}

.token-ratios b {
  color: var(--redis-red-dark);
}

.ratio-value {
  position: relative;
  display: inline-block;
  border-bottom: 1px dotted var(--redis-red-dark);
  cursor: help;
  outline: none;
}

.ratio-tooltip {
  position: absolute;
  z-index: 12;
  right: -5px;
  bottom: calc(100% + 8px);
  display: none;
  width: min(330px, calc(100vw - 48px));
  padding: 11px 12px;
  border: 1px solid #b8bbb8;
  border-radius: 5px;
  color: var(--ink);
  background: var(--white);
  box-shadow: 0 10px 24px rgba(39, 31, 26, 0.16);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.7rem;
  font-weight: 500;
  line-height: 1.5;
  text-align: left;
  white-space: normal;
}

.ratio-value:hover .ratio-tooltip,
.ratio-value:focus .ratio-tooltip,
.ratio-value:focus-within .ratio-tooltip {
  display: block;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
}

.data-table thead th {
  padding: 7px 5px;
  border-bottom: 1px solid #bfc3c0;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  text-align: right;
  text-transform: uppercase;
}

.data-table thead th:first-child {
  text-align: left;
}

.data-table th,
.data-table td {
  padding: 10px 5px;
  border-bottom: 1px solid #e5e5e1;
}

.data-table th {
  color: #4f5753;
  font-weight: 500;
  text-align: left;
}

.data-table td {
  font-weight: 700;
  text-align: right;
}

.data-table tfoot th,
.data-table tfoot td {
  padding: 10px 5px;
  border-top: 2px solid #bfc3c0;
  border-bottom: 0;
  color: var(--ink);
  font-weight: 750;
}

.database-estimate {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 26px;
  padding: 16px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--redis-red);
  border-radius: 5px;
  background: #fbfbfa;
}

.database-estimate span,
.database-estimate strong {
  display: block;
}

.database-estimate span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 600;
}

.database-estimate strong {
  margin-top: 4px;
  font-size: 1.45rem;
}

.database-estimate p {
  max-width: 240px;
  margin: 0 0 0 18px;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.45;
  text-align: right;
}

.database-estimate b {
  color: var(--ink);
}

.query-equation {
  display: grid;
  grid-template-columns: 1fr auto 1fr auto 1.1fr;
  gap: 7px;
  align-items: center;
  margin-bottom: 15px;
  padding: 14px;
  border-radius: 7px;
  color: var(--white);
  background: var(--ink);
}

.query-equation > div {
  min-width: 0;
  padding: 9px;
  border: 1px solid #454b48;
  border-radius: 4px;
}

.query-equation span,
.query-equation b,
.query-equation small {
  display: block;
}

.query-equation span {
  overflow: hidden;
  color: #b8c0bc;
  font-size: 0.72rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.query-equation b {
  margin: 5px 0 1px;
  font-size: 1.12rem;
}

.query-equation small {
  color: #969f9b;
  font-size: 0.7rem;
}

.query-equation > i {
  color: var(--redis-red);
  font-size: 1.1rem;
  font-style: normal;
  font-weight: 800;
}

.query-equation .query-total {
  border-color: var(--redis-red);
  background: #2a2e2c;
}

.query-equation .query-total b {
  color: #ff8c84;
}

.notes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 20px;
  margin-top: 28px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.notes p {
  margin: 0;
  color: #7b827e;
  font-size: 0.7rem;
  line-height: 1.55;
}

.notes p:last-child {
  grid-column: 1 / -1;
}

.notes a {
  color: var(--redis-red-dark);
  text-underline-offset: 2px;
}

@media (max-width: 980px) {
  #calculator-form {
    grid-template-columns: 390px minmax(0, 1fr);
  }

  .setup,
  .estimate {
    padding: 22px;
  }

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

@media (max-width: 760px) {
  .page {
    width: min(620px, calc(100% - 20px));
    padding-top: 22px;
  }

  .calculator-header {
    display: block;
  }

  .header-actions {
    align-items: flex-start;
    margin-top: 10px;
  }

  #calculator-form {
    display: block;
  }

  .setup {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}

@media (max-width: 440px) {
  .setup,
  .estimate {
    padding: 18px 14px;
  }

  .setup-grid,
  .memory-group,
  .notes {
    grid-template-columns: 1fr;
  }

  .model-group,
  .memory-group {
    grid-column: auto;
  }

  .notes p:last-child,
  .retention-field {
    grid-column: auto;
  }

  .preset-row {
    grid-template-columns: 1fr;
  }

  .preset-row p {
    grid-column: auto;
  }

  .cost-summary {
    display: block;
  }

  .cost-summary > div {
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .cost-summary > div:first-child {
    border-top: 0;
  }

  .cost-summary > div:nth-child(2) {
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .query-equation {
    grid-template-columns: 1fr;
  }

  .database-estimate {
    display: block;
  }

  .database-estimate p {
    max-width: none;
    margin: 8px 0 0;
    text-align: left;
  }

  .query-equation > i {
    text-align: center;
  }
}
