/* ============================================================
   Components — buttons, forms, tables, badges, modals, etc.
   ============================================================ */

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: var(--fs-base);
  font-weight: 500;
  font-family: inherit;
  line-height: 1.2;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, color 0.15s;
  user-select: none;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--color-primary-hover); color: #fff; }
.btn-secondary { background: var(--color-surface); color: var(--slate-700); border-color: var(--slate-300); }
.btn-secondary:hover:not(:disabled) { background: var(--slate-50); }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--color-danger-hover); color: #fff; }
.btn-ghost { background: transparent; color: var(--slate-600); }
.btn-ghost:hover:not(:disabled) { background: var(--slate-100); color: var(--slate-900); }
.btn-link { background: none; padding: 0; color: var(--color-primary); height: auto; }
.btn-link:hover { text-decoration: underline; }
.btn-link.danger { color: var(--color-danger); }
.btn-sm { padding: 5px 10px; font-size: var(--fs-sm); }
.btn-xs { padding: 3px 8px; font-size: var(--fs-xs); }
.btn-lg { padding: 11px 22px; font-size: var(--fs-md); }
.btn-block { width: 100%; }

/* ---------- Forms ---------- */
.form-group { margin-bottom: var(--sp-4); }
.form-label {
  display: block;
  font-size: var(--fs-sm);
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--slate-700);
}
.form-label .req { color: var(--color-danger); margin-left: 2px; }
.form-hint { font-size: var(--fs-xs); color: var(--color-text-muted); margin-top: 4px; }
.form-control {
  width: 100%;
  padding: 8px 12px;
  font-size: var(--fs-base);
  font-family: inherit;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--slate-300);
  border-radius: var(--radius);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-control:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}
.form-control:disabled { background: var(--slate-100); color: var(--color-text-muted); }
textarea.form-control { min-height: 84px; resize: vertical; line-height: 1.5; }
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='%2364748b' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; }
.form-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--sp-4); }
.form-row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-4); }
.form-error { font-size: var(--fs-xs); color: var(--color-danger); margin-top: 4px; }
.form-control.invalid { border-color: var(--color-danger); }
.form-control.invalid:focus { box-shadow: 0 0 0 3px var(--color-danger-light); }
.checkbox-row, .radio-row { display: flex; align-items: center; gap: 8px; font-size: var(--fs-base); }
.checkbox-row input, .radio-row input { width: 16px; height: 16px; accent-color: var(--color-primary); cursor: pointer; }
.checkbox-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: var(--sp-2); }
fieldset.fieldset { border: 1px solid var(--color-border); border-radius: var(--radius); padding: var(--sp-4); margin: 0 0 var(--sp-4); }
fieldset.fieldset legend { font-size: var(--fs-sm); font-weight: 600; padding: 0 var(--sp-2); color: var(--slate-700); }

/* Switch toggle */
.switch { position: relative; display: inline-block; width: 38px; height: 22px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; cursor: pointer;
  background: var(--slate-300); border-radius: 22px; transition: 0.2s;
}
.switch .slider::before {
  content: ""; position: absolute; height: 16px; width: 16px;
  left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: 0.2s;
  box-shadow: var(--shadow-sm);
}
.switch input:checked + .slider { background: var(--color-success); }
.switch input:checked + .slider::before { transform: translateX(16px); }
.switch input:disabled + .slider { opacity: 0.5; cursor: not-allowed; }

