:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --border: #2a2d3a;
  --text: #e2e8f0;
  --muted: #64748b;
  --green: #22c55e;
  --red: #ef4444;
  --blue: #3b82f6;
  --yellow: #f59e0b;
  --font: "SF Mono", "Fira Code", "Consolas", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Nav */
nav {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-brand { font-weight: 700; font-size: 16px; color: var(--text); margin-right: auto; }
nav a { color: var(--muted); text-decoration: none; font-size: 13px; padding: 4px 8px; border-radius: 4px; transition: color 0.15s; }
nav a:hover, nav a.active { color: var(--text); background: var(--border); }

main { flex: 1; padding: 24px; max-width: 1400px; margin: 0 auto; width: 100%; }
footer { text-align: center; padding: 16px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--border); }

/* Page header */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.page-header h1 { font-size: 20px; font-weight: 600; }
.last-price { font-size: 13px; color: var(--muted); }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 20px; margin-bottom: 16px; }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.section-header h2 { font-size: 15px; font-weight: 600; }
.card h2 { font-size: 15px; font-weight: 600; margin-bottom: 16px; }
.link-btn { color: var(--blue); text-decoration: none; font-size: 13px; }
.link-btn:hover { text-decoration: underline; }

/* Stats grid */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stats-grid.compact .stat-card { padding: 12px 16px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 16px 20px; }
.stat-card label { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 4px; }
.stat-val { font-size: 20px; font-weight: 700; font-family: var(--font); }
.stats-grid.compact .stat-val { font-size: 16px; }

/* Control row */
.control-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; }
.info-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 32px; }
.info-grid > div { display: flex; flex-direction: column; }
.info-grid label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.info-grid span { font-size: 14px; font-weight: 500; margin-top: 2px; }
.btn-group { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }

/* Status dot */
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; }
.status-dot.green { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-dot.red { background: var(--red); }
.status-label { font-size: 13px; color: var(--muted); }

/* Buttons */
.btn { padding: 8px 16px; border-radius: 6px; border: none; cursor: pointer; font-size: 13px; font-weight: 500; transition: opacity 0.15s; }
.btn:hover { opacity: 0.85; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-danger { background: var(--red); color: #fff; }
.btn-sm { padding: 4px 12px; font-size: 12px; }

/* Badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.badge-buy { background: rgba(34,197,94,0.15); color: var(--green); }
.badge-sell { background: rgba(239,68,68,0.15); color: var(--red); }
.badge-warn { background: rgba(245,158,11,0.15); color: var(--yellow); }
.badge-live { background: rgba(59,130,246,0.15); color: var(--blue); }
.badge-filled { background: rgba(34,197,94,0.12); color: var(--green); }
.badge-open { background: rgba(59,130,246,0.12); color: var(--blue); }
.badge-dry_run { background: rgba(245,158,11,0.12); color: var(--yellow); }
.badge-cancelled { background: rgba(100,116,139,0.2); color: var(--muted); }

/* Filter bar */
.filter-bar { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; padding: 14px 20px; }
.filter-bar form { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; width: 100%; }
.filter-group { display: flex; align-items: center; gap: 8px; }
.filter-group label { font-size: 12px; color: var(--muted); white-space: nowrap; }
select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 10px;
  border-radius: 5px;
  font-size: 13px;
  cursor: pointer;
}
select:focus { outline: none; border-color: var(--blue); }

/* Table */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; padding: 8px 12px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 9px 12px; border-bottom: 1px solid rgba(42,45,58,0.6); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,0.02); }
.mono { font-family: var(--font); font-size: 12px; }
.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 32px; font-size: 13px; }

/* Colors */
.green { color: var(--green); }
.red { color: var(--red); }

/* Pagination */
.pagination { display: flex; align-items: center; justify-content: center; gap: 16px; padding: 16px 0 4px; }
.page-info { font-size: 12px; color: var(--muted); }

/* HTMX loading indicator */
.htmx-indicator { opacity: 0; transition: opacity 0.2s; }
.htmx-request .htmx-indicator { opacity: 1; }

