/*
 * Trade Performance — light (default) + dark themes
 * Grouped SaaS navigation · Inter · data-dense
 */

/* ── Light (default) ── */

:root {
  color-scheme: light;

  --bg: #f6f5f2;
  --sidebar-bg: #fdfcfb;
  --card: #ffffff;
  --card-hover: #faf9f7;
  --border: #e8e6e1;
  --border-subtle: #f0efeb;
  --accent: #141414;
  --accent-soft: rgba(20, 20, 20, 0.06);
  --nav-active-border: #141414;
  --link: #3d3d3d;
  --link-hover: #141414;
  --tagline: #737373;
  --text: #141414;
  --text-secondary: #3d3d3d;
  --text-muted: #737373;
  --text-faint: #9a9a96;
  --hover-bg: rgba(20, 20, 20, 0.04);
  --topbar-bg: rgba(253, 252, 251, 0.92);
  --table-head-bg: #faf9f7;
  --panel-head-bg: linear-gradient(to bottom, #ffffff, #fcfbfa);
  --visual-card-bg: linear-gradient(145deg, #faf9f7 0%, #f3f2ef 100%);
  --metric-inner-bg: #f6f5f2;
  --success: #2d6a4f;
  --danger: #6b5c5c;
  --shadow-sm: 0 1px 2px rgba(20, 20, 20, 0.04);
  --shadow-md: 0 4px 24px rgba(20, 20, 20, 0.06);

  /* Typography — 15px base, 13px nav, 26px titles */
  --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --fs-nav: 0.8667rem;
  --fs-body: 1rem;
  --fs-title: 1.733rem;
  --fw-nav: 400;
  --fw-heading: 600;
  --letter-spacing-caps: 0.07em;

  /* Layout */
  --sidebar-width: 15.5rem;
  --topbar-height: 3.25rem;
  --content-max-width: 72rem;
  --nav-group-gap: 1.75rem;
  --nav-item-gap: 0.125rem;
  --transition: 0.16s ease;
}

/* ── Dark — off-black, desaturated greys ── */

[data-theme="dark"] {
  color-scheme: dark;

  --bg: #0c0c0c;
  --sidebar-bg: #111111;
  --card: #1a1a1a;
  --card-hover: #222222;
  --border: #2e2e2e;
  --border-subtle: #242424;
  --accent: #e8e8e6;
  --accent-soft: rgba(255, 255, 255, 0.06);
  --nav-active-border: #8a8a86;
  --link: #b0b0ac;
  --link-hover: #e8e8e6;
  --tagline: #6b6b68;
  --text: #ececea;
  --text-secondary: #b8b8b4;
  --text-muted: #8a8a86;
  --text-faint: #5c5c5a;
  --hover-bg: rgba(255, 255, 255, 0.04);
  --topbar-bg: rgba(12, 12, 12, 0.92);
  --table-head-bg: #161616;
  --panel-head-bg: rgba(255, 255, 255, 0.02);
  --visual-card-bg: linear-gradient(145deg, #1e1e1e 0%, #141414 100%);
  --metric-inner-bg: #141414;
  --success: #7a8a7e;
  --danger: #8a807a;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 4px 24px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html {
  font-size: 15px;
}

body,
.app-body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  font-weight: 400;
  background: var(--bg);
  color: var(--text-secondary);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: inherit;
  text-decoration: none;
}

/* ── App frame ── */

.app-frame {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100vh;
}

.app-shell {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100vh;
}

/* ── Sidebar ── */

.app-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border-subtle);
  overflow: hidden;
}

.sidebar-brand {
  flex-shrink: 0;
  padding: 1.35rem 1.25rem 1.15rem;
  border-bottom: 1px solid var(--border);
}

.brand-mark {
  display: block;
  font-size: var(--fs-nav);
  font-weight: var(--fw-heading);
  letter-spacing: var(--letter-spacing-caps);
  text-transform: uppercase;
  color: var(--text);
  transition: color var(--transition);
}

