/* ==========================================================================
   EA Dashboard — layout and components
   Shell: sidebar (fixed nav) + main (topbar, filters, stat cards, table)
   ========================================================================== */

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

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font-text);
  font-size: var(--t-base);
  line-height: 1.45;
  font-feature-settings: "tnum" 1;
}

button, input, select { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.num {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

/* --- App shell ------------------------------------------------------------ */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* --- Sidebar ---------------------------------------------------------------- */

.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  padding: var(--s-5) var(--s-3);
  display: flex;
  flex-direction: column;
}

.sidebar__brand {
  padding: 0 var(--s-3) var(--s-5);
}

.sidebar__name {
  margin: 0;
  font-size: var(--t-md);
  font-weight: 700;
  letter-spacing: -0.01em;
}

.sidebar__tag {
  margin: 2px 0 0;
  font-size: var(--t-xs);
  color: var(--ink-muted);
}

.nav-label {
  padding: 0 var(--s-3);
  margin: var(--s-4) 0 var(--s-2);
  font-size: var(--t-xs);
  font-weight: 600;
  color: var(--ink-muted);
  letter-spacing: 0.04em;
}
.nav-label:first-of-type { margin-top: 0; }

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: 8px var(--s-3);
  border-radius: var(--radius-sm);
  color: var(--ink-dim);
  font-size: var(--t-sm);
  text-decoration: none;
  cursor: pointer;
  border: 1px solid transparent;
  background: none;
  width: 100%;
  text-align: left;
}
.nav-item:hover { color: var(--ink); background: var(--surface); }
.nav-item[aria-current="page"] {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: rgba(45, 212, 200, 0.25);
  font-weight: 500;
}
.nav-item .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.7; flex: none; }

.sidebar__footer {
  margin-top: auto;
  padding: var(--s-3);
  border-top: 1px solid var(--line-soft);
  font-size: var(--t-xs);
  color: var(--ink-muted);
}
.sidebar__footer strong { display: block; color: var(--ink-dim); font-size: var(--t-sm); font-weight: 500; margin-bottom: 2px; }

/* --- Main ------------------------------------------------------------------- */

.main { min-width: 0; }

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-4);
  padding: var(--s-5) var(--s-5) var(--s-4);
  border-bottom: 1px solid var(--line-soft);
}

.topbar__title {
  margin: 0;
  font-size: var(--t-lg);
  font-weight: 700;
  margin-right: var(--s-2);
}

.pill {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  background: var(--pill);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 5px 11px;
  font-size: var(--t-xs);
}
.pill__label { color: var(--ink-muted); letter-spacing: 0.03em; }
.pill__value { font-size: var(--t-sm); font-weight: 600; color: var(--ink); }
.pill__ccy { color: var(--ink-muted); font-size: var(--t-xs); }

.topbar__meta {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--s-4);
  font-size: var(--t-xs);
  color: var(--ink-muted);
}

.sync {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.sync__dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--up);
}
.sync__dot[data-feed="stale"]   { background: var(--warn); }
.sync__dot[data-feed="offline"] { background: var(--down); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink-dim);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: var(--t-sm);
  cursor: pointer;
}
.btn:hover { color: var(--ink); border-color: var(--accent); }

/* --- Filter bar --------------------------------------------------------- */

.filterbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-4) var(--s-5);
}

.chip {
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink-dim);
  padding: 6px 13px;
  border-radius: var(--radius-pill);
  font-size: var(--t-sm);
  cursor: pointer;
}
.chip:hover { border-color: var(--accent); color: var(--ink); }
.chip[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--ground);
  font-weight: 600;
}

.chip-group {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  padding: 3px;
  gap: 2px;
}
.chip-group .chip { border: none; background: none; padding: 5px 12px; }
.chip-group .chip[aria-pressed="true"] { background: var(--ink); color: var(--ground); }

.search {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 7px 11px;
  font-size: var(--t-sm);
  flex: 1 1 220px;
  max-width: 300px;
}
.search::placeholder { color: var(--ink-muted); }

.filterbar__spacer { flex: 1 1 auto; }

/* --- Dropdown ------------------------------------------------------------- */

.dropdown { position: relative; }

.dropdown__trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.dropdown__trigger::after {
  content: "";
  width: 0; height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
  opacity: 0.6;
}
.dropdown__trigger[aria-expanded="true"] {
  border-color: var(--accent);
  color: var(--ink);
}

.dropdown__panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 30;
  min-width: 240px;
  max-height: 340px;
  overflow-y: auto;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
  padding: var(--s-2);
}
.dropdown__panel[hidden] { display: none; }

.dropdown__group-label {
  padding: 6px 8px 2px;
  font-size: var(--t-xs);
  color: var(--ink-muted);
  letter-spacing: 0.03em;
}

