/* ============================================================
   Component library — buttons, cards, forms, tables, badges,
   modals, toasts, skeletons, empty states
   ============================================================ */

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  padding: 9px 18px; border-radius: var(--radius-sm); border: 1px solid transparent;
  font-size: .9rem; font-weight: var(--fw-medium); cursor: pointer; white-space: nowrap;
  transition: all var(--dur) var(--ease); user-select: none;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); box-shadow: var(--shadow); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(.92); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn-success { background: var(--success); color: #fff; }
.btn-sm { padding: 5px 12px; font-size: .82rem; }
.btn-lg { padding: 13px 26px; font-size: 1rem; }
.btn-icon { padding: 8px; border-radius: var(--radius-sm); }
.btn-block { width: 100%; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
  padding: var(--s6);
  transition: box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.card-hover:hover { box-shadow: var(--shadow); border-color: var(--border-strong); }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--s4); }
.card-title { font-size: 1rem; font-weight: var(--fw-semibold); }

/* Stat card */
.stat-card { display: flex; align-items: center; gap: var(--s4); }
.stat-icon {
  width: 46px; height: 46px; border-radius: var(--radius); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 1.3rem;
}
.stat-value { font-size: 1.55rem; font-weight: var(--fw-bold); line-height: 1.15; }
.stat-label { font-size: .82rem; color: var(--text-2); }

/* ---------- Forms ---------- */
.form-group { margin-bottom: var(--s4); }
.form-label { display: block; font-size: .84rem; font-weight: var(--fw-medium); color: var(--text-2); margin-bottom: 6px; }
.form-label .req { color: var(--danger); }
.form-control {
  width: 100%; padding: 9px 13px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: var(--surface); color: var(--text);
  font-size: .92rem; transition: border-color var(--dur), box-shadow var(--dur);
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.form-control::placeholder { color: var(--text-3); }
select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2398A1B3' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 34px; }
textarea.form-control { resize: vertical; min-height: 84px; }
.form-hint { font-size: .78rem; color: var(--text-3); margin-top: 4px; }
.form-error { font-size: .78rem; color: var(--danger); margin-top: 4px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s4); }
@media (max-width: 640px) {
  .form-row { grid-template-columns: 1fr; }
  /* iOS Safari auto-zooms the whole page when a focused input's font-size
     is under 16px — the single biggest cause of "distorted" mobile layouts.
     Keep inputs at exactly 16px on phones to suppress that zoom. */
  .form-control { font-size: 16px; }
  /* Tighter modal chrome on small screens */
  .modal-header { padding: var(--s4) var(--s4); }
  .modal-body { padding: var(--s4); }
  .modal-footer { padding: var(--s3) var(--s4); }
}

/* Toggle switch */
.switch { position: relative; width: 42px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track { position: absolute; inset: 0; background: var(--border-strong); border-radius: 12px; transition: background var(--dur); cursor: pointer; }
.switch .track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; background: #fff; border-radius: 50%; transition: transform var(--dur) var(--ease); }
.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track::after { transform: translateX(18px); }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px;
  border-radius: var(--radius-full); font-size: .74rem; font-weight: var(--fw-semibold);
}
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger  { background: var(--danger-soft);  color: var(--danger); }
.badge-info    { background: var(--info-soft);    color: var(--info); }
.badge-neutral { background: var(--surface-2);    color: var(--text-2); }
.badge-primary { background: var(--primary-soft); color: var(--primary); }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ---------- Avatar ---------- */
.avatar {
  width: 36px; height: 36px; border-radius: 50%; overflow: hidden; flex-shrink: 0;
  background: var(--primary-soft); color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-weight: var(--fw-semibold); font-size: .82rem;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-lg { width: 56px; height: 56px; font-size: 1.1rem; }
.avatar-xl { width: 88px; height: 88px; font-size: 1.6rem; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
table.table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.table th {
  text-align: left; padding: 12px 16px; font-size: .74rem; text-transform: uppercase;
  letter-spacing: .05em; color: var(--text-3); font-weight: var(--fw-semibold);
  background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background var(--dur); }
.table tbody tr:hover { background: var(--surface-2); }

/* Pagination */
.pagination { display: flex; align-items: center; justify-content: space-between; padding: var(--s3) var(--s4); font-size: .84rem; color: var(--text-2); }
.pagination .pages { display: flex; gap: var(--s1); }
.page-btn { min-width: 32px; height: 32px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--text-2); cursor: pointer; font-size: .84rem; }
.page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(10, 15, 30, .5); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; z-index: 1000;
  padding: var(--s4); animation: fadeIn .18s var(--ease);
}
.modal {
  background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 520px; max-height: 90vh; display: flex; flex-direction: column;
  animation: fadeUp .22s var(--ease);
}
.modal-lg { max-width: 760px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: var(--s5) var(--s6); border-bottom: 1px solid var(--border); }
.modal-body { padding: var(--s6); overflow-y: auto; }
.modal-footer { display: flex; justify-content: flex-end; gap: var(--s3); padding: var(--s4) var(--s6); border-top: 1px solid var(--border); }
.modal-close { background: none; border: none; font-size: 1.4rem; color: var(--text-3); cursor: pointer; line-height: 1; }
.modal-close:hover { color: var(--text); }

