/* =====================================================================================
   Seoffix Tech Lab — Shared Component Kit
   =====================================================================================
   The one place card, KPI, tab, ranked-bar, pill, button and table styles live.
   Public pages, all 383 tools, /dashboard, /admin/ and /agents all consume these classes,
   so no page ever hand-rolls its own card CSS.

   Depends on seoffix-web-tokens.css. Every colour is a var(--sfx-*) reference; this file
   must not introduce a raw hex of its own (the consistency gate enforces that).
   ===================================================================================== */

/* Closed drawers and a second theme logo must not widen the page or cover Get Pro. */
html, body { overflow-x: clip; }
#mobileDrawerPanel { max-width: min(24rem, 100vw); }
#themeToggle .fa-sun,
#themeToggleMobile .fa-sun { display: none; }
html.dark #themeToggle .fa-moon,
html.dark #themeToggleMobile .fa-moon { display: none; }
html.dark #themeToggle .fa-sun,
html.dark #themeToggleMobile .fa-sun { display: inline-block; }
html.dark img.dark\:hidden,
html.dark .dark\:hidden { display: none !important; }
html.dark img.hidden.dark\:block,
html.dark .hidden.dark\:block { display: block !important; }
html.dark .hidden.dark\:inline { display: inline-block !important; }
header nav[aria-label="Primary Navigation"] { min-width: 0; flex: 1 1 auto; gap: 10px; padding-right: 12px; }
/* Between 1024 and 1535 the nav is tight: tighten gaps and drop the small count badges
   (they repeat the section names) so Roadmap stays clear of the theme button. */
@media (min-width: 1024px) and (max-width: 1535px) {
  header nav[aria-label="Primary Navigation"] { gap: 9px; font-size: 12.5px; padding-right: 10px; }
  header nav[aria-label="Primary Navigation"] > a,
  header nav[aria-label="Primary Navigation"] > div { flex: 0 0 auto; }
  header nav[aria-label="Primary Navigation"] span.text-\[9px\] { display: none; }
}
/* Keep the right-hand actions clear of the nav so Roadmap never slides under the theme button. */
header .flex.items-center.gap-2 { flex-shrink: 0; position: relative; z-index: 1; margin-left: 8px; }

.sfx-link {
  color: var(--sfx-primary);
  font-weight: 600;
  text-decoration: none;
}
.sfx-link:hover { color: var(--sfx-primary-hover); }

/* ------------------------------------------------------------------------------------
   Card
   ------------------------------------------------------------------------------------ */
.sfx-card {
  background: var(--sfx-card-bg);
  border: 1px solid var(--sfx-border);
  border-radius: var(--sfx-radius-card);
  box-shadow: var(--sfx-shadow-card);
  box-sizing: border-box;
  min-width: 0;
}

.sfx-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sfx-space-3);
  padding: 12px 14px;
  border-bottom: 1px solid var(--sfx-border-soft);
  min-width: 0;
}

.sfx-card-title {
  font-family: var(--sfx-font-brand);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--sfx-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sfx-card-sub {
  font-size: 11px;
  color: var(--sfx-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sfx-card-body {
  padding: 14px;
}

.sfx-panel {
  background: var(--sfx-card-bg);
  border: 1px solid var(--sfx-border);
  border-radius: var(--sfx-radius-card);
  padding: 14px 16px;
  box-shadow: var(--sfx-shadow-card);
  min-width: 0;
}

/* ------------------------------------------------------------------------------------
   KPI grid and cards (48-point sparkline sits flush against the bottom border)
   ------------------------------------------------------------------------------------ */
.sfx-kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: var(--sfx-gap);
}

@media (max-width: 1200px) {
  .sfx-kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .sfx-kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.sfx-kpi-card {
  background: var(--sfx-card-bg);
  border: 1px solid var(--sfx-border);
  border-radius: var(--sfx-radius-card);
  box-shadow: var(--sfx-shadow-card);
  padding: 11px 13px 0 13px;
  height: 108px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  box-sizing: border-box;
  min-width: 0;
}

.sfx-kpi-title {
  font-size: 11px;
  font-weight: 500;
  color: var(--sfx-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sfx-kpi-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-top: 2px;
  min-width: 0;
}

.sfx-kpi-num {
  font-size: var(--sfx-fs-kpi);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--sfx-ink);
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
  white-space: nowrap;
}

.sfx-kpi-delta {
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.sfx-kpi-delta.up { color: var(--sfx-green); }
.sfx-kpi-delta.down { color: var(--sfx-red); }

.sfx-kpi-spark {
  margin: 4px -13px 0 -13px;
  height: 38px;
  width: calc(100% + 26px);
  display: block;
}

/* ------------------------------------------------------------------------------------
   Segmented pill tabs
   ------------------------------------------------------------------------------------ */
.sfx-seg-tabs {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background: var(--sfx-subtle-bg);
  border: 1px solid var(--sfx-border);
  border-radius: 7px;
  max-width: 100%;
}

.sfx-seg-tab {
  height: 26px;
  padding: 0 11px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--sfx-muted);
  font-family: inherit;
  font-size: var(--sfx-fs-table);
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}

.sfx-seg-tab:hover { color: var(--sfx-ink); }

.sfx-seg-tab.is-active {
  background: var(--sfx-card-bg);
  color: var(--sfx-ink);
  font-weight: 600;
  box-shadow: var(--sfx-shadow-tab);
}

/* ------------------------------------------------------------------------------------
   Ranked bar list: label | proportional track | right-aligned count
   ------------------------------------------------------------------------------------ */
.sfx-rank-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.sfx-rank-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 136px 52px;
  align-items: center;
  gap: var(--sfx-gap);
  height: 27px;
  font-size: var(--sfx-fs-table);
  min-width: 0;
}

.sfx-rank-label {
  color: var(--sfx-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sfx-rank-track {
  height: 5px;
  width: 100%;
  background: var(--sfx-border);
  border-radius: var(--sfx-radius-pill);
  overflow: hidden;
  display: block;
}

.sfx-rank-fill {
  display: block;
  height: 100%;
  min-width: 3px;
  background: var(--sfx-primary);
  border-radius: var(--sfx-radius-pill);
}

.sfx-rank-val {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--sfx-ink-secondary);
  font-weight: 500;
}

@media (max-width: 640px) {
  .sfx-rank-row { grid-template-columns: minmax(0, 1fr) 72px 44px; gap: var(--sfx-space-2); }
}

/* ------------------------------------------------------------------------------------
   Status pills
   ------------------------------------------------------------------------------------ */
.sfx-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 20px;
  padding: 0 8px;
  border-radius: var(--sfx-radius-pill);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid transparent;
}

.sfx-pill.is-ok {
  background: var(--sfx-green-soft);
  color: var(--sfx-green);
  border-color: var(--sfx-green);
}
.sfx-pill.is-warn {
  background: var(--sfx-amber-soft);
  color: var(--sfx-amber);
  border-color: var(--sfx-amber);
}
.sfx-pill.is-err {
  background: var(--sfx-red-soft);
  color: var(--sfx-red);
  border-color: var(--sfx-red);
}
.sfx-pill.is-info {
  background: var(--sfx-primary-soft);
  color: var(--sfx-primary-deep);
  border-color: var(--sfx-primary);
}
.sfx-pill.is-muted {
  background: var(--sfx-subtle-bg);
  color: var(--sfx-muted);
  border-color: var(--sfx-border);
}

/* ------------------------------------------------------------------------------------
   Buttons
   ------------------------------------------------------------------------------------ */
.sfx-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 30px;
  padding: 0 12px;
  border-radius: var(--sfx-radius-ctrl);
  border: 1px solid var(--sfx-border);
  background: var(--sfx-card-bg);
  color: var(--sfx-ink-secondary);
  font-family: inherit;
  font-size: var(--sfx-fs-table);
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  box-sizing: border-box;
}

.sfx-btn:hover { background: var(--sfx-hover-bg); color: var(--sfx-ink); }

.sfx-btn-primary {
  background: var(--sfx-primary);
  border-color: var(--sfx-primary);
  color: #FFFFFF;
}
.sfx-btn-primary:hover { background: var(--sfx-primary-hover); border-color: var(--sfx-primary-hover); color: #FFFFFF; }

.sfx-btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--sfx-muted);
}
.sfx-btn-ghost:hover { background: var(--sfx-hover-bg); color: var(--sfx-ink); }

