/* ==========================================================================
   Market Neuron — v2 design system
   Single shared stylesheet (replaces per-page inline <style> blocks)
   ========================================================================== */

:root {
  --brand-900: #142c56;
  --brand-800: #1e3c72;
  --brand-700: #2a5298;
  --brand-100: #eaf1fb;
  --brand-50:  #f6fbff;

  --accent-green: #16a34a;
  --accent-green-dark: #0a6b0a;
  --accent-red: #dc2626;
  --accent-red-dark: #a30000;

  --ink-900: #0f172a;
  --ink-700: #334155;
  --ink-500: #64748b;
  --ink-300: #cbd5e1;
  --ink-100: #e9ecef;

  --surface: #ffffff;
  --surface-muted: #f4f6f9;
  --page-bg: #f2f5f9;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 6px 20px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 20px 45px rgba(15, 23, 42, 0.10);

  --gradient-brand: linear-gradient(135deg, var(--brand-800) 0%, var(--brand-700) 100%);
  --gradient-green: linear-gradient(135deg, #16a34a 0%, #22c55e 100%);

  --container-max: 1280px;
  --font-body: "Inter", "GD Sherpa Regular", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

/* ---------- Reset / base ---------- */

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink-900);
  background: var(--page-bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0 0 0.5em; line-height: 1.25; font-weight: 700; color: var(--ink-900); }
h1 { font-size: 1.9rem; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 0.75em; color: var(--ink-700); }

ul { list-style: none; margin: 0; padding: 0; }

a {
  color: var(--brand-700);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

img { max-width: 100%; display: block; }

.container {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 20px;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Skip link for keyboard/screen-reader users */
.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--brand-900);
  color: #fff;
  padding: 10px 16px;
  z-index: 2000;
  border-radius: 0 0 8px 0;
}
.skip-link:focus {
  left: 0;
}

/* ---------- Header ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: var(--gradient-brand);
  box-shadow: var(--shadow-sm);
}

.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 8px;
  padding-bottom: 8px;
  gap: 16px;
}

.site-header .logo {
  display: flex;
  align-items: center;
  gap: 10px;
}
.site-header .logo img {
  height: 44px;
  width: auto;
}

.header-tagline {
  display: none;
  color: rgba(255,255,255,0.85);
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.02em;
}
@media (min-width: 640px) {
  .header-tagline { display: block; }
}

/* ---------- Sub navigation (Swing / Intraday / ...) ---------- */

.subnav-wrap {
  position: sticky;
  top: 60px;
  z-index: 900;
  background: var(--surface);
  border-bottom: 1px solid var(--ink-100);
}

.subnav {
  overflow-x: auto;
  scrollbar-width: thin;
}
.subnav ul {
  display: flex;
  gap: 4px;
  padding: 0 4px;
}
.subnav ul li { flex: none; }
.subnav a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 12px 16px;
  color: var(--ink-700);
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  border-bottom: 3px solid transparent;
  text-decoration: none;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.subnav a:hover {
  color: var(--brand-800);
  background: var(--brand-50);
}
.subnav a.active {
  color: var(--brand-800);
  border-bottom-color: var(--brand-700);
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: none;
  border: none;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.btn:hover { text-decoration: none; }

.btn-primary {
  background: var(--gradient-brand);
  color: #fff;
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 18px rgba(30, 60, 114, 0.35);
  color: #fff;
}

.btn-ghost {
  background: rgba(255,255,255,0.12);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.4);
}
.btn-ghost:hover {
  background: rgba(255,255,255,0.22);
  color: #fff;
}

.btn-outline {
  background: transparent;
  color: var(--brand-800);
  border: 1.5px solid var(--brand-700);
}
.btn-outline:hover {
  background: var(--brand-50);
  color: var(--brand-800);
}

.btn-sm { padding: 7px 14px; font-size: 0.82rem; }

/* ---------- Hero ---------- */

.hero {
  background: var(--gradient-brand);
  color: #fff;
  padding: 28px 0;
}
.hero .container {
  display: grid;
  gap: 20px;
}
@media (min-width: 860px) {
  .hero .container {
    grid-template-columns: 1.5fr 1fr;
    align-items: center;
  }
}
.hero h1 {
  color: #fff;
  font-size: clamp(1.4rem, 2.6vw, 1.9rem);
  margin-bottom: 8px;
}
.hero p {
  color: rgba(255,255,255,0.88);
  font-size: 0.94rem;
  max-width: 56ch;
  margin-bottom: 0;
}
.hero .hero-actions {
  margin-top: 14px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.hero-card {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.22);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  backdrop-filter: blur(2px);
}
.hero-card strong {
  display: block;
  margin-bottom: 6px;
  font-size: 0.82rem;
  color: #fff;
}
.hero-card ul { display: flex; flex-direction: column; gap: 4px; }
.hero-card li {
  color: rgba(255,255,255,0.92);
  font-size: 0.8rem;
  padding-left: 18px;
  position: relative;
}
.hero-card li::before {
  content: "✓";
  position: absolute;
  left: 0;
  color: #7ee2a8;
  font-weight: 700;
}

/* Trust strip under hero */
.trust-strip {
  background: var(--surface);
  border-bottom: 1px solid var(--ink-100);
}
.trust-strip .container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
  padding-top: 8px;
  padding-bottom: 8px;
  justify-content: center;
}
.trust-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--ink-700);
}
.trust-item .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent-green);
  flex: none;
}

