/* ========================================
   COMPONENTS - Buttons, Cards, Forms,
   Tables, Modals, Toasts, etc.
   ======================================== */

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-5);
  border-radius: var(--radius-lg);
  font-weight: 600;
  font-size: var(--font-sm);
  line-height: 1;
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
  white-space: nowrap;
  user-select: none;
  position: relative;
  overflow: hidden;
}

.btn svg {
  width: 18px;
  height: 18px;
}

/* Primary Button */
.btn-primary {
  background: var(--gradient-accent);
  color: var(--text-inverse);
  box-shadow: var(--shadow-md), 0 0 20px rgba(34, 211, 238, 0.15);
}

.btn-primary:hover {
  box-shadow: var(--shadow-lg), 0 0 30px rgba(34, 211, 238, 0.25);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

/* Secondary Button */
.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--glass-border);
}

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

/* Ghost Button */
.btn-ghost {
  color: var(--text-secondary);
  background: transparent;
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
}

/* Danger Button */
.btn-danger {
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid var(--red-border);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.2);
}

/* Success Button */
.btn-success {
  background: var(--green-bg);
  color: var(--green);
  border: 1px solid var(--green-border);
}

.btn-success:hover {
  background: rgba(16, 185, 129, 0.2);
}

/* Button Sizes */
.btn-sm {
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--font-xs);
  border-radius: var(--radius-md);
}

.btn-lg {
  padding: var(--sp-4) var(--sp-8);
  font-size: var(--font-base);
  border-radius: var(--radius-xl);
}

/* Icon Button */
.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: var(--radius-lg);
  flex-shrink: 0;
}

.btn-icon.btn-sm {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
}

/* ---- Cards ---- */
.card {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-xl);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  transition: all var(--duration-base) var(--ease-out);
  overflow: hidden;
}

.card:hover {
  border-color: var(--glass-border-hover);
}

.card-interactive:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: var(--glass-border-hover);
}

.card-header {
  padding: var(--sp-5) var(--sp-6);
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
}

.card-header h3 {
  font-size: var(--font-lg);
  font-weight: 700;
  color: var(--text-primary);
}

.card-body {
  padding: var(--sp-6);
}

.card-footer {
  padding: var(--sp-4) var(--sp-6);
  border-top: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--sp-3);
}

/* Glow Card (for stats) */
.card-glow {
  position: relative;
}

.card-glow::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  border-radius: var(--radius-full) var(--radius-full) 0 0;
}

