/* ==========================================================================
   components.css — shadcn/ui primitives recreated in plain CSS
   Markup mirrors the shadcn API (card/header/title/content, tab, badge...)
   ========================================================================== */

/* ------------------------------------------------------------------ button */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  height: 2.25rem;
  padding-inline: 1rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: var(--primary);
  color: var(--primary-foreground);
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  box-shadow: var(--shadow-xs);
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease,
    box-shadow 0.15s ease, transform 0.1s ease;
}
.btn:hover { background: color-mix(in oklab, var(--primary) 90%, var(--muted)); }
.btn:active { transform: translateY(0.5px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px color-mix(in oklab, var(--ring) 45%, transparent); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; pointer-events: none; }
.btn svg { width: 1rem; height: 1rem; flex: none; }
.btn svg.spin { animation: wx-spin 1s linear infinite; }

.btn-secondary {
  background: var(--secondary);
  color: var(--secondary-foreground);
  border-color: transparent;
}
.btn-secondary:hover { background: color-mix(in oklab, var(--secondary) 82%, var(--foreground)); }

.btn-outline {
  background: var(--background);
  color: var(--foreground);
  border-color: var(--border);
  box-shadow: var(--shadow-xs);
}
.btn-outline:hover { background: var(--accent); color: var(--accent-foreground); }

.btn-ghost { background: transparent; color: var(--foreground); box-shadow: none; }
.btn-ghost:hover { background: var(--accent); color: var(--accent-foreground); }

.btn-destructive {
  background: var(--destructive);
  color: #fff;
}
.btn-destructive:hover { background: color-mix(in oklab, var(--destructive) 88%, #000); }

.btn-sm { height: 2rem; padding-inline: 0.75rem; font-size: 0.75rem; border-radius: var(--radius-sm); }
.btn-lg { height: 2.5rem; padding-inline: 1.5rem; font-size: 0.875rem; }
.btn-icon { width: 2.25rem; height: 2.25rem; padding: 0; }
.btn-icon.btn-sm { width: 2rem; height: 2rem; }
.btn-block { width: 100%; }

.btn-link {
  background: none;
  color: var(--primary);
  box-shadow: none;
  height: auto;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ------------------------------------------------------------------- card */
.card {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding-block: 1.25rem;
  background: var(--card);
  color: var(--card-foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
}
.card-header {
  display: grid;
  grid-auto-rows: min-content;
  align-items: start;
  gap: 0.35rem;
  padding-inline: 1.25rem;
}
.card-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
}
.card-title svg { width: 1rem; height: 1rem; color: var(--muted-foreground); flex: none; }
.card-description { color: var(--muted-foreground); font-size: 0.78rem; }
.card-content { padding-inline: 1.25rem; flex: 1 1 auto; }
.card-footer {
  display: flex;
  align-items: center;
  padding-inline: 1.25rem;
  padding-block-start: 0.5rem;
  gap: 0.5rem;
}
.card-action { margin-inline-start: auto; }
.card-inset { border: 0; box-shadow: none; background: transparent; }

/* ------------------------------------------------------------------ badge */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  padding: 0.15rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--background);
  color: var(--foreground);
  font-size: 0.7rem;
  font-weight: 500;
  line-height: 1.4;
  white-space: nowrap;
  width: fit-content;
}
.badge svg { width: 0.8rem; height: 0.8rem; }
.badge-primary { background: var(--primary); border-color: transparent; color: var(--primary-foreground); }
.badge-secondary { background: var(--secondary); border-color: transparent; color: var(--secondary-foreground); }
.badge-outline { background: transparent; }
.badge-muted { background: var(--muted); border-color: transparent; color: var(--muted-foreground); }
.badge-rain {
  background: color-mix(in oklab, var(--wx-rain) 14%, transparent);
  border-color: color-mix(in oklab, var(--wx-rain) 32%, transparent);
  color: var(--wx-rain);
}
.badge-warn {
  background: color-mix(in oklab, var(--wx-temp) 16%, transparent);
  border-color: color-mix(in oklab, var(--wx-temp) 35%, transparent);
  color: color-mix(in oklab, var(--wx-temp) 82%, var(--foreground));
}
.badge-danger {
  background: color-mix(in oklab, var(--destructive) 14%, transparent);
  border-color: color-mix(in oklab, var(--destructive) 32%, transparent);
  color: var(--destructive);
}
.badge-good {
  background: color-mix(in oklab, var(--wx-aqi-good) 16%, transparent);
  border-color: color-mix(in oklab, var(--wx-aqi-good) 34%, transparent);
  color: color-mix(in oklab, var(--wx-aqi-good) 85%, var(--foreground));
}

/* ------------------------------------------------------------------ input */
.input,
.select,
.textarea {
  width: 100%;
  min-width: 0;
  height: 2.25rem;
  padding-inline: 0.75rem;
  padding-block: 0.25rem;
  border: 1px solid var(--input);
  border-radius: var(--radius-md);
  background: var(--background);
  color: var(--foreground);
  font-size: 0.875rem;
  box-shadow: var(--shadow-xs);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.textarea { height: auto; padding-block: 0.5rem; resize: vertical; min-height: 6rem; }
.input::placeholder, .textarea::placeholder { color: var(--muted-foreground); }
.input:focus-visible,
.select:focus-visible,
.textarea:focus-visible {
  border-color: var(--ring);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--ring) 30%, transparent);
}
.input-lg { height: 2.75rem; font-size: 0.9375rem; border-radius: var(--radius-lg); }
.label {
  display: block;
  font-size: 0.78rem;
  font-weight: 500;
  margin-block-end: 0.4rem;
}
.field-hint { font-size: 0.72rem; color: var(--muted-foreground); margin-block-start: 0.35rem; }

.search-field { position: relative; display: flex; align-items: center; }
.search-field > svg {
  position: absolute;
  inset-inline-start: 0.8rem;
  width: 1rem;
  height: 1rem;
  color: var(--muted-foreground);
  pointer-events: none;
}
.search-field > .input { padding-inline-start: 2.3rem; }
html[dir="rtl"] .flip-x { transform: scaleX(-1); }

.kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.35rem;
  height: 1.35rem;
  padding-inline: 0.3rem;
  border: 1px solid var(--border);
  border-block-end-width: 2px;
  border-radius: var(--radius-sm);
  background: var(--muted);
  color: var(--muted-foreground);
  font-family: var(--font-mono);
  font-size: 0.65rem;
  line-height: 1;
}

