*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --mono: "SF Mono", "Fira Code", "Consolas", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --radius: 6px;
  --tr: 120ms ease;
  --cell-pad: 7px 14px;
}

[data-theme="light"] {
  --bg: #fafafa; --bg-alt: #f0f0f3; --bg-hover: #e8e8ed; --border: #dddde4;
  --text: #2c2c3a; --text-dim: #70708a; --accent: #507c34;
  --accent-dim: rgba(80,124,52,0.10); --green: #1a9a4a; --red: #cc2d2d; --orange: #c07b0a;
  --shadow: 0 6px 24px rgba(0,0,0,0.08); color-scheme: light;
}

[data-theme="dark"] {
  --bg: #111116; --bg-alt: #19191f; --bg-hover: #222230; --border: #2a2a38;
  --text: #d4d4de; --text-dim: #6e6e88; --accent: #98C379;
  --accent-dim: rgba(152,195,121,0.10); --green: #3ec96e; --red: #f06060; --orange: #e6a830;
  --shadow: 0 6px 24px rgba(0,0,0,0.5); color-scheme: dark;
}

html { font: 14px/1.5 var(--sans); background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; height: 100%; }
body { display: flex; flex-direction: column; min-height: 100dvh; min-height: -webkit-fill-available; padding-bottom: env(safe-area-inset-bottom); }

/* ── Utilities ────────────────────────────────────────────── */
.dim, .no  { color: var(--text-dim); }
.mono, model-table td.num { font-family: var(--mono); font-size: 12px; }
.yes  { color: var(--green); }

/* ── Header ───────────────────────────────────────────────── */
header { position: sticky; top: 0; z-index: 100; background: var(--bg); border-bottom: 1px solid var(--border); }

.bar, .bar-right { display: flex; align-items: center; }
.bar { gap: 12px; padding: 10px 16px; }
.bar-right { gap: 8px; margin-left: auto; }

.brand { display: flex; flex-direction: column; white-space: nowrap; }

h1 {
  font-size: 17px; font-weight: 700; letter-spacing: -0.01em; line-height: 1.2;
  & .flip { color: var(--accent); font-weight: 800; }
}

.powered-by {
  font-size: 10px; color: var(--text-dim); line-height: 1;
  & a { color: var(--text-dim); text-decoration: none; &:hover { color: var(--accent); text-decoration: underline; } }
}

#github-link,
.icon-btn,
.copy-all,
#compare-btn,
.d-provider,
.d-id-row,
.cmp-id {
  display: inline-flex;
  align-items: center;
}

#github-link,
button {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-alt);
  color: var(--text);
  transition: all var(--tr);
}

#github-link {
  justify-content: center;
  width: 34px; height: 34px;
  &:hover { border-color: var(--accent); color: var(--accent); }
}

/* ── Search ───────────────────────────────────────────────── */
.search-wrap {
  position: relative; flex: 1; min-width: 0;

  & .search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-dim); pointer-events: none; }

  & input {
    width: 100%; height: 36px; padding: 0 44px 0 36px;
    background: var(--bg-alt); border: 1px solid var(--border); border-radius: var(--radius);
    color: var(--text); font: inherit; font-size: 13px; outline: none; transition: border-color var(--tr);
    &:focus { border-color: var(--accent); }
    &::placeholder { color: var(--text-dim); font-size: 12px; }
  }

  & kbd {
    font: 10px var(--sans); color: var(--text-dim); background: var(--bg);
    border: 1px solid var(--border); border-radius: 3px; padding: 1px 5px; pointer-events: none;
    position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  }
}

/* ── Buttons ──────────────────────────────────────────────── */
button {
  height: 34px; padding: 0 14px; font: 13px/1 var(--sans); font-weight: 500;
  cursor: pointer; white-space: nowrap;
  &:hover { border-color: var(--accent); color: var(--accent); }
  &:disabled { opacity: 0.35; pointer-events: none; }
}

.icon-btn {
  width: 28px; height: 28px; padding: 0; border-radius: 5px;
  justify-content: center;
  &.sm { width: 24px; height: 24px; }
}

.copy-all {
  height: 30px; padding: 0 10px; border-radius: 6px; font-size: 12px;
  gap: 5px;
}

.copied { color: var(--green); border-color: var(--green); }

#compare-btn {
  gap: 6px;
  & span { display: inline-block; min-width: 10px; text-align: center; }
  & kbd {
    font: 10px var(--sans); color: var(--text-dim); background: var(--bg); border: 1px solid var(--border); border-radius: 3px; padding: 1px 5px; margin-left: 2px;
  }
}

#theme-toggle { width: 34px; padding: 0; font-size: 17px; line-height: 32px; }

