* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg: #0f0d17;
  --bg-card: #1a1725;
  --bg-inner: #141120;
  --border: #2d2839;
  --border-focus: #facc15;
  --text: #f0eef7;
  --text-muted: #8b8599;
  --text-faint: #5a5568;
  --green: #34d399;
  --green-bg: rgba(52, 211, 153, 0.12);
  --red: #f87171;
  --red-bg: rgba(248, 113, 113, 0.12);
  --yellow: #facc15;
  --yellow-bg: rgba(250, 204, 21, 0.12);
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  --mono: 'JetBrains Mono', 'SF Mono', Menlo, monospace;
}

html, body { height: 100%; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(ellipse at top, #1a1625 0%, #0f0d17 60%) fixed;
  color: var(--text);
  display: flex;
  justify-content: center;
  padding: 24px 16px 80px;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.container { width: 100%; max-width: 460px; }

/* HEADER */
.header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.logo { display: flex; align-items: center; gap: 10px; }

.logo-mark {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, var(--yellow) 0%, #f59e0b 100%);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 18px; color: #0f0d17;
  box-shadow: 0 6px 20px rgba(250, 204, 21, 0.3);
}

.logo-text { font-size: 15px; font-weight: 700; letter-spacing: -0.01em; }
.logo-sub { font-size: 11px; color: var(--text-faint); margin-top: 1px; }

.auth-chip {
  background: rgba(250, 204, 21, 0.1);
  color: var(--yellow);
  border: 1px solid rgba(250, 204, 21, 0.3);
  padding: 8px 16px; border-radius: 100px;
  font-size: 13px; font-weight: 600; cursor: pointer;
  transition: all 0.2s; font-family: inherit;
}
.auth-chip:active { transform: scale(0.96); background: rgba(250, 204, 21, 0.2); }

.user-chip {
  font-size: 11px; color: var(--text-faint);
  text-align: right; margin-top: -14px; margin-bottom: 18px;
  word-break: break-all;
}

/* VERDICT BANNER */
.verdict {
  border-radius: var(--radius);
  padding: 22px 20px;
  text-align: center;
  margin-bottom: 20px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  transition: all 0.4s;
}

.verdict.verdict-neutral {
  background: var(--bg-card);
}

.verdict.verdict-profit {
  background: linear-gradient(135deg, var(--green-bg) 0%, rgba(52, 211, 153, 0.05) 100%);
  border-color: rgba(52, 211, 153, 0.4);
}

.verdict.verdict-loss {
  background: linear-gradient(135deg, var(--red-bg) 0%, rgba(248, 113, 113, 0.05) 100%);
  border-color: rgba(248, 113, 113, 0.4);
}

.verdict-label {
  font-size: 10px; font-weight: 700; letter-spacing: 0.15em;
  color: var(--text-muted); margin-bottom: 6px;
}

.verdict-value {
  font-family: var(--mono);
  font-size: 40px; font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
  margin-bottom: 6px;
  color: var(--text-muted);
}

.verdict.verdict-profit .verdict-value {
  color: var(--green);
  text-shadow: 0 0 24px rgba(52, 211, 153, 0.5);
}

.verdict.verdict-loss .verdict-value {
  color: var(--red);
  text-shadow: 0 0 24px rgba(248, 113, 113, 0.5);
}

.verdict-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.verdict.verdict-profit .verdict-sub { color: var(--green); font-weight: 600; }
.verdict.verdict-loss .verdict-sub { color: var(--red); font-weight: 600; }

/* SECTION TITLES */
.section-title {
  font-size: 11px; font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin: 22px 0 12px;
  padding-left: 4px;
}

/* CARD */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 20px;
  box-shadow: var(--shadow);
}

.form-group { margin-bottom: 16px; }
.form-group:last-child { margin-bottom: 0; }

label {
  display: block;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 8px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.input-wrap {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--bg-inner);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 14px;
  transition: all 0.2s;
}

.input-wrap:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(250, 204, 21, 0.1);
}

input, select {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 15px;
  font-weight: 500;
  padding: 13px 0;
  outline: none;
  font-family: var(--mono);
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  min-width: 0;
}

