/* CARD */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.card-tight { padding: 16px; }
.card-compact { padding: 14px 16px; }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.card-header h2, .card-header h3 { font-size: 15px; font-weight: 600; }
.card-header .link-btn { color: var(--accent-green); font-size: 13px; font-weight: 500; }

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: var(--transition-fast);
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent-green);
  color: var(--text-inverse);
}
.btn-primary:hover { background: var(--accent-green-dark); }

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--bg-hover); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }

.btn-danger {
  background: var(--status-danger);
  color: var(--text-inverse);
}

.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn-lg { padding: 11px 20px; font-size: 14px; }
.btn-icon { padding: 9px; width: 38px; height: 38px; }

.btn .icon { width: 16px; height: 16px; }

/* BADGE */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 11.5px;
  font-weight: 600;
}
.badge-success { background: var(--status-success-bg); color: var(--accent-green-dark); }
.badge-warning { background: var(--status-warning-bg); color: #B45309; }
.badge-danger { background: var(--status-danger-bg); color: #B91C1C; }
.badge-info { background: var(--status-info-bg); color: #1D4ED8; }
.badge-purple { background: var(--status-purple-bg); color: #6D28D9; }
.badge-pink { background: var(--status-pink-bg); color: #BE185D; }
.badge-orange { background: var(--status-orange-bg); color: #C2410C; }
.badge-neutral { background: var(--bg-hover); color: var(--text-secondary); }

.badge-dot::before {
  content: '';
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* KPI CARD */
.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: var(--shadow-sm);
}
.kpi-card .kpi-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.kpi-card .kpi-icon {
  width: 36px; height: 36px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
}
.kpi-card .kpi-label {
  font-size: 12.5px;
  color: var(--text-secondary);
  font-weight: 500;
}
.kpi-card .kpi-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}
.kpi-card .kpi-change {
  font-size: 12px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.kpi-card .kpi-change.up { color: var(--accent-green); }
.kpi-card .kpi-change.down { color: var(--status-danger); }

/* TABLE */
.table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  /* overflow visible so row-action dropdowns can escape the wrapper */
  overflow: visible;
  position: relative;
}
.table-wrap .table { border-collapse: separate; border-spacing: 0; }
.table-wrap thead th:first-child { border-top-left-radius: var(--radius-lg); }
.table-wrap thead th:last-child { border-top-right-radius: var(--radius-lg); }
.table-wrap tbody tr:last-child td:first-child { border-bottom-left-radius: var(--radius-lg); }
.table-wrap tbody tr:last-child td:last-child { border-bottom-right-radius: var(--radius-lg); }

/* Row-actions dropdown opens above other rows */
.row-actions { position: relative; }
.row-actions .dropdown-menu { z-index: 60; min-width: 180px; }
/* Last few rows: open menu upward to avoid being cut */
.table tbody tr:nth-last-child(-n+3) .row-actions .dropdown-menu {
  top: auto;
  bottom: calc(100% + 6px);
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.table th {
  text-align: left;
  padding: 12px 16px;
  background: var(--bg-app);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
}
.table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-soft);
  color: var(--text-primary);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr { transition: var(--transition-fast); }
.table tbody tr:hover { background: var(--bg-app); }
.table .row-checkbox { width: 32px; }

/* TABLE PAGINATION */
.table-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--text-secondary);
}
.pagination-pages { display: flex; gap: 4px; }
.pagination-pages .page-btn {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 12.5px;
}
.pagination-pages .page-btn:hover { background: var(--bg-hover); }
.pagination-pages .page-btn.active { background: var(--accent-green); color: white; }

/* FORM */
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.form-label {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-secondary);
}
.form-input, .form-select, .form-textarea {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  font-size: 13.5px;
  color: var(--text-primary);
  outline: none;
  transition: var(--transition-fast);
  width: 100%;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--accent-green);
  box-shadow: 0 0 0 3px var(--accent-green-soft);
}
.form-textarea { min-height: 90px; resize: vertical; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }

/* TABS */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
  overflow-x: auto;
}
.tab {
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  white-space: nowrap;
  transition: var(--transition-fast);
}
.tab:hover { color: var(--text-primary); }
.tab.active {
  color: var(--accent-green-dark);
  border-bottom-color: var(--accent-green);
  font-weight: 600;
}

