/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  border: 1px solid transparent;
  outline: none;
}
.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.btn-primary {
  background-color: var(--primary);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background-color: var(--primary-dark); }
.btn-secondary {
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) { background-color: var(--border); }
.btn-danger {
  background-color: var(--danger);
  color: #fff;
}
.btn-danger:hover:not(:disabled) { filter: brightness(0.9); }
.btn-ghost {
  background-color: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover:not(:disabled) { background-color: var(--bg-secondary); color: var(--text-primary); }
.btn-sm { padding: 4px 12px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 16px; }

/* Inputs */
.input-group {
  margin-bottom: 16px;
  position: relative;
}
.input-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 4px;
  color: var(--text-secondary);
}
.input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
}
.input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px var(--primary-light);
  outline: none;
}
.input-error {
  border-color: var(--danger);
}

/* Cards */
.card {
  background-color: var(--bg-primary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 24px;
  border: 1px solid var(--border);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 9999px;
  font-size: 12px;
  font-weight: 500;
}
.badge-success { background: rgba(16,185,129,0.1); color: var(--success); }
.badge-danger { background: rgba(239,68,68,0.1); color: var(--danger); }
.badge-warning { background: rgba(245,158,11,0.1); color: var(--warning); }
.badge-info { background: rgba(59,130,246,0.1); color: var(--info); }
.badge-neutral { background: var(--bg-secondary); color: var(--text-secondary); }

/* Tables */
.table-container {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}
.table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}
.table th, .table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.table th {
  background-color: var(--bg-secondary);
  color: var(--text-secondary);
  font-weight: 500;
}
.table tr:last-child td { border-bottom: none; }
.table tbody tr:nth-child(even) { background-color: var(--bg-secondary); }

/* Modals */
.modal-backdrop {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  display: none; justify-content: center; align-items: center;
  z-index: 1000;
}
.modal {
  background: var(--bg-primary);
  width: 100%; max-width: 500px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}
.modal-header { padding: 16px 24px; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 18px; }
.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* Toasts */
.toast-container { position: fixed; top: 24px; right: 24px; display: flex; flex-direction: column; gap: 8px; z-index: 1100; }
.toast {
  padding: 12px 16px; border-radius: var(--radius-md); box-shadow: var(--shadow-md);
  background: var(--bg-primary); color: var(--text-primary);
  display: flex; align-items: center; gap: 8px; font-size: 14px;
  animation: slideIn 0.3s ease;
}
.toast-success { border-left: 4px solid var(--success); }
.toast-danger { border-left: 4px solid var(--danger); }
.toast-warning { border-left: 4px solid var(--warning); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Progress */
.progress-bar-container {
  height: 8px; background: var(--bg-secondary); border-radius: 9999px; overflow: hidden;
}
.progress-bar-fill {
  height: 100%; background: var(--primary); border-radius: 9999px; width: 0%;
  position: relative; overflow: hidden;
}
.progress-bar-fill::after {
  content: ""; position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(90deg, rgba(255,255,255,0) 0%, rgba(255,255,255,0.2) 50%, rgba(255,255,255,0) 100%);
  animation: shimmer 1.5s infinite;
}
@keyframes shimmer { 0% { transform: translateX(-100%); } 100% { transform: translateX(100%); } }

/* Stat Card */
.stat-card { display: flex; flex-direction: column; gap: 8px; padding: 24px; background: var(--bg-primary); border-radius: var(--radius-lg); border: 1px solid var(--border); }
.stat-card .val { font-size: 32px; font-weight: 700; color: var(--text-primary); }
.stat-card .lbl { font-size: 14px; color: var(--text-secondary); }

/* Empty State */
.empty-state { text-align: center; padding: 48px 24px; color: var(--text-secondary); }
.empty-state svg { width: 48px; height: 48px; margin-bottom: 16px; opacity: 0.5; }

/* Spinners */
.spinner { border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; width: 16px; height: 16px; animation: spin 1s linear infinite; display: inline-block; }
.spinner-sm { width: 12px; height: 12px; }
.spinner-lg { width: 24px; height: 24px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Tabs */
.tabs { display: flex; border-bottom: 1px solid var(--border); gap: 16px; margin-bottom: 24px; }
.tab-item { padding: 8px 0; color: var(--text-secondary); font-weight: 500; cursor: pointer; border-bottom: 2px solid transparent; font-size: 14px; }
.tab-item.active { color: var(--primary); border-bottom-color: var(--primary); }

/* Dropdowns */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu { display: none; position: absolute; right: 0; top: 100%; margin-top: 4px; background: var(--bg-primary); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-md); min-width: 150px; z-index: 100; }
.dropdown-menu.show { display: block; }
.dropdown-item { padding: 8px 16px; cursor: pointer; font-size: 14px; display: block; color: var(--text-primary); }
.dropdown-item:hover { background: var(--bg-secondary); }

/* Toggles */
.toggle { position: relative; display: inline-block; width: 36px; height: 20px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: var(--border); border-radius: 20px; transition: .4s; }
.slider:before { position: absolute; content: ""; height: 16px; width: 16px; left: 2px; bottom: 2px; background-color: white; border-radius: 50%; transition: .4s; }
input:checked + .slider { background-color: var(--primary); }
input:checked + .slider:before { transform: translateX(16px); }

/* ── Mobile overlay (injected by sidebar.js) ─────────────────────── */
.sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.45); z-index: 49; backdrop-filter: blur(2px);
}
.sidebar-overlay.show { display: block; }

