/* =====================================================================
   components.css - buttons, cards, tables, modals, toasts, skeletons
   ===================================================================== */

/* --------------------------------------------------------------- buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-primary);
  font-size: var(--fs-base);
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease),
              transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.btn:active { transform: scale(0.975); }
.btn:disabled, .btn.is-disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.12);
}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); color: #fff; }

.btn-secondary {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text-primary);
}
.btn-secondary:hover:not(:disabled) { background: var(--surface-hover); border-color: var(--border-strong); }

.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text-primary); }

.btn-soft { background: var(--primary-soft); color: var(--primary); }
.btn-soft:hover:not(:disabled) { background: var(--primary-soft); filter: brightness(0.96); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; color: #fff; }

.btn-danger-soft { background: var(--danger-soft); color: var(--danger); }
.btn-danger-soft:hover:not(:disabled) { background: var(--danger); color: #fff; }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #15803d; color: #fff; }

.btn-sm { min-height: 34px; padding: 0 13px; font-size: var(--fs-sm); border-radius: var(--radius-xs); gap: 6px; }
.btn-lg { min-height: 50px; padding: 0 26px; font-size: var(--fs-md); border-radius: var(--radius); }
.btn-block { display: flex; width: 100%; }
.btn-pill { border-radius: var(--radius-pill); }

.btn-icon {
  width: 42px; min-height: 42px; padding: 0;
  border-radius: var(--radius-sm);
}
.btn-icon.btn-sm { width: 34px; min-height: 34px; }
.btn-icon.btn-lg { width: 50px; min-height: 50px; }

.btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
  content: "";
  position: absolute;
  width: 17px; height: 17px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  color: #fff;
  animation: spin 0.6s linear infinite;
}
.btn-secondary.is-loading::after, .btn-ghost.is-loading::after { color: var(--text-secondary); }

@keyframes spin { to { transform: rotate(360deg); } }

.btn-group { display: inline-flex; gap: 2px; padding: 3px; background: var(--surface-2); border-radius: var(--radius-sm); }
.btn-group .btn { background: transparent; border: 0; box-shadow: none; }
.btn-group .btn.is-active { background: var(--surface); box-shadow: var(--shadow-xs); }

/* ----------------------------------------------------------------- cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.card-pad { padding: var(--sp-5); }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
}
.card-header h2, .card-header h3 { font-size: var(--fs-md); font-weight: 650; }
.card-body { padding: var(--sp-5); }
.card-footer { padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--border); background: var(--surface-2); }

.card-hover { transition: transform var(--dur) var(--ease-out), box-shadow var(--dur) var(--ease-out); }
.card-hover:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }

/* ---------------------------------------------------------------- badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--text-secondary);
  font-size: var(--fs-xs);
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
}
.badge-primary { background: var(--primary-soft); color: var(--primary); }
.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-new     { background: var(--danger); color: #fff; letter-spacing: 0.04em; }
.badge-dot::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* ----------------------------------------------------------- progressbar */
.progress {
  position: relative;
  height: 6px;
  background: var(--surface-3);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: var(--primary);
  border-radius: inherit;
  transition: width var(--dur-slow) var(--ease-out);
}
.progress-bar.is-complete { background: var(--success); }
.progress-sm { height: 4px; }
.progress-lg { height: 10px; }

.progress-ring { transform: rotate(-90deg); }
.progress-ring circle { fill: none; stroke-width: 3; }
.progress-ring .track { stroke: var(--surface-3); }
.progress-ring .value { stroke: var(--primary); stroke-linecap: round; transition: stroke-dashoffset var(--dur-slow) var(--ease-out); }

/* ---------------------------------------------------------------- avatar */
.avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700;
  font-size: var(--fs-sm);
  overflow: hidden;
  text-transform: uppercase;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-sm { width: 30px; height: 30px; font-size: var(--fs-xs); }
.avatar-lg { width: 56px; height: 56px; font-size: var(--fs-lg); }
.avatar-xl { width: 88px; height: 88px; font-size: var(--fs-2xl); }

/* ----------------------------------------------------------------- table */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius);
}

