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

  :root {
    --excel-green: #1d6f42;
    --excel-green-dark: #14512f;
    --grid-line: #d0d4d1;
    --grid-line-strong: #b7bcb8;
    --header-bg: #f3f4f2;
    --row-alt: #f7f8f7;
    --text-main: #1f2421;
    --text-sub: #5c635e;
    --score-high-bg: #ceead6;
    --score-high-text: #0d652d;
    --score-mid-bg: #fef0c7;
    --score-mid-text: #8a6100;
    --score-low-bg: #fce8e6;
    --score-low-text: #a33b2c;
  }

  body {
    font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--text-main);
    background: #ffffff;
    font-size: 13px;
    line-height: 1.4;
  }

  .app {
    max-width: 1100px;
    margin: 0 auto;
    border: 1px solid var(--grid-line-strong);
  }

  /* ── View switch ────────────────────── */
  .view-switch {
    display: flex;
    background: var(--excel-green-dark);
  }
  .view-switch-btn {
    padding: 8px 10px;
    font-size: 12.5px;
    font-weight: 600;
    border: none;
    background: transparent;
    color: #cfe3d6;
    cursor: pointer;
    white-space: nowrap;
  }
  .view-switch-btn:hover { background: rgba(255,255,255,0.08); }
  .view-switch-btn.active {
    background: var(--excel-green);
    color: #ffffff;
  }

  /* ── Toolbar ─────────────────────────── */
  .toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: var(--header-bg);
    border-bottom: 1px solid var(--grid-line-strong);
    flex-wrap: wrap;
  }

  .toolbar-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    font-size: 12px;
    font-weight: 600;
    border: 1px solid var(--grid-line-strong);
    background: #ffffff;
    color: var(--text-main);
    border-radius: 3px;
    cursor: pointer;
    white-space: nowrap;
  }

  .toolbar-btn:hover:not(:disabled) { background: #eef1ef; }
  .toolbar-btn:active:not(:disabled) { background: #e4e8e5; }
  .toolbar-btn:disabled { opacity: 0.5; cursor: not-allowed; }

  .toolbar-btn.primary {
    background: var(--excel-green);
    border-color: var(--excel-green-dark);
    color: #ffffff;
  }
  .toolbar-btn.primary:hover:not(:disabled) { background: var(--excel-green-dark); }

  .toolbar-sep {
    width: 1px;
    align-self: stretch;
    background: var(--grid-line-strong);
    margin: 0 2px;
  }

  .toolbar-status {
    font-size: 11.5px;
    color: var(--text-sub);
    margin-left: auto;
    white-space: nowrap;
  }
  .toolbar-status.err { color: #a33b2c; font-weight: 600; }
  .toolbar-status.ok { color: var(--excel-green-dark); font-weight: 600; }

  .spinner {
    width: 11px; height: 11px;
    border: 2px solid var(--grid-line-strong);
    border-top-color: var(--excel-green);
    border-radius: 50%;
    display: inline-block;
    animation: spin 0.7s linear infinite;
    vertical-align: -1px;
  }
  @keyframes spin { to { transform: rotate(360deg); } }

  /* ── Stats strip ─────────────────────── */
  .stats-strip {
    display: none;
    grid-template-columns: repeat(4, 1fr);
    border-bottom: 1px solid var(--grid-line-strong);
  }
  .stat-cell {
    padding: 6px 10px;
    border-right: 1px solid var(--grid-line);
    text-align: center;
  }
  .stat-cell:last-child { border-right: none; }
  .stat-cell .v { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
  .stat-cell .l { font-size: 10.5px; color: var(--text-sub); }

  /* ── Tabs ─────────────────────────────── */
  .tabs-wrap-outer { position: relative; display: none; }
  .tabs {
    overflow-x: auto;
    background: var(--header-bg);
    border-bottom: 1px solid var(--grid-line-strong);
    scrollbar-width: thin;
    scrollbar-color: var(--excel-green) var(--grid-line);
  }
  .tabs::-webkit-scrollbar { height: 7px; }
  .tabs::-webkit-scrollbar-thumb { background: var(--excel-green); border-radius: 4px; }
  .tabs::-webkit-scrollbar-track { background: var(--grid-line); }
  .tabs-fade-left, .tabs-fade-right {
    position: absolute;
    top: 0;
    bottom: 7px;
    width: 28px;
    pointer-events: none;
    z-index: 2;
    opacity: 0;
    transition: opacity 0.15s;
  }
  .tabs-fade-left {
    left: 0;
    background: linear-gradient(to right, var(--header-bg), transparent);
  }
  .tabs-fade-right {
    right: 0;
    background: linear-gradient(to left, var(--header-bg), transparent);
  }
  .tabs-wrap-outer.show-left .tabs-fade-left { opacity: 1; }
  .tabs-wrap-outer.show-right .tabs-fade-right { opacity: 1; }
  .tab-row { display: flex; }
  .tab-btn {
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-sub);
    background: transparent;
    border: none;
    border-right: 1px solid var(--grid-line);
    border-bottom: 2px solid transparent;
    cursor: pointer;
    white-space: nowrap;
  }
  .tab-btn:hover { background: #eaece9; }
  .tab-btn.active {
    color: var(--excel-green-dark);
    font-weight: 700;
    border-bottom: 2px solid var(--excel-green);
    background: #ffffff;
  }
  .tab-count {
    color: var(--text-sub);
    font-weight: 400;
    font-size: 10.5px;
  }

  /* ── Market ticker ─────────────────────── */
  .market-ticker {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    padding: 6px 10px;
    background: #fafbfa;
    border-bottom: 1px solid var(--grid-line-strong);
    font-size: 12px;
  }
  .ticker-index {
    display: flex;
    align-items: baseline;
    gap: 6px;
    font-weight: 700;
  }
  .ticker-index .label { font-size: 11px; font-weight: 500; color: var(--text-sub); }
  .ticker-index .value { font-size: 15px; font-variant-numeric: tabular-nums; }
  .ticker-index .delta { font-size: 12px; font-variant-numeric: tabular-nums; }
  .ticker-breadth {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-sub);
    font-variant-numeric: tabular-nums;
  }
  .ticker-breadth b { font-weight: 700; }
  .external-link {
    margin-left: auto;
    font-size: 12px;
    color: var(--excel-green-dark);
    text-decoration: none;
    font-weight: 600;
    white-space: nowrap;
  }
  .external-link:hover { text-decoration: underline; }

  /* ── Table ────────────────────────────── */
  .grid-wrap {
    display: none;
    overflow-x: auto;
    overflow-y: auto;
    max-height: 68vh;
  }
  table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
  }
  thead th {
    position: sticky;
    top: 0;
    background: var(--header-bg);
    border: 1px solid var(--grid-line-strong);
    padding: 5px 8px;
    text-align: left;
    font-weight: 600;
    color: var(--text-main);
    white-space: nowrap;
  }
  th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
  tbody td {
    border: 1px solid var(--grid-line);
    padding: 4px 8px;
    white-space: nowrap;
  }
  tbody tr:nth-child(even) { background: var(--row-alt); }
  tbody tr:hover { background: #eaf3ee; cursor: pointer; }
  tbody tr.row-selected {
    background: #fff3cd !important;
    box-shadow: inset 3px 0 0 var(--excel-green);
  }
  tbody tr.row-selected:hover { background: #fdecb0 !important; }

  .code-badge {
    font-family: "SF Mono", Consolas, monospace;
    font-size: 11px;
    color: var(--text-sub);
  }
  .margin-link {
    text-decoration: none;
    font-size: 11px;
    opacity: 0.55;
  }
  .margin-link:hover { opacity: 1; }
  .star-toggle {
    cursor: pointer;
    font-size: 13px;
    color: #c98a1f;
    user-select: none;
  }
  .star-toggle:hover { opacity: 0.7; }

  .score-pill {
    display: inline-block;
    min-width: 26px;
    padding: 1px 6px;
    border-radius: 3px;
    font-weight: 700;
    text-align: center;
  }
  .score-high { background: var(--score-high-bg); color: var(--score-high-text); }
  .score-mid  { background: var(--score-mid-bg);  color: var(--score-mid-text); }
  .score-low  { background: var(--score-low-bg);  color: var(--score-low-text); }

  .eval-tag { font-size: 11px; color: var(--text-sub); }
  .eval-tag.hit { color: var(--score-high-text); font-weight: 600; }
  .eval-tag.muted { color: #999; font-style: italic; }

  .chg-up { color: var(--score-low-text); }
  .chg-down { color: var(--score-high-text); }

  .empty-state {
    padding: 28px 12px;
    text-align: center;
    color: var(--text-sub);
    font-size: 12.5px;
  }

  /* ── Compare FAB & Modal ──────────────── */
  #compareFab {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 60;
    display: flex;
    align-items: center;
    gap: 8px;
    background: #ffffff;
    padding: 8px;
    border-radius: 24px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  }
  #compareFabStatus {
    font-size: 11px;
    color: var(--score-low-text);
    font-weight: 600;
  }
  #compareModalOverlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 70;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
  }
  #compareModal {
    background: #ffffff;
    border-radius: 8px;
    max-width: 520px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    padding: 16px;
  }
  .compare-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-main);
  }
