/* ─── Fonts ──────────────────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ─── Design tokens — OptionGig brand ───────────────────────────────────────── */
:root {
  --tthf-bg:          #f4f6f8;
  --tthf-surface:     #ffffff;
  --tthf-surface-2:   #f4f6f8;
  --tthf-surface-3:   #e8edf2;
  --tthf-border:      #dde3e8;
  --tthf-border-2:    #bcc8d4;
  --tthf-text:        #232323;
  --tthf-text-2:      #556070;
  --tthf-text-3:      #8a99a8;
  --tthf-accent:      #39c8df;
  --tthf-accent-dim:  rgba(57,200,223,0.12);
  --tthf-accent-2:    #2e9fff;
  --tthf-up:          #1a9e5e;
  --tthf-up-bg:       rgba(26,158,94,0.10);
  --tthf-down:        #d63c3c;
  --tthf-down-bg:     rgba(214,60,60,0.10);
  --tthf-new:         #1a9e5e;
  --tthf-new-bg:      rgba(26,158,94,0.08);
  --tthf-sold:        #d63c3c;
  --tthf-sold-bg:     rgba(214,60,60,0.08);
  --tthf-mono:        'SFMono-Regular', Consolas, monospace;
  --tthf-sans:        'Inter', -apple-system, sans-serif;
  --tthf-radius:      6px;
  --tthf-radius-lg:   8px;
  --tthf-shadow:      0 1px 4px rgba(52,82,111,0.08);
  --tthf-transition:  0.15s ease;
  --tthf-navy:        #34526f;
  --tthf-navy-dark:   #243a50;
}

/* ─── App shell ──────────────────────────────────────────────────────────────── */
.tthf-app {
  font-family: var(--tthf-sans);
  background: var(--tthf-bg);
  color: var(--tthf-text);
  border-radius: 0;
  overflow: visible;
  min-height: 400px;
  width: 100%;
  position: relative;
  border: none;
  box-shadow: none;
}

/* ─── Theme tabs ─────────────────────────────────────────────────────────────── */
.tthf-theme-nav {
  display: flex;
  gap: 0;
  padding: 0 1.2rem;
  background: var(--tthf-surface);
  border-bottom: 2px solid var(--tthf-border);
  overflow-x: auto;
  scrollbar-width: none;
}
.tthf-theme-nav::-webkit-scrollbar { display: none; }

.tthf-tab {
  font-family: var(--tthf-sans);
  font-size: 0.94rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--tthf-text-3);
  padding: 0.85rem 1.2rem;
  border: none;
  background: transparent;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  transition: color var(--tthf-transition), border-color var(--tthf-transition);
}
.tthf-tab:hover { color: var(--tthf-navy); }
.tthf-tab.active {
  color: #2aafca;
  border-bottom-color: var(--tthf-accent);
}
.tthf-tab.active::after { display: none; }
.tthf-tab.locked {
  color: var(--tthf-text-3);
  cursor: not-allowed;
  opacity: 0.5;
}
.tthf-tab.locked::before {
  content: '⚿';
  margin-right: 5px;
  font-size: 10px;
}

/* ─── Pivot toolbar ──────────────────────────────────────────────────────────── */
.tthf-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--tthf-surface);
  border-bottom: 1px solid var(--tthf-border);
  flex-wrap: wrap;
}
.tthf-toolbar-label {
  font-size: 0.94rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--tthf-text-3);
}
.tthf-select {
  font-family: var(--tthf-sans);
  font-size: 0.94rem;
  font-weight: 400;
  color: var(--tthf-text);
  background: var(--tthf-surface);
  border: 1px solid var(--tthf-border);
  border-radius: var(--tthf-radius);
  padding: 6px 28px 6px 10px;
  cursor: pointer;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238a99a8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  min-width: 140px;
  transition: border-color var(--tthf-transition);
}
.tthf-select:hover { border-color: var(--tthf-border-2); }
.tthf-select:focus { border-color: var(--tthf-accent); outline: none; }
.tthf-select option { background: var(--tthf-surface); }

.tthf-toolbar-sep {
  width: 1px;
  height: 20px;
  background: var(--tthf-border);
  margin: 0 2px;
}

.tthf-search {
  font-family: var(--tthf-sans);
  font-size: 0.94rem;
  color: var(--tthf-text);
  background: var(--tthf-surface);
  border: 1px solid var(--tthf-border);
  border-radius: var(--tthf-radius);
  padding: 6px 10px 6px 32px;
  outline: none;
  transition: border-color var(--tthf-transition);
  min-width: 200px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' fill='none' stroke='%238a99a8' stroke-width='2'%3E%3Ccircle cx='6' cy='6' r='4'/%3E%3Cpath d='M9.5 9.5l3 3'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 10px center;
}
.tthf-search::placeholder { color: var(--tthf-text-3); }
.tthf-search:focus { border-color: var(--tthf-accent); }