.table { width: 100%; border-collapse: collapse; font-size: var(--fs-base); }
.table th {
  padding: 12px 14px;
  background: var(--surface-2);
  color: var(--text-secondary);
  font-size: var(--fs-xs);
  font-weight: 650;
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0.045em;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
.table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr { transition: background var(--dur-fast) var(--ease); }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr.is-selected { background: var(--primary-soft); }
.table .col-actions { width: 1%; white-space: nowrap; text-align: right; }
.table .col-check { width: 1%; padding-right: 0; }
.table-fixed-first td:first-child, .table-fixed-first th:first-child { position: sticky; left: 0; background: inherit; }

.table-thumb {
  width: 74px; height: 44px;
  border-radius: var(--radius-xs);
  object-fit: cover;
  background: var(--surface-3);
}

/* ------------------------------------------------------------ pagination */
.pagination { display: flex; align-items: center; justify-content: center; gap: 4px; flex-wrap: wrap; }
.pagination button, .pagination a {
  min-width: 36px; height: 36px;
  padding: 0 10px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: var(--fs-sm);
  font-weight: 600;
  cursor: pointer;
}
.pagination button:hover:not(:disabled), .pagination a:hover { background: var(--surface-hover); color: var(--text-primary); }
.pagination .is-active { background: var(--primary); border-color: var(--primary); color: #fff; }
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }

/* ----------------------------------------------------------------- tabs */
.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative;
  padding: 11px 16px;
  border: 0;
  background: none;
  color: var(--text-secondary);
  font-size: var(--fs-base);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.tab::after {
  content: "";
  position: absolute;
  left: 12px; right: 12px; bottom: -1px;
  height: 2px;
  background: transparent;
  border-radius: 2px 2px 0 0;
  transition: background var(--dur) var(--ease);
}
.tab:hover { color: var(--text-primary); }
.tab.is-active { color: var(--primary); }
.tab.is-active::after { background: var(--primary); }

/* ---------------------------------------------------------------- chips */
.chip-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: var(--fs-sm);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease);
}
.chip:hover { border-color: var(--border-strong); color: var(--text-primary); }
.chip.is-active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* -------------------------------------------------------------- dropdown */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px); right: 0;
  z-index: var(--z-sticky);
  min-width: 190px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px);
  transition: opacity var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease), visibility var(--dur-fast);
}
.dropdown.is-open .dropdown-menu { opacity: 1; visibility: visible; transform: translateY(0); }
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 11px;
  border: 0;
  border-radius: var(--radius-xs);
  background: none;
  color: var(--text-primary);
  font-size: var(--fs-base);
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}
.dropdown-item:hover { background: var(--surface-2); color: var(--text-primary); }
.dropdown-item.is-danger { color: var(--danger); }
.dropdown-item.is-danger:hover { background: var(--danger-soft); }
.dropdown-divider { height: 1px; margin: 5px 0; background: var(--border); }

/* --------------------------------------------------------------- modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: grid;
  place-items: center;
  padding: var(--sp-4);
  background: var(--overlay);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--dur) var(--ease), visibility var(--dur);
}
.modal-backdrop.is-open { opacity: 1; visibility: visible; }

.modal {
  width: 100%;
  max-width: 480px;
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  transform: translateY(14px) scale(0.98);
  transition: transform var(--dur) var(--ease-out);
  overflow: hidden;
}
.modal-backdrop.is-open .modal { transform: translateY(0) scale(1); }
.modal-lg { max-width: 720px; }
.modal-xl { max-width: 980px; }

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-5) var(--sp-5) var(--sp-3);
}
.modal-header h3 { font-size: var(--fs-lg); }
.modal-body { padding: 0 var(--sp-5) var(--sp-5); overflow-y: auto; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}
.modal-close {
  flex: none;
  display: grid; place-items: center;
  width: 34px; height: 34px;
  border: 0; border-radius: var(--radius-xs);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}
.modal-close:hover { background: var(--surface-2); color: var(--text-primary); }

.modal-icon {
  display: grid;
  place-items: center;
  width: 48px; height: 48px;
  margin-bottom: var(--sp-3);
  border-radius: var(--radius);
  background: var(--danger-soft);
  color: var(--danger);
}
.modal-icon.is-warning { background: var(--warning-soft); color: var(--warning); }
.modal-icon.is-info { background: var(--info-soft); color: var(--info); }

/* --------------------------------------------------------------- toasts */
.toast-stack {
  position: fixed;
  right: var(--sp-4);
  bottom: calc(var(--sp-4) + var(--safe-bottom));
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(360px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 13px 15px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: toast-in var(--dur-slow) var(--ease-out);
}
.toast.is-out { animation: toast-out var(--dur) var(--ease) forwards; }
.toast-success { border-left-color: var(--success); }
.toast-error   { border-left-color: var(--danger); }
.toast-warning { border-left-color: var(--warning); }
.toast-info    { border-left-color: var(--info); }
.toast .ico { margin-top: 1px; }
.toast-success .ico { color: var(--success); }
.toast-error .ico   { color: var(--danger); }
.toast-warning .ico { color: var(--warning); }
.toast-info .ico    { color: var(--info); }
.toast-msg { flex: 1; font-size: var(--fs-base); line-height: 1.45; }
.toast-close {
  flex: none;
  border: 0; background: none; padding: 0;
  color: var(--text-muted); cursor: pointer;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(28px) scale(0.97); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateX(28px) scale(0.97); }
}

/* ------------------------------------------------------------- skeletons */
.skeleton {
  position: relative;
  background: var(--surface-3);
  border-radius: var(--radius-xs);
  overflow: hidden;
}
.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.28), transparent);
  animation: shimmer 1.4s infinite;
}
[data-theme="dark"] .skeleton::after {
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.06), transparent);
}
@keyframes shimmer { 100% { transform: translateX(100%); } }

.skeleton-text { height: 12px; border-radius: var(--radius-pill); }
.skeleton-title { height: 16px; width: 65%; border-radius: var(--radius-pill); }
.skeleton-thumb { aspect-ratio: 16 / 9; width: 100%; border-radius: var(--radius-sm); }
.skeleton-avatar { width: 38px; height: 38px; border-radius: 50%; }

