/* Калькулятор маржи — clean SMB dark theme */
:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --border: #2d3a4f;
  --text: #e8eef7;
  --muted: #8b9bb4;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --green: #22c55e;
  --green-bg: rgba(34, 197, 94, 0.12);
  --red: #ef4444;
  --red-bg: rgba(239, 68, 68, 0.12);
  --radius: 10px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.25rem 1rem 2.5rem;
}

.header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.header h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.875rem;
}

.mp-switch {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.mp-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.mp-btn:hover { color: var(--text); }
.mp-btn.active {
  background: var(--accent);
  color: #fff;
}

.presets {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.preset-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.preset-btn:hover {
  border-color: var(--accent);
  background: var(--surface);
}

.preset-hint {
  font-size: 0.75rem;
  color: var(--muted);
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  align-items: start;
}

@media (max-width: 720px) {
  .grid { grid-template-columns: 1fr; }
  .header h1 { font-size: 1.15rem; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem;
}

.card h2 {
  margin: 0 0 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 0.75rem;
}

.field span {
  font-size: 0.8rem;
  color: var(--muted);
}

.field em {
  font-style: normal;
  opacity: 0.7;
  font-size: 0.75rem;
}

.field input[type="number"] {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
}

.field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.25);
}

/* hide number spinners on some browsers for cleaner look, keep usable */
.field input::-webkit-outer-spin-button,
.field input::-webkit-inner-spin-button {
  opacity: 0.4;
}

.tax-mode {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.65rem 0.85rem;
  margin: 0.5rem 0 0.5rem;
}

.tax-mode legend {
  font-size: 0.8rem;
  color: var(--muted);
  padding: 0 0.35rem;
}

.radio {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.875rem;
  margin: 0.35rem 0;
  cursor: pointer;
}

.note {
  margin: 0.5rem 0 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.metric {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}

.metric.big {
  padding: 0.75rem 0;
}

.metric-label {
  font-size: 0.875rem;
  color: var(--muted);
}

.metric-value {
  font-size: 1.15rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.metric.big .metric-value { font-size: 1.4rem; }

.muted {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
  margin-top: 0.15rem;
}

.breakdown {
  margin: 0.5rem 0 0.75rem;
  padding: 0.65rem 0.75rem;
  background: var(--bg);
  border-radius: 6px;
  font-size: 0.8rem;
}

.breakdown-row {
  display: flex;
  justify-content: space-between;
  padding: 0.2rem 0;
  color: var(--muted);
}

.breakdown-row strong {
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.breakdown-total {
  margin-top: 0.4rem;
  padding-top: 0.4rem;
  border-top: 1px dashed var(--border);
  color: var(--text);
  font-weight: 600;
}

.margin-row.positive {
  background: var(--green-bg);
  margin: 0 -0.5rem;
  padding-left: 0.5rem;
  padding-right: 0.5rem;
  border-radius: 6px;
  border-bottom: none;
}

.margin-row.negative {
  background: var(--red-bg);
  margin: 0 -0.5rem;
  padding-left: 0.5rem;
  padding-right: 0.5rem;
  border-radius: 6px;
  border-bottom: none;
}

.margin-row.positive .metric-value { color: var(--green); }
.margin-row.negative .metric-value { color: var(--red); }

.verdict {
  margin-top: 0.85rem;
  padding: 0.65rem 0.85rem;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 600;
  text-align: center;
}

.verdict.ok {
  background: var(--green-bg);
  color: var(--green);
}

.verdict.bad {
  background: var(--red-bg);
  color: var(--red);
}

.formula-box {
  margin-top: 1rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.formula-box summary {
  cursor: pointer;
  user-select: none;
}

.formula-box pre {
  margin: 0.5rem 0 0;
  padding: 0.75rem;
  background: var(--bg);
  border-radius: 6px;
  overflow-x: auto;
  white-space: pre-wrap;
  font-size: 0.72rem;
  line-height: 1.5;
  color: var(--text);
}

.footer {
  margin-top: 1.5rem;
  text-align: center;
}

.footer p {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
}