/* ------------------------------------------------------------------- tabs */
.tabs {
  display: inline-flex;
  align-items: center;
  height: 2.25rem;
  padding: 3px;
  background: var(--muted);
  border-radius: var(--radius-lg);
  gap: 2px;
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  height: calc(100% - 1px);
  padding-inline: 0.65rem;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  color: var(--muted-foreground);
  font-size: 0.78rem;
  font-weight: 500;
  white-space: nowrap;
  transition: color 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}
.tab svg { width: 0.9rem; height: 0.9rem; }
.tab:hover { color: var(--foreground); }
.tab[aria-selected="true"] {
  background: var(--background);
  color: var(--foreground);
  box-shadow: var(--shadow-xs);
  border-color: var(--border);
}
.tabs-lg { height: 2.6rem; }
.tabs-lg .tab { font-size: 0.84rem; padding-inline: 0.9rem; }

.tab-panel { display: none; animation: wx-fade-in 0.28s ease both; }
.tab-panel.is-active { display: block; }

/* ------------------------------------------------------------------ table */
.table-wrap {
  position: relative;
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--card);
}
.table { width: 100%; font-size: 0.8125rem; caption-side: bottom; }
.table thead tr { border-block-end: 1px solid var(--border); }
.table th {
  height: 2.5rem;
  padding-inline: 0.7rem;
  text-align: start;
  vertical-align: middle;
  font-weight: 500;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted-foreground);
  white-space: nowrap;
}
.table td {
  padding: 0.6rem 0.7rem;
  vertical-align: middle;
  border-block-end: 1px solid color-mix(in oklab, var(--border) 65%, transparent);
}
.table tbody tr:last-child td { border-block-end: 0; }
.table tbody tr { transition: background-color 0.12s ease; }
.table tbody tr:hover { background: color-mix(in oklab, var(--muted) 55%, transparent); }
.table .num { text-align: end; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ alert */
.alert {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.15rem 0.75rem;
  align-items: start;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--card);
  font-size: 0.8125rem;
}
.alert > svg { width: 1rem; height: 1rem; margin-block-start: 0.15rem; color: var(--muted-foreground); }
.alert-title { font-weight: 600; font-size: 0.82rem; }
.alert-desc { color: var(--muted-foreground); font-size: 0.78rem; grid-column: 2; }
.alert-warn {
  border-color: color-mix(in oklab, var(--wx-temp) 40%, var(--border));
  background: color-mix(in oklab, var(--wx-temp) 9%, var(--card));
}
.alert-warn > svg { color: var(--wx-temp); }
.alert-danger {
  border-color: color-mix(in oklab, var(--destructive) 40%, var(--border));
  background: color-mix(in oklab, var(--destructive) 8%, var(--card));
}
.alert-danger > svg { color: var(--destructive); }

