/* ============================================
   COMPONENTS — Buttons, cards, forms, chips,
   modals, drawers, badges, tabs
   ============================================ */

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  padding: 10px 20px; border-radius: var(--radius-md);
  font-size: var(--text-sm); font-weight: var(--weight-semibold);
  transition: all var(--transition-fast); cursor: pointer;
  border: 1px solid transparent; white-space: nowrap; text-decoration: none;
}
.btn:focus-visible { outline: 2px solid var(--brand-primary); outline-offset: 2px; }
.btn-primary { background: var(--brand-primary); color: #fff; }
.btn-primary:hover { background: var(--brand-primary-hover); }
.btn-secondary { background: transparent; border-color: var(--brand-primary); color: var(--brand-primary); }
.btn-secondary:hover { background: var(--brand-primary-muted); }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-danger { background: var(--error); color: #fff; }
.btn-danger:hover { background: #c0392b; }
.btn-sm { padding: 6px 14px; font-size: var(--text-xs); }
.btn-lg { padding: 14px 28px; font-size: var(--text-base); }
.btn-icon { padding: 8px; border-radius: var(--radius-md); }
.btn[disabled], .btn.disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }
.btn-block { width: 100%; }

/* ---------- Cards ---------- */
.card {
  background: var(--bg-surface); border: 1px solid var(--border-default);
  border-radius: var(--radius-lg); padding: var(--space-5);
}
.card-compact { padding: var(--space-4); }
.card-elevated { background: var(--bg-elevated); }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-4); }
.card-title { font-size: var(--text-lg); font-weight: var(--weight-semibold); }

/* ---------- Forms ---------- */
.form-group { display: flex; flex-direction: column; gap: var(--space-2); }
.form-label { font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--text-secondary); }
.form-input, .form-select, .form-textarea {
  background: var(--bg-elevated); border: 1px solid var(--border-default);
  border-radius: var(--radius-md); padding: 10px 14px;
  font-size: var(--text-sm); color: var(--text-primary);
  transition: border-color var(--transition-fast);
  width: 100%;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none; border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--brand-primary-muted);
}
.form-input::placeholder { color: var(--text-muted); }
.form-textarea { resize: vertical; min-height: 80px; }
.form-hint { font-size: var(--text-xs); color: var(--text-muted); }
.form-error { font-size: var(--text-xs); color: var(--error); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }
@media (max-width: 480px) { .form-row { grid-template-columns: 1fr; } }

/* ---------- Chips / Tags ---------- */
.chip {
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: 4px 12px; border-radius: var(--radius-full);
  font-size: var(--text-xs); font-weight: var(--weight-medium);
  background: var(--bg-elevated); border: 1px solid var(--border-default);
  color: var(--text-secondary);
}
.chip-brand { background: var(--brand-primary-muted); border-color: var(--brand-primary); color: var(--brand-primary); }
.chip-success { background: var(--success-bg); color: var(--success); }
.chip-remove { cursor: pointer; opacity: 0.6; transition: opacity var(--transition-fast); }
.chip-remove:hover { opacity: 1; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; padding: 2px 8px;
  border-radius: var(--radius-full); font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
}
.badge-primary { background: var(--brand-primary-muted); color: var(--brand-primary); }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-error { background: var(--error-bg); color: var(--error); }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border-default); }
.tab {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm); font-weight: var(--weight-medium);
  color: var(--text-muted); cursor: pointer;
  border-bottom: 2px solid transparent; transition: all var(--transition-fast);
  background: none;
}
.tab:hover { color: var(--text-secondary); }
.tab.active { color: var(--brand-primary); border-bottom-color: var(--brand-primary); }
.tab-panel { display: none; padding-top: var(--space-4); }
.tab-panel.active { display: block; }

/* ---------- Segmented Control ---------- */
.segmented {
  display: inline-flex; background: var(--bg-elevated); border-radius: var(--radius-md);
  padding: 3px; border: 1px solid var(--border-default);
}
.segmented-btn {
  padding: 6px 16px; border-radius: var(--radius-sm);
  font-size: var(--text-sm); font-weight: var(--weight-medium);
  color: var(--text-secondary); cursor: pointer; transition: all var(--transition-fast);
  background: none; border: none;
}
.segmented-btn.active, .segmented-btn:hover { background: var(--brand-primary); color: #fff; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 300;
  background: var(--bg-overlay); display: none;
  align-items: center; justify-content: center;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--bg-surface); border: 1px solid var(--border-default);
  border-radius: var(--radius-xl); width: 90%; max-width: 640px;
  max-height: 85vh; overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-5); border-bottom: 1px solid var(--border-subtle);
}
.modal-title { font-size: var(--text-xl); font-weight: var(--weight-semibold); }
.modal-close { color: var(--text-muted); padding: var(--space-1); cursor: pointer; background: none; border: none; }
.modal-close:hover { color: var(--text-primary); }
.modal-body { padding: var(--space-5); }
.modal-footer { padding: var(--space-4) var(--space-5); border-top: 1px solid var(--border-subtle); display: flex; justify-content: flex-end; gap: var(--space-3); }

/* ---------- Drawer ---------- */
.drawer-backdrop {
  position: fixed; inset: 0; z-index: 300;
  background: var(--bg-overlay); display: none;
}
.drawer-backdrop.open { display: block; }
.drawer {
  position: fixed; top: 0; right: -400px; bottom: 0; z-index: 301;
  width: 400px; max-width: 90vw;
  background: var(--bg-surface); border-left: 1px solid var(--border-default);
  transition: right var(--transition-slow);
  display: flex; flex-direction: column;
}
.drawer-backdrop.open .drawer { right: 0; }
.drawer-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-5); border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}
.drawer-body { flex: 1; overflow-y: auto; padding: var(--space-5); }