/* ---------- Section wrapper ---------- */

.section {
  padding: 24px 0 40px;
}
.section-title {
  text-align: center;
  margin-bottom: 6px;
}
.section-subtitle {
  text-align: center;
  color: var(--ink-500);
  max-width: 60ch;
  margin: 0 auto 18px;
}

/* ---------- Category grid (home page) ---------- */

.grid-container {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
}
@media (min-width: 601px) and (max-width: 1024px) {
  .grid-container { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  .grid-container { grid-template-columns: 1fr; }
}

.stock-category {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--ink-100);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.stock-category:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-md);
}
.stock-category .cat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--brand-100);
  margin-bottom: 6px;
}
.stock-category .cat-icon {
  width: 30px; height: 30px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.94rem;
  flex: none;
}
.stock-category.tone-1 .cat-icon { background: #dcfce7; }
.stock-category.tone-2 .cat-icon { background: #fef3c7; }
.stock-category.tone-3 .cat-icon { background: #e0e7ff; }
.stock-category.tone-4 .cat-icon { background: #dbeafe; }

.stock-category h3 {
  color: var(--brand-800);
  font-size: 1rem;
  margin: 0;
}
.stock-category .home-summary {
  font-size: 0.84rem;
  color: var(--ink-500);
  min-height: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.stock-category .watchlist-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 700;
  color: var(--ink-500);
  margin: 10px 0 6px;
}
.stock-category ul li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 38px;
  padding: 8px 0;
  border-bottom: 1px solid var(--ink-100);
  font-size: 0.88rem;
}
.stock-category ul li:last-child { border-bottom: none; }
.stock-category ul li a {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink-900);
  font-weight: 600;
  text-decoration: none;
}
.stock-category ul li a:hover { color: var(--brand-800); text-decoration: underline; }
.stock-category ul li .rating-pill,
.stock-category ul li .rank {
  flex: none;
}
.stock-category ul li .rating-pill {
  min-width: 52px;
  justify-content: center;
}

.stock-category .action {
  margin-top: auto;
  padding-top: 16px;
}
.stock-category .action .btn { width: 100%; }

/* Rating pill (replaces circular rate.js widget in card lists, still using JS one on detail pages) */
.rating-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--brand-50);
  color: var(--brand-800);
}
.rating-pill.good { background: #dcfce7; color: var(--accent-green-dark); }
.rating-pill.mid { background: #fef9c3; color: #854d0e; }
.rating-pill.low { background: #fee2e2; color: var(--accent-red-dark); }

/* ---------- Method / analysis boxes ---------- */

.analysis-box {
  background: var(--brand-50);
  border: 1px solid var(--brand-100);
  border-left: 4px solid var(--brand-700);
  border-radius: var(--radius-md);
  padding: 26px;
  margin: 0 0 20px;
}
.analysis-box:last-child { margin-bottom: 0; }

.method-grid {
  display: grid;
  gap: 14px;
  margin-top: 16px;
}
@media (min-width: 640px) {
  .method-grid { grid-template-columns: repeat(2, 1fr); }
}
.method-item {
  background: var(--surface);
  border: 1px solid var(--ink-100);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}
.method-item strong { display: block; margin-bottom: 4px; color: var(--brand-800); font-size: 0.9rem; }
.method-item p { font-size: 0.86rem; margin: 0; color: var(--ink-500); }

/* ---------- Stock detail page ---------- */

.stockh1 {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--ink-100);
  border-left: 5px solid var(--brand-700);
  border-radius: var(--radius-md);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
  margin: 20px 0;
}
.stockh1 h1 {
  color: var(--brand-800);
  font-size: 1.5rem;
  margin: 0;
}

.meta-info {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--ink-100);
  border-radius: var(--radius-md);
  padding: 14px 20px;
  margin: 0 0 20px;
  box-shadow: var(--shadow-sm);
}
.rating-section h3 {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--gradient-green);
  color: #fff;
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 1.05rem;
  box-shadow: 0 3px 10px rgba(22, 163, 74, 0.28);
  margin: 0;
}
.updated-time {
  color: var(--accent-green-dark);
  font-weight: 600;
  font-size: 0.85rem;
  margin: 0;
}