.card-glow.glow-cyan::before { background: var(--gradient-accent); }
.card-glow.glow-green::before { background: linear-gradient(90deg, #10b981, #34d399); }
.card-glow.glow-yellow::before { background: linear-gradient(90deg, #f59e0b, #fbbf24); }
.card-glow.glow-purple::before { background: linear-gradient(90deg, #8b5cf6, #a78bfa); }
.card-glow.glow-red::before { background: linear-gradient(90deg, #ef4444, #f87171); }
.card-glow.glow-blue::before { background: linear-gradient(90deg, #3b82f6, #60a5fa); }

/* ---- Form Elements ---- */
.form-group {
  margin-bottom: var(--sp-5);
}

.form-label {
  display: block;
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--sp-2);
  letter-spacing: 0.01em;
}

.form-label .required {
  color: var(--red);
  margin-left: 2px;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: var(--sp-3) var(--sp-4);
  background: var(--bg-surface);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  color: var(--text-primary);
  font-size: var(--font-sm);
  transition: all var(--duration-fast);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-muted);
  outline: none;
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--text-muted);
}

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8.825a.5.5 0 0 1-.354-.146L2.146 5.179a.5.5 0 0 1 .708-.708L6 7.617l3.146-3.146a.5.5 0 0 1 .708.708L6.354 8.679A.5.5 0 0 1 6 8.825Z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--sp-4) center;
  padding-right: var(--sp-10);
  cursor: pointer;
}

.form-select option {
  background: var(--bg-surface);
  color: var(--text-primary);
}

.form-textarea {
  resize: vertical;
  min-height: 100px;
  line-height: var(--leading-relaxed);
}

.form-hint {
  font-size: var(--font-xs);
  color: var(--text-muted);
  margin-top: var(--sp-1);
}

.form-error {
  font-size: var(--font-xs);
  color: var(--red);
  margin-top: var(--sp-1);
}

/* Form Row (inline fields) */
.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--sp-5);
}

/* Checkbox & Radio */
.form-check {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  cursor: pointer;
  font-size: var(--font-sm);
  color: var(--text-secondary);
}

.form-check input[type="checkbox"],
.form-check input[type="radio"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ---- Tables ---- */
.table-container {
  overflow-x: auto;
  border-radius: var(--radius-xl);
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table thead th {
  padding: var(--sp-4) var(--sp-5);
  text-align: left;
  font-size: var(--font-xs);
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border-bottom: 1px solid var(--glass-border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  background: var(--bg-elevated);
}

.table tbody tr {
  transition: background var(--duration-fast);
}

.table tbody tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

.table tbody td {
  padding: var(--sp-4) var(--sp-5);
  font-size: var(--font-sm);
  color: var(--text-secondary);
  border-bottom: 1px solid var(--glass-border);
  vertical-align: middle;
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.table tbody td.text-primary {
  color: var(--text-primary);
  font-weight: 500;
}

.table-row-clickable {
  cursor: pointer;
}

.table-row-clickable:hover td {
  color: var(--text-primary);
}

/* ---- Badges ---- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: var(--font-xs);
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.badge-green {
  background: var(--green-bg);
  color: var(--green);
  border: 1px solid var(--green-border);
}

.badge-yellow {
  background: var(--yellow-bg);
  color: var(--yellow);
  border: 1px solid var(--yellow-border);
}

.badge-red {
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid var(--red-border);
}

.badge-blue {
  background: var(--blue-bg);
  color: var(--blue);
  border: 1px solid var(--blue-border);
}

.badge-purple {
  background: var(--purple-bg);
  color: var(--purple);
  border: 1px solid var(--purple-border);
}

.badge-cyan {
  background: var(--cyan-bg);
  color: var(--cyan);
  border: 1px solid var(--cyan-border);
}

.badge-dot::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

/* ---- Modal ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: var(--z-overlay);
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--sp-6);
  animation: fadeIn var(--duration-fast);
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-2xl);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
  animation: scaleIn var(--duration-base) var(--ease-spring);
}

.modal-header {
  padding: var(--sp-6);
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: var(--font-xl);
  font-weight: 700;
}

.modal-body {
  padding: var(--sp-6);
}

.modal-footer {
  padding: var(--sp-4) var(--sp-6);
  border-top: 1px solid var(--glass-border);
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-3);
}

/* ---- Toast Notifications ---- */
.toast-container {
  position: fixed;
  top: var(--sp-6);
  right: var(--sp-6);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  max-width: 400px;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  background: var(--bg-elevated);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  animation: slideInRight var(--duration-base) var(--ease-spring);
  min-width: 300px;
}

.toast-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  margin-top: 1px;
}

.toast-content {
  flex: 1;
}

.toast-title {
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--text-primary);
}

.toast-message {
  font-size: var(--font-xs);
  color: var(--text-secondary);
  margin-top: 2px;
}

.toast-close {
  width: 20px;
  height: 20px;
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
}

.toast-close:hover {
  color: var(--text-primary);
}

.toast.toast-success { border-left: 3px solid var(--green); }
.toast.toast-error { border-left: 3px solid var(--red); }
.toast.toast-warning { border-left: 3px solid var(--yellow); }
.toast.toast-info { border-left: 3px solid var(--blue); }

.toast.removing {
  animation: slideInRight var(--duration-base) var(--ease-out) reverse forwards;
}

/* ---- Search Bar ---- */
.search-bar {
  position: relative;
  max-width: 400px;
  width: 100%;
}

.search-bar input {
  width: 100%;
  padding: var(--sp-3) var(--sp-4) var(--sp-3) var(--sp-10);
  background: var(--bg-surface);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  color: var(--text-primary);
  font-size: var(--font-sm);
  transition: all var(--duration-fast);
}

.search-bar input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

.search-bar .search-icon {
  position: absolute;
  left: var(--sp-4);
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}

/* ---- File Upload ---- */
.file-upload {
  border: 2px dashed var(--glass-border);
  border-radius: var(--radius-xl);
  padding: var(--sp-8) var(--sp-6);
  text-align: center;
  cursor: pointer;
  transition: all var(--duration-base);
  background: var(--bg-surface);
}

.file-upload:hover,
.file-upload.dragover {
  border-color: var(--accent);
  background: var(--accent-muted);
}

.file-upload-icon {
  font-size: 2.5rem;
  margin-bottom: var(--sp-3);
  opacity: 0.5;
}

.file-upload-text {
  font-size: var(--font-sm);
  color: var(--text-secondary);
}

.file-upload-hint {
  font-size: var(--font-xs);
  color: var(--text-muted);
  margin-top: var(--sp-2);
}

/* ---- Empty State ---- */
.empty-state {
  text-align: center;
  padding: var(--sp-16) var(--sp-8);
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 3.5rem;
  margin-bottom: var(--sp-4);
  opacity: 0.4;
}

.empty-state-title {
  font-size: var(--font-xl);
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--sp-2);
}

.empty-state-text {
  font-size: var(--font-sm);
  max-width: 400px;
  margin: 0 auto var(--sp-6);
  line-height: var(--leading-relaxed);
}

/* ---- Loading Spinner ---- */
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--glass-border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.spinner-sm {
  width: 18px;
  height: 18px;
  border-width: 2px;
}

.loading-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-16);
}

/* ---- Tabs ---- */
.tabs {
  display: flex;
  gap: var(--sp-1);
  border-bottom: 1px solid var(--glass-border);
  margin-bottom: var(--sp-6);
  overflow-x: auto;
}

.tab {
  padding: var(--sp-3) var(--sp-5);
  font-size: var(--font-sm);
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all var(--duration-fast);
  white-space: nowrap;
  margin-bottom: -1px;
}

.tab:hover {
  color: var(--text-secondary);
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ---- Lightbox ---- */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  z-index: var(--z-lightbox);
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--sp-8);
}

.lightbox.active {
  display: flex;
  animation: fadeIn var(--duration-fast);
}

.lightbox img {
  max-width: 90vw;
  max-height: 85vh;
  object-fit: contain;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
}

.lightbox-close {
  position: absolute;
  top: var(--sp-6);
  right: var(--sp-6);
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-full);
  color: white;
  font-size: 1.5rem;
  cursor: pointer;
  transition: background var(--duration-fast);
}

