/* ============================================================
   AFFILIATE NETWORK - Core Design System
   Mobile-first, dark theme, professional UI
   ============================================================ */

/* === Reset === */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  overflow-x: hidden;
  min-height: 100vh;
  min-height: 100dvh;
}

/* === CSS Variables === */
:root {
  /* Colors - Dark Theme */
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --bg-card: #1e293b;
  --bg-hover: #334155;
  --bg-active: #475569;
  --bg-input: #1e293b;
  --bg-overlay: rgba(0, 0, 0, 0.6);

  --border: #334155;
  --border-light: #475569;
  --border-focus: #3b82f6;

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-inverse: #0f172a;

  /* Accent Colors */
  --blue: #3b82f6;
  --blue-hover: #2563eb;
  --blue-light: rgba(59, 130, 246, 0.15);
  --green: #22c55e;
  --green-light: rgba(34, 197, 94, 0.15);
  --red: #ef4444;
  --red-light: rgba(239, 68, 68, 0.15);
  --yellow: #eab308;
  --yellow-light: rgba(234, 179, 8, 0.15);
  --purple: #a855f7;
  --purple-light: rgba(168, 85, 247, 0.15);
  --orange: #f97316;
  --orange-light: rgba(249, 115, 22, 0.15);
  --cyan: #06b6d4;
  --cyan-light: rgba(6, 182, 212, 0.15);
  --pink: #ec4899;
  --pink-light: rgba(236, 72, 153, 0.15);

  /* Layout */
  --sidebar-width: 260px;
  --sidebar-collapsed: 72px;
  --header-height: 56px;
  --border-radius: 8px;
  --border-radius-lg: 12px;
  --border-radius-sm: 6px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.4);
  --shadow-xl: 0 20px 50px rgba(0, 0, 0, 0.5);

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow: 400ms ease;

  /* Z-index layers */
  --z-sidebar: 100;
  --z-header: 90;
  --z-overlay: 200;
  --z-modal: 300;
  --z-toast: 400;
}

/* === Typography === */
h1 { font-size: 1.75rem; font-weight: 700; letter-spacing: -0.025em; }
h2 { font-size: 1.375rem; font-weight: 600; letter-spacing: -0.02em; }
h3 { font-size: 1.125rem; font-weight: 600; }
h4 { font-size: 1rem; font-weight: 600; }
h5 { font-size: 0.875rem; font-weight: 600; }
h6 { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }

a { color: var(--blue); text-decoration: none; }
a:hover { color: var(--blue-hover); }

/* === Scrollbar === */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-tertiary); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* === Screens === */
.screen { display: none; }
.screen.active { display: flex; }

/* === Login Screen === */
#login-screen {
  min-height: 100vh;
  min-height: 100dvh;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
  padding: 1rem;
}

.login-container {
  width: 100%;
  max-width: 380px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--border-radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow-xl);
}

.login-logo {
  text-align: center;
  margin-bottom: 2rem;
}

.logo-icon {
  width: 64px;
  height: 64px;
  background: linear-gradient(135deg, var(--blue), var(--purple));
  border-radius: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 800;
  color: white;
  margin-bottom: 1rem;
}

.logo-icon.small {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  font-size: 0.875rem;
}

.login-logo h1 {
  font-size: 1.375rem;
  margin-bottom: 0.25rem;
}

.login-logo p {
  color: var(--text-secondary);
  font-size: 0.875rem;
}

/* === Forms === */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.375rem;
}

input, select, textarea {
  width: 100%;
  padding: 0.625rem 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--border-radius-sm);
  color: var(--text-primary);
  font-size: 0.875rem;
  font-family: inherit;
  transition: border-color var(--transition-fast);
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--blue-light);
}

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

textarea {
  resize: vertical;
  min-height: 80px;
}

select {
  cursor: pointer;
  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='%2394a3b8' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2rem;
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  border: 1px solid transparent;
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  text-decoration: none;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--blue);
  color: white;
}
.btn-primary:hover { background: var(--blue-hover); }

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

