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

:root {
  --bg:           #07080f;
  --glass-bg:     rgba(255,255,255,0.035);
  --glass-border: rgba(255,255,255,0.07);
  --glass-hover:  rgba(255,255,255,0.06);
  --accent:       #6ee7f7;
  --accent-dim:   rgba(110,231,247,0.12);
  --accent-2:     #818cf8;
  --success:      #4ade80;
  --error:        #f87171;
  --text:         #e2e8f0;
  --text-muted:   #64748b;
  --text-dim:     #94a3b8;
  --mono:         'JetBrains Mono', monospace;
  --sans:         'Space Grotesk', sans-serif;
  --body:         'Inter', sans-serif;
  --radius:       14px;
  --tr:           0.2s cubic-bezier(0.4,0,0.2,1);
}

html, body { height: 100%; overflow: hidden; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--body);
  font-size: 13px;
  line-height: 1.6;
  display: flex;
  flex-direction: column;
}

.accent { color: var(--accent); }
.mono   { font-family: var(--mono); }

.glass-card {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 1rem;
  border-radius: 7px;
  font-size: 0.8rem;
  font-weight: 500;
  font-family: var(--sans);
  cursor: pointer;
  border: none;
  transition: all var(--tr);
}
.btn-primary { background: var(--accent); color: #07080f; font-weight: 600; }
.btn-primary:hover { background: #93f0ff; }
.btn-ghost   { background: transparent; color: var(--text-dim); border: 1px solid var(--glass-border); }
.btn-ghost:hover { background: var(--glass-hover); color: var(--text); }
.btn-sm { padding: 0.3rem 0.75rem; font-size: 0.75rem; }
.btn-full { width: 100%; justify-content: center; }
.btn-row { display: flex; gap: 0.5rem; }

/* ── NAV ── */
.nav {
  flex-shrink: 0;
  background: rgba(7,8,15,0.9);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--glass-border);
  padding: 0 1.25rem;
  z-index: 50;
}
.nav-inner {
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.nav-brand { font-family: var(--sans); font-weight: 700; font-size: 0.95rem; }
.nav-right  { display: flex; gap: 0.5rem; }

/* ── LAYOUT ── */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 220px 1fr 360px;
  gap: 0;
  overflow: hidden;
}

/* ── SIDEBARS ── */
.sidebar-left,
.sidebar-right {
  overflow-y: auto;
  padding: 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  border-right: 1px solid var(--glass-border);
}
.sidebar-right { border-right: none; border-left: 1px solid var(--glass-border); }

.sidebar-section { padding: 1rem; }
.section-title {
  font-family: var(--mono);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
  margin-bottom: 0.85rem;
}

/* Form controls */
.field-row {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 0.65rem;
}
.field-row label {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-family: var(--mono);
  letter-spacing: 0.05em;
}
.field-row input,
.search-wrap input {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--glass-border);
  border-radius: 7px;
  padding: 0.45rem 0.65rem;
  color: var(--text);
  font-size: 0.8rem;
  font-family: var(--sans);
  outline: none;
  width: 100%;
  transition: border-color var(--tr);
}
.field-row input:focus,
.search-wrap input:focus { border-color: rgba(110,231,247,0.4); }
.field-row input::placeholder,
.search-wrap input::placeholder { color: var(--text-muted); }

.item-search-card { z-index: 2; }
.search-wrap { position: relative; margin-bottom: 0.65rem; }
.autocomplete {
  position: absolute;
  top: 100%;
  left: 0; right: 0;
  background: #111827;
  border: 1px solid var(--glass-border);
  border-radius: 7px;
  margin-top: 2px;
  z-index: 100;
  max-height: 180px;
  overflow-y: auto;
}
.autocomplete.hidden { display: none; }
.autocomplete-item {
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  font-size: 0.8rem;
  transition: background var(--tr);
}
.autocomplete-item:hover { background: var(--glass-hover); color: var(--accent); }

.day-nav { display: flex; gap: 0.4rem; margin-bottom: 0.65rem; }
.day-nav .btn { flex: 1; justify-content: center; }

/* ── MAIN ── */
.main-area {
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.chart-card { padding: 1.25rem; display: flex; flex-direction: column; gap: 1rem; }

.chart-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.item-name {
  font-family: var(--sans);
  font-size: 1.1rem;
  font-weight: 600;
  display: block;
}
.item-price {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--accent);
  display: block;
  margin-top: 0.2rem;
}