/* ---------- Filter bar ---------- */
.filter-bar {
  display: flex; flex-wrap: wrap; gap: var(--sp-3);
  padding: var(--sp-4);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  margin-bottom: var(--sp-4);
}
.filter-bar .form-group { margin: 0; min-width: 150px; flex: 1; }
.filter-bar .filter-actions { display: flex; gap: var(--sp-2); align-items: flex-end; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.data-table th {
  text-align: left;
  padding: 10px var(--sp-4);
  background: var(--slate-50);
  color: var(--slate-600);
  font-weight: 600;
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}
.data-table th.sortable { cursor: pointer; user-select: none; }
.data-table th.sortable:hover { color: var(--slate-900); }
.data-table td { padding: 10px var(--sp-4); border-bottom: 1px solid var(--slate-100); vertical-align: middle; }
.data-table tbody tr:hover { background: var(--slate-50); }
.data-table tbody tr:last-child td { border-bottom: none; }
.table-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-sm); color: var(--color-text-muted);
}

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px;
  font-size: var(--fs-xs);
  font-weight: 600;
  border-radius: 999px;
  white-space: nowrap;
}
.badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-gray { background: var(--slate-100); color: var(--slate-600); }
.badge-blue { background: var(--color-primary-light); color: var(--color-primary-dark); }
.badge-green { background: var(--color-success-light); color: var(--color-success); }
.badge-red { background: var(--color-danger-light); color: var(--color-danger); }
.badge-amber { background: var(--color-warning-light); color: var(--color-warning); }
.badge-cyan { background: var(--color-info-light); color: var(--color-info); }

/* Tags (removable chips) */
.tag {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 6px 3px 10px;
  background: var(--color-primary-light);
  color: var(--color-primary-dark);
  border-radius: var(--radius);
  font-size: var(--fs-xs);
  font-weight: 500;
}
.tag .tag-remove {
  cursor: pointer; border: none; background: none; color: inherit;
  font-size: 14px; line-height: 1; padding: 0 2px;
}
.tag.gray { background: var(--slate-100); color: var(--slate-600); }

