/* ===== Layout for Best Mutual Funds (Live) ===== */

/* Controls layout: desktop */
#mfLive .mf-controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  padding: 0 16px 12px 16px;
}

#mfLive .mf-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#mfLive .mf-label {
  font-size: 0.8rem;
  opacity: 0.8;
}

/* Make Refresh button align nicely on desktop */
#mfLive .mf-field-btn button {
  height: 36px;
  font-weight: 600;
}

/* Table: let it scroll horizontally if needed */
#mfLive .mf-wrap {
  width: 100%;
  overflow-x: auto;
  padding: 0 16px 8px 16px;
}

#mfLive .mf-wrap table {
  min-width: 720px;     /* so columns don't squeeze too much */
}

#mfLive .mf-wrap th,
#mfLive .mf-wrap td {
  white-space: nowrap;
}

/* ------- Mobile (phone) layout ------- */
@media (max-width: 768px) {

  #mfLive.ai-card {
    margin-left: -12px;
    margin-right: -12px;
    border-radius: 0;
  }

  #mfLive .ai-card-head {
    padding: 12px 16px 4px 16px;
  }

  #mfLive .mf-controls {
    grid-template-columns: 1fr;   /* one per row */
    padding: 0 16px 12px 16px;
  }

  #mfLive .mf-field-btn button {
    width: 100%;
    height: 44px;
    font-weight: 600;
  }

  #mfLive #mfStatus {
    padding-left: 16px;
    padding-right: 16px;
  }

  #mfLive .mf-wrap {
    padding-left: 0;
    padding-right: 0;
  }

  #mfLive footer.ai-note {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  #mfLive footer.ai-note > .d-flex {
    width: 100%;
    flex-wrap: wrap;
    gap: 8px;
  }
}

/* ====== TABLE LAYOUT ====== */

#mfLive .mf-wrap {
  display: block;
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 16px 8px 16px;
}

/* The actual table */
#mfLive .mf-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  /* big enough so columns don’t crush on phone, will make horizontal scroll */
  min-width: 720px;
}

#mfLive .mf-table thead {
  position: sticky;
  top: 0;
  background: #020617; /* dark header row */
  z-index: 1;
}

#mfLive .mf-table th,
#mfLive .mf-table td {
  padding: 6px 8px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.25);
  white-space: nowrap;          /* keep columns on one line */
}

#mfLive .mf-table th {
  text-align: left;
  font-weight: 600;
  color: #e5e7eb;
}

#mfLive .mf-table td {
  color: #cbd5f5;
}

/* narrow first column (#) */
#mfLive .mf-table th:first-child,
#mfLive .mf-table td:first-child {
  width: 40px;
  text-align: right;
}

/* Scheme column gets more space */
#mfLive .mf-table th:nth-child(2),
#mfLive .mf-table td:nth-child(2) {
  max-width: 260px;
}

/* numeric columns right-aligned */
#mfLive .mf-table th:nth-child(n+4),
#mfLive .mf-table td:nth-child(n+4) {
  text-align: right;
}

/* coloured percentages we already generate in JS */
#mfLive .mf-pos { color: #4ade80; }
#mfLive .mf-neg { color: #f97373; }

/* ====== Mobile tweaks ====== */
@media (max-width: 768px) {
  #mfLive .mf-wrap {
    padding-left: 0;
    padding-right: 0;
    margin-left: -4px;          /* let the table touch both sides nicely */
    margin-right: -4px;
  }

  #mfLive .mf-table {
    min-width: 640px;           /* slightly tighter for phones */
  }
}



/* -----------------------------
   Base tweaks (desktop + mobile)
   ----------------------------- */

/* Let the table scroll horizontally instead of shrinking */
#mfLive .mf-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Make sure the table can be wider than the card if needed */
#mfLive .mf-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

/* keep index column narrow */
#mfLive .mf-table th:first-child,
#mfLive .mf-table td:first-child {
  width: 40px;
  text-align: right;
}

/* Make numbers right-aligned and prevent weird wrapping */
#mfLive .mf-table th:nth-child(n+4),
#mfLive .mf-table td:nth-child(n+4) {
  text-align: right;
  white-space: nowrap;
}

/* ---------------------------------
   Mobile layout (phone, small width)
   --------------------------------- */