/* Timeframe buttons */
.timeframe-btns { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.tf-btn {
  background: transparent;
  border: 1px solid var(--glass-border);
  border-radius: 6px;
  padding: 0.25rem 0.6rem;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: 0.72rem;
  cursor: pointer;
  transition: all var(--tr);
}
.tf-btn:hover { color: var(--text); border-color: rgba(110,231,247,0.3); }
.tf-btn.active { background: var(--accent-dim); color: var(--accent); border-color: rgba(110,231,247,0.35); }

/* Chart type tabs */
.chart-type-tabs { display: flex; gap: 0.35rem; }
.ct-btn {
  background: transparent;
  border: 1px solid var(--glass-border);
  border-radius: 6px;
  padding: 0.25rem 0.75rem;
  color: var(--text-muted);
  font-family: var(--sans);
  font-size: 0.78rem;
  cursor: pointer;
  transition: all var(--tr);
}
.ct-btn.active { background: var(--accent-dim); color: var(--accent); border-color: rgba(110,231,247,0.35); }

.chart-area { position: relative; min-height: 320px; }
canvas#priceChart { max-height: 360px; }
.chart-status {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.875rem;
  background: transparent;
  pointer-events: none;
}
.chart-status.hidden { display: none; }

.chart-footer { display: flex; justify-content: flex-end; }

/* Data table */
.data-table { overflow-x: auto; margin-top: 0.5rem; }
.data-table.hidden { display: none; }
.data-table table { width: 100%; border-collapse: collapse; font-size: 0.78rem; }
.data-table thead th {
  padding: 0.5rem 0.75rem;
  text-align: left;
  font-family: var(--mono);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--glass-border);
}
.data-table tbody td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid rgba(255,255,255,0.03);
  color: var(--text-dim);
}

/* ── CALCULATOR ── */
.calc-results {
  background: rgba(0,0,0,0.2);
  border-radius: 8px;
  padding: 0.75rem;
  margin: 0.75rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.calc-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-dim);
}
.calc-row span:last-child { font-family: var(--mono); font-weight: 500; }
.profit-row span:last-child { font-size: 0.875rem; }
.neutral  { color: var(--text-dim); }
.positive { color: var(--success); }
.negative { color: var(--error); }

/* ── BEST ITEMS ── */
.best-items-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}
.btn-refresh {
  background: none;
  border: 1px solid var(--glass-border);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0.2rem 0.45rem;
  transition: color var(--tr), border-color var(--tr), transform 0.3s;
}
.btn-refresh:hover { color: var(--accent); border-color: var(--accent); }
.btn-refresh.spinning { animation: spin 0.6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.best-items-header {
  display: grid;
  grid-template-columns: 1fr 70px 52px 44px;
  gap: 0.25rem;
  font-family: var(--mono);
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--glass-border);
  margin-bottom: 0.5rem;
}
.best-items-header span:not(:first-child) { text-align: right; }
.bi-sort {
  cursor: pointer;
  user-select: none;
  transition: color var(--tr);
  white-space: nowrap;
}
.bi-sort:hover { color: var(--text-dim); }
.bi-sort.bi-sorted { color: var(--accent); }
.bi-sort-icon { margin-left: 2px; }
.best-item-row {
  display: grid;
  grid-template-columns: 1fr 70px 52px 44px;
  gap: 0.25rem;
  align-items: center;
  padding: 0.45rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.03);
  cursor: pointer;
  transition: background var(--tr);
  border-radius: 6px;
  padding: 0.4rem 0.35rem;
}
.best-item-row:hover { background: var(--glass-hover); }
.best-item-name  { font-size: 0.78rem; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.best-item-price { font-family: var(--mono); font-size: 0.72rem; color: var(--text-dim); white-space: nowrap; text-align: right; }
.best-item-margin {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--accent);
  background: var(--accent-dim);
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
  white-space: nowrap;
  text-align: right;
}
.best-item-margin.mid  { color: var(--warn);    background: rgba(251,191,36,0.12); }
.best-item-margin.high { color: var(--success); background: rgba(74,222,128,0.12); }
.bi-conf {
  font-family: var(--mono);
  font-size: 0.7rem;
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
  white-space: nowrap;
  text-align: right;
}
.bi-conf.low  { color: var(--error);   background: rgba(248,113,113,0.12); }
.bi-conf.mid  { color: var(--warn);    background: rgba(251,191,36,0.12); }
.bi-conf.high { color: var(--success); background: rgba(74,222,128,0.12); }
.loading-msg { color: var(--text-muted); font-size: 0.8rem; padding: 0.5rem 0; }

@media (max-width: 1024px) {
  html, body { overflow: auto; }
  .layout { grid-template-columns: 1fr; grid-template-rows: auto; }
  .sidebar-left, .sidebar-right { border: none; }
  .main-area { padding: 0.75rem; }
}