/* ---------- Alerts ---------- */
.alert {
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius);
  font-size: var(--fs-sm);
  border: 1px solid transparent;
  margin-bottom: var(--sp-4);
}
.alert-info { background: var(--color-info-light); border-color: #a5f3fc; color: #155e75; }
.alert-warning { background: var(--color-warning-light); border-color: #fde68a; color: #92400e; }
.alert-danger { background: var(--color-danger-light); border-color: #fecaca; color: #991b1b; }
.alert-success { background: var(--color-success-light); border-color: #bbf7d0; color: #166534; }

/* ---------- Empty / loading ---------- */
.empty-state {
  padding: var(--sp-12) var(--sp-6);
  text-align: center;
  color: var(--color-text-muted);
}
.empty-state .empty-icon { font-size: 36px; margin-bottom: var(--sp-3); opacity: 0.5; }
.empty-state p { margin-bottom: var(--sp-4); }
.spinner {
  width: 20px; height: 20px;
  border: 2.5px solid var(--slate-200);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
.spinner-lg { width: 32px; height: 32px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-block { display: flex; justify-content: center; padding: var(--sp-10); }

/* ---------- Pagination ---------- */
.pagination { display: flex; align-items: center; gap: 4px; }
.pagination button {
  min-width: 30px; height: 30px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  border-radius: var(--radius-sm);
  cursor: pointer; font-size: var(--fs-sm);
  color: var(--slate-700);
}
.pagination button:hover:not(:disabled) { background: var(--slate-50); }
.pagination button.active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
.pagination button:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---------- Tabs ---------- */
.tabs {
  display: flex; gap: var(--sp-1);
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--sp-5);
}
.tab-btn {
  padding: 9px 16px;
  background: none; border: none;
  border-bottom: 2px solid transparent;
  font-size: var(--fs-base); font-weight: 500;
  color: var(--color-text-muted);
  cursor: pointer;
  font-family: inherit;
}
.tab-btn:hover { color: var(--slate-900); }
.tab-btn.active { color: var(--color-primary); border-bottom-color: var(--color-primary); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: var(--z-modal);
  padding: var(--sp-6);
  animation: fadeIn 0.15s ease;
}
.modal {
  background: var(--color-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: modalIn 0.18s ease;
}
.modal.modal-lg { max-width: 760px; }
.modal.modal-xl { max-width: 960px; }
.modal-header {
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--color-border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-header h3 { font-size: var(--fs-md); }
.modal-close {
  border: none; background: none; font-size: 22px;
  color: var(--color-text-muted); cursor: pointer; line-height: 1; padding: 0;
}
.modal-close:hover { color: var(--slate-900); }
.modal-body { padding: var(--sp-5); overflow-y: auto; }
.modal-footer {
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--color-border);
  display: flex; justify-content: flex-end; gap: var(--sp-2);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalIn { from { opacity: 0; transform: translateY(8px) scale(0.99); } to { opacity: 1; transform: none; } }

/* ---------- Toast ---------- */
.toast-container {
  position: fixed; top: var(--sp-5); right: var(--sp-5);
  z-index: var(--z-toast);
  display: flex; flex-direction: column; gap: var(--sp-2);
  pointer-events: none;
}
.toast {
  min-width: 260px; max-width: 380px;
  padding: 10px 14px;
  background: var(--slate-800);
  color: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: var(--fs-sm);
  display: flex; align-items: center; gap: 10px;
  pointer-events: auto;
  animation: toastIn 0.2s ease;
}
.toast.toast-success { background: #14532d; }
.toast.toast-error { background: #7f1d1d; }
.toast.toast-warning { background: #78350f; }
.toast .toast-icon { font-size: 15px; }
@keyframes toastIn { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }

/* ---------- Dropdown ---------- */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
  position: absolute; right: 0; top: calc(100% + 6px);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  min-width: 160px;
  padding: 6px;
  z-index: var(--z-dropdown);
}
.dropdown-item {
  display: block; width: 100%; text-align: left;
  padding: 8px 10px;
  background: none; border: none;
  font-size: var(--fs-sm); cursor: pointer;
  border-radius: var(--radius-sm);
  color: var(--slate-700);
  font-family: inherit;
}
.dropdown-item:hover { background: var(--slate-100); }
.dropdown-item.danger { color: var(--color-danger); }
.dropdown-item.danger:hover { background: var(--color-danger-light); }

/* ---------- Email preview ---------- */
.email-preview {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: #fff;
}
.email-preview .ep-head { padding: var(--sp-4); border-bottom: 1px solid var(--color-border); background: var(--slate-50); }
.email-preview .ep-subject { font-weight: 600; margin-bottom: var(--sp-2); }
.email-preview .ep-meta { font-size: var(--fs-xs); color: var(--color-text-muted); }
.email-preview .ep-body { padding: var(--sp-5); font-size: var(--fs-sm); line-height: 1.65; word-break: break-word; overflow-wrap: anywhere; }
.email-preview .ep-body a, .email-preview .link-group a { overflow-wrap: anywhere; word-break: break-all; }
.email-preview .platform-block { border: 1px solid var(--color-border); border-radius: var(--radius); padding: var(--sp-4); margin-bottom: var(--sp-4); min-width: 0; }
.email-preview .link-group { margin-top: var(--sp-3); min-width: 0; }
.email-preview .link-group .lg-title { font-size: var(--fs-xs); text-transform: uppercase; font-weight: 700; letter-spacing: 0.05em; margin-bottom: 6px; }
.email-preview a.disabled-link { color: var(--slate-400); text-decoration: line-through; pointer-events: none; cursor: not-allowed; }
.email-preview table.event-table { width: 100%; border-collapse: collapse; margin: var(--sp-3) 0; }
.email-preview .event-table th, .email-preview .event-table td { border: 1px solid var(--slate-200); padding: 7px 10px; font-size: var(--fs-sm); text-align: left; }
.email-preview .event-table th { background: var(--slate-50); }

/* ---------- Long link text wrapping (Platforms & Links) ---------- */
.link-text { min-width: 0; word-break: break-word; overflow-wrap: anywhere; }