/* ── Table ────────────────────────────────────────────────── */
model-table {
  display: block; overflow: auto; flex: 1; min-height: 0;

  & table { width: 100%; border-collapse: collapse; white-space: nowrap; font-variant-numeric: tabular-nums; }
  & thead { position: sticky; top: 0; z-index: 10; }

  & th {
    background: var(--bg-alt); border-bottom: 2px solid var(--border); padding: var(--cell-pad);
    text-align: left; font-weight: 600; font-size: 11px; color: var(--text-dim);
    text-transform: uppercase; letter-spacing: 0.04em; cursor: pointer; user-select: none; transition: color var(--tr);
    &:hover { color: var(--text); }
    &.num { text-align: right; }
    & .col-count { font-weight: 400; font-size: 10px; opacity: 0.6; text-transform: none; letter-spacing: 0; }
    & .sort-arrow { display: inline-block; width: 12px; text-align: center; font-size: 8px; opacity: 0.3; }
    &.sorted .sort-arrow { opacity: 1; color: var(--accent); }
  }

  & td {
    padding: var(--cell-pad); border-bottom: 1px solid var(--border); overflow: hidden; text-overflow: ellipsis;
    &:first-child { overflow: visible; text-overflow: clip; }
    &.num { text-align: right; }
    &.bool { text-align: center; }
  }

  & tbody tr {
    &:nth-child(even) td { background: var(--bg-alt); }
    &:hover td { background: var(--bg-hover); }
  }

  & tr.selected td { background: var(--accent-dim) !important; }

  & .model-link { color: var(--accent); text-decoration: none; cursor: pointer; font-weight: 500; &:hover { text-decoration: underline; } }
  & .id-cell .model-link { color: var(--text-dim); font-weight: inherit; }

  & .cmp-cell { cursor: pointer; }

  & .compare-cb {
    width: 15px; height: 15px; margin: 0; padding: 0;
    appearance: none; -webkit-appearance: none; -moz-appearance: none;
    border: 1.5px solid var(--border); border-radius: 3px; background: transparent;
    outline: none; cursor: pointer; position: relative; vertical-align: middle; flex-shrink: 0; transition: all var(--tr);
    &::before, &::after { content: none; }
    &:checked { background: var(--accent); border-color: var(--accent);
      &::after { content: ""; display: block; position: absolute; left: 4px; top: 1px; width: 4px; height: 8px; border: solid white; border-width: 0 1.5px 1.5px 0; transform: rotate(45deg); }
    }
    &:hover { border-color: var(--accent); }
  }

  & .id-cell .id-wrap { display: inline-flex; align-items: center; gap: 6px; }
  & .id-cell .copy-id { opacity: 0; pointer-events: none; transition: opacity var(--tr), border-color var(--tr), color var(--tr); will-change: opacity; }
  & tbody tr:hover .id-cell .copy-id { opacity: 1; pointer-events: auto; }

  & .status-deprecated { opacity: 0.35; }
}