.points-section {
  background: var(--surface);
  border: 1px solid var(--ink-100);
  border-radius: var(--radius-md);
  padding: 24px;
  margin: 0 0 20px;
  box-shadow: var(--shadow-sm);
}

/* ---- Key Parameters grid (v5): compact label/value pairs, no giant label gutters ---- */

.param-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--ink-100);
  border: 1px solid var(--ink-100);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
@media (min-width: 901px) and (max-width: 1180px) {
  .param-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 601px) and (max-width: 900px) {
  .param-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  .param-grid { grid-template-columns: repeat(2, 1fr); }
}

.param-cell {
  background: var(--surface);
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.param-cell .param-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-weight: 700;
  color: var(--ink-500);
  white-space: nowrap;
}
.param-cell .param-value {
  font-size: 0.94rem;
  font-weight: 700;
  color: var(--ink-900);
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: center;
  gap: 5px;
}
.param-cell .param-value .trend-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  flex: none;
}
.param-cell.chip-green .param-value { color: var(--accent-green-dark); }
.param-cell.chip-green .trend-dot { background: var(--accent-green); }
.param-cell.chip-red .param-value { color: var(--accent-red-dark); }
.param-cell.chip-red .trend-dot { background: var(--accent-red); }

.gemma-section {
  background: var(--surface);
  border: 1px solid var(--ink-100);
  border-radius: var(--radius-md);
  padding: 18px 22px;
  margin: 0 0 14px;
  box-shadow: var(--shadow-sm);
}
.gemma-section h3 { font-size: 0.95rem; margin-bottom: 6px; }
.gemma-section p { margin: 0; font-size: 0.92rem; }

/* ---------- List / table page (DataTable wrapper) ---------- */

.list-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--ink-100);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.list-search {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--ink-300);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  background: var(--surface);
  min-width: 260px;
}
.list-search input {
  border: none;
  outline: none;
  font-size: 0.9rem;
  width: 100%;
}

