/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 6px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
  white-space: nowrap;
  line-height: 1.4;
}

.btn--primary {
  background: #238636;
  color: #fff;
  border: 1px solid rgba(240, 246, 252, 0.1);
}

.btn--primary:hover {
  background: #2ea043;
}

.btn--secondary {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn--secondary:hover {
  background: var(--bg-hover);
  border-color: var(--text-muted);
}

.btn--ghost {
  color: var(--text-secondary);
  border: 1px solid transparent;
  padding: 5px 10px;
}

.btn--ghost:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
  border-color: var(--border);
}

.btn--sm {
  font-size: 12px;
  padding: 4px 10px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---- Input ---- */
.input-wrap {
  display: flex;
  gap: var(--space-2);
  max-width: 520px;
  margin: 0 auto;
}

.input {
  flex: 1;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  padding: 10px 14px;
  font-size: 15px;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

.input::placeholder {
  color: var(--text-muted);
}

.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.12);
}

.input--full {
  width: 100%;
  max-width: none;
}

/* ---- Model card ---- */
.model-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-6);
  overflow: hidden;
}

.model-card__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border-muted);
}

.model-card__identity {}

.model-card__actions {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  flex-shrink: 0;
}

.model-card__name {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: var(--space-2);
  line-height: 1.2;
}

.model-card__name a {
  color: var(--text-primary);
  transition: color var(--transition);
}

.model-card__name a:hover {
  color: var(--accent);
}

.model-card__tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

.model-card__stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  divide-x: 1px solid var(--border-muted);
}

.model-card__stat {
  padding: var(--space-4) var(--space-6);
  border-right: 1px solid var(--border-muted);
}

.model-card__stat:last-child {
  border-right: none;
}

.model-card__stat-value {
  font-size: 24px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-primary);
  letter-spacing: -0.03em;
  line-height: 1.2;
  margin-bottom: 3px;
}

.model-card__stat-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
}

/* ---- Badge ---- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
  border: 1px solid;
}

.badge--neutral {
  background: var(--bg-hover);
  color: var(--text-secondary);
  border-color: var(--border);
}

.badge--blue {
  background: rgba(88, 166, 255, 0.1);
  color: #79c0ff;
  border-color: rgba(88, 166, 255, 0.25);
}

.badge--green {
  background: var(--green-subtle);
  color: var(--green);
  border-color: var(--green-border);
}

.badge--yellow {
  background: var(--yellow-subtle);
  color: var(--yellow);
  border-color: var(--yellow-border);
}

.badge--red {
  background: var(--red-subtle);
  color: var(--red);
  border-color: var(--red-border);
}

.badge--orange {
  background: rgba(210, 153, 34, 0.1);
  color: #e3a23a;
  border-color: rgba(210, 153, 34, 0.3);
}

.badge--purple {
  background: rgba(163, 113, 247, 0.1);
  color: #b392f0;
  border-color: rgba(163, 113, 247, 0.3);
}

.badge--pink {
  background: rgba(219, 97, 162, 0.1);
  color: #db61a2;
  border-color: rgba(219, 97, 162, 0.3);
}

.badge--teal {
  background: rgba(45, 212, 191, 0.1);
  color: #2dd4bf;
  border-color: rgba(45, 212, 191, 0.3);
}

.badge--yellow {
  background: var(--yellow-subtle);
  color: var(--yellow);
  border-color: var(--yellow-border);
}

.badge--format {
  background: rgba(139, 148, 158, 0.1);
  color: var(--text-secondary);
  border-color: var(--border);
  font-family: var(--font-mono);
  letter-spacing: 0.03em;
}

/* ---- Quant table ---- */
.quant-table-wrap {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  overflow-x: auto;
}

.quant-table {
  width: 100%;
  font-size: 14px;
  table-layout: fixed;
}

.quant-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 10px var(--space-4);
  border-bottom: 1px solid var(--border);
  background: var(--bg-primary);
  white-space: nowrap;
}

.quant-table th:not(:first-child) {
  text-align: right;
}