.lightbox-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-full);
  color: white;
  font-size: 1.5rem;
  cursor: pointer;
  transition: background var(--duration-fast);
}

.lightbox-nav:hover {
  background: rgba(255, 255, 255, 0.2);
}

.lightbox-prev { left: var(--sp-6); }
.lightbox-next { right: var(--sp-6); }

/* ---- Divider ---- */
.divider {
  height: 1px;
  background: var(--glass-border);
  margin: var(--sp-6) 0;
}

/* ---- Avatar / Animal Icon ---- */
.avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  flex-shrink: 0;
}

.avatar-sm { width: 32px; height: 32px; font-size: 1rem; }
.avatar-lg { width: 56px; height: 56px; font-size: 1.75rem; }

.avatar-cyan { background: var(--cyan-bg); }
.avatar-green { background: var(--green-bg); }
.avatar-yellow { background: var(--yellow-bg); }
.avatar-red { background: var(--red-bg); }
.avatar-blue { background: var(--blue-bg); }
.avatar-purple { background: var(--purple-bg); }

/* ---- Tag / Chip ---- */
.tag {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: var(--sp-1) var(--sp-3);
  background: var(--bg-elevated);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-full);
  font-size: var(--font-xs);
  color: var(--text-secondary);
}

.tag-remove {
  width: 14px;
  height: 14px;
  cursor: pointer;
  opacity: 0.5;
}

.tag-remove:hover {
  opacity: 1;
}

/* ---- Photo Grid ---- */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: var(--sp-3);
}

.photo-thumb {
  aspect-ratio: 1;
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  position: relative;
  border: 1px solid var(--glass-border);
  transition: all var(--duration-fast);
}

.photo-thumb:hover {
  transform: scale(1.03);
  border-color: var(--accent);
  box-shadow: var(--shadow-glow);
}

.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-thumb-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity var(--duration-fast);
}

.photo-thumb:hover .photo-thumb-overlay {
  opacity: 1;
}

/* ---- Toolbar ---- */
.toolbar {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-wrap: wrap;
  margin-bottom: var(--sp-6);
}

.toolbar-spacer {
  flex: 1;
}

/* ---- Confirm Dialog ---- */
.confirm-dialog {
  text-align: center;
  padding: var(--sp-4) 0;
}

.confirm-dialog-icon {
  font-size: 3rem;
  margin-bottom: var(--sp-4);
}

.confirm-dialog h4 {
  font-size: var(--font-xl);
  font-weight: 700;
  margin-bottom: var(--sp-2);
}

.confirm-dialog p {
  font-size: var(--font-sm);
  color: var(--text-secondary);
  max-width: 320px;
  margin: 0 auto;
  line-height: var(--leading-relaxed);
}