.data-panel {
  background: var(--surface);
  border: 1px solid var(--ink-100);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

/* ---------- Footer ---------- */

.site-footer {
  margin-top: auto;
  background: var(--gradient-brand);
  color: #fff;
  padding: 40px 0 0;
}
.footer-disclaimer {
  background: rgba(255,255,255,0.1);
  border-radius: var(--radius-md);
  padding: 20px;
  margin-bottom: 24px;
  font-size: 0.84rem;
  line-height: 1.7;
  color: rgba(255,255,255,0.92);
}
.footer-disclaimer p { color: rgba(255,255,255,0.92); margin: 0; }
.footer-disclaimer strong { color: #fff; }

.footer-grid {
  display: grid;
  gap: 24px;
  padding-bottom: 24px;
  border-bottom: 1px solid rgba(255,255,255,0.15);
}
@media (min-width: 720px) {
  .footer-grid { grid-template-columns: 1.2fr 1fr 1fr; }
}
.footer-col h4 {
  color: #fff;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 12px;
}
.footer-col p { color: rgba(255,255,255,0.75); font-size: 0.86rem; }
.footer-col ul { display: flex; flex-direction: column; gap: 8px; }
.footer-col a {
  color: rgba(255,255,255,0.85);
  font-size: 0.86rem;
}
.footer-col a:hover { color: #fff; }

.footer-bottom {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding: 18px 0;
  font-size: 0.8rem;
  color: rgba(255,255,255,0.7);
}

/* ---------- Utility ---------- */

.back-link,
a.glow-teal {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  background: var(--gradient-brand);
  color: #fff;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.85rem;
  text-decoration: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.back-link:hover,
a.glow-teal:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(30, 60, 114, 0.3);
  color: #fff;
  text-decoration: none;
}

@media (max-width: 600px) {
  .container { padding: 0 12px; }
  .stockh1 { padding: 16px; }
  .points-section, .gemma-section { padding: 16px; }

  /* Home hero: compress hard so watchlist cards reach the fold on phones */
  .hero { padding: 18px 0; }
  .hero h1 { font-size: 1.3rem; margin-bottom: 6px; }
  .hero p { font-size: 0.86rem; }
  .hero .hero-actions { margin-top: 12px; gap: 8px; }
  .hero .btn { padding: 10px 16px; font-size: 0.86rem; }
  .hero-card { display: none; }

  .trust-strip .container {
    flex-wrap: nowrap;
    overflow-x: auto;
    justify-content: flex-start;
    gap: 16px;
    padding: 7px 12px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .trust-strip .container::-webkit-scrollbar { display: none; }
  .trust-item { white-space: nowrap; font-size: 0.72rem; }

  .section { padding: 16px 0 28px; }
  .section-title { font-size: 1.2rem; margin-bottom: 4px; }
  .section-subtitle { font-size: 0.86rem; margin-bottom: 12px; }
}

/* ==========================================================================
   v5 — Top-5-by-index widget (matches list_top_5_stocks.php: NIFTY 50 /
   NEXT 50 / MIDCAP 150 / SMALLCAP 250), shown above the table and above
   the stock report.
   ========================================================================== */

.top5-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin: 20px 0 28px;
}
@media (min-width: 601px) and (max-width: 1024px) {
  .top5-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  .top5-grid { grid-template-columns: 1fr; }
}

.top5-card {
  background: var(--surface);
  border: 1px solid var(--ink-100);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  border-top: 3px solid var(--brand-700);
}
.top5-card.tone-nifty50 { border-top-color: #1e3c72; }
.top5-card.tone-next50 { border-top-color: #b3771f; }
.top5-card.tone-midcap { border-top-color: #5b3fae; }
.top5-card.tone-smallcap { border-top-color: #0a8f65; }

.top5-card h4 {
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 800;
  color: var(--ink-500);
  margin: 0 0 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--ink-100);
}
.top5-card ul li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 0;
  font-size: 0.85rem;
}
.top5-card ul li a {
  color: var(--ink-900);
  font-weight: 600;
  text-decoration: none;
}
.top5-card ul li a:hover { color: var(--brand-800); text-decoration: underline; }
.top5-card .rank { color: var(--ink-300); font-weight: 500; margin-right: 4px; }

/* ==========================================================================
   v5 — Advanced data table module
   Layered on top of the v2 design system: same tokens, same visual language,
   table experience rebuilt for real sort / filter / paginate / column control.
   ========================================================================== */

.table-app {
  background: var(--surface);
  border: 1px solid var(--ink-100);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

/* ---- Toolbar ---- */

.table-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--ink-100);
}

.search-field {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1.5px solid var(--ink-300);
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  background: var(--surface);
  min-width: 240px;
  flex: 1 1 240px;
  max-width: 360px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.search-field:focus-within {
  border-color: var(--brand-700);
  box-shadow: 0 0 0 3px var(--brand-100);
}
.search-field svg { flex: none; color: var(--ink-500); }
.search-field input {
  border: none;
  outline: none;
  font-size: 0.9rem;
  width: 100%;
  font-family: var(--font-body);
  color: var(--ink-900);
}
.search-field input::placeholder { color: var(--ink-500); }
.search-kbd {
  flex: none;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ink-500);
  background: var(--surface-muted);
  border: 1px solid var(--ink-100);
  border-radius: 4px;
  padding: 2px 6px;
}

.toolbar-spacer { flex: 1 1 auto; }

.chip-filter {
  position: relative;
}
.chip-filter-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border: 1.5px solid var(--ink-300);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink-700);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.chip-filter-btn:hover { border-color: var(--brand-700); color: var(--brand-800); }
.chip-filter-btn.is-active {
  border-color: var(--brand-700);
  background: var(--brand-50);
  color: var(--brand-800);
}
.chip-filter-btn .count {
  background: var(--brand-700);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 1px 6px;
  line-height: 1.4;
}
.chip-filter-btn .caret { font-size: 0.6rem; color: var(--ink-500); }

.chip-panel {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 50;
  min-width: 220px;
  max-height: 280px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--ink-100);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 8px;
  display: none;
}
.chip-panel.is-open { display: block; }
.chip-panel label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 6px;
  font-size: 0.86rem;
  color: var(--ink-700);
  cursor: pointer;
}
.chip-panel label:hover { background: var(--surface-muted); }
.chip-panel input[type="checkbox"],
.chip-panel input[type="radio"] { accent-color: var(--brand-700); }
.chip-panel label .rating-star { color: #d4a017; }
.chip-panel .chip-panel-foot {
  display: flex;
  justify-content: space-between;
  padding: 8px 8px 2px;
  margin-top: 4px;
  border-top: 1px solid var(--ink-100);
}
.chip-panel .chip-panel-foot button {
  background: none;
  border: none;
  color: var(--brand-700);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  padding: 4px;
}
.chip-panel .chip-panel-foot button:hover { text-decoration: underline; }

.active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 20px 14px;
}
.active-filters:empty { display: none; }
.filter-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--brand-50);
  color: var(--brand-800);
  border: 1px solid var(--brand-100);
  border-radius: 999px;
  padding: 4px 6px 4px 12px;
  font-size: 0.8rem;
  font-weight: 600;
}
.filter-tag button {
  background: rgba(30, 60, 114, 0.12);
  border: none;
  border-radius: 50%;
  width: 16px; height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--brand-800);
  font-size: 0.7rem;
  line-height: 1;
  padding: 0;
}
.filter-tag button:hover { background: rgba(30, 60, 114, 0.22); }
.filter-clear-all {
  background: none;
  border: none;
  color: var(--ink-500);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 8px;
}
.filter-clear-all:hover { color: var(--accent-red); text-decoration: underline; }