@media (max-width: 768px) {
  /* card should never be wider than the screen */
  #mfLive.ai-card {
    margin-left: 0;
    margin-right: 0;
    border-radius: 16px;
  }

  /* stack heading + controls vertically */
  #mfLive .ai-card-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  /* put the 3 selects + button in two rows */
  #mfLive .ai-card-head > .d-flex {
    width: 100%;
    flex-wrap: wrap;
    gap: 0.5rem;
  }
  #mfLive .ai-card-head select,
  #mfLive .ai-card-head button {
    flex: 1 1 48%;
  }

  /* make status + footer text a bit smaller */
  #mfLive .mf-status,
  #mfLive .ai-note,
  #mfLive #mfFoot,
  #mfLive #mfPage {
    font-size: 0.8rem;
  }

  /* table: slightly smaller text + tighter padding */
  #mfLive .mf-table {
    font-size: 0.78rem;
    min-width: 720px;  /* force horizontal scroll instead of squashing */
  }
  #mfLive .mf-table th,
  #mfLive .mf-table td {
    padding: 6px 8px;
  }

  /* footer controls on two lines if needed */
  #mfLive footer.ai-note {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }
  #mfLive footer.ai-note > .d-flex {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 0.5rem;
  }
}


/* =========================================
   DESKTOP: make Scheme + Category readable
   ========================================= */
@media (min-width: 769px) {
  /* let browser decide natural widths again */
  #mfLive .mf-table {
    table-layout: auto;
    min-width: auto;
  }

  /* All cells: nicer spacing + no weird overlap */
  #mfLive .mf-table th,
  #mfLive .mf-table td {
    padding: 6px 10px;
    line-height: 1.25;
    vertical-align: top;
  }

  /* # column stays narrow */
  #mfLive .mf-table th:nth-child(1),
  #mfLive .mf-table td:nth-child(1) {
    width: 40px;
    text-align: right;
    white-space: nowrap;
  }

  /* Scheme: wide column, allow wrapping on multiple lines */
  #mfLive .mf-table th:nth-child(2),
  #mfLive .mf-table td:nth-child(2) {
    width: 40%;
    white-space: normal;      /* allow multi-line */
    word-break: break-word;   /* break long words if needed */
  }

  /* Category: medium width, keep on one line */
  #mfLive .mf-table th:nth-child(3),
  #mfLive .mf-table td:nth-child(3) {
    width: 22%;
    white-space: nowrap;
  }

  /* Numeric columns: right aligned, no wrapping */
  #mfLive .mf-table th:nth-child(n+4),
  #mfLive .mf-table td:nth-child(n+4) {
    text-align: right;
    white-space: nowrap;
  }
}



/* ===========================
   Best Mutual Funds (Live)
   TABLE + WRAPPER
   =========================== */

/* Scroll area for the table */
.mf-wrap {
  margin: 0 16px 8px;
  max-height: 420px;
  overflow-y: auto;   /* scroll for many rows */
  overflow-x: auto;   /* horizontal scroll on phone */
}

/* Hard reset for anything inside our table –
   stops floats / flex / weird global styles
   from breaking layout */
.mf-table,
.mf-table * {
  box-sizing: border-box;
}

/* Base table (desktop + mobile) */
.mf-table {
  width: 100%;
  border-collapse: collapse;
  border-spacing: 0;
  table-layout: fixed;

  /* so on narrow screens the user scrolls horizontally
     instead of columns collapsing & overlapping */
  min-width: 800px;
}

/* Make sure rows & cells behave like a normal table */
.mf-table tr {
  display: table-row;
}

.mf-table th,
.mf-table td {
  display: table-cell !important;
  float: none !important;
  position: static !important;

  padding: 6px 8px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.3);
  font-size: 13px;
  line-height: 1.4;
  color: #e5e7eb;
  white-space: nowrap; /* default – numbers stay on one line */
}

/* Header row */
.mf-table thead tr {
  background: #020617;
  position: sticky;
  top: 0;
  z-index: 1;
}

/* Left-align first 3 columns, right-align % columns */
.mf-table th:nth-child(1),
.mf-table td:nth-child(1),
.mf-table th:nth-child(2),
.mf-table td:nth-child(2),
.mf-table th:nth-child(3),
.mf-table td:nth-child(3) {
  text-align: left;
}