/* ── Loading / Empty ──────────────────────────────────────── */
.loading, .empty { text-align: center; padding: 80px 16px; color: var(--text-dim); }
.spinner { display: inline-block; width: 20px; height: 20px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .5s linear infinite; margin-bottom: 10px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Dialog ───────────────────────────────────────────────── */
dialog {
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 12px; padding: 0; max-height: 90dvh; box-shadow: var(--shadow);
  overflow: auto; margin: auto; position: relative;
  &::backdrop { background: rgba(0,0,0,0.5); backdrop-filter: blur(4px); }
}

.dialog-close { position: absolute; top: 12px; right: 12px; width: 30px; height: 30px; padding: 0; border-radius: 50%; font-size: 15px; line-height: 28px; z-index: 2; }
.dialog-footer { display: flex; justify-content: flex-end; margin-top: 20px; }

/* ── Detail dialog ────────────────────────────────────────── */
#detail-dialog { width: min(720px, 84vw); }

model-detail {
  display: block; width: 100%; padding: 40px 48px 32px;

  & .d-hero { display: flex; flex-direction: column; align-items: center; text-align: center; margin-bottom: 28px; }
  & .d-provider { gap: 8px; font-size: 13px; color: var(--text-dim); margin-bottom: 8px;
    & img { width: 22px; height: 22px; border-radius: 4px; }
  }
  & .d-name { font-size: 28px; font-weight: 700; letter-spacing: -0.025em; line-height: 1.2; margin-bottom: 6px; color: var(--accent); }
  & .d-id-row { gap: 8px; margin-bottom: 14px; }
  & .d-id { font: 13px/1 var(--mono); color: var(--text-dim); }
  & .d-badges { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }

  & .d-body { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

  & .d-card {
    background: var(--bg-alt); border-radius: 8px; padding: 16px 18px;
    & h3 { font-size: 12px; font-weight: 600; color: var(--text); margin-bottom: 10px; }
    & table { width: 100%; border-collapse: collapse; }
    & td { padding: 4px 0; font-size: 13px; border: none;
      &.kl { color: var(--text-dim); padding-right: 12px; }
      &.kv { text-align: right; font: 13px var(--mono); color: var(--text); }
    }
  }
}

.badge { font-size: 12px; padding: 3px 10px; border-radius: 5px; font-weight: 500; }
.b-green  { background: rgba(34,197,94,0.10);  color: var(--green); }
.b-orange { background: rgba(230,168,48,0.10);  color: var(--orange); }
.b-red    { background: rgba(240,96,96,0.10);   color: var(--red); }
.b-dim    { background: rgba(110,110,136,0.08);  color: var(--text-dim); }

/* ── Compare dialog ───────────────────────────────────────── */
#compare-dialog { width: min(1100px, 95vw); }

model-compare {
  display: block; padding: 28px 32px; overflow-x: auto;
  & h2 { font-size: 18px; font-weight: 700; margin-bottom: 20px; padding-right: 40px; }
  & table { width: 100%; border-collapse: collapse; }
  & th, & td { padding: var(--cell-pad); text-align: left; border-bottom: 1px solid var(--border); }
  & th { font-size: 11px; font-weight: 600; color: var(--text-dim); background: var(--bg-alt); }
  & td { font: 13px var(--mono);
    &:first-child { font: 13px var(--sans); color: var(--text-dim); font-weight: 500; }
  }
  & .best { color: var(--green); font-weight: 600; }
  & .col-head { line-height: 1.3; & small { display: block; font-size: 10px; font-weight: 400; color: var(--text-dim); } }
  & .cmp-id { gap: 6px; }
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 700px) {
  html { font-size: 14px; }

  header { padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left); }

  .bar { flex-wrap: wrap; padding: 8px 12px; gap: 8px; }

  .brand { flex: 1; min-width: 0; }
  .brand h1 { font-size: 16px; }

  .search-wrap {
    order: 10; flex-basis: 100%; max-width: none;
    & kbd { display: none; }
    & input { height: 40px; font-size: 16px; padding: 0 12px 0 36px; /* 16px prevents iOS zoom */ }
    & input::placeholder { font-size: 13px; }
  }

  .bar-right { gap: 6px; }

  #compare-btn {
    padding: 0 10px; font-size: 12px; height: 36px;
    & kbd { display: none; }
  }

  #theme-toggle, #github-link { width: 36px; height: 36px; }

  /* Table */
  model-table {
    -webkit-overflow-scrolling: touch;
  }

  model-table th, model-table td { padding: 8px 10px; }

  model-table .compare-cb { width: 22px; height: 22px;
    &:checked::after { left: 6px; top: 2px; width: 6px; height: 10px; }
  }

  model-table .cmp-cell { padding: 0; text-align: center; vertical-align: middle; }
  model-table .cmp-cell label { display: flex; align-items: center; justify-content: center; min-height: 44px; min-width: 44px; cursor: pointer; }

  /* Always show copy buttons on mobile (no hover) */
  model-table .id-cell .copy-id { opacity: 1; pointer-events: auto; }

  .icon-btn { width: 32px; height: 32px; }
  .icon-btn.sm { width: 28px; height: 28px; }

  /* Dialogs */
  dialog {
    max-width: 100vw; width: 100vw !important; max-height: 92dvh;
    border-radius: 12px; margin: auto;
  }
  dialog::backdrop { backdrop-filter: blur(6px); }

  #detail-dialog { width: 100vw !important; }

  model-detail {
    padding: 16px 12px calc(12px + env(safe-area-inset-bottom));
    & .d-hero { margin-bottom: 14px; }
    & .d-name { font-size: 20px; margin-bottom: 4px; }
    & .d-provider { font-size: 12px; margin-bottom: 4px; }
    & .d-id { font-size: 11px; word-break: break-all; }
    & .d-id-row { gap: 6px; margin-bottom: 8px; flex-wrap: wrap; justify-content: center; }
    & .d-badges { gap: 4px; }
    & .d-body { grid-template-columns: 1fr 1fr; gap: 8px; }
    & .d-card { padding: 10px 12px; & h3 { font-size: 11px; margin-bottom: 6px; } & td { font-size: 12px; padding: 2px 0; } & td.kv { font-size: 12px; } }
  }

  .dialog-footer { margin-top: 12px; }

  .dialog-close { top: 10px; right: 10px; width: 36px; height: 36px; font-size: 16px; line-height: 34px; }

  /* Compare dialog */
  #compare-dialog { width: 100vw !important; }

  model-compare {
    padding: 16px 6px calc(12px + env(safe-area-inset-bottom));
    & h2 { font-size: 15px; margin-bottom: 10px; padding-left: 6px; }
    & th, & td { padding: 6px 6px; font-size: 11px; }
    & td:first-child { font-size: 11px; white-space: nowrap; }
  }

  /* Badges */
  .badge { font-size: 11px; padding: 2px 8px; }
}

@media (max-width: 480px) {
  #github-link { display: none; }

  .brand h1 { font-size: 15px; }
  .powered-by { font-size: 9px; }

  .compare-label { display: none; }
  #compare-btn { padding: 0 10px; gap: 4px; }

  model-table th, model-table td { padding: 7px 8px; font-size: 12px; }
  model-table .mono { font-size: 11px; }
}