.btn-danger {
  background: var(--red);
  color: white;
}
.btn-danger:hover { background: #dc2626; }

.btn-success {
  background: var(--green);
  color: white;
}
.btn-success:hover { background: #16a34a; }

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

.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.8125rem; }
.btn-lg { padding: 0.75rem 1.5rem; font-size: 1rem; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

/* === Badge === */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.125rem 0.5rem;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-radius: 100px;
  background: var(--blue-light);
  color: var(--blue);
}

.badge-green { background: var(--green-light); color: var(--green); }
.badge-red { background: var(--red-light); color: var(--red); }
.badge-yellow { background: var(--yellow-light); color: var(--yellow); }
.badge-purple { background: var(--purple-light); color: var(--purple); }
.badge-orange { background: var(--orange-light); color: var(--orange); }

/* === Cards === */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--border-radius);
  padding: 1.25rem;
  transition: border-color var(--transition-fast);
}

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

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.card-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
}

.card-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* === Stat Cards === */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--border-radius);
  padding: 1rem;
}

.stat-card .stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
}

.stat-card .stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.stat-card .stat-change {
  font-size: 0.75rem;
  margin-top: 0.25rem;
}

.stat-change.up { color: var(--green); }
.stat-change.down { color: var(--red); }

/* === Tables === */
.table-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: var(--border-radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

thead {
  background: var(--bg-secondary);
  position: sticky;
  top: 0;
  z-index: 1;
}

th {
  text-align: left;
  padding: 0.75rem 1rem;
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-hover); }

/* === Tabs === */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  gap: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.tab {
  padding: 0.75rem 1.25rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition-fast);
  font-family: inherit;
}

.tab:hover { color: var(--text-secondary); }
.tab.active {
  color: var(--blue);
  border-bottom-color: var(--blue);
}

/* === Toast Notifications === */
#toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--border-radius);
  padding: 0.75rem 1rem;
  font-size: 0.8125rem;
  color: var(--text-primary);
  box-shadow: var(--shadow-lg);
  pointer-events: all;
  animation: toast-in 0.3s ease;
  max-width: 360px;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

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

.toast.removing { animation: toast-out 0.3s ease forwards; }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(100%); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(100%); }
}

/* === Modal === */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  animation: fade-in 0.2s ease;
}

#modal-overlay.hidden { display: none; }

#modal-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--border-radius-lg);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  max-height: 90dvh;
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
  animation: modal-in 0.25s ease;
}

#modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

#modal-body { padding: 1.25rem; }

#modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

/* === Loading Spinner === */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.spinner-lg { width: 32px; height: 32px; border-width: 3px; }

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

/* === Empty State === */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-muted);
}

.empty-state svg {
  width: 48px;
  height: 48px;
  margin-bottom: 1rem;
  opacity: 0.5;
}

.empty-state h3 {
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

/* === Utility Classes === */
.hidden { display: none !important; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.text-sm { font-size: 0.8125rem; }
.text-xs { font-size: 0.75rem; }
.text-muted { color: var(--text-muted); }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-right { text-align: right; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.error-text { color: var(--red); font-size: 0.8125rem; margin-top: 0.5rem; }
.w-full { width: 100%; }

/* === Section Page Layout === */
.section-page {
  padding: 1.25rem;
  max-width: 1400px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.section-header h2 {
  font-size: 1.25rem;
}

.section-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.search-input {
  position: relative;
}

.search-input input {
  padding-left: 2.25rem;
  width: 200px;
}

.search-input svg {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  width: 16px;
  height: 16px;
}

/* === Pagination === */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  margin-top: 1rem;
}

.pagination button {
  min-width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  font-size: 0.8125rem;
  font-family: inherit;
}

.pagination button.active {
  background: var(--blue);
  border-color: var(--blue);
  color: white;
}

.pagination button:hover:not(.active) {
  background: var(--bg-hover);
}

/* === Mobile-only helper === */
.mobile-only { display: none; }
@media (max-width: 768px) {
  .mobile-only { display: flex; }
  .desktop-only { display: none !important; }
}