/* --------------------------------------------------------------- progress */
.progress {
  position: relative;
  height: 0.5rem;
  width: 100%;
  overflow: hidden;
  border-radius: 999px;
  background: color-mix(in oklab, var(--primary) 18%, transparent);
}
.progress > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
  transition: width 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}
.progress-sm { height: 0.35rem; }

/* --------------------------------------------------------------- skeleton */
.skeleton {
  background: var(--accent);
  border-radius: var(--radius-md);
  animation: wx-pulse 1.8s ease-in-out infinite;
}
.skeleton-text { height: 0.7rem; border-radius: 99px; }
.skeleton-circle { border-radius: 999px; }

@keyframes wx-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}
@keyframes wx-spin { to { transform: rotate(360deg); } }
@keyframes wx-fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
@keyframes wx-slide-up {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

/* ----------------------------------------------------------------- switch */
.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.78rem;
  color: var(--muted-foreground);
  cursor: pointer;
  user-select: none;
}
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  position: relative;
  width: 2rem;
  height: 1.15rem;
  border-radius: 999px;
  background: var(--input);
  transition: background-color 0.18s ease;
  flex: none;
}
.switch-track::after {
  content: "";
  position: absolute;
  inset-block-start: 2px;
  inset-inline-start: 2px;
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 999px;
  background: var(--background);
  box-shadow: var(--shadow-xs);
  transition: inset-inline-start 0.18s ease;
}
.switch input:checked + .switch-track { background: var(--primary); }
.switch input:checked + .switch-track::after {
  inset-inline-start: calc(100% - 0.9rem - 2px);
  background: var(--primary-foreground);
}
.switch input:focus-visible + .switch-track {
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--ring) 40%, transparent);
}

/* --------------------------------------------------------------- segmented */
.segmented {
  display: inline-flex;
  padding: 2px;
  background: var(--muted);
  border-radius: var(--radius-md);
  gap: 2px;
}
.segmented button {
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--muted-foreground);
  transition: all 0.15s ease;
}
.segmented button[aria-pressed="true"] {
  background: var(--background);
  color: var(--foreground);
  box-shadow: var(--shadow-xs);
}

/* ---------------------------------------------------------------- tooltip */
.tip { position: relative; display: inline-flex; }
.tip::after {
  content: attr(data-tip);
  position: absolute;
  inset-block-end: calc(100% + 0.4rem);
  inset-inline-start: 50%;
  transform: translateX(-50%) translateY(4px);
  padding: 0.3rem 0.5rem;
  border-radius: var(--radius-sm);
  background: var(--popover);
  color: var(--popover-foreground);
  border: 1px solid var(--border);
  font-size: 0.68rem;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
  box-shadow: var(--shadow-md);
  z-index: 60;
}
.tip:hover::after, .tip:focus-visible::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ----------------------------------------------------------------- dialog */
dialog.modal {
  padding: 0;
  border: 0;
  background: transparent;
  max-width: min(44rem, calc(100% - 2rem));
  width: 100%;
  margin: auto;
  color: var(--foreground);
  overflow: visible;
}
dialog.modal::backdrop {
  background: color-mix(in oklab, oklch(0.1 0 0) 55%, transparent);
  backdrop-filter: blur(4px);
}
.modal-content {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.5rem;
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  animation: wx-slide-up 0.22s ease both;
}
.modal-header { display: flex; align-items: flex-start; gap: 0.75rem; }
.modal-title { font-size: 1rem; font-weight: 600; }
.modal-desc { color: var(--muted-foreground); font-size: 0.8rem; }
.modal-close { margin-inline-start: auto; }
.modal-body { max-height: min(60vh, 32rem); overflow-y: auto; }

