/* ============================================================
   COMPONENTS — reusable primitives
   Every visual element in the app should be expressible as a
   class combination from this file. If you find yourself
   writing inline `style="..."` you're breaking the system.
   ============================================================ */

/* ─── Button ────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--touch-min);
  padding: 0 var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  line-height: 1;
  white-space: nowrap;
  border: 1px solid transparent;
  transition: background var(--duration-fast) var(--ease),
              border-color var(--duration-fast) var(--ease),
              color var(--duration-fast) var(--ease),
              transform var(--duration-fast) var(--ease);
  user-select: none;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn .btn-icon { width: 16px; height: 16px; flex-shrink: 0; }

.btn-primary {
  background: var(--color-accent);
  color: var(--color-accent-fg);
}
.btn-primary:hover { background: var(--color-accent-hover); }

.btn-secondary {
  background: var(--color-surface-2);
  color: var(--color-text);
  border-color: var(--color-border);
}
.btn-secondary:hover { background: var(--color-surface-3); }

.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
}
.btn-ghost:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
}

.btn-danger {
  background: var(--color-danger);
  color: #fff;
}
.btn-danger:hover { filter: brightness(0.95); }

.btn-block { width: 100%; }
.btn-lg { min-height: 48px; padding: 0 var(--space-5); font-size: var(--text-base); }
.btn-sm { min-height: 32px; padding: 0 var(--space-3); font-size: var(--text-xs); }

/* ─── Icon button (square, icon-only) ──────────────────── */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--touch-min);
  height: var(--touch-min);
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  transition: background var(--duration-fast) var(--ease),
              color var(--duration-fast) var(--ease);
}
.icon-btn:hover { background: var(--color-surface-2); color: var(--color-text); }
.icon-btn svg { width: 20px; height: 20px; }

/* ─── Card ──────────────────────────────────────────────── */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.card-title {
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  color: var(--color-text);
}
.card-subtitle {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: 2px;
}

/* ─── Stat (KPI tile) ──────────────────────────────────── */
.stat {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-5);
  background: var(--color-surface);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-lg);
}
.stat-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--color-text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.stat-value {
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
  font-variant-numeric: tabular-nums;
  color: var(--color-text);
  letter-spacing: -0.02em;
}
.stat-delta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  font-variant-numeric: tabular-nums;
}
.stat-delta svg { width: 12px; height: 12px; }
.stat-delta.up   { color: var(--color-success); }
.stat-delta.down { color: var(--color-danger); }
.stat-delta.flat { color: var(--color-text-subtle); }

/* ─── Badge / Pill ─────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px var(--space-2);
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: var(--weight-semibold);
  letter-spacing: 0.2px;
}
.badge-success { background: var(--color-success-soft); color: var(--color-success); }
.badge-danger  { background: var(--color-danger-soft);  color: var(--color-danger);  }
.badge-warning { background: var(--color-warning-soft); color: var(--color-warning); }
.badge-accent  { background: var(--color-accent-soft);  color: var(--color-accent);  }
.badge-neutral { background: var(--color-surface-3);    color: var(--color-text-muted); }

/* ─── Input ─────────────────────────────────────────────── */
.input, .select, .textarea {
  width: 100%;
  min-height: var(--touch-min);
  padding: 0 var(--space-3);
  background: var(--color-surface-2);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  transition: border-color var(--duration-fast) var(--ease);
  -webkit-appearance: none;
  appearance: none;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--color-accent); }
.input::placeholder { color: var(--color-text-subtle); }
.textarea { min-height: 96px; padding: var(--space-3); resize: vertical; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: var(--text-xs); font-weight: var(--weight-medium); color: var(--color-text-muted); }
.field-hint  { font-size: var(--text-xs); color: var(--color-text-subtle); }

/* ─── Segmented control ────────────────────────────────── */
.segmented {
  display: inline-flex;
  padding: 3px;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-md);
  gap: 2px;
}
.segmented > button {
  min-height: 32px;
  padding: 0 var(--space-3);
  border-radius: 5px;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--color-text-muted);
  transition: background var(--duration-fast) var(--ease),
              color var(--duration-fast) var(--ease);
}
.segmented > button:hover { color: var(--color-text); }
.segmented > button[aria-pressed="true"] {
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--shadow-sm);
}

/* ─── Divider ───────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--color-border-subtle);
  border: 0;
  margin: var(--space-4) 0;
}

/* ─── Skeleton loader ──────────────────────────────────── */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--color-surface-2) 25%,
    var(--color-surface-3) 50%,
    var(--color-surface-2) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

/* ─── Data table ───────────────────────────────────────── */
.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.table th, .table td {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  font-size: var(--text-sm);
  border-bottom: 1px solid var(--color-border-subtle);
}
.table th {
  background: var(--color-surface-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; }

/* ─── List row (mobile-friendly alternative to table) ─── */
.list-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border-subtle);
}
.list-row:last-child { border-bottom: 0; }
.list-row-main   { flex: 1; min-width: 0; }
.list-row-title  { font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--color-text); }
.list-row-sub    { font-size: var(--text-xs); color: var(--color-text-muted); margin-top: 2px; }
.list-row-value  { text-align: right; font-variant-numeric: tabular-nums; flex-shrink: 0; }

/* ─── Avatar (initials fallback) ───────────────────────── */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border-radius: var(--radius-pill);
  background: var(--color-accent-soft);
  color: var(--color-accent);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  text-transform: uppercase;
}

/* ─── Dot indicator ────────────────────────────────────── */
.dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: var(--radius-pill);
  flex-shrink: 0;
}

/* ─── Switch (iOS-style toggle) ────────────────────────── */
.switch {
  position: relative;
  display: inline-block;
  width: 40px; height: 24px;
  flex-shrink: 0;
}
.switch input {
  position: absolute;
  opacity: 0;
  width: 100%; height: 100%;
  margin: 0;
  cursor: pointer;
}
.switch .slider {
  position: absolute;
  inset: 0;
  background: var(--color-surface-3);
  border-radius: var(--radius-pill);
  transition: background var(--duration-fast) var(--ease);
  pointer-events: none;
}
.switch .slider::before {
  content: "";
  position: absolute;
  left: 3px; top: 3px;
  width: 18px; height: 18px;
  background: #fff;
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
  transition: transform var(--duration-fast) var(--ease);
}
.switch input:checked + .slider { background: var(--color-accent); }
.switch input:checked + .slider::before { transform: translateX(16px); }
.switch input:focus-visible + .slider {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}