.tthf-btn {
  font-family: var(--tthf-sans);
  font-size: 0.94rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 6px 14px;
  border-radius: var(--tthf-radius);
  border: 1px solid var(--tthf-border);
  background: transparent;
  color: var(--tthf-text-2);
  cursor: pointer;
  transition: all var(--tthf-transition);
  white-space: nowrap;
}
.tthf-btn:hover { border-color: var(--tthf-border-2); color: var(--tthf-navy); background: var(--tthf-surface-2); }
.tthf-btn.active { background: rgba(57,200,223,0.08); color: #2aafca; border-color: var(--tthf-accent); }

.tthf-filter-pills { display: flex; gap: 4px; flex-wrap: wrap; }
.tthf-pill {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 4px;
  border: 1px solid var(--tthf-border);
  cursor: pointer;
  transition: all var(--tthf-transition);
  background: var(--tthf-surface);
  color: var(--tthf-text-3);
  letter-spacing: 0.03em;
}
.tthf-pill:hover { color: var(--tthf-text-2); border-color: var(--tthf-border-2); }
.tthf-pill.all.active      { background: var(--tthf-surface-3); color: var(--tthf-text); border-color: var(--tthf-border-2); }
.tthf-pill.new.active      { background: var(--tthf-new-bg);  color: var(--tthf-new);  border-color: rgba(26,158,94,0.3); }
.tthf-pill.increased.active{ background: var(--tthf-up-bg);   color: var(--tthf-up);   border-color: rgba(26,158,94,0.3); }
.tthf-pill.decreased.active{ background: var(--tthf-down-bg); color: var(--tthf-down); border-color: rgba(214,60,60,0.3); }
.tthf-pill.sold.active     { background: var(--tthf-sold-bg); color: var(--tthf-sold); border-color: rgba(214,60,60,0.3); }
.tthf-pill.unchanged.active{ background: var(--tthf-surface-3); color: var(--tthf-text-2); border-color: var(--tthf-border-2); }

/* ─── Summary bar ────────────────────────────────────────────────────────────── */
.tthf-summary {
  display: flex;
  border-bottom: 1px solid var(--tthf-border);
  background: var(--tthf-surface);
  overflow-x: auto;
  scrollbar-width: none;
}
.tthf-summary::-webkit-scrollbar { display: none; }
.tthf-stat {
  padding: 10px 18px;
  border-right: 1px solid var(--tthf-border);
  white-space: nowrap;
  flex-shrink: 0;
}
.tthf-stat:last-child { border-right: none; }
.tthf-stat-label {
  font-size: 0.94rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--tthf-text-3);
  margin-bottom: 3px;
}
.tthf-stat-value {
  font-family: var(--tthf-mono);
  font-size: 0.94rem;
  font-weight: 600;
  color: var(--tthf-navy);
}
.tthf-stat-value.up   { color: var(--tthf-up); }
.tthf-stat-value.down { color: var(--tthf-down); }

/* ─── Data table ─────────────────────────────────────────────────────────────── */
.tthf-table-wrap {
  overflow-x: auto;
  overflow-y: visible;
  scrollbar-width: thin;
  scrollbar-color: var(--tthf-border-2) transparent;
}
.tthf-table-wrap::-webkit-scrollbar { width: 6px; height: 6px; }
.tthf-table-wrap::-webkit-scrollbar-track { background: transparent; }
.tthf-table-wrap::-webkit-scrollbar-thumb { background: var(--tthf-border-2); border-radius: 3px; }