.brand-mark:hover {
  color: var(--accent);
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 0.75rem 1.5rem;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.nav-group + .nav-group {
  margin-top: var(--nav-group-gap);
}

.nav-group-label {
  margin: 0 0 0.5rem;
  padding: 0 0.625rem;
  font-size: 0.6667rem; /* ~10px */
  font-weight: var(--fw-heading);
  letter-spacing: var(--letter-spacing-caps);
  text-transform: uppercase;
  color: var(--text-faint);
  user-select: none;
}

.nav-group-items {
  display: flex;
  flex-direction: column;
  gap: var(--nav-item-gap);
}

.nav-item {
  display: block;
  padding: 0.4375rem 0.625rem 0.4375rem 0.75rem;
  border-radius: 6px;
  border-left: 3px solid transparent;
  font-size: var(--fs-nav);
  font-weight: var(--fw-nav);
  color: var(--text-muted);
  transition:
    background var(--transition),
    color var(--transition),
    border-color var(--transition);
}

.nav-item:hover {
  background: var(--hover-bg);
  color: var(--text-secondary);
}

.nav-item.is-active {
  background: var(--accent-soft);
  border-left-color: var(--nav-active-border);
  color: var(--text);
  font-weight: 500;
}

/* ── Top bar ── */

.top-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(12rem, 22rem) auto;
  align-items: center;
  gap: 1rem;
  height: var(--topbar-height);
  padding: 0 1.5rem;
  background: var(--topbar-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
}

.top-bar-context {
  font-size: var(--fs-nav);
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-bar-search {
  width: 100%;
  padding: 0.4375rem 0.75rem 0.4375rem 2rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background-color: var(--card);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' fill='%23737373' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85zm-5.242 1.156a5 5 0 1 1 0-10 5 5 0 0 1 0 10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 0.65rem center;
  font-family: inherit;
  font-size: var(--fs-nav);
  color: var(--text);
  opacity: 0.7;
  cursor: not-allowed;
}

[data-theme="dark"] .top-bar-search {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' fill='%238a8a86' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85zm-5.242 1.156a5 5 0 1 1 0-10 5 5 0 0 1 0 10z'/%3E%3C/svg%3E");
}

.top-bar-search::placeholder {
  color: var(--text-faint);
}

.top-bar-theme {
  padding: 0.375rem 0.625rem;
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  background: transparent;
  font-family: inherit;
  font-size: var(--fs-nav);
  font-weight: var(--fw-nav);
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.top-bar-theme:hover {
  background: var(--hover-bg);
  color: var(--text-secondary);
  border-color: var(--border);
}

.top-bar-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.top-bar-action {
  padding: 0.375rem 0.625rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  font-family: inherit;
  font-size: var(--fs-nav);
  font-weight: var(--fw-nav);
  color: var(--text-muted);
  cursor: not-allowed;
  opacity: 0.65;
  transition: background var(--transition), color var(--transition);
}

.top-bar-user {
  padding: 0.25rem;
}

.user-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  background: var(--card);
  border: 1px solid var(--border);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
}

/* ── Main content ── */

.app-main {
  flex: 1;
  min-width: 0;
  background: var(--bg);
}

.app-content {
  width: 100%;
  max-width: var(--content-max-width);
  margin: 0 auto;
  padding: 2rem 2rem 2.5rem;
  animation: content-in 0.28s ease;
}

@keyframes content-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ── View headers ── */

.view-header {
  margin-bottom: 1.75rem;
}

.view-header h1 {
  margin: 0 0 0.35rem;
  font-size: var(--fs-title);
  font-weight: var(--fw-heading);
  letter-spacing: -0.025em;
  color: var(--text);
  line-height: 1.2;
}

.view-tagline {
  margin: 0 0 0.45rem;
  font-size: var(--fs-nav);
  font-weight: 500;
  letter-spacing: var(--letter-spacing-caps);
  text-transform: uppercase;
  color: var(--tagline);
}

.view-desc {
  margin: 0;
  font-size: var(--fs-body);
  color: var(--text-muted);
  max-width: 38rem;
  line-height: 1.6;
}

/* ── Panels ── */

.panel {
  background: var(--card);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.15rem;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--panel-head-bg);
}

.panel-head h3 {
  margin: 0;
  font-size: var(--fs-nav);
  font-weight: var(--fw-heading);
  letter-spacing: var(--letter-spacing-caps);
  text-transform: uppercase;
  color: var(--text-muted);
}

.panel-note {
  font-size: var(--fs-nav);
  color: var(--text-faint);
}

.panel-link,
.inline-link {
  font-size: var(--fs-nav);
  color: var(--link);
  transition: color var(--transition);
}

.panel-link:hover,
.inline-link:hover {
  color: var(--link-hover);
}

.panel-body.padded {
  padding: 1.15rem;
}

/* ── Metric grid ── */

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
  gap: 0.625rem;
}