/* ---------- Toasts ---------- */
#toast-container { position: fixed; top: var(--s5); right: var(--s5); z-index: 2000; display: flex; flex-direction: column; gap: var(--s2); }
.toast {
  display: flex; align-items: center; gap: var(--s3); min-width: 260px; max-width: 380px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 13px 16px; font-size: .88rem;
  animation: fadeUp .25s var(--ease);
}
.toast.leaving { opacity: 0; transform: translateX(20px); transition: all .25s var(--ease); }
.toast-bar { width: 4px; align-self: stretch; border-radius: 2px; flex-shrink: 0; }
.toast-success .toast-bar { background: var(--success); }
.toast-error   .toast-bar { background: var(--danger); }
.toast-info    .toast-bar { background: var(--info); }
.toast-warning .toast-bar { background: var(--warning); }
@media (max-width: 640px) { #toast-container { left: var(--s4); right: var(--s4); } .toast { min-width: 0; max-width: none; } }

/* ---------- Skeletons ---------- */
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 50%, var(--surface-2) 75%);
  background-size: 800px 100%; animation: shimmer 1.4s infinite linear; border-radius: var(--radius-sm);
}
.skeleton-text { height: 14px; margin: 6px 0; }
.skeleton-circle { border-radius: 50%; }

/* ---------- Empty state ---------- */
.empty-state { text-align: center; padding: var(--s12) var(--s6); color: var(--text-2); }
.empty-state .icon { font-size: 2.6rem; margin-bottom: var(--s3); opacity: .55; }
.empty-state h3 { color: var(--text); margin-bottom: var(--s1); }
.empty-state p { font-size: .88rem; max-width: 340px; margin: 0 auto var(--s4); }

/* ---------- Tabs / filter chips ---------- */
.tabs { display: flex; gap: var(--s1); border-bottom: 1px solid var(--border); margin-bottom: var(--s5); overflow-x: auto; }
.tab { padding: 10px 16px; font-size: .9rem; font-weight: var(--fw-medium); color: var(--text-2); cursor: pointer; border: none; background: none; border-bottom: 2px solid transparent; white-space: nowrap; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.chips { display: flex; gap: var(--s2); flex-wrap: wrap; }
.chip { padding: 6px 14px; border-radius: var(--radius-full); border: 1px solid var(--border-strong); background: var(--surface); font-size: .82rem; cursor: pointer; color: var(--text-2); transition: all var(--dur); }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ---------- Dropdown menu ---------- */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 180px; z-index: 100;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: var(--s2); animation: fadeUp .15s var(--ease);
}
.dropdown-item { display: flex; align-items: center; gap: var(--s2); width: 100%; padding: 8px 12px; border-radius: var(--radius-sm); font-size: .88rem; color: var(--text); background: none; border: none; cursor: pointer; text-align: left; }
.dropdown-item:hover { background: var(--surface-2); }
.dropdown-item.danger { color: var(--danger); }