/* Column visibility */
.col-menu-panel {
  right: 0;
  left: auto;
  min-width: 190px;
}

/* Density toggle */
.density-toggle {
  display: inline-flex;
  border: 1.5px solid var(--ink-300);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.density-toggle button {
  border: none;
  background: var(--surface);
  color: var(--ink-500);
  padding: 8px 10px;
  font-size: 0.8rem;
  cursor: pointer;
  line-height: 1;
  border-left: 1px solid var(--ink-100);
}
.density-toggle button:first-child { border-left: none; }
.density-toggle button.is-active { background: var(--brand-800); color: #fff; }

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

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

table.smart-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.87rem;
  min-width: 780px;
}
table.smart-table thead th {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--surface-muted);
  text-align: left;
  padding: 12px 14px;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 700;
  color: var(--ink-500);
  border-bottom: 1px solid var(--ink-100);
  white-space: nowrap;
  user-select: none;
}
table.smart-table th.sortable {
  cursor: pointer;
  transition: color 0.15s ease;
}
table.smart-table th.sortable:hover { color: var(--brand-800); }
table.smart-table th .th-inner {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
table.smart-table th .sort-arrows {
  display: inline-flex;
  flex-direction: column;
  line-height: 0;
  gap: 1px;
}
table.smart-table th .sort-arrows span {
  font-size: 8px;
  color: var(--ink-300);
}
table.smart-table th[data-sort-dir="asc"] .sort-arrows span.up,
table.smart-table th[data-sort-dir="desc"] .sort-arrows span.down {
  color: var(--brand-800);
}
table.smart-table th.num, table.smart-table td.num { text-align: right; }

table.smart-table tbody td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--ink-100);
  color: var(--ink-700);
  vertical-align: middle;
}
table.smart-table tbody tr { transition: background 0.1s ease; }
table.smart-table tbody tr:hover { background: var(--brand-50); }
table.smart-table td.sym { font-weight: 700; color: var(--ink-900); }
table.smart-table td.sym a { color: inherit; }
table.smart-table td.sym a:hover { color: var(--brand-800); }
table.smart-table td .stock-name-sub { display: block; color: var(--ink-500); font-size: 0.78rem; font-weight: 400; margin-top: 1px; }