input[type=text] { text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
input::placeholder { color: var(--text-faint); font-weight: 400; text-transform: none; }

input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

/* LEG CARD */
.leg {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  animation: fadeInUp 0.3s ease;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.leg-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.leg-number {
  font-size: 11px;
  font-weight: 700;
  color: var(--yellow);
  letter-spacing: 0.1em;
}

.leg-pair {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}

.leg-remove {
  background: rgba(248, 113, 113, 0.1);
  color: var(--red);
  border: 1px solid rgba(248, 113, 113, 0.25);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
}
.leg-remove:active { background: rgba(248, 113, 113, 0.2); transform: scale(0.96); }

.leg-row {
  display: flex;
  gap: 10px;
}

.leg-row .form-group {
  flex: 1;
  margin-bottom: 12px;
}

.leg-row .form-group:last-child { margin-bottom: 0; }

/* ROW ACTIONS */
.row-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}

.row-actions .btn-secondary {
  flex: 1;
  margin-top: 0;
}

/* BUTTONS */
.btn-primary {
  width: 100%;
  background: linear-gradient(135deg, var(--yellow) 0%, #f59e0b 100%);
  color: #0f0d17;
  border: none;
  padding: 16px;
  font-size: 15px;
  font-weight: 700;
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin-top: 20px;
  font-family: inherit;
  transition: all 0.2s;
  box-shadow: 0 8px 24px rgba(250, 204, 21, 0.25);
  letter-spacing: -0.01em;
}
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-secondary {
  width: 100%;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 13px;
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin-top: 8px;
  font-family: inherit;
  transition: all 0.2s;
}
.btn-secondary:active {
  background: rgba(250, 204, 21, 0.08);
  border-color: var(--border-focus);
  transform: scale(0.98);
}

/* RESULTS */
.results { margin-top: 8px; animation: fadeInUp 0.4s ease; }

.result-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 20px;
}

.breakdown-leg {
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.breakdown-leg:last-child { border-bottom: none; }

.breakdown-leg-title {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--yellow);
  font-weight: 600;
  margin-bottom: 6px;
}

.breakdown-leg-detail {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 3px;
  font-family: var(--mono);
}

.breakdown-leg-detail span:last-child { color: var(--text); font-weight: 500; }

.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.detail-row:last-child { border-bottom: none; }
.detail-label { color: var(--text-muted); font-weight: 500; font-size: 13px; }
.detail-value {
  font-weight: 600;
  text-align: right;
  color: var(--text);
  font-family: var(--mono);
  font-size: 14px;
}

/* HISTORY */
#history-list { margin-top: 8px; }

.history-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 16px;
  border-radius: var(--radius);
  margin-bottom: 10px;
  animation: fadeInUp 0.3s ease;
}

.history-route {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
  word-break: break-word;
}

.history-profit {
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}

.history-profit.positive { color: var(--green); }
.history-profit.negative { color: var(--red); }

.history-meta {
  color: var(--text-muted);
  font-size: 11px;
  font-family: var(--mono);
}

.history-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.history-actions button {
  flex: 1;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
}

.btn-edit:active {
  background: rgba(250, 204, 21, 0.1);
  border-color: var(--yellow);
  color: var(--yellow);
  transform: scale(0.97);
}
.btn-delete:active {
  background: rgba(248, 113, 113, 0.1);
  border-color: var(--red);
  color: var(--red);
  transform: scale(0.97);
}

.preset-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.preset-info { flex: 1; min-width: 0; }
.preset-name { font-weight: 600; font-size: 14px; margin-bottom: 3px; }
.preset-route {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-muted);
  word-break: break-word;
}

.preset-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.preset-actions button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.preset-actions button:active { transform: scale(0.95); }

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 13px;
}
.empty-state .icon { font-size: 32px; margin-bottom: 12px; opacity: 0.4; }

/* MODAL */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
  overflow-y: auto;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-overlay.hidden { display: none; }

.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 32px 24px 24px;
  border-radius: 20px;
  width: 100%;
  max-width: 380px;
  position: relative;
  box-shadow: var(--shadow);
  animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  max-height: 90vh;
  overflow-y: auto;
  margin: auto;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-icon { font-size: 32px; text-align: center; margin-bottom: 12px; }
.modal-box h2 {
  font-size: 20px; font-weight: 700; margin-bottom: 6px;
  text-align: center; letter-spacing: -0.01em;
}
.modal-sub {
  font-size: 13px; color: var(--text-muted);
  margin-bottom: 20px; text-align: center; line-height: 1.5;
}

.modal-close {
  position: absolute; top: 14px; right: 14px;
  background: rgba(250, 204, 21, 0.1);
  border: none; color: var(--text-muted); font-size: 16px;
  cursor: pointer; width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}
.modal-close:active {
  background: rgba(250, 204, 21, 0.2); transform: scale(0.9);
}

.modal-status {
  margin-top: 14px; font-size: 13px; color: var(--yellow);
  text-align: center; min-height: 18px; line-height: 1.4;
}

/* TOAST */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 100px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow);
  z-index: 2000;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  max-width: 90vw;
  text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.success { border-color: rgba(52, 211, 153, 0.5); color: var(--green); }
.toast.error { border-color: rgba(248, 113, 113, 0.5); color: var(--red); }
.op-toggle {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.op-btn {
  flex: 1;
  background: var(--bg-inner);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
}

.op-btn.active {
  background: rgba(250, 204, 21, 0.15);
  border-color: var(--yellow);
  color: var(--yellow);
}

.op-btn:active { transform: scale(0.97); }