.skeleton-card { display: flex; flex-direction: column; gap: 10px; }
.skeleton-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; }

/* ---------------------------------------------------------- empty states */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  padding: var(--sp-10) var(--sp-5);
  text-align: center;
}
.empty-state .empty-icon {
  display: grid;
  place-items: center;
  width: 66px; height: 66px;
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  color: var(--text-muted);
}
.empty-state h3 { font-size: var(--fs-md); font-weight: 650; }
.empty-state p { max-width: 340px; color: var(--text-muted); font-size: var(--fs-base); }

/* ------------------------------------------------------------ stat cards */
.stat-grid { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

.stat-card {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.stat-icon {
  flex: none;
  display: grid; place-items: center;
  width: 46px; height: 46px;
  border-radius: var(--radius-sm);
  background: var(--primary-soft);
  color: var(--primary);
}
.stat-icon.is-success { background: var(--success-soft); color: var(--success); }
.stat-icon.is-warning { background: var(--warning-soft); color: var(--warning); }
.stat-icon.is-info    { background: var(--info-soft);    color: var(--info); }
.stat-icon.is-danger  { background: var(--danger-soft);  color: var(--danger); }
.stat-value { font-size: var(--fs-2xl); font-weight: 700; line-height: 1.15; letter-spacing: -0.02em; }
.stat-label { font-size: var(--fs-sm); color: var(--text-secondary); }

/* ------------------------------------------------------------ bar charts */
.bar-chart { display: flex; align-items: flex-end; gap: 6px; height: 160px; padding-top: var(--sp-3); }
.bar-chart-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 7px; min-width: 0; }
.bar-chart-bar {
  width: 100%;
  max-width: 42px;
  min-height: 3px;
  background: var(--primary);
  border-radius: var(--radius-xs) var(--radius-xs) 0 0;
  transition: height var(--dur-slow) var(--ease-out);
}
.bar-chart-bar:hover { background: var(--primary-hover); }
.bar-chart-label { font-size: 10px; color: var(--text-muted); white-space: nowrap; }

.hbar-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; padding: 9px 0; }
.hbar-track { grid-column: 1 / -1; height: 6px; background: var(--surface-3); border-radius: var(--radius-pill); overflow: hidden; }
.hbar-fill { height: 100%; background: var(--primary); border-radius: inherit; }

/* -------------------------------------------------------- offline banner */
.net-banner {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bottomnav-h) + var(--safe-bottom) + 12px);
  transform: translate(-50%, 20px);
  z-index: var(--z-toast);
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 17px;
  background: var(--text-primary);
  color: var(--bg);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-lg);
  font-size: var(--fs-sm);
  font-weight: 600;
  opacity: 0;
  visibility: hidden;
  transition: all var(--dur) var(--ease-out);
}
.net-banner.is-visible { opacity: 1; visibility: visible; transform: translate(-50%, 0); }
.net-banner.is-online { background: var(--success); color: #fff; }

/* ------------------------------------------------------------- alert box */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 13px 15px;
  border-radius: var(--radius-sm);
  background: var(--info-soft);
  color: var(--text-primary);
  font-size: var(--fs-base);
  line-height: 1.5;
}
.alert .ico { flex: none; margin-top: 1px; color: var(--info); }
.alert-success { background: var(--success-soft); }
.alert-success .ico { color: var(--success); }
.alert-warning { background: var(--warning-soft); }
.alert-warning .ico { color: var(--warning); }
.alert-danger { background: var(--danger-soft); }
.alert-danger .ico { color: var(--danger); }

/* ----------------------------------------------------------- breadcrumbs */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
  font-size: var(--fs-sm);
  color: var(--text-muted);
}
.breadcrumb a { color: var(--text-secondary); font-weight: 500; }
.breadcrumb a:hover { color: var(--primary); }
.breadcrumb .ico { color: var(--text-muted); }
.breadcrumb .current { color: var(--text-primary); font-weight: 600; }

/* ------------------------------------------------------- section headers */
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}
.section-head h2 {
  font-size: var(--fs-lg);
  font-weight: 700;
  letter-spacing: -0.015em;
}
.section-head .link-more {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--primary);
}

/* ------------------------------------------------------------- drag zone */
.dropzone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  min-height: 220px;
  padding: var(--sp-8) var(--sp-5);
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  text-align: center;
  cursor: pointer;
  transition: all var(--dur) var(--ease);
}
.dropzone:hover { border-color: var(--primary); background: var(--primary-soft); }
.dropzone.is-dragover {
  border-color: var(--primary);
  background: var(--primary-soft);
  transform: scale(1.007);
}
.dropzone-icon {
  display: grid; place-items: center;
  width: 62px; height: 62px;
  border-radius: 50%;
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}
.dropzone h3 { font-size: var(--fs-md); }
.dropzone p { color: var(--text-muted); font-size: var(--fs-sm); }
.dropzone input[type="file"] { display: none; }