.dropdown__item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  font-size: var(--t-sm);
  cursor: pointer;
}
.dropdown__item:hover { background: var(--surface); }
.dropdown__item input[type="checkbox"],
.dropdown__item input[type="radio"] { accent-color: var(--accent); }
.dropdown__item span.count { margin-left: auto; color: var(--ink-muted); font-size: var(--t-xs); }

.dropdown__divider { height: 1px; background: var(--line-soft); margin: var(--s-2) 4px; }

.dropdown__foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--s-2) 8px 2px;
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: var(--t-xs);
  cursor: pointer;
  padding: 0;
}
.link-btn:hover { text-decoration: underline; }

/* --- Date range ------------------------------------------------------------ */

.daterange {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
}
.daterange input[type="date"] {
  background: none;
  border: none;
  color: var(--ink);
  font-size: var(--t-sm);
  font-family: var(--font-num);
  color-scheme: dark;
}
.daterange span { color: var(--ink-muted); font-size: var(--t-sm); }

/* --- Content -------------------------------------------------------------- */

.content { padding: 0 var(--s-5) var(--s-7); }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.panel__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s-3);
  padding: var(--s-4) var(--s-4) var(--s-3);
}
.panel__title { margin: 0; font-size: var(--t-md); font-weight: 700; }
.panel__hint { margin: 2px 0 0; font-size: var(--t-xs); color: var(--ink-muted); }
.panel__right { font-size: var(--t-xs); color: var(--ink-muted); display: flex; align-items: center; gap: var(--s-2); }

/* --- Stat cards row -------------------------------------------------------- */

.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-top: 1px solid var(--line-soft);
}

.stat {
  padding: var(--s-4);
  border-right: 1px solid var(--line-soft);
}
.stat:last-child { border-right: none; }

.stat__label { font-size: var(--t-xs); color: var(--ink-muted); }
.stat__value {
  margin-top: 4px;
  font-size: var(--t-lg);
  font-weight: 700;
}

/* --- Table ------------------------------------------------------------------ */

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--t-sm);
  min-width: 1080px;
}

thead th {
  position: sticky;
  top: 0;
  background: var(--surface-raised);
  text-align: left;
  font-weight: 500;
  color: var(--ink-muted);
  font-size: var(--t-xs);
  padding: var(--s-2) var(--s-3);
  border-top: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
thead th:hover { color: var(--ink); }
thead th[aria-sort] { color: var(--accent); }
thead th[aria-sort="descending"]::after { content: " ↓"; }
thead th[aria-sort="ascending"]::after  { content: " ↑"; }

tbody td {
  padding: 10px var(--s-3);
  border-bottom: 1px solid var(--line-soft);
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-raised); }

.right { text-align: right; }

.sym {
  font-weight: 500;
}
.sym__ticket { color: var(--ink-muted); font-size: var(--t-xs); }

.side {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 500;
}
.side[data-side="buy"]  { color: var(--up); }
.side[data-side="sell"] { color: var(--down); }
.side::before { content: ""; width: 0; height: 0; border-left: 4px solid transparent; border-right: 4px solid transparent; }
.side[data-side="buy"]::before  { border-bottom: 6px solid var(--up); }
.side[data-side="sell"]::before { border-top: 6px solid var(--down); }

.strategy-tag {
  font-size: var(--t-xs);
  color: var(--ink-dim);
  background: var(--pill);
  border: 1px solid var(--line);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
}

.dash { color: var(--ink-muted); }

.up   { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--ink-dim); }

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: var(--radius-pill);
  font-size: var(--t-xs);
}
.badge[data-state="up"]      { background: var(--up-soft);   color: var(--up); }
.badge[data-state="down"]    { background: var(--down-soft); color: var(--down); }
.badge[data-state="warn"]    { background: var(--warn-soft); color: var(--warn); }
.badge[data-state="offline"] { background: var(--surface-raised); color: var(--offline); }

.empty {
  padding: var(--s-6) var(--s-4);
  color: var(--ink-muted);
  font-size: var(--t-sm);
  text-align: center;
}

.panel__filters {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  padding: 0 var(--s-4) var(--s-4);
}

.group-row {
  cursor: pointer;
}
.group-row td { font-weight: 500; }
.group-row .strategy-tag { font-weight: 400; }

/* --- Motion --------------------------------------------------------------- */

.chip, .nav-item, thead th, .btn { transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* --- Narrow screens --------------------------------------------------------- */

@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--line);
    padding: var(--s-3);
  }
  .sidebar__brand, .nav-label, .sidebar__footer { display: none; }
  .nav-item { white-space: nowrap; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .stat:nth-child(2) { border-right: none; }
  .topbar, .filterbar, .content { padding-left: var(--s-4); padding-right: var(--s-4); }
}