/* ── Hamburger button ────────────────────────────────────────────── */
.mobile-menu-btn {
  display: none; align-items: center; justify-content: center;
  width: 40px; height: 40px; border: 1px solid var(--border);
  border-radius: var(--radius-md); background: var(--bg-primary);
  cursor: pointer; font-size: 18px; color: var(--text-primary);
  flex-shrink: 0;
}

/* ── Mobile ≤ 768px ──────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Show hamburger */
  .mobile-menu-btn { display: flex; }

  /* Cards */
  .card { padding: 16px; border-radius: var(--radius-md); }

  /* Buttons */
  .btn { font-size: 13px; }
  .btn-lg { padding: 10px 18px; font-size: 14px; }

  /* Modals — slide up from bottom */
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal {
    max-width: 100%; width: 100%;
    border-radius: 20px 20px 0 0;
    max-height: 92vh; display: flex; flex-direction: column;
  }
  .modal-body { overflow-y: auto; flex: 1; }

  /* Toasts — bottom of screen */
  .toast-container { top: auto; bottom: 16px; right: 12px; left: 12px; max-width: 100%; }

  /* Tables — horizontal scroll with sticky first col */
  .table-container { border-radius: var(--radius-sm); }
  .table th, .table td { padding: 10px 12px; font-size: 13px; white-space: nowrap; }

  /* Stat cards */
  .stat-card .val { font-size: 24px; }

  /* Tabs — horizontal scroll */
  .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; gap: 0; padding-bottom: 1px; flex-wrap: nowrap; }
  .tab-item { white-space: nowrap; padding: 10px 14px; font-size: 13px; }

  /* Input groups */
  .input { font-size: 16px; } /* prevents iOS zoom on focus */
  select.input { font-size: 16px; }
}

/* ── Small phones ≤ 480px ────────────────────────────────────────── */
@media (max-width: 480px) {
  .card { padding: 12px; }
  .page-header-actions { flex-wrap: wrap; }
  .btn-sm { padding: 5px 10px; font-size: 12px; }
  .modal-header { font-size: 16px; padding: 14px 16px; }
  .modal-body { padding: 16px; }
  .modal-footer { padding: 12px 16px; }
  .stat-card .val { font-size: 20px; }
}
