:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-2: #f0f4f2;
  --border: #d8ded8;
  --text: #17201b;
  --muted: #66736c;
  --muted-2: #8a968f;
  --green: #0b8f62;
  --green-soft: #dff3ea;
  --red: #c5403c;
  --red-soft: #f7e1df;
  --blue: #1e68b2;
  --blue-soft: #e0edf9;
  --amber: #a86400;
  --amber-soft: #f6ead6;
  --ink-soft: #e8ece8;
  --shadow: 0 10px 30px rgba(24, 32, 27, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
}

button,
input {
  font: inherit;
}

.shell {
  width: min(1680px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 18px 0 32px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #18372b;
  color: #ffffff;
  font-weight: 800;
  font-size: 14px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.language-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  user-select: none;
}

.language-switch select {
  border: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  outline: none;
  pointer-events: none;
}

.language-switch:focus-within,
.language-switch:focus-visible {
  border-color: #9fb5aa;
  box-shadow: 0 0 0 3px rgba(11, 143, 98, 0.12);
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(20px, 2vw, 28px);
  line-height: 1.1;
}

h2 {
  font-size: 16px;
  line-height: 1.2;
}

.subtitle,
.panel-heading span,
.metric-sub,
.muted {
  color: var(--muted);
}

.subtitle {
  margin-top: 3px;
  font-size: 13px;
}

.segmented {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.chart-title-block {
  display: flex;
  min-width: 0;
  flex-direction: column;
  align-items: flex-start;
  gap: 7px;
}

.chart-title-row {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 12px;
}

.chart-session-tabs {
  flex: 0 0 auto;
}

.chart-session-tabs.hidden {
  visibility: hidden;
  pointer-events: none;
}

.segment:hover {
  background: var(--surface-2);
}

.status-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.status-item {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  gap: 7px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font-size: 13px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted-2);
}

.status-dot.ok {
  background: var(--green);
}

.status-dot.warn {
  background: var(--amber);
}

.status-dot.bad {
  background: var(--red);
}

.dashboard-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(420px, 28vw, 500px);
  gap: 12px;
}

.kpi-grid {
  display: grid;
  grid-column: 1;
  grid-template-columns: 1.35fr 1fr 1fr;
  gap: 12px;
}

.metric {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric.primary {
  background: #ffffff;
}

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

.metric strong {
  display: block;
  margin: 8px 0 4px;
  font-size: clamp(22px, 3vw, 34px);
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.metric:not(.primary) strong {
  font-size: clamp(20px, 2.3vw, 28px);
}

.metric-sub {
  display: block;
  min-height: 18px;
  font-size: 13px;
}

.up {
  color: var(--green);
}

.down {
  color: var(--red);
}

.workspace {
  display: contents;
}

.chart-panel,
.side-panel,
.holdings-panel {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.chart-panel {
  grid-column: 1;
}

.side-panel {
  grid-column: 2;
  grid-row: 1 / span 2;
}

.holdings-panel {
  grid-column: 1 / -1;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.panel-heading.compact {
  padding-bottom: 12px;
}

.panel-heading span {
  display: block;
  margin-top: 4px;
  font-size: 12px;
}

.segment {
  min-width: 54px;
  height: 30px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}

.segment.active {
  color: #ffffff;
  background: #18372b;
}

.chart-wrap {
  position: relative;
  height: min(58vh, 560px);
  min-height: 380px;
}

#navChart {
  width: 100%;
  height: 100%;
  display: block;
}

.chart-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 10px;
  background: rgba(255, 255, 255, 0.58);
  color: var(--muted);
  pointer-events: none;
}

.chart-empty.is-loading::before {
  content: "";
  width: 26px;
  height: 26px;
  border: 3px solid rgba(216, 222, 216, 0.95);
  border-top-color: #18372b;
  border-radius: 50%;
  animation: chart-loading-spin 0.85s linear infinite;
}

.chart-empty.hidden {
  display: none;
}

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

.chart-tooltip {
  position: absolute;
  display: none;
  min-width: 174px;
  padding: 8px 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 8px 22px rgba(24, 32, 27, 0.12);
  color: var(--text);
  font-size: 12px;
  pointer-events: none;
  z-index: 5;
}

.side-panel {
  display: flex;
  flex-direction: column;
  min-height: 380px;
}

.holding-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 10px;
}

.holding-card {
  border-bottom: 1px solid var(--ink-soft);
  padding: 8px 8px 9px;
}

.holding-card:last-child {
  border-bottom: 0;
}

.holding-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 7px;
}

.holding-title {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 9px;
}