/* PILL TABS (no border bottom) */
.pill-tabs {
  display: inline-flex;
  background: var(--bg-app);
  border-radius: var(--radius-md);
  padding: 4px;
  gap: 2px;
}
.pill-tabs .tab {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  border-bottom: none;
  margin: 0;
}
.pill-tabs .tab.active {
  background: var(--bg-card);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

/* AVATAR */
.avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #C7F2EA, #B6F0E5);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: var(--accent-green-dark);
  font-size: 13px;
  overflow: hidden;
  flex-shrink: 0;
}
.avatar.sm { width: 28px; height: 28px; font-size: 11px; }
.avatar.lg { width: 56px; height: 56px; font-size: 18px; }
.avatar.xl { width: 80px; height: 80px; font-size: 24px; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.avatar-stack { display: inline-flex; }
.avatar-stack .avatar { border: 2px solid var(--bg-card); margin-right: -8px; }

/* USER ROW */
.user-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.user-row .name { font-weight: 500; color: var(--text-primary); font-size: 13px; }
.user-row .meta { font-size: 11.5px; color: var(--text-muted); }

/* SUCCESS TOAST */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px 14px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  min-width: 280px;
  pointer-events: auto;
  animation: toastIn 0.32s cubic-bezier(.4,1.4,.6,1);
}
.toast.toast-out { animation: toastOut 0.28s ease forwards; }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(40px) scale(.96); }
  to { opacity: 1; transform: none; }
}
@keyframes toastOut {
  to { opacity: 0; transform: translateX(40px) scale(.96); }
}
.toast .toast-logo {
  width: 40px; height: 40px;
  border-radius: var(--radius-md);
  background: var(--accent-green-bg);
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.toast .toast-logo img {
  width: 100%; height: 100%;
  object-fit: contain;
  padding: 4px;
  animation: blinkLogo 0.4s steps(2, end) 4;
}
@keyframes blinkLogo {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.2; }
}
.toast .toast-content { flex: 1; min-width: 0; }
.toast .toast-title { font-weight: 600; font-size: 13.5px; color: var(--text-primary); }
.toast .toast-desc { font-size: 12.5px; color: var(--text-secondary); }

/* DROPDOWN */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  min-width: 200px;
  padding: 6px;
  z-index: 50;
  display: none;
}
.dropdown.open .dropdown-menu { display: block; }
.dropdown-item {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
}
.dropdown-item:hover { background: var(--bg-hover); }
.dropdown-item.danger { color: var(--status-danger); }

/* GLOBAL SEARCH RESULTS */
.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0; right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  max-height: 380px;
  overflow-y: auto;
  z-index: 60;
  display: none;
}
.search-results.open { display: block; }
.search-results .empty-search {
  padding: 24px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}
.search-section { padding: 6px; }
.search-section + .search-section { border-top: 1px solid var(--border-soft); }
.search-section h6 {
  padding: 8px 10px 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
  margin: 0;
}
.search-result-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
  color: inherit;
}
.search-result-item:hover { background: var(--bg-hover); }
.search-result-item .info { flex: 1; min-width: 0; }
.search-result-item .info .title { font-size: 13px; font-weight: 500; color: var(--text-primary); }
.search-result-item .info .meta { font-size: 11.5px; color: var(--text-muted); }
.search-result-item mark { background: var(--accent-green-bg); color: var(--accent-green-dark); padding: 0 2px; border-radius: 2px; }

/* MODAL */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(2px);
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  width: min(560px, 90vw);
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border-soft);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-header h2 { font-size: 16px; }
.modal-body { padding: 22px; }
.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border-soft);
  display: flex; justify-content: flex-end; gap: 10px;
}

/* CHIP / FILTER */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  font-size: 12.5px;
  color: var(--text-secondary);
  background: var(--bg-card);
  cursor: pointer;
}
.chip:hover { background: var(--bg-hover); }
.chip.active { background: var(--accent-green-bg); border-color: var(--accent-green); color: var(--accent-green-dark); font-weight: 500; }

/* PROGRESS */
.progress {
  height: 6px;
  background: var(--bg-hover);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: var(--accent-green);
  border-radius: var(--radius-pill);
}
.progress-bar.warning { background: var(--status-warning); }
.progress-bar.danger { background: var(--status-danger); }

/* DIVIDER */
.divider { height: 1px; background: var(--border-soft); margin: 12px 0; border: none; }

/* EMPTY STATE */
.empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
}
.empty .icon { width: 40px; height: 40px; margin: 0 auto 12px; opacity: 0.6; }