.mf-table th:nth-child(n + 4),
.mf-table td:nth-child(n + 4) {
  text-align: right;
}

/* Allow Scheme + Category to wrap on multiple lines
   instead of crashing into each other on small screens */
.mf-table td:nth-child(2),
.mf-table td:nth-child(3) {
  white-space: normal;
  word-wrap: break-word;
  word-break: break-word;
}

/* Simple zebra stripe (optional) */
.mf-table tbody tr:nth-child(even) {
  background: rgba(15, 23, 42, 0.9);
}

/* Green / red percentages (from your JS fmtPct) */
.mf-pos { color: #4ade80; }
.mf-neg { color: #f97373; }

/* -------- MOBILE TUNING -------- */

@media (max-width: 768px) {
  /* card fills width; looks like a full-width section */
  #mfLive.ai-card {
    margin-inline: 0;
    border-radius: 0;
  }

  .mf-wrap {
    max-height: 360px;  /* a bit shorter so footer & next card are visible */
  }

  .mf-table {
    min-width: 650px;   /* slightly narrower but still scrollable horizontally */
  }

  .mf-table th,
  .mf-table td {
    padding: 4px 6px;
    font-size: 12px;
  }
}



/* FINAL FIX — proper table layout on mobile + laptop */

.mf-wrap {
  width: 100%;
  overflow-x: auto;
  overflow-y: auto;
  margin: 0 auto;
  max-height: 420px;
  background: rgba(15, 23, 42, 0.8);
}

.mf-wrap table {
  border-collapse: collapse !important;
  width: 100% !important;
  min-width: 750px;
  table-layout: fixed !important;
  display: table !important;
}

/* enforce pure table structure */
.mf-wrap table tr {
  display: table-row !important;
}

.mf-wrap table th,
.mf-wrap table td {
  display: table-cell !important;
  float: none !important;
  position: static !important;
  vertical-align: top !important;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
  padding: 6px 8px;
  color: #f1f5f9;
  font-size: 13px;
  line-height: 1.4;
  white-space: nowrap;
}

/* let Scheme + Category wrap naturally */
.mf-wrap table td:nth-child(2),
.mf-wrap table td:nth-child(3) {
  white-space: normal !important;
  word-break: break-word !important;
}

/* right-align numeric columns */
.mf-wrap table th:nth-child(n + 4),
.mf-wrap table td:nth-child(n + 4) {
  text-align: right !important;
}

/* header row sticky + dark */
.mf-wrap table thead tr {
  background: #020617;
  position: sticky;
  top: 0;
  z-index: 2;
}

/* zebra row striping (optional) */
.mf-wrap table tbody tr:nth-child(even) {
  background: rgba(30, 41, 59, 0.9);
}

/* green / red for % */
.mf-pos { color: #22c55e !important; }
.mf-neg { color: #f87171 !important; }

/* Responsive tuning */
@media (max-width: 768px) {
  .mf-wrap {
    max-height: 360px;
  }
  .mf-wrap table {
    min-width: 620px;
  }
  .mf-wrap table th,
  .mf-wrap table td {
    font-size: 12px;
    padding: 4px 6px;
  }
}


/* Make scheme text slightly smaller on very narrow screens */
@media (max-width: 480px) {
  #mfLive .mf-table td:nth-child(2) {   /* Scheme */
    font-size: 0.82rem;
  }
  #mfLive .mf-table td:nth-child(3) {   /* Category */
    font-size: 0.76rem;
  }
}

/* Slightly reduce row height so more fits on screen */
#mfLive .mf-table td {
  padding-top: 0.35rem;
  padding-bottom: 0.35rem;
}

/* Scrollbar polish */
.mf-wrap {
  overflow-x: auto;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #1e293b #0f172a;
}

/* Chrome/WebKit scrollbar styling */
.mf-wrap::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
.mf-wrap::-webkit-scrollbar-thumb {
  background: #475569;
  border-radius: 4px;
}
.mf-wrap::-webkit-scrollbar-thumb:hover {
  background: #64748b;
}
.mf-wrap::-webkit-scrollbar-track {
  background: #0f172a;
}