/* Column widths */
.quant-table th:nth-child(1) { width: 120px; }  /* Format */
.quant-table th:nth-child(2) { width: 110px; }  /* Bits */
.quant-table th:nth-child(3) { width: 130px; }  /* Model size */
.quant-table th:nth-child(4) { width: 130px; }  /* VRAM */
.quant-table th:nth-child(5) { width: 120px; }  /* KV cache */
.quant-table th:nth-child(6) { width: 130px; }  /* Total VRAM */

.quant-table td {
  padding: 10px var(--space-4);
  border-bottom: 1px solid var(--border-muted);
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-secondary);
}

.quant-table td:first-child {
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
}

.quant-table td:not(:first-child) {
  text-align: right;
}

.quant-table tbody tr {
  cursor: pointer;
  transition: background var(--transition);
}

.quant-table tbody tr:hover {
  background: var(--bg-hover);
}

.quant-table tbody tr:last-child td {
  border-bottom: none;
}

.quant-table tbody tr.selected {
  background: rgba(88, 166, 255, 0.07);
}

.quant-table tbody tr.selected td:first-child {
  color: var(--accent);
}

/* Group header rows */
.quant-table .group-header td {
  background: var(--bg-primary);
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 6px var(--space-4);
  border-bottom: 1px solid var(--border-muted);
  cursor: default;
}

.quant-table .group-header:hover {
  background: var(--bg-primary) !important;
}

/* ---- Hardware card ---- */
.hw-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-4);
  transition: border-color var(--transition);
}

.hw-card--green  { border-left-color: var(--green); }
.hw-card--yellow { border-left-color: var(--yellow); }
.hw-card--red    { border-left-color: var(--red); }
.hw-card--neutral { border-left-color: var(--border); }

.hw-card__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.hw-card__name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.hw-card__vram-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  font-family: var(--font-mono);
}

.hw-card__status {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.hw-card__status--green  { color: var(--green); }
.hw-card__status--yellow { color: var(--yellow); }
.hw-card__status--red    { color: var(--red); }

.hw-card__bar-wrap {
  height: 3px;
  background: var(--bg-hover);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: var(--space-2);
}

.hw-card__bar {
  height: 100%;
  border-radius: 2px;
  transition: width 300ms ease;
}

.hw-card__bar--green  { background: var(--green); }
.hw-card__bar--yellow { background: var(--yellow); }
.hw-card__bar--red    { background: var(--red); }

.hw-card__detail {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.hw-card__input-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.hw-card__input-row label {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.hw-card__input {
  width: 64px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 2px var(--space-2);
  font-size: 12px;
  font-family: var(--font-mono);
  outline: none;
  text-align: right;
}

.hw-card__input:focus {
  border-color: var(--accent);
}

/* ---- Slider section ---- */
.slider-section {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5) var(--space-6);
}

.slider-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}

.slider-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.slider-value {
  font-size: 24px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--accent);
  letter-spacing: -0.03em;
}

.slider-input {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  height: 4px;
  background: var(--bg-hover);
  border-radius: 2px;
  outline: none;
  margin-bottom: var(--space-3);
  cursor: pointer;
}

.slider-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-primary);
  cursor: pointer;
  transition: transform var(--transition);
}

.slider-input::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

.slider-input::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-primary);
  cursor: pointer;
}

.slider-ticks {
  position: relative;
  height: 16px;
  margin-bottom: var(--space-5);
}

.slider-ticks span {
  position: absolute;
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  transform: translateX(-50%);
}

.slider-ticks span:first-child { transform: none; }
.slider-ticks span:last-child  { transform: translateX(-100%); }

.kv-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border-muted);
}

.kv-stat {}

.kv-stat__label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
  margin-bottom: 4px;
}

.kv-stat__value {
  font-size: 20px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-primary);
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.kv-stat__sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ---- Alert ---- */
.alert {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  font-size: 14px;
  border: 1px solid;
  line-height: 1.6;
}

.alert a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.alert a:hover { opacity: 0.8; }