.metric-card {
  padding: 0.75rem 0.875rem;
  background: var(--metric-inner-bg);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  transition: border-color var(--transition), background var(--transition);
}

.metric-card:hover {
  border-color: var(--border);
  background: var(--card-hover);
}

.metric-label {
  display: block;
  font-size: 0.6667rem;
  font-weight: var(--fw-heading);
  letter-spacing: var(--letter-spacing-caps);
  text-transform: uppercase;
  color: var(--text-faint);
}

.metric-value {
  display: block;
  margin-top: 0.3rem;
  font-size: 1.0667rem;
  font-weight: 500;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.visual-card {
  min-height: 5rem;
  display: flex;
  align-items: flex-end;
  background: var(--visual-card-bg);
}

.visual-card .metric-value {
  font-size: var(--fs-nav);
  color: var(--text-faint);
}

/* ── Actions ── */

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.btn-action {
  padding: 0.4375rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  font-family: inherit;
  font-size: var(--fs-nav);
  font-weight: var(--fw-nav);
  color: var(--text-muted);
  cursor: not-allowed;
  opacity: 0.7;
}

/* ── Content blocks ── */

.content-block {
  margin-bottom: 1rem;
  padding: 1.15rem 1.25rem;
  background: var(--card);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
}

.content-block h3 {
  margin: 0 0 0.75rem;
  font-size: var(--fs-nav);
  font-weight: var(--fw-heading);
  letter-spacing: var(--letter-spacing-caps);
  text-transform: uppercase;
  color: var(--text-muted);
}

.feature-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(10.5rem, 1fr));
  gap: 0.3rem 1rem;
}

.feature-list li {
  font-size: var(--fs-nav);
  color: var(--text-muted);
  padding-left: 0.875rem;
  position: relative;
}

.feature-list li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.55em;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--border);
}

.placeholder-msg {
  margin: 0;
  font-size: var(--fs-body);
  color: var(--text-muted);
  line-height: 1.6;
}

.insight-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.insight-list li {
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--border-subtle);
  font-size: var(--fs-body);
  color: var(--text-secondary);
  line-height: 1.55;
}

.insight-list li:last-child {
  border-bottom: none;
}

.insight-list li::before {
  content: "—";
  margin-right: 0.5rem;
  color: var(--text-faint);
}

/* ── Tables ── */

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-nav);
}

th,
td {
  padding: 0.65rem 1.15rem;
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--border-subtle);
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--table-head-bg);
  font-size: 0.6667rem;
  font-weight: var(--fw-heading);
  letter-spacing: var(--letter-spacing-caps);
  text-transform: uppercase;
  color: var(--text-faint);
  white-space: nowrap;
}

tbody tr {
  transition: background var(--transition);
}

tbody tr:hover {
  background: var(--hover-bg);
}

tbody tr:last-child td {
  border-bottom: none;
}