.holding-title .holding-session {
  flex: 0 0 auto;
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
}

.holding-logo {
  position: relative;
  display: inline-grid;
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: linear-gradient(135deg, #f8faf7, #edf3ee);
  color: var(--green);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: -0.04em;
}

.holding-logo-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 4px;
  background: #ffffff;
  object-fit: contain;
}

.holding-card-head strong {
  color: var(--text);
  font-size: 15px;
  font-weight: 800;
}

.holding-card-head span {
  color: var(--muted);
  font-size: 12px;
}

.holding-card-head .holding-session-pct {
  flex: 0 0 auto;
  color: var(--text);
  font-size: 17px;
  font-variant-numeric: tabular-nums;
  font-weight: 850;
  line-height: 1;
  white-space: nowrap;
}

.holding-card-head .holding-session-pct.up {
  color: var(--green);
}

.holding-card-head .holding-session-pct.down {
  color: var(--red);
}

.holding-metrics {
  display: grid;
  grid-template-columns: minmax(96px, 0.8fr) minmax(220px, 1.5fr);
  gap: 8px 12px;
}

.holding-metrics div {
  display: flex;
  min-height: 20px;
  min-width: 0;
  align-items: baseline;
  gap: 6px;
}

.holding-metrics span {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 11px;
}

.holding-metrics strong {
  display: inline-block;
  min-width: 0;
  color: var(--text);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.empty-card {
  padding: 18px 8px;
  color: var(--muted);
  text-align: center;
}

.trade-list {
  overflow: auto;
  padding: 8px;
}

.trade-list.bottom {
  max-height: 34vh;
}

.trade-item {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 10px 8px;
  border-bottom: 1px solid var(--ink-soft);
  font-size: 13px;
}

.trade-item:last-child {
  border-bottom: 0;
}

.trade-side {
  display: inline-flex;
  justify-content: center;
  padding: 4px 6px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 12px;
}

.trade-side.buy {
  color: var(--green);
  background: var(--green-soft);
}

.trade-side.sell {
  color: var(--red);
  background: var(--red-soft);
}

.trade-side.trade {
  color: var(--muted);
  background: var(--ink-soft);
}

.trade-main {
  min-width: 0;
}

.trade-main strong,
.trade-main span {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.trade-main span,
.trade-time {
  color: var(--muted);
  font-size: 12px;
}

.trade-main .trade-pnl.up {
  color: var(--green);
}

.trade-main .trade-pnl.down {
  color: var(--red);
}

.holding-metrics strong.up {
  color: var(--green);
}

.holding-metrics strong.down {
  color: var(--red);
}

.holdings-panel {
  overflow: hidden;
}

.filter-input {
  width: min(220px, 45vw);
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  background: #ffffff;
}

.filter-input.compact {
  width: 88px;
  height: 30px;
}

.filter-input:focus {
  border-color: var(--blue);
}

.table-wrap {
  overflow: auto;
  max-height: 42vh;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  padding: 11px 16px;
  border-bottom: 1px solid var(--ink-soft);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--muted);
  background: #fbfcfb;
  font-weight: 700;
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.symbol-cell {
  font-weight: 800;
}

.data-badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 3px 7px;
  border-radius: 6px;
  color: var(--blue);
  background: var(--blue-soft);
  font-size: 12px;
}

.session-badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 3px 7px;
  border-radius: 6px;
  color: var(--amber);
  background: var(--amber-soft);
  font-size: 12px;
}

.empty-row {
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1100px) {
  .dashboard-layout {
    grid-template-columns: 1fr;
  }

  .kpi-grid {
    grid-column: 1;
    grid-template-columns: 1fr 1fr;
  }

  .chart-panel,
  .side-panel,
  .holdings-panel {
    grid-column: 1;
  }

  .side-panel {
    grid-row: auto;
    min-height: 240px;
  }
}

@media (max-width: 760px) {
  .shell {
    width: min(100vw - 16px, 1680px);
    padding-top: 10px;
  }

  .topbar,
  .panel-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions,
  .language-switch {
    width: 100%;
  }

  .top-actions {
    margin-left: 0;
  }

  .language-switch {
    justify-content: space-between;
  }

  .segmented {
    width: 100%;
  }

  .chart-title-row {
    width: 100%;
    align-items: flex-start;
    flex-direction: column;
  }

  .segment {
    flex: 1;
  }

  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .chart-wrap {
    height: 420px;
    min-height: 340px;
  }

  .metric strong {
    font-size: 24px;
  }

  th,
  td {
    padding: 10px 12px;
  }
}