.sfx-btn:disabled,
.sfx-btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
}

/* ------------------------------------------------------------------------------------
   Table wrapper — the guard against horizontal overflow at 375px
   ------------------------------------------------------------------------------------ */
.sfx-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

table.sfx-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--sfx-fs-table);
}

table.sfx-table th {
  text-align: left;
  font-size: var(--sfx-fs-label);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--sfx-muted);
  padding: 8px 10px;
  border-bottom: 1px solid var(--sfx-border);
  white-space: nowrap;
}

table.sfx-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--sfx-border-soft);
  color: var(--sfx-ink-secondary);
  vertical-align: middle;
}

table.sfx-table tbody tr:hover { background: var(--sfx-canvas); }

table.sfx-table td.sfx-cell-strong { color: var(--sfx-ink); font-weight: 600; }

/* Slim latency bar used inside table cells. */
.sfx-cell-bar {
  display: inline-block;
  width: 60px;
  height: 5px;
  border-radius: var(--sfx-radius-pill);
  background: var(--sfx-border);
  overflow: hidden;
  vertical-align: middle;
  margin-left: 6px;
}
.sfx-cell-bar > span {
  display: block;
  height: 100%;
  background: var(--sfx-primary);
  border-radius: var(--sfx-radius-pill);
}

/* ------------------------------------------------------------------------------------
   Empty state
   ------------------------------------------------------------------------------------ */
.sfx-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 28px 16px;
  text-align: center;
  color: var(--sfx-muted);
  font-size: var(--sfx-fs-table);
}

.sfx-empty-state .sfx-empty-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--sfx-ink);
}

/* ------------------------------------------------------------------------------------
   Report-broken-tool micro button (injected by the health beacon)
   ------------------------------------------------------------------------------------ */
.sfx-report-tool-btn {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 60;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 12px;
  border-radius: var(--sfx-radius-pill);
  border: 1px solid var(--sfx-border);
  background: var(--sfx-card-bg);
  color: var(--sfx-muted);
  font-family: var(--sfx-font-ui);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--sfx-shadow-tooltip);
  opacity: 0.85;
}
.sfx-report-tool-btn:hover { opacity: 1; color: var(--sfx-ink); }

.sfx-toast {
  position: fixed;
  right: 14px;
  bottom: 54px;
  z-index: 61;
  padding: 8px 12px;
  border-radius: var(--sfx-radius-ctrl);
  background: var(--sfx-ink);
  color: var(--sfx-card-bg);
  font-family: var(--sfx-font-ui);
  font-size: 11.5px;
  font-weight: 600;
  box-shadow: var(--sfx-shadow-tooltip);
}

/* ------------------------------------------------------------------------------------
   Utility: keep a long value from breaking a grid column
   ------------------------------------------------------------------------------------ */
.sfx-truncate {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sfx-nowrap { white-space: nowrap; }
.sfx-mt-3 { margin-top: var(--sfx-space-3); }
.sfx-mb-3 { margin-bottom: var(--sfx-space-3); }
