/* ─── Reset & tokens ─── */
:root {
  --brand:       #2563EB;
  --brand-dk:    #1D4ED8;
  --brand-lt:    #DBEAFE;
  --success:     #16A34A;
  --danger:      #DC2626;
  --bg:          #F1F5F9;
  --surface:     #FFFFFF;
  --border:      #E2E8F0;
  --text:        #0F172A;
  --muted:       #64748B;
  --sidebar-w:   370px;
  --radius:      12px;
  --radius-sm:   8px;
  --shadow:      0 1px 3px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.07);
  --shadow-lg:   0 8px 32px rgba(0,0,0,.14);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ─── Shell layout ─── */
.shell {
  display: flex;
  min-height: 100vh;
}

/* ─── Sidebar ─── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  max-height: 100vh;
  overflow-y: auto;
  position: sticky;
  top: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--brand);
  color: #fff;
  font-size: 20px;
  font-weight: 800;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.brand-name { font-size: 15px; font-weight: 700; }
.brand-sub  { font-size: 11px; color: var(--muted); }

/* ─── Steps ─── */
.step {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.step-last { border-bottom: none; }

.step-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.step-head h2 {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.step-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

/* ─── Form controls ─── */
.input-row { display: flex; gap: 8px; margin-bottom: 8px; }
.select-row { display: flex; gap: 8px; }
.field-pair { display: flex; gap: 10px; }
.field-pair .field { flex: 1; }
.field { margin-bottom: 10px; }

.lbl {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.inp, .sel {
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
  appearance: auto;
}
.inp:focus, .sel:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-lt);
}

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
  height: 36px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  border: none;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dk); }
.btn-primary:disabled { background: #94A3B8; cursor: not-allowed; }

.btn-outline {
  background: transparent;
  color: var(--brand);
  border: 1.5px solid var(--brand);
  height: 34px;
}
.btn-outline:hover { background: var(--brand-lt); }

.btn-block { width: 100%; justify-content: center; height: 40px; font-size: 14px; margin-top: 4px; }
.btn-sm { height: 30px; font-size: 12px; padding: 0 10px; }

/* ─── Status ─── */
.status {
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
  min-height: 16px;
}
.status.error {
  color: var(--danger);
  background: #FEF2F2;
  border: 1px solid #FECACA;
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}
.status.ok { color: var(--success); }

/* ─── Asset list ─── */
.asset-list {
  list-style: none;
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
  padding-right: 2px;
}

.asset-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: default;
  transition: background 0.1s;
}
.asset-item:hover { background: #F8FAFC; }

.asset-info { flex: 1; min-width: 0; }
.asset-sym  { font-weight: 700; font-size: 13px; }
.asset-name { color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.asset-tags { display: flex; gap: 4px; margin-top: 3px; }

.tag {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 99px;
  background: var(--brand-lt);
  color: var(--brand-dk);
}

/* ─── Cart chips ─── */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--brand-lt);
  color: var(--brand-dk);
  border-radius: 99px;
  padding: 3px 10px 3px 10px;
  font-size: 12px;
  font-weight: 700;
}

.chip-rm {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--brand-dk);
  font-size: 15px;
  line-height: 1;
  padding: 0;
  opacity: 0.55;
  height: auto;
  display: flex;
  align-items: center;
}
.chip-rm:hover { opacity: 1; }

.badge {
  background: var(--brand);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  border-radius: 99px;
  padding: 1px 6px;
}

/* ─── Main area ─── */
.main-area {
  flex: 1;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-height: 100vh;
}

.hidden { display: none !important; }

/* ─── Empty state ─── */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--muted);
  padding: 60px 20px;
  gap: 12px;
}
.empty-icon { font-size: 64px; filter: grayscale(0.3); }
.empty-state h3 { font-size: 20px; color: var(--text); font-weight: 700; }
.empty-state p { max-width: 360px; font-size: 14px; line-height: 1.7; }

/* ─── Cards ─── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.card-header h2 { font-size: 15px; font-weight: 700; }
.card-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ─── Metrics grid ─── */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.metric-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  text-align: center;
}