td {
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

td:first-child,
td:nth-child(2),
td:nth-child(3) {
  color: var(--text);
  font-weight: 500;
}

.pnl-pos {
  font-weight: 600;
}

.pnl-neg {
  font-weight: 600;
}

:root .pnl-pos {
  color: var(--text);
}

:root .pnl-neg {
  color: var(--text-muted);
}

[data-theme="dark"] .pnl-pos {
  color: var(--success);
}

[data-theme="dark"] .pnl-neg {
  color: var(--danger);
}

code {
  display: inline-block;
  max-width: 10rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  background: var(--bg);
  border: 1px solid var(--border-subtle);
  font-family: var(--font-mono);
  font-size: 0.7333rem;
  color: var(--text-muted);
}

.empty {
  padding: 3rem 1.5rem;
  text-align: center;
  font-size: var(--fs-body);
  color: var(--text-muted);
}

.trades-sample-banner {
  margin: 0;
  padding: 0.65rem 1.15rem;
  font-size: var(--fs-nav);
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--accent-soft);
  border-bottom: 1px solid var(--border-subtle);
}

.source-badge {
  display: inline-block;
  padding: 0.125rem 0.45rem;
  border-radius: 4px;
  font-size: 0.6667rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.source-live {
  color: var(--text-muted);
  background: transparent;
}

.source-sample {
  color: var(--text-secondary);
  background: var(--accent-soft);
  border: 1px solid var(--border);
}

.source-replay {
  color: var(--text-muted);
  background: var(--metric-inner-bg);
  border: 1px solid var(--border-subtle);
}

.row-sample td {
  opacity: 0.92;
}

/* ── Server status ── */

.server-body {
  padding: 1rem 1.15rem 1.15rem;
}

.status-grid {
  margin: 0;
}

.status-row {
  display: grid;
  grid-template-columns: 9.5rem 1fr;
  gap: 1rem;
  align-items: baseline;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border-subtle);
  font-size: var(--fs-nav);
}

.status-row:last-child {
  border-bottom: none;
}

.status-row dt {
  margin: 0;
  font-size: 0.7333rem;
  font-weight: var(--fw-heading);
  letter-spacing: var(--letter-spacing-caps);
  text-transform: uppercase;
  color: var(--text-faint);
}

.status-row dd {
  margin: 0;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.status-ok {
  font-weight: 500;
  color: var(--text);
}

.status-ok::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 0.45rem;
  border-radius: 50%;
  background: var(--success);
  vertical-align: middle;
  position: relative;
  top: -1px;
}

/* ── Theme settings ── */

.theme-segment {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--metric-inner-bg);
  gap: 2px;
}

.theme-option {
  padding: 0.4375rem 0.875rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  font-family: inherit;
  font-size: var(--fs-nav);
  font-weight: var(--fw-nav);
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--transition), color var(--transition), box-shadow var(--transition);
}

.theme-option:hover {
  color: var(--text-secondary);
}

.theme-option.is-active {
  background: var(--card);
  color: var(--text);
  font-weight: 500;
  box-shadow: var(--shadow-sm);
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  padding: 0.25rem 0;
}

.setting-label {
  font-size: var(--fs-body);
  color: var(--text-secondary);
}

.setting-hint {
  margin: 0.25rem 0 0;
  font-size: var(--fs-nav);
  color: var(--text-faint);
}

/* ── Responsive ── */

@media (max-width: 960px) {
  .app-frame {
    grid-template-columns: 1fr;
  }

  .app-sidebar {
    position: static;
    height: auto;
    max-height: none;
  }

  .sidebar-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    padding: 1rem;
  }

  .nav-group {
    flex: 1 1 10rem;
    margin-top: 0 !important;
  }

  .top-bar {
    grid-template-columns: 1fr auto;
    padding: 0 1rem;
  }

  .top-bar-center {
    display: none;
  }

  .app-content {
    padding: 1.25rem 1rem 2rem;
  }
}

@media (max-width: 640px) {
  .view-header h1 {
    font-size: 1.4667rem;
  }
}