.alert--error   { background: var(--red-subtle);    color: var(--red);    border-color: var(--red-border); }
.alert--warning { background: var(--yellow-subtle);  color: var(--yellow); border-color: var(--yellow-border); }
.alert--info    { background: rgba(88,166,255,0.08); color: #79c0ff;      border-color: rgba(88,166,255,0.3); }

/* ---- Token overlay ---- */
.token-overlay {
  position: fixed;
  inset: 0;
  background: rgba(1, 4, 9, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: var(--space-4);
  animation: fadeIn 150ms ease;
}

.token-overlay.hidden { display: none; }

.token-dialog {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  width: 100%;
  max-width: 440px;
}

.token-dialog__title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: var(--space-2);
}

.token-dialog__desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: var(--space-4);
}

.token-dialog__desc a { color: var(--accent); }
.token-dialog__desc a:hover { text-decoration: underline; }

.token-dialog__actions {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

/* ---- Skeleton ---- */
.skel-line {
  height: 14px;
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-2);
}
.skel-line--sm { height: 10px; }
.skel-line--lg { height: 20px; }

/* ---- Loading ---- */
.loading-state {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-8) 0;
  color: var(--text-secondary);
  font-size: 14px;
}

/* ---- Misc ---- */
.note {
  font-size: 12px;
  color: var(--text-muted);
}

.quant-hint {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: var(--space-3);
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

/* ---- Token status bar ---- */
.token-bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: rgba(63, 185, 80, 0.06);
  border: 1px solid var(--green-border);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--green);
  margin-bottom: var(--space-4);
}

.token-bar span { flex: 1; }

/* ---- Trending chips (step 1) ---- */
.trending-section {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-5);
  justify-content: center;
}

.trending-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  flex-shrink: 0;
}

.trending-chip {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
  font-family: var(--font-mono);
  white-space: nowrap;
}

.trending-chip:hover {
  background: var(--bg-hover);
  border-color: var(--border);
  color: var(--text-primary);
}

/* ---- Multi-GPU toggle ---- */
.hw-section-controls {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.gpu-mult-wrap {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.gpu-mult-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

.gpu-mult-btns {
  display: flex;
  gap: 2px;
  background: var(--bg-surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2px;
}

.gpu-mult-btn {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 3px;
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.gpu-mult-btn:hover {
  color: var(--text-primary);
}

.gpu-mult-btn.active {
  background: var(--accent);
  color: #fff;
}

/* ---- Hardware card footer (TPS + best quant) ---- */
.hw-card__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: var(--space-2);
  padding-top: var(--space-2);
  border-top: 1px solid var(--border-muted);
  gap: var(--space-2);
}

.hw-card__best {
  font-size: 11px;
  color: var(--text-muted);
}

.hw-card__best-quant {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 600;
}

.hw-card__best-quant--match {
  color: var(--green);
}

.hw-card__tps {
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--accent);
  white-space: nowrap;
}

/* ---- Apple Silicon preset select ---- */
.hw-card__select {
  background: var(--bg-surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 12px;
  padding: 3px 6px;
  cursor: pointer;
  width: 100%;
  outline: none;
  font-family: var(--font-sans);
}

.hw-card__select:focus {
  border-color: var(--accent);
}

@media (max-width: 640px) {
  .model-card__stats {
    grid-template-columns: 1fr 1fr;
  }

  .model-card__stat {
    border-right: none;
    border-bottom: 1px solid var(--border-muted);
    padding: var(--space-3) var(--space-4);
  }

  .model-card__stat:nth-child(odd) {
    border-right: 1px solid var(--border-muted);
  }

  .model-card__stat:last-child,
  .model-card__stat:nth-last-child(2):nth-child(odd) {
    border-bottom: none;
  }

  .model-card__stat-value {
    font-size: 18px;
  }

  .model-card__header {
    flex-direction: column;
    padding: var(--space-4);
  }

  .kv-stats {
    grid-template-columns: 1fr 1fr;
  }

  .token-dialog__actions {
    flex-direction: column;
  }
}
