/* ==========================================================================
   MIPB Glycemic Index Tools — gi-table.css
   Covers [gi_table] (.mgi-*) and [compare_gi] (.mgic-*)
   ========================================================================== */

/* ---- Shared variables ---- */
:root {
  --gi-primary:   #e65100;   /* warm orange — food energy theme */
  --gi-accent:    #ff8a50;
  --gi-bar-bg:    #fff3e0;
  --gi-bar-fill:  #e65100;
  --gi-border:    #e0e0e0;
  --gi-row-hover: #fff8f0;
  --gi-muted:     #757575;
  --gi-radius:    6px;
}

/* ============================================================
   [gi_table] — Ranking tool (.mgi-*)
   ============================================================ */

/* Static top-10 SEO block */
.mgi-top10 { margin-bottom: 2rem; }
.mgi-top10 h2 { font-size: 1.25rem; margin-bottom: .5rem; }
.mgi-top10-list { margin: 0; padding-left: 1.4rem; }
.mgi-top10-list li { margin-bottom: .3rem; line-height: 1.5; }

/* Controls */
.mgi-wrap { max-width: 1100px; margin: 0 auto; font-family: inherit; }
.mgi-controls {
  display: flex; flex-wrap: wrap; gap: .6rem; align-items: center;
  margin-bottom: 1rem;
}
.mgi-search, .mgi-category-select {
  padding: .45rem .7rem; border: 1px solid var(--gi-border);
  border-radius: var(--gi-radius); font-size: .93rem;
  background: #fff; flex: 1 1 180px; max-width: 320px;
}
.mgi-search:focus, .mgi-category-select:focus { outline: 2px solid var(--gi-primary); outline-offset: 1px; }
.mgi-order-btn {
  padding: .45rem .9rem; background: var(--gi-primary); color: #fff;
  border: none; border-radius: var(--gi-radius); font-size: .88rem;
  cursor: pointer; white-space: nowrap; flex-shrink: 0;
}
.mgi-order-btn:hover { background: #d84315; }

/* Sort tabs */
.mgi-tabs { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .8rem; }
.mgi-tab {
  padding: .38rem .85rem; background: #f1f3f4; border: 1px solid var(--gi-border);
  border-radius: 20px; font-size: .85rem; cursor: pointer; color: #333;
  transition: background .15s, color .15s;
}
.mgi-tab:hover { background: var(--gi-bar-bg); }
.mgi-tab.active {
  background: var(--gi-primary); color: #fff; border-color: var(--gi-primary);
}

/* Table */
.mgi-table-wrap { overflow-x: auto; border: 1px solid var(--gi-border); border-radius: var(--gi-radius); }
.mgi-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.mgi-table thead th {
  background: #f8f9fa; padding: .6rem .7rem; text-align: left;
  font-weight: 600; color: #333; border-bottom: 2px solid var(--gi-border);
  white-space: nowrap;
}
.mgi-table tbody tr { border-bottom: 1px solid var(--gi-border); transition: background .1s; }
.mgi-table tbody tr:last-child { border-bottom: none; }
.mgi-table tbody tr:hover { background: var(--gi-row-hover); }
.mgi-table td { padding: .55rem .7rem; vertical-align: middle; }
.mgi-rank { width: 3rem; text-align: right; color: var(--gi-muted); font-size: .82rem; }
.mgi-name { font-weight: 500; }
.mgi-val  { text-align: right; font-variant-numeric: tabular-nums; }
.mgi-null { color: var(--gi-muted); }
.mgi-loading { text-align: center; padding: 2rem; color: var(--gi-muted); }

/* Bar column */
.mgi-col-bar { width: 90px; padding-right: .5rem; }
.mgi-bar { height: 10px; background: var(--gi-bar-fill); border-radius: 3px; min-width: 2px; }

/* Pagination */
.mgi-pagination {
  display: flex; align-items: center; justify-content: center;
  gap: .6rem; margin-top: .8rem; font-size: .88rem;
}
.mgi-pg-btn {
  padding: .3rem .8rem; background: var(--gi-primary); color: #fff;
  border: none; border-radius: var(--gi-radius); cursor: pointer; font-size: .85rem;
}
.mgi-pg-btn:hover { background: #d84315; }
.mgi-pg-info { color: #555; }

/* Legend & FAQ */
.mgi-legend { font-size: .82rem; color: #666; margin-top: .7rem; }
.mgi-faq { margin-top: 2rem; }
.mgi-faq h2 { font-size: 1.15rem; margin-bottom: .7rem; }
.mgi-faq details { border: 1px solid var(--gi-border); border-radius: var(--gi-radius); margin-bottom: .5rem; }
.mgi-faq summary {
  padding: .65rem .9rem; font-weight: 500; cursor: pointer;
  list-style: none; display: flex; justify-content: space-between; align-items: center;
}
.mgi-faq summary::-webkit-details-marker { display: none; }
.mgi-faq summary::after { content: '+'; font-size: 1.1rem; color: var(--gi-primary); }
.mgi-faq details[open] summary::after { content: '−'; }
.mgi-faq details p { padding: .1rem .9rem .8rem; margin: 0; font-size: .9rem; line-height: 1.6; }

/* Responsive */
@media (max-width: 720px) {
  .mgi-col-category, .mgi-col-studies, .mgi-col-bar { display: none; }
}

/* ============================================================
   [compare_gi] — Comparison tool (.mgic-*)
   ============================================================ */

.mgic-wrap { max-width: 1100px; margin: 0 auto; font-family: inherit; }
.mgic-label { font-weight: 500; margin-bottom: .4rem; display: block; }

.mgic-autocomplete { position: relative; max-width: 480px; }
.mgic-input {
  width: 100%; padding: .45rem .7rem; border: 1px solid var(--gi-border);
  border-radius: var(--gi-radius); font-size: .93rem; box-sizing: border-box;
}
.mgic-input:focus { outline: 2px solid var(--gi-primary); outline-offset: 1px; }
.mgic-dropdown {
  position: absolute; top: 100%; left: 0; right: 0;
  background: #fff; border: 1px solid var(--gi-border);
  border-top: none; border-radius: 0 0 var(--gi-radius) var(--gi-radius);
  list-style: none; margin: 0; padding: 0; max-height: 240px;
  overflow-y: auto; z-index: 100; box-shadow: 0 4px 10px rgba(0,0,0,.1);
}
.mgic-dropdown li {
  padding: .5rem .8rem; cursor: pointer; font-size: .9rem; border-bottom: 1px solid #f0f0f0;
}
.mgic-dropdown li:hover { background: var(--gi-bar-bg); }
.mgic-hint { color: var(--gi-muted); font-size: .8rem; display: block; }

/* Chips */
.mgic-chips { display: flex; flex-wrap: wrap; gap: .4rem; margin: .6rem 0; min-height: 1.8rem; }
.mgic-chip {
  display: inline-flex; align-items: center; gap: .3rem;
  background: var(--gi-bar-bg); border: 1px solid var(--gi-accent);
  border-radius: 20px; padding: .2rem .7rem; font-size: .85rem;
}
.mgic-chip-remove {
  background: none; border: none; cursor: pointer;
  color: var(--gi-primary); font-size: 1rem; padding: 0; line-height: 1;
}

/* Tabs */
.mgic-tabs { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .8rem; }
.mgic-tab {
  padding: .38rem .85rem; background: #f1f3f4; border: 1px solid var(--gi-border);
  border-radius: 20px; font-size: .85rem; cursor: pointer;
}
.mgic-tab.active { background: var(--gi-primary); color: #fff; border-color: var(--gi-primary); }

/* Placeholder */
.mgic-placeholder { color: var(--gi-muted); font-style: italic; padding: 1.5rem 0; }

/* Results table */
.mgic-table-wrap { overflow-x: auto; border: 1px solid var(--gi-border); border-radius: var(--gi-radius); margin-bottom: .5rem; }
.mgic-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.mgic-table thead th {
  background: #f8f9fa; padding: .55rem .7rem; text-align: left;
  font-weight: 600; border-bottom: 2px solid var(--gi-border); white-space: nowrap;
}
.mgic-active-col { background: #fff3e0 !important; }
.mgic-table tbody tr { border-bottom: 1px solid var(--gi-border); transition: background .1s; }
.mgic-table tbody tr:last-child { border-bottom: none; }
.mgic-table tbody tr:hover { background: var(--gi-row-hover); }
.mgic-table tbody tr.mgic-top { background: var(--gi-bar-bg); font-weight: 600; }
.mgic-table td { padding: .5rem .7rem; vertical-align: middle; }
.mgic-val { text-align: right; font-variant-numeric: tabular-nums; }
.mgic-bar-col { width: 90px; }
.mgic-bar { height: 10px; background: var(--gi-bar-fill); border-radius: 3px; min-width: 2px; }

/* Legend */
.mgic-legend { font-size: .82rem; color: #666; margin-top: .4rem; }

/* Responsive */
@media (max-width: 640px) {
  .mgic-table th:nth-child(2),
  .mgic-table td:nth-child(2) { display: none; }
  .mgic-bar-col { display: none; }
}

/* ── Header grid (two-column layout) ────────────────────────── */
.mgi-header-grid {
    max-width: 1040px;
    margin: 0 auto 2rem;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    align-items: start;
}
@media (max-width: 720px) {
    .mgi-header-grid { grid-template-columns: 1fr; }
}

/* ── Insight box (dataset snapshot) ─────────────────────────── */
.mgi-insight-box {
    background: #fff3e0;
    border: 1px solid var(--gi-accent);
    border-radius: 8px;
    padding: 1rem 1.2rem;
}
.mgi-insight-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--gi-primary);
    margin: 0 0 .6rem;
}
.mgi-insight-list {
    list-style: none;
    margin: 0;
    padding: 0;
    font-size: .9rem;
    line-height: 1.7;
    color: #333;
}
.mgi-insight-list li { border-bottom: 1px solid #ffe0b2; padding: .2rem 0; }
.mgi-insight-list li:last-child { border-bottom: none; }

/* ── Context card ────────────────────────────────────────────── */
.mgi-context-card {
    margin-top: .8rem;
    background: #fff8e1;
    border-left: 4px solid #f9a825;
    border-radius: 0 6px 6px 0;
    padding: .7rem 1rem;
    font-size: .88rem;
    color: #444;
    line-height: 1.6;
}
.mgi-context-label {
    font-weight: 700;
    font-size: .85rem;
    color: #c43e00;
    margin: 0 0 .3rem;
}
.mgi-context-card p:last-child { margin: 0; }
.mgi-context-card a { color: var(--gi-primary); }

/* ── Related tools section ───────────────────────────────────── */
.mgi-related {
    max-width: 1120px;
    width: 100vw;
    margin-left: 50%;
    transform: translateX(-50%);
    margin-top: 2.5rem;
    padding: 0 1rem;
    box-sizing: border-box;
}
.mgi-related-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--gi-primary);
    margin-bottom: 1rem;
}
.mgi-related-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
}
.mgi-related-card {
    display: flex;
    align-items: flex-start;
    gap: .75rem;
    padding: .9rem 1rem;
    border: 1px solid #dde;
    border-top: 3px solid var(--card-accent, var(--gi-primary));
    border-radius: 8px;
    text-decoration: none;
    background: #fff;
    min-height: 140px;
    transition: box-shadow .18s, transform .18s;
}
.mgi-related-card:hover {
    box-shadow: 0 4px 14px rgba(0,0,0,.1);
    transform: translateY(-2px);
}
.mgi-related-icon { font-size: 2.25rem; flex-shrink: 0; line-height: 1; color: var(--card-accent, #e65100); }
.mgi-related-icon svg { width: 38px; height: 38px; flex-shrink: 0; }
.mgi-related-body { display: flex; flex-direction: column; gap: .25rem; }
.mgi-related-name { font-size: .9rem; font-weight: 700; color: #1a1a2e; }
.mgi-related-desc { font-size: .8rem; color: #555; margin: 0; line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