.tthf-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.94rem;
}
.tthf-table thead {
  position: sticky;
  top: 0;
  z-index: 2;
}
.tthf-table th {
  font-family: var(--tthf-sans);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #ffffff !important;
  background: var(--tthf-navy) !important;
  padding: 4px 6px;
  text-align: left;
  border-bottom: none;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
.tthf-table th:hover { color: #ffffff !important; background: var(--tthf-navy-dark) !important; }
.tthf-table th.sorted { color: var(--tthf-accent) !important; }
.tthf-table th .sort-icon { margin-left: 4px; opacity: 0.5; font-style: normal; }
.tthf-table th.sorted .sort-icon { opacity: 1; }
.tthf-table th.num,
.tthf-table td.num { text-align: right; }

.tthf-table tbody tr {
  border-bottom: 1px solid var(--tthf-border);
  transition: background var(--tthf-transition);
  animation: tthf-row-in 0.15s ease both;
}
.tthf-table tbody tr:nth-child(even) td { background: #f9fbfc; }
.tthf-table tbody tr:hover td { background: rgba(57,200,223,0.06) !important; }

@keyframes tthf-row-in {
  from { opacity: 0; transform: translateY(3px); }
  to   { opacity: 1; transform: translateY(0); }
}

.tthf-table td {
  padding: 3px 6px;
  color: var(--tthf-text);
  font-family: var(--tthf-sans);
  vertical-align: middle;
  background: var(--tthf-surface);
}
.tthf-table td.mono {
  font-family: var(--tthf-mono);
  font-size: 0.94rem;
}
.tthf-table td.primary { color: var(--tthf-navy); font-weight: 600; }
.tthf-table td.accent  { color: #2aafca; }

/* ─── Change type badges ─────────────────────────────────────────────────────── */
.tthf-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--tthf-sans);
  font-size: 0.94rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 4px;
  border: 1px solid;
  white-space: nowrap;
}
.tthf-badge.new       { background: var(--tthf-new-bg);  color: var(--tthf-new);  border-color: rgba(26,158,94,0.25); }
.tthf-badge.increased { background: var(--tthf-up-bg);   color: var(--tthf-up);   border-color: rgba(26,158,94,0.25); }
.tthf-badge.decreased { background: var(--tthf-down-bg); color: var(--tthf-down); border-color: rgba(214,60,60,0.25); }
.tthf-badge.sold      { background: var(--tthf-sold-bg); color: var(--tthf-sold); border-color: rgba(214,60,60,0.25); }
.tthf-badge.unchanged { background: var(--tthf-surface-3); color: var(--tthf-text-3); border-color: var(--tthf-border); }

/* ─── Delta cells ────────────────────────────────────────────────────────────── */
.tthf-delta { font-family: var(--tthf-mono); font-size: 0.94rem; }
.tthf-delta.pos  { color: var(--tthf-up); font-weight: 600; }
.tthf-delta.neg  { color: var(--tthf-down); font-weight: 600; }
.tthf-delta.zero { color: var(--tthf-text-3); }

/* ─── Bar chart (inline value bars) ─────────────────────────────────────────── */
.tthf-bar-cell { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.tthf-bar-track {
  width: 80px; height: 4px;
  background: var(--tthf-surface-3);
  border-radius: 2px;
  overflow: hidden;
  flex-shrink: 0;
}
.tthf-bar-fill {
  height: 100%;
  background: var(--tthf-accent);
  border-radius: 2px;
  transition: width 0.4s ease;
}

/* ─── Chart panel ────────────────────────────────────────────────────────────── */
.tthf-chart-panel {
  padding: 20px 24px;
  border-top: 1px solid var(--tthf-border);
  background: var(--tthf-surface);
}
.tthf-chart-panel canvas { max-height: 420px; }

/* ─── State screens ──────────────────────────────────────────────────────────── */
.tthf-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  color: var(--tthf-text-3);
  gap: 12px;
  font-size: 14px;
  background: var(--tthf-surface);
}
.tthf-state-icon { font-size: 32px; opacity: 0.3; }
.tthf-spinner {
  width: 24px; height: 24px;
  border: 2px solid var(--tthf-border);
  border-top-color: var(--tthf-accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.tthf-empty-label { color: var(--tthf-text-3); font-size: 0.94rem; }

/* ─── Upgrade notice ─────────────────────────────────────────────────────────── */
.tthf-upgrade-notice {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  gap: 16px;
  padding: 32px;
  text-align: center;
  background: var(--tthf-surface);
}
.tthf-upgrade-notice p { color: var(--tthf-text-2); font-size: 14px; }
.tthf-btn--upgrade {
  display: inline-block;
  background: #1a1a2e;
  color: #fff;
  font-family: var(--tthf-sans);
  font-weight: 600;
  font-size: 0.94rem;
  padding: 10px 24px;
  border-radius: var(--tthf-radius);
  text-decoration: none;
  transition: background var(--tthf-transition);
}
.tthf-btn--upgrade:hover { background: var(--tthf-navy-dark); color: #fff; }

/* ─── Autocomplete suggestions ───────────────────────────────────────────────── */
.tthf-suggest-item:hover { background: rgba(57,200,223,0.06); }
.tthf-suggest-item:last-child { border-bottom: none !important; }

/* ─── Manager name ───────────────────────────────────────────────────────────── */
.tthf-manager {
  font-weight: 400;
  color: var(--tthf-text-3);
  font-size: 0.94rem;
  display: block;
  margin-top: 1px;
}

/* ─── Pagination ─────────────────────────────────────────────────────────────── */
.tthf-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-top: 1px solid var(--tthf-border);
  background: var(--tthf-surface);
  font-size: 11px;
  color: var(--tthf-text-3);
}
.tthf-page-btns { display: flex; gap: 4px; }
.tthf-page-btn {
  font-family: var(--tthf-mono);
  font-size: 11px;
  padding: 3px 9px;
  border-radius: var(--tthf-radius);
  border: 1px solid var(--tthf-border);
  background: var(--tthf-surface);
  color: var(--tthf-text-2);
  cursor: pointer;
  transition: all var(--tthf-transition);
}
.tthf-page-btn:hover:not(:disabled) { border-color: var(--tthf-navy); color: var(--tthf-navy); }
.tthf-page-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.tthf-page-btn.current { background: var(--tthf-navy); color: #fff; border-color: var(--tthf-navy); }

/* ─── Multi-period QoQ table ─────────────────────────────────────────────────── */
/* Sticky first two columns (Security + Ticker) so they stay visible on horizontal scroll */
.tthf-mp-table th:nth-child(1),
.tthf-mp-table td:nth-child(1) {
  position: sticky;
  left: 0;
  z-index: 3;
  background: var(--tthf-surface);
}
.tthf-mp-table th:nth-child(1) {
  background: var(--tthf-navy) !important;
  z-index: 4;
}
.tthf-mp-table th:nth-child(2),
.tthf-mp-table td:nth-child(2) {
  position: sticky;
  left: 200px; /* matches min-width of col 1 */
  z-index: 3;
  background: var(--tthf-surface);
  border-right: 2px solid var(--tthf-border-2);
}
.tthf-mp-table th:nth-child(2) {
  background: var(--tthf-navy) !important;
  z-index: 4;
  border-right: 2px solid rgba(255,255,255,0.2);
}
.tthf-mp-table tbody tr:nth-child(even) td:nth-child(1),
.tthf-mp-table tbody tr:nth-child(even) td:nth-child(2) {
  background: #f9fbfc;
}
.tthf-mp-table tbody tr:hover td:nth-child(1),
.tthf-mp-table tbody tr:hover td:nth-child(2) {
  background: rgba(57,200,223,0.06) !important;
}


/* ── QoQ row selection & chart ────────────────────────────────────────────── */
.tthf-mp-table tbody tr[data-row-key] {
  cursor: pointer;
  transition: background 0.15s;
}
.tthf-mp-table tbody tr[data-row-key]:hover {
  background: rgba(57, 200, 223, 0.06);
}
#tthf-qoq-chart-area {
  animation: tthf-fadein 0.25s ease;
}

/* ── QoQ inline chart button ──────────────────────────────────────────────── */
.tthf-qoq-chart-btn:hover {
  background: rgba(0,200,150,0.15) !important;
}
.tthf-qoq-inline-panel td {
  padding: 0 !important;
}

/* ── QoQ sticky columns ───────────────────────────────────────────────────── */
.tthf-mp-table thead th:nth-child(1),
.tthf-mp-table thead th:nth-child(2) {
  position: sticky;
  z-index: 3;
}
/* Fix overlap: override inline background:inherit with solid colours */
.tthf-mp-table tbody td:nth-child(1),
.tthf-mp-table tbody td:nth-child(2) {
  position: sticky;
  z-index: 2;
  background: #ffffff !important;
}
.tthf-mp-table tbody tr:nth-child(even) td:nth-child(1),
.tthf-mp-table tbody tr:nth-child(even) td:nth-child(2) {
  background: #f9fbfc !important;
}
.tthf-mp-table tbody tr:hover td:nth-child(1),
.tthf-mp-table tbody tr:hover td:nth-child(2) {
  background: #edf9fb !important;
}

/* ── Top scrollbar mirror ─────────────────────────────────────────────────── */
.tthf-scroll-mirror {
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--tthf-border-2) transparent;
  border-bottom: 1px solid var(--tthf-border);
}
.tthf-scroll-mirror::-webkit-scrollbar { height: 6px; }
.tthf-scroll-mirror::-webkit-scrollbar-track { background: transparent; }
.tthf-scroll-mirror::-webkit-scrollbar-thumb { background: var(--tthf-border-2); border-radius: 3px; }
.tthf-scroll-mirror-inner { height: 1px; }