.tag-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 5px;
  background: var(--surface-muted);
  color: var(--ink-500);
  border: 1px solid var(--ink-100);
}

/* Density variants */
.table-app[data-density="compact"] table.smart-table tbody td { padding: 7px 14px; }
.table-app[data-density="compact"] table.smart-table thead th { padding: 8px 14px; }

/* Empty state */
.table-empty {
  padding: 64px 20px;
  text-align: center;
  color: var(--ink-500);
}
.table-empty strong { display: block; color: var(--ink-900); margin-bottom: 6px; font-size: 1rem; }
.table-empty button {
  margin-top: 14px;
  background: none;
  border: 1.5px solid var(--brand-700);
  color: var(--brand-800);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
}
.table-empty button:hover { background: var(--brand-50); }

/* ---- Footer bar: pagination + page size ---- */

.table-footbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 20px;
  border-top: 1px solid var(--ink-100);
  background: var(--surface-muted);
}
.footbar-info { font-size: 0.83rem; color: var(--ink-500); }
.footbar-info strong { color: var(--ink-900); }

.page-size-select {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.83rem;
  color: var(--ink-500);
}
.page-size-select select {
  border: 1.5px solid var(--ink-300);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 0.83rem;
  color: var(--ink-900);
  background: var(--surface);
  font-family: var(--font-body);
}

.pagination {
  display: flex;
  align-items: center;
  gap: 4px;
}
.pagination button {
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  border: 1.5px solid transparent;
  background: none;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-700);
  cursor: pointer;
  transition: all 0.12s ease;
}
.pagination button:hover:not(:disabled) { background: var(--surface); border-color: var(--ink-300); }
.pagination button.is-active {
  background: var(--brand-800);
  color: #fff;
}
.pagination button:disabled { color: var(--ink-300); cursor: not-allowed; }
.pagination .ellipsis { color: var(--ink-400); padding: 0 4px; }

@media (max-width: 720px) {
  .table-toolbar { padding: 14px; }
  .table-footbar { padding: 12px 14px; flex-direction: column; align-items: stretch; }
  .pagination { justify-content: center; }
}
