/* Components: icon, button, badge, card, stat, meter, table, menu, dialog, toast,
 * alert, empty state, code block, tabs, avatar, skeleton, chart. See static/README.md. */

/* --- icon ------------------------------------------------------------------------- */

.icon {
  display: inline-block;
  flex: none;
  width: 16px;
  height: 16px;
  vertical-align: -3px;
}

.icon-sm {
  width: 14px;
  height: 14px;
}

.icon-lg {
  width: 20px;
  height: 20px;
}

/* --- button ----------------------------------------------------------------------- */

.btn {
  --btn-bg: var(--surface);
  --btn-fg: var(--text);
  --btn-border: var(--border-strong);
  --btn-hover: var(--surface-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--btn-border);
  border-radius: var(--radius);
  background: var(--btn-bg);
  color: var(--btn-fg);
  box-shadow: var(--shadow-xs);
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.btn:hover {
  background: var(--btn-hover);
  text-decoration: none;
}

.btn:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

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

.btn-primary {
  --btn-bg: var(--primary);
  --btn-fg: var(--primary-text);
  --btn-border: var(--primary);
  --btn-hover: var(--primary-hover);
}

.btn-primary:hover {
  border-color: var(--primary-hover);
}

.btn-secondary {
  /* the default look, named for readability in templates */
}

.btn-ghost {
  --btn-bg: transparent;
  --btn-border: transparent;
  --btn-fg: var(--text-2);
  --btn-hover: var(--surface-3);
  box-shadow: none;
}

.btn-ghost:hover {
  color: var(--text);
}

.btn-danger {
  --btn-bg: var(--danger-solid);
  --btn-fg: #ffffff;
  --btn-border: var(--danger-solid);
  --btn-hover: var(--danger-solid-hover);
}

.btn-danger:focus-visible {
  box-shadow: var(--ring-danger);
}

.btn-danger-ghost {
  --btn-bg: transparent;
  --btn-border: transparent;
  --btn-fg: var(--danger);
  --btn-hover: var(--danger-bg);
  box-shadow: none;
}

.btn-sm {
  height: 28px;
  padding: 0 10px;
  font-size: 13px;
  gap: 5px;
}

.btn-lg {
  height: 40px;
  padding: 0 16px;
  font-size: 14px;
}

.btn-block {
  display: flex;
  width: 100%;
}

.btn-icon {
  width: 34px;
  padding: 0;
}

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

.linkbutton {
  padding: 0;
  border: 0;
  background: none;
  color: var(--link);
  font-weight: 500;
  cursor: pointer;
}

.linkbutton:hover {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.form-inline {
  display: inline;
}

/* --- badge ------------------------------------------------------------------------ */

.badge {
  --badge-fg: var(--neutral);
  --badge-bg: var(--neutral-bg);
  --badge-border: var(--neutral-border);
  --badge-dot: var(--neutral-dot);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 22px;
  padding: 0 8px;
  border: 1px solid var(--badge-border);
  border-radius: 999px;
  background: var(--badge-bg);
  color: var(--badge-fg);
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
}

.badge-dot::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--badge-dot);
}

.badge-live {
  --badge-fg: var(--ok);
  --badge-bg: var(--ok-bg);
  --badge-border: var(--ok-border);
  --badge-dot: var(--ok-dot);
}

.badge-pending {
  --badge-fg: var(--warn);
  --badge-bg: var(--warn-bg);
  --badge-border: var(--warn-border);
  --badge-dot: var(--warn-dot);
}

.badge-error {
  --badge-fg: var(--danger);
  --badge-bg: var(--danger-bg);
  --badge-border: var(--danger-border);
  --badge-dot: var(--danger-dot);
}

/* Paused (1.3): neutral like Disabled, but told apart by a dashed edge and a pause
 * glyph for a dot, so the two never read as the same state. */
.badge-paused {
  --badge-border: var(--neutral-dot);
  border-style: dashed;
}

.badge-paused.badge-dot::before {
  width: 6px;
  height: 7px;
  border-radius: 0;
  background: linear-gradient(
    to right,
    var(--badge-dot) 0 2px,
    transparent 2px 4px,
    var(--badge-dot) 4px 6px
  );
}

.badge-info {
  --badge-fg: var(--primary-soft-text);
  --badge-bg: var(--primary-soft);
  --badge-border: transparent;
}

.badge-pro {
  --badge-fg: var(--highlight-text);
  --badge-bg: var(--highlight);
  --badge-border: var(--highlight);
  font-weight: 600;
  letter-spacing: 0.01em;
}

.badge-free {
  --badge-fg: var(--text-2);
  --badge-bg: var(--surface-3);
  --badge-border: var(--border);
}

/* --- card ------------------------------------------------------------------------- */

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.card-header-plain {
  border-bottom: 0;
  padding-bottom: 0;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.4;
}