/* --------------------------------------------------------- command/search */
.command-list { display: grid; gap: 0.25rem; margin-block-start: 0.5rem; }
.command-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  padding: 0.55rem 0.65rem;
  border-radius: var(--radius-md);
  font-size: 0.83rem;
  text-align: start;
  color: var(--foreground);
  transition: background-color 0.12s ease;
}
.command-item:hover, .command-item[data-active="true"] { background: var(--accent); }
.command-item svg { width: 0.95rem; height: 0.95rem; color: var(--muted-foreground); flex: none; }
.command-meta { margin-inline-start: auto; color: var(--muted-foreground); font-size: 0.7rem; }

/* ------------------------------------------------------------------ sheet */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: grid;
  grid-template-rows: 1fr;
  pointer-events: none;
}
.sheet[data-open="true"] { pointer-events: auto; }
.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: color-mix(in oklab, oklch(0.1 0 0) 50%, transparent);
  opacity: 0;
  transition: opacity 0.2s ease;
  backdrop-filter: blur(2px);
}
.sheet[data-open="true"] .sheet-backdrop { opacity: 1; }
.sheet-panel {
  position: absolute;
  inset-block: 0;
  inset-inline-end: 0;
  width: min(19rem, 88vw);
  padding: 1.1rem;
  background: var(--background);
  border-inline-start: 1px solid var(--border);
  transform: translateX(100%);
  transition: transform 0.24s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
html[dir="rtl"] .sheet-panel { transform: translateX(-100%); }
.sheet[data-open="true"] .sheet-panel { transform: translateX(0); }
.sheet-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.6rem 0.7rem;
  border-radius: var(--radius-md);
  font-size: 0.86rem;
  color: var(--foreground);
}
.sheet-link:hover { background: var(--accent); }
.sheet-link svg { width: 1rem; height: 1rem; color: var(--muted-foreground); }

/* ------------------------------------------------------------------ toast */
.toast-stack {
  position: fixed;
  inset-block-end: 1rem;
  inset-inline: 1rem;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: center;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  max-width: 26rem;
  padding: 0.6rem 0.9rem;
  background: var(--popover);
  color: var(--popover-foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 0.8rem;
  animation: wx-slide-up 0.2s ease both;
  pointer-events: auto;
}
.toast svg { width: 0.95rem; height: 0.95rem; flex: none; }
.toast[data-type="error"] svg { color: var(--destructive); }
.toast[data-type="success"] svg { color: var(--wx-aqi-good); }
.toast.is-leaving { animation: wx-toast-out 0.18s ease forwards; }
@keyframes wx-toast-out {
  to { opacity: 0; transform: translateY(6px); }
}

/* ----------------------------------------------------------------- misc */
.empty-state {
  display: grid;
  place-items: center;
  gap: 0.6rem;
  padding: 2.5rem 1rem;
  text-align: center;
  color: var(--muted-foreground);
  font-size: 0.83rem;
}
.empty-state svg { width: 1.75rem; height: 1.75rem; opacity: 0.6; }

.pill-row { display: flex; flex-wrap: wrap; gap: 0.4rem; }

.divider-label {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--muted-foreground);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.divider-label::before,
.divider-label::after {
  content: "";
  height: 1px;
  flex: 1;
  background: var(--border);
}

.link-underline {
  text-decoration: underline;
  text-decoration-color: color-mix(in oklab, var(--primary) 40%, transparent);
  text-underline-offset: 3px;
  transition: text-decoration-color 0.15s ease;
}
.link-underline:hover { text-decoration-color: var(--primary); }

.scroll-x {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-block-end: 0.35rem;
  scroll-snap-type: x mandatory;
  scrollbar-width: thin;
}
.scroll-x > * { scroll-snap-align: start; flex: none; }
