:root {
  color-scheme: light;
  --bg: #f4f7f5;
  --surface: #ffffff;
  --surface-strong: #101820;
  --text: #111827;
  --muted: #667085;
  --line: #d7dfda;
  --accent: #0f8b8d;
  --accent-strong: #0a6d6f;
  --profit: #0f8b57;
  --loss: #c2413b;
  --warning: #a06107;
  --shadow: 0 16px 42px rgba(16, 24, 32, 0.1);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(15, 139, 141, 0.11), rgba(244, 247, 245, 0) 280px),
    var(--bg);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(100%, 760px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 14px max(22px, env(safe-area-inset-bottom));
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(26px, 8vw, 38px);
  line-height: 1.05;
}

h2 {
  font-size: 20px;
  line-height: 1.2;
}

.icon-button,
.primary-button,
.text-button,
.tab {
  min-height: 44px;
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
}

.icon-button {
  width: 46px;
  flex: 0 0 46px;
  color: #ffffff;
  background: var(--surface-strong);
  font-size: 24px;
  line-height: 1;
}

.icon-button:active,
.primary-button:active,
.tab:active,
.text-button:active {
  transform: translateY(1px);
}

.rate-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  padding: 14px;
  border: 1px solid rgba(15, 139, 141, 0.2);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.82);
  box-shadow: var(--shadow);
}

.rate-panel strong {
  display: block;
  margin-top: 2px;
  font-size: 18px;
}

.rate-panel small {
  max-width: 45%;
  color: var(--muted);
  text-align: right;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 14px 0;
}

.tab {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.72);
  font-weight: 800;
}

.tab.active {
  color: #ffffff;
  background: var(--surface-strong);
}

.tab span {
  display: inline-grid;
  min-width: 23px;
  height: 23px;
  margin-left: 5px;
  place-items: center;
  border-radius: 999px;
  color: inherit;
  background: rgba(255, 255, 255, 0.16);
  font-size: 12px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.calculator-form,
.result-panel,
.history-header,
.history-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.calculator-form {
  padding: 14px;
}

.field-grid {
  display: grid;
  gap: 12px;
}

.field {
  display: grid;
  gap: 7px;
}

.field-wide {
  grid-column: 1 / -1;
}

.field span {
  color: #344054;
  font-size: 14px;
  font-weight: 750;
}

.field input {
  width: 100%;
  min-height: 48px;
  border: 1px solid #cbd5d1;
  border-radius: var(--radius);
  padding: 11px 12px;
  color: var(--text);
  background: #fbfcfc;
  font-size: 17px;
  outline: none;
}

.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 139, 141, 0.17);
}

.field input.input-error {
  border-color: var(--loss);
  background: #fff8f7;
}

.error {
  min-height: 22px;
  margin-top: 10px;
  color: var(--loss);
  font-size: 14px;
  font-weight: 700;
}

.primary-button {
  width: 100%;
  margin-top: 2px;
  padding: 13px 16px;
  color: #ffffff;
  background: var(--accent);
  font-size: 16px;
  font-weight: 850;
}

.primary-button:focus-visible,
.icon-button:focus-visible,
.tab:focus-visible,
.text-button:focus-visible {
  outline: 3px solid rgba(15, 139, 141, 0.38);
  outline-offset: 2px;
}

.result-panel {
  min-height: 130px;
  margin-top: 14px;
  padding: 14px;
}

.empty-state {
  display: grid;
  gap: 5px;
  min-height: 100px;
  place-content: center;
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  color: var(--text);
  font-size: 18px;
}

.result-summary {
  display: grid;
  gap: 10px;
}

.result-note {
  color: var(--accent-strong);
  font-size: 15px;
  font-weight: 850;
  overflow-wrap: anywhere;
}

.quantity-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid #dfe6e2;
  border-radius: var(--radius);
  background: #fbfcfc;
}

.quantity-panel span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.quantity-control {
  display: grid;
  grid-template-columns: 42px minmax(58px, 82px) 42px;
  gap: 6px;
  align-items: center;
}

.quantity-control input {
  width: 100%;
  min-height: 38px;
  border: 1px solid #cbd5d1;
  border-radius: var(--radius);
  color: var(--text);
  background: var(--surface);
  text-align: center;
  font-weight: 850;
}

.save-status {
  min-height: 20px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 750;
  text-align: center;
}

.primary-button:disabled,
.text-button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.hero-metric {
  padding: 14px;
  border-radius: var(--radius);
  color: #ffffff;
  background: var(--surface-strong);
}

.hero-metric span,
.metric span {
  display: block;
  color: rgba(255, 255, 255, 0.72);
  font-size: 13px;
  font-weight: 700;
}

.hero-metric strong {
  display: block;
  margin-top: 4px;
  font-size: 30px;
  line-height: 1.05;
}

.metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.metric {
  min-width: 0;
  padding: 12px;
  border: 1px solid #dfe6e2;
  border-radius: var(--radius);
  background: #fbfcfc;
}

.metric span {
  color: var(--muted);
}

.metric strong {
  display: block;
  margin-top: 5px;
  overflow-wrap: anywhere;
  font-size: 17px;
}

.metric.profit strong {
  color: var(--profit);
}

.metric.loss strong {
  color: var(--loss);
}

.history-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 14px;
}

.history-header p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
}

.text-button {
  padding: 9px 11px;
  color: var(--accent-strong);
  background: rgba(15, 139, 141, 0.08);
  font-weight: 800;
}

.text-button.danger {
  color: var(--loss);
  background: rgba(194, 65, 59, 0.08);
}

.history-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.history-item {
  display: grid;
  gap: 10px;
  padding: 13px;
}

.history-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.history-title {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.history-title strong {
  overflow-wrap: anywhere;
  font-size: 17px;
}

.history-title small {
  color: var(--muted);
}

.history-actions {
  display: flex;
  gap: 7px;
}

.history-actions .text-button {
  min-height: 38px;
  padding: 7px 9px;
  font-size: 13px;
}

.history-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.history-stat {
  min-width: 0;
}

.history-stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.history-stat strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 14px;
}

@media (min-width: 620px) {
  .app-shell {
    padding-top: 28px;
  }

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

  .calculator-form,
  .result-panel,
  .history-header,
  .history-item {
    padding: 18px;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0d1114;
    --surface: #141b1f;
    --surface-strong: #e9f3ef;
    --text: #f4f7f5;
    --muted: #9ba8a3;
    --line: #29343a;
    --accent: #21a7a8;
    --accent-strong: #72d6d3;
    --profit: #5bd38c;
    --loss: #ff766f;
    --shadow: 0 16px 38px rgba(0, 0, 0, 0.28);
  }

  body {
    background:
      linear-gradient(180deg, rgba(33, 167, 168, 0.15), rgba(13, 17, 20, 0) 280px),
      var(--bg);
  }

  .icon-button,
  .tab.active,
  .hero-metric {
    color: #0d1114;
    background: var(--surface-strong);
  }

  .rate-panel,
  .tab,
  .field input,
  .quantity-panel,
  .quantity-control input,
  .metric {
    background: #10171b;
  }

  .field span {
    color: #d9e2de;
  }

  .hero-metric span {
    color: rgba(13, 17, 20, 0.65);
  }
}