.metric-val {
  font-size: 26px;
  font-weight: 800;
  color: var(--brand);
  line-height: 1.15;
}
.metric-val.pos { color: var(--success); }
.metric-val.neu { color: var(--muted); font-size: 22px; }

.metric-lbl {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-top: 4px;
}

/* ─── Allocation bars ─── */
.alloc-bars {
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.alloc-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.alloc-sym {
  width: 88px;
  font-size: 12px;
  font-weight: 700;
  text-align: right;
  flex-shrink: 0;
  color: var(--text);
}

.alloc-track {
  flex: 1;
  height: 22px;
  background: #F1F5F9;
  border-radius: 6px;
  overflow: hidden;
}

.alloc-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--brand) 0%, #60A5FA 100%);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 7px;
  min-width: 4px;
  transition: width 0.7s cubic-bezier(0.4,0,0.2,1);
}

.alloc-fill-pct { font-size: 11px; font-weight: 700; color: #fff; }
.alloc-fill.small .alloc-fill-pct { display: none; }

.alloc-out-pct {
  width: 44px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  flex-shrink: 0;
  display: none;
}
.alloc-out-pct.show { display: block; }

/* ─── Frontier canvas ─── */
.frontier-wrap {
  padding: 16px 20px 4px;
  position: relative;
}

#frontier-canvas {
  width: 100%;
  height: auto;
  display: block;
  cursor: crosshair;
  border-radius: var(--radius-sm);
}

.f-tip {
  position: absolute;
  background: var(--text);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 6px;
  pointer-events: none;
  white-space: nowrap;
  z-index: 10;
  transform: translateY(-50%);
}

/* ─── Loading overlay ─── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(3px);
}

.overlay-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 32px 44px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.overlay-card p { font-size: 15px; font-weight: 600; color: var(--muted); }

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Responsive ─── */
@media (max-width: 800px) {
  .shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    min-width: 0;
    max-height: none;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .main-area { padding: 16px; }
  .field-pair { flex-direction: column; }
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }
}


* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: radial-gradient(circle at top right, #ddeaf6, var(--bg) 45%);
  color: var(--text);
}

.topbar {
  padding: 24px 24px 0;
  max-width: 1100px;
  margin: 0 auto;
}

.topbar h1 { margin: 0; }

.subtitle {
  margin-top: 6px;
  color: var(--muted);
}

.layout {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  gap: 20px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px 24px;
  box-shadow: 0 10px 24px rgba(10, 20, 35, 0.06);
}

.panel h2 {
  margin-top: 0;
}

.hint {
  color: var(--muted);
  margin-top: -6px;
  font-size: 14px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  align-items: end;
}

label {
  display: grid;
  gap: 6px;
  font-weight: 600;
  font-size: 14px;
}

input,
select,
button {
  border: 1px solid var(--border);
  border-radius: 8px;
  min-height: 40px;
  padding: 0 12px;
  font-size: 14px;
  font-family: inherit;
}

button {
  background: var(--brand);
  color: #fff;
  border: none;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.15s ease;
}

button:hover { background: var(--brand-dark); }
button:disabled { background: #9fb3ab; cursor: not-allowed; }

.status {
  margin-top: 14px;
  color: var(--muted);
  min-height: 20px;
}

.status.error {
  color: var(--danger);
  background: var(--danger-bg);
  border: 1px solid var(--danger);
  border-radius: 8px;
  padding: 10px 12px;
}

.results,
.cart {
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 10px;
}

.results li,
.cart li {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.results li .meta,
.cart li .meta {
  flex: 1;
  min-width: 200px;
}

.results li button,
.cart li button {
  min-height: 34px;
  padding: 0 14px;
}

.cart li button {
  background: var(--danger);
}

.cart li button:hover { background: #8f1e18; }

.hidden { display: none !important; }

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metric-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  text-align: center;
}

.metric-card .value {
  font-size: 22px;
  font-weight: 700;
  color: var(--brand-dark);
}

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

.allocation-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 16px;
}

.allocation-table th,
.allocation-table td {
  border-bottom: 1px solid var(--border);
  padding: 8px 10px;
  text-align: left;
  font-size: 14px;
}

#frontier-canvas {
  width: 100%;
  max-width: 640px;
  height: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}

@media (max-width: 640px) {
  .panel { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
}