/* Confirmation Modal */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(4px);
}
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 100%; max-width: 420px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.5);
  animation: modal-in 0.15s ease;
}
@keyframes modal-in {
  from { opacity: 0; transform: scale(0.95); }
  to   { opacity: 1; transform: scale(1); }
}
.modal-icon { font-size: 36px; text-align: center; margin-bottom: 12px; }
.modal-box h3 { font-size: 18px; font-weight: 700; text-align: center; margin-bottom: 8px; }
.modal-box p { font-size: 13px; color: var(--muted); text-align: center; margin-bottom: 20px; }
.modal-meta { background: var(--bg); border-radius: 8px; padding: 12px 16px; margin-bottom: 24px; }
.meta-row { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; font-size: 13px; }
.meta-row.warn { color: var(--yellow); justify-content: flex-start; gap: 8px; }
.modal-btns { display: flex; gap: 12px; }
.modal-btns .btn { flex: 1; justify-content: center; padding: 10px; font-size: 14px; }
.btn-ghost { background: var(--border); color: var(--muted); }
.btn-ghost:hover { background: var(--border); color: var(--text); opacity: 1; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

/* Alerts */
.alert { padding: 12px 16px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; line-height: 1.5; }
.alert-error { background: rgba(239,68,68,0.08); border: 1px solid rgba(239,68,68,0.25); color: #f87171; }
.alert-success { background: rgba(34,197,94,0.08); border: 1px solid rgba(34,197,94,0.25); color: #4ade80; }
.alert ul { margin: 6px 0 0 16px; }

/* Settings layout */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.settings-grid + .settings-grid { margin-top: 20px; }
.span-2 { grid-column: 1 / -1; }

.card-section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding-bottom: 14px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

/* Field */
.field { display: flex; flex-direction: column; gap: 7px; }
.field-label { font-size: 13px; font-weight: 500; color: var(--text); }
.field-hint { font-size: 11px; color: var(--muted); line-height: 1.5; }

/* Bare input — used standalone (no prefix) */
input[type="text"],
input[type="number"] {
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  font-family: var(--font);
  width: 100%;
  height: 44px;
  transition: border-color 0.18s, box-shadow 0.18s, background 0.18s;
  -moz-appearance: textfield;
}
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { opacity: 0.4; }
input[type="text"]:hover,
input[type="number"]:hover { border-color: #3d4052; background: rgba(255,255,255,0.05); }
input[type="text"]:focus,
input[type="number"]:focus {
  outline: none;
  border-color: var(--blue);
  background: rgba(59,130,246,0.05);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
}

/* Input wrapper with $ prefix — border lives on the wrapper, not the input */
.input-wrap {
  display: flex;
  align-items: center;
  height: 44px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: border-color 0.18s, box-shadow 0.18s, background 0.18s;
}
.input-wrap:hover { border-color: #3d4052; background: rgba(255,255,255,0.05); }
.input-wrap:focus-within {
  border-color: var(--blue);
  background: rgba(59,130,246,0.05);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
}
.input-wrap .prefix {
  padding: 0 6px 0 13px;
  font-size: 13px;
  color: var(--muted);
  font-family: var(--font);
  flex-shrink: 0;
  user-select: none;
  pointer-events: none;
}
.input-wrap input {
  flex: 1;
  height: 100%;
  background: transparent;
  border: none;
  outline: none;
  box-shadow: none;
  padding: 0 14px 0 0;
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
  -moz-appearance: textfield;
}
.input-wrap input:hover,
.input-wrap input:focus {
  border: none;
  background: transparent;
  box-shadow: none;
}

/* Range pair row */
.range-row { display: flex; align-items: center; gap: 10px; }
.range-row .input-wrap { flex: 1; }
.range-sep { color: var(--muted); font-size: 16px; flex-shrink: 0; padding-top: 2px; }

/* Form footer */
.form-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 20px;
  margin-top: 24px;
  border-top: 1px solid var(--border);
  gap: 16px;
}
.form-footer .btn { padding: 10px 28px; font-size: 14px; }
.field-note { font-size: 12px; color: var(--muted); }

/* Preview panel */
.preview-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 1px;
  background: var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.preview-cell {
  background: var(--bg);
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.preview-cell:first-child { border-radius: 10px 0 0 10px; }
.preview-cell:last-child  { border-radius: 0 10px 10px 0; }
.preview-label { font-size: 10px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.07em; }
.preview-val { font-size: 16px; font-weight: 700; font-family: var(--font); color: var(--text); }
