:root {
  --bg: #0b0f17;
  --surface: #131a26;
  --surface-2: #1b2434;
  --border: #263247;
  --text: #e6edf7;
  --muted: #8b9bb4;
  --cyan: #38bdf8;
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body {
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  padding-bottom: 40px;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 20;
}

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

.logo-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 10px var(--cyan);
}

.brand h1 {
  font-size: 1.05rem;
  letter-spacing: 0.05em;
}

.subtitle {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
}

.header-actions {
  display: flex;
  gap: 8px;
}

.container {
  max-width: 820px;
  margin: 16px auto;
  padding: 0 14px;
}

/* CIRCUIT BREAKER */
.circuit-banner {
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid var(--red);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.circuit-icon {
  font-size: 1.6rem;
}

.circuit-content h3 {
  color: #fca5a5;
  font-size: 0.9rem;
  margin-bottom: 2px;
}

.circuit-content p {
  font-size: 0.8rem;
  color: var(--text);
}

/* METRICS */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

@media (min-width: 640px) {
  .metrics-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 14px;
}

.metric-card {
  margin-bottom: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

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

.metric-value {
  font-size: 1.1rem;
  margin: 4px 0;
  font-variant-numeric: tabular-nums;
}

.metric-sub {
  font-size: 0.74rem;
  color: var(--muted);
}

/* TABS */
.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  overflow-x: auto;
}

.tab-btn {
  flex: 1;
  white-space: nowrap;
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.tab-btn.active {
  background: var(--cyan);
  color: #06101d;
  border-color: var(--cyan);
}

.tab-panel {
  display: none;
}

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

.card-title {
  font-size: 0.98rem;
  margin-bottom: 4px;
}

.card-desc {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 14px;
}

/* FORMS */
.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

@media (min-width: 560px) {
  .form-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.form-group label {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.form-group input,
.form-group select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.92rem;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--cyan);
}

.full-width {
  margin-bottom: 14px;
}

/* RESULT BOX */
.calc-result-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-top: 10px;
}

.res-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px dashed var(--border);
  font-size: 0.84rem;
}

.res-row:last-of-type {
  border-bottom: none;
}

.warning-msg {
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(245, 158, 11, 0.14);
  border: 1px solid var(--amber);
  color: #fcd34d;
  font-size: 0.78rem;
}

/* BUTTONS */
.btn-primary {
  width: 100%;
  background: var(--cyan);
  color: #06101d;
  border: none;
  padding: 12px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 0.92rem;
  cursor: pointer;
}

.btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-ghost {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 0.78rem;
  cursor: pointer;
}

.link-btn {
  background: none;
  border: none;
  color: var(--cyan);
  font-size: 0.74rem;
  text-align: left;
  cursor: pointer;
  padding: 0;
}

.btn-danger-outline {
  background: transparent;
  border: 1px solid var(--red);
  color: #fca5a5;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 0.75rem;
  cursor: pointer;
  white-space: nowrap;
}

.btn-danger-text {
  background: none;
  border: none;
  color: var(--red);
  font-size: 0.78rem;
  cursor: pointer;
}

/* HISTORY */
.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.trade-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.trade-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}

.trade-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.trade-sym {
  font-weight: 700;
  font-size: 0.96rem;
}

.badge {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 99px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
}

.trade-meta {
  font-size: 0.78rem;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
}

.trade-note {
  margin-top: 6px;
  font-size: 0.78rem;
  color: #cbd5e1;
  font-style: italic;
}

.chart-wrapper {
  width: 100%;
  overflow-x: auto;
}

canvas {
  width: 100%;
  display: block;
}

/* MODAL */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  width: 100%;
  max-width: 380px;
}

.modal-box h3 {
  font-size: 0.96rem;
  margin-bottom: 12px;
}

.modal-box input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 14px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.hidden {
  display: none !important;
}

.highlight-cyan { color: var(--cyan); }
.text-green { color: var(--green); }
.text-red { color: var(--red); }

.trade-actions { display: flex; justify-content: flex-end; gap: 20px; margin-top: 8px; }
.trade-actions button { padding: 8px 4px; font-size: 0.85rem; }
#btn-cancel-edit { margin-top: 8px; width: 100%; padding: 10px; }