/* ---------- Disclosure (details/summary) ---------- */
details.disclosure { border: 1px solid var(--border-default); border-radius: var(--radius-md); }
details.disclosure summary {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm); font-weight: var(--weight-medium);
  color: var(--text-secondary); cursor: pointer;
  display: flex; align-items: center; gap: var(--space-2);
  list-style: none;
}
details.disclosure summary::-webkit-details-marker { display: none; }
details.disclosure summary::before { content: '▸'; transition: transform var(--transition-fast); }
details.disclosure[open] summary::before { transform: rotate(90deg); }
details.disclosure .disclosure-body { padding: var(--space-4); border-top: 1px solid var(--border-subtle); }

/* ---------- Toast / Alert ---------- */
.alert {
  padding: var(--space-3) var(--space-4); border-radius: var(--radius-md);
  font-size: var(--text-sm); display: flex; align-items: center; gap: var(--space-3);
}
.alert-info { background: var(--info-bg); color: var(--info); }
.alert-success { background: var(--success-bg); color: var(--success); }
.alert-warning { background: var(--warning-bg); color: var(--warning); }
.alert-error { background: var(--error-bg); color: var(--error); }

/* ---------- Progress Bar ---------- */
.progress { height: 6px; background: var(--bg-elevated); border-radius: var(--radius-full); overflow: hidden; }
.progress-bar { height: 100%; background: var(--brand-primary); border-radius: var(--radius-full); transition: width var(--transition-base); }

/* ---------- Avatar ---------- */
.avatar {
  width: 32px; height: 32px; border-radius: var(--radius-full);
  background: var(--brand-primary-muted); color: var(--brand-primary);
  display: flex; align-items: center; justify-content: center;
  font-size: var(--text-xs); font-weight: var(--weight-bold);
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-lg { width: 48px; height: 48px; font-size: var(--text-sm); }

/* ---------- Dropdown ---------- */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
  position: absolute; top: 100%; right: 0; z-index: 50;
  min-width: 180px; margin-top: var(--space-2);
  background: var(--bg-surface); border: 1px solid var(--border-default);
  border-radius: var(--radius-md); padding: var(--space-2) 0;
  box-shadow: var(--shadow-md); display: none;
}
.dropdown.open .dropdown-menu { display: block; }
.dropdown-item {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm); color: var(--text-secondary);
  cursor: pointer; transition: background var(--transition-fast);
  border: none; background: none; width: 100%; text-align: left;
}
.dropdown-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.dropdown-divider { height: 1px; background: var(--border-subtle); margin: var(--space-2) 0; }

/* ---------- Skeleton Loading ---------- */
.skeleton {
  background: linear-gradient(90deg, var(--bg-elevated) 25%, var(--bg-hover) 50%, var(--bg-elevated) 75%);
  background-size: 200% 100%;
  animation: skeleton-pulse 1.5s infinite;
  border-radius: var(--radius-md);
}
@keyframes skeleton-pulse { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ---------- Empty State ---------- */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: var(--space-8) var(--space-5); text-align: center;
}
.empty-state-icon { font-size: 48px; margin-bottom: var(--space-4); opacity: 0.3; }
.empty-state h3 { margin-bottom: var(--space-2); }
.empty-state p { color: var(--text-muted); margin-bottom: var(--space-5); max-width: 360px; }

/* ---------- Divider ---------- */
.divider { height: 1px; background: var(--border-subtle); margin: var(--space-4) 0; }
.divider-text {
  display: flex; align-items: center; gap: var(--space-3);
  font-size: var(--text-xs); color: var(--text-muted);
}
.divider-text::before, .divider-text::after {
  content: ''; flex: 1; height: 1px; background: var(--border-subtle);
}

/* ---------- Range Slider ---------- */
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 6px; border-radius: var(--radius-full);
  background: var(--bg-elevated); outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 18px; height: 18px; border-radius: var(--radius-full);
  background: var(--brand-primary); cursor: pointer;
  border: 2px solid var(--bg-base);
}
input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: var(--radius-full);
  background: var(--brand-primary); cursor: pointer; border: 2px solid var(--bg-base);
}

/* ---------- Toggle Switch ---------- */
.toggle { position: relative; display: inline-flex; width: 44px; height: 24px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-track {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--bg-elevated); border: 1px solid var(--border-default);
  border-radius: var(--radius-full); transition: all var(--transition-fast);
}
.toggle-track::before {
  content: ''; position: absolute; height: 18px; width: 18px;
  left: 2px; bottom: 2px; background: var(--text-muted);
  border-radius: var(--radius-full); transition: all var(--transition-fast);
}
.toggle input:checked + .toggle-track { background: var(--brand-primary); border-color: var(--brand-primary); }
.toggle input:checked + .toggle-track::before { transform: translateX(20px); background: #fff; }

/* ---------- Google Sign In Button ---------- */
.btn-google {
  display: inline-flex; align-items: center; gap: var(--space-3);
  padding: 10px 20px; border-radius: var(--radius-md);
  background: #fff; color: #333; font-weight: var(--weight-medium);
  font-size: var(--text-sm); border: 1px solid #ddd;
  transition: background var(--transition-fast);
}
.btn-google:hover { background: #f5f5f5; }
.btn-google svg { width: 18px; height: 18px; }