.card-desc {
  margin-top: 2px;
  color: var(--text-2);
  font-size: 13px;
}

.card-body {
  padding: 20px;
}

.card-body-tight {
  padding: 12px 20px 0;
}

/* a card in a grid row that fills the row, footer pinned to the bottom */
.card-stretch {
  display: flex;
  flex-direction: column;
}

.card-stretch > .card-body {
  flex: 1;
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  color: var(--text-2);
  font-size: 13px;
}

.card-danger {
  border-color: var(--danger-border);
}

.card-danger .card-header {
  border-bottom-color: var(--danger-border);
}

/* definition list of facts inside a card */
.facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 16px;
}

.fact dt {
  color: var(--text-3);
  font-size: 12px;
  font-weight: 500;
}

.fact dd {
  margin-top: 2px;
  font-size: 14px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

/* --- stat tile -------------------------------------------------------------------- */

.stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 20px;
}

.stat-label {
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
}

.stat-value {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

.stat-sub {
  color: var(--text-3);
  font-size: 12px;
}

.stat-spark {
  margin-top: 8px;
  width: 100%;
  height: 36px;
  color: var(--chart-1);
}

/* --- sparkline -------------------------------------------------------------------- */

.spark {
  display: inline-block;
  width: 88px;
  height: 24px;
  color: var(--chart-1);
  overflow: visible;
}

.spark-line {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.spark-area {
  fill: currentColor;
  opacity: 0.1;
}

.spark-flat {
  stroke: var(--border-strong);
  stroke-width: 1.5;
  stroke-dasharray: 2 3;
  vector-effect: non-scaling-stroke;
}

/* --- meter ------------------------------------------------------------------------ */

.meter {
  position: relative;
  height: 6px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}

.meter-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
}

.meter[data-state="warn"] .meter-fill {
  background: var(--warn-dot);
}

.meter[data-state="full"] .meter-fill {
  background: var(--danger-dot);
}

.usage {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 200px;
}

.usage-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  color: var(--text-2);
}

.usage-line strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* --- alert (inline, server-rendered) ---------------------------------------------- */

.alert {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;
  border: 1px solid var(--neutral-border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
}

.alert .icon {
  margin-top: 1px;
}

.alert-ok {
  border-color: var(--ok-border);
  background: var(--ok-bg);
  color: var(--ok);
}

.alert-warn {
  border-color: var(--warn-border);
  background: var(--warn-bg);
  color: var(--warn);
}

.alert-error {
  border-color: var(--danger-border);
  background: var(--danger-bg);
  color: var(--danger);
}

.alert-info {
  border-color: transparent;
  background: var(--primary-soft);
  color: var(--primary-soft-text);
}

.alert-body {
  flex: 1;
  min-width: 0;
}

.alert-close {
  margin: -4px -6px -4px 0;
  color: inherit;
}

/* --- empty state ------------------------------------------------------------------ */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 40px 24px;
  text-align: center;
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-bottom: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  color: var(--text-2);
  box-shadow: var(--shadow-xs);
}

.empty-title {
  font-size: 15px;
  font-weight: 600;
}

.empty-desc {
  max-width: 420px;
  color: var(--text-2);
  font-size: 13px;
}

/* --- code block ------------------------------------------------------------------- */

.code {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 10px 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.code-text {
  flex: 1;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font: 12.5px/1.6 var(--mono);
  resize: none;
  white-space: pre-wrap;
  word-break: break-all;
}

.code-text:focus {
  outline: none;
}

.code:focus-within {
  border-color: var(--primary);
  box-shadow: var(--ring);
}

/* --- avatar ----------------------------------------------------------------------- */

.avatar {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary-soft-text);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.avatar-lg {
  width: 40px;
  height: 40px;
  font-size: 14px;
}

/* --- skeleton --------------------------------------------------------------------- */

.skeleton {
  display: block;
  height: 12px;
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--surface-3), var(--surface-2), var(--surface-3));
  background-size: 200% 100%;
  animation: skeleton 1.4s ease-in-out infinite;
}

@keyframes skeleton {
  from {
    background-position: 200% 0;
  }
  to {
    background-position: -200% 0;
  }
}

/* --- tabs ------------------------------------------------------------------------- */

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}

.tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 10px 12px;
  color: var(--text-2);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  text-decoration: none;
}

.tab:hover {
  color: var(--text);
  text-decoration: none;
}

.tab[aria-current="page"],
.tab[aria-selected="true"] {
  color: var(--text);
}

.tab[aria-current="page"]::after,
.tab[aria-selected="true"]::after {
  content: "";
  position: absolute;
  right: 8px;
  bottom: -1px;
  left: 8px;
  height: 2px;
  border-radius: 2px;
  background: var(--primary);
}

.empty-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 8px;
}
