/* =========================================================================
   Kuy UGC CRM — Design System
   Flat + Micro-interactions (per ui-ux-pro-max: Productivity Tool)
   All theme values as CSS custom properties for maintainability.
   ========================================================================= */

:root {
  /* Color tokens */
  --kuy-bg: #0a0a0f;
  --kuy-bg-2: #0f0f14;
  --kuy-surface: #18181b;
  --kuy-surface-2: #1e1e22;
  --kuy-surface-3: #242428;
  --kuy-border: #27272a;
  --kuy-border-strong: #3f3f46;
  --kuy-text: #e4e4e7;
  --kuy-text-muted: #a1a1aa;
  --kuy-text-dim: #71717a;

  --kuy-accent: #ec4899;
  --kuy-accent-hover: #db2777;
  --kuy-accent-soft: rgba(236, 72, 153, 0.12);

  --kuy-success: #10b981;
  --kuy-success-bg: rgba(16, 185, 129, 0.10);
  --kuy-success-text: #6ee7b7;

  --kuy-warn: #eab308;
  --kuy-warn-bg: rgba(234, 179, 8, 0.10);
  --kuy-warn-text: #fcd34d;

  --kuy-danger: #ef4444;
  --kuy-danger-bg: rgba(239, 68, 68, 0.10);
  --kuy-danger-text: #fca5a5;

  --kuy-info-text: #93c5fd;

  /* Spacing + radii */
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  /* Motion */
  --t-fast: 120ms;
  --t: 180ms;
  --t-slow: 280ms;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);

  /* Shadows (subtle, dark-mode appropriate) */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.45);

  /* Focus ring */
  --ring: 0 0 0 2px var(--kuy-bg), 0 0 0 4px var(--kuy-accent);
}

/* =========================================================================
   Base
   ========================================================================= */

* {
  box-sizing: border-box;
}

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

body {
  background: var(--kuy-bg);
  color: var(--kuy-text);
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'SF Pro Display', system-ui, sans-serif;
  font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  margin: 0;
}

::selection {
  background: var(--kuy-accent-soft);
  color: #fff;
}

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--kuy-border);
  border-radius: 10px;
  border: 2px solid var(--kuy-bg);
}
::-webkit-scrollbar-thumb:hover { background: var(--kuy-border-strong); }

/* =========================================================================
   Focus states (accessibility — per ux-guidelines severity high)
   ========================================================================= */

:focus { outline: none; }

:focus-visible {
  outline: none;
  box-shadow: var(--ring);
  border-radius: var(--radius-sm);
}

.btn:focus-visible,
.input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  box-shadow: 0 0 0 2px var(--kuy-bg), 0 0 0 4px var(--kuy-accent);
  border-color: var(--kuy-accent);
}

/* =========================================================================
   Typography
   ========================================================================= */

h1, h2, h3, h4 {
  margin: 0;
  letter-spacing: -0.01em;
  color: #fff;
}

a {
  color: var(--kuy-info-text);
  text-decoration: none;
  transition: color var(--t-fast) var(--ease);
}

a:hover { color: #bfdbfe; }

code, .mono {
  font-family: 'SF Mono', 'JetBrains Mono', 'Menlo', 'Consolas', monospace;
  font-size: 0.85em;
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* =========================================================================
   Cards
   ========================================================================= */

.card {
  background: var(--kuy-surface);
  border: 1px solid var(--kuy-border);
  border-radius: var(--radius-lg);
  transition: border-color var(--t) var(--ease), box-shadow var(--t) var(--ease);
}

.card:hover {
  /* subtle lift, no big shadow */
}

.card-interactive:hover {
  border-color: var(--kuy-border-strong);
  box-shadow: var(--shadow);
}

/* =========================================================================
   Buttons
   ========================================================================= */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.2;
  cursor: pointer;
  border: 1px solid transparent;
  background: transparent;
  color: inherit;
  transition: background var(--t-fast) var(--ease),
              color var(--t-fast) var(--ease),
              border-color var(--t-fast) var(--ease),
              transform var(--t-fast) var(--ease);
  user-select: none;
  white-space: nowrap;
}

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

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--kuy-accent);
  color: #fff;
  border-color: var(--kuy-accent);
}

.btn-primary:hover:not(:disabled) {
  background: var(--kuy-accent-hover);
  border-color: var(--kuy-accent-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--kuy-text-muted);
  border-color: var(--kuy-border);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--kuy-surface-3);
  color: #fff;
  border-color: var(--kuy-border-strong);
}

.btn-danger {
  background: transparent;
  color: var(--kuy-danger-text);
  border-color: var(--kuy-danger);
}

.btn-danger:hover:not(:disabled) {
  background: var(--kuy-danger-bg);
}

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-xs { padding: 3px 8px; font-size: 11px; }

/* Loading state: btn + .btn-loading shows spinner, disables clicks */
.btn-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}

.btn-loading::after {
  content: '';
  position: absolute;
  inset: 0;
  margin: auto;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  color: #fff;
  animation: spin 0.7s linear infinite;
}

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

/* =========================================================================
   Inputs
   ========================================================================= */

.input, select, textarea {
  background: var(--kuy-surface);
  border: 1px solid var(--kuy-border);
  color: #fff;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  width: 100%;
  font-family: inherit;
  transition: border-color var(--t-fast) var(--ease),
              background var(--t-fast) var(--ease);
}

.input::placeholder,
textarea::placeholder {
  color: var(--kuy-text-dim);
}

.input:hover:not(:disabled),
select:hover:not(:disabled),
textarea:hover:not(:disabled) {
  border-color: var(--kuy-border-strong);
}

.input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--kuy-accent);
  background: var(--kuy-bg-2);
}

select {
  appearance: none;
  -webkit-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='%23a1a1aa' d='M6 8L2 4h8z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}

/* =========================================================================
   Badges
   ========================================================================= */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.3;
}

.color-GREEN,
.badge-success {
  background: var(--kuy-success-bg);
  color: var(--kuy-success-text);
  border: 1px solid rgba(16, 185, 129, 0.25);
}

.color-YELLOW,
.badge-warn {
  background: var(--kuy-warn-bg);
  color: var(--kuy-warn-text);
  border: 1px solid rgba(234, 179, 8, 0.25);
}

.color-RED,
.badge-danger {
  background: var(--kuy-danger-bg);
  color: var(--kuy-danger-text);
  border: 1px solid rgba(239, 68, 68, 0.25);
}

.badge-info {
  background: rgba(59, 130, 246, 0.12);
  color: var(--kuy-info-text);
  border: 1px solid rgba(59, 130, 246, 0.25);
}

.badge-neutral {
  background: var(--kuy-surface-3);
  color: var(--kuy-text-muted);
  border: 1px solid var(--kuy-border);
}

/* =========================================================================
   Navigation
   ========================================================================= */

.nav-bar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(24, 24, 27, 0.85);
  backdrop-filter: saturate(180%) blur(10px);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--kuy-border);
}

.nav-link {
  display: inline-flex;
  align-items: center;
  padding: 7px 14px;
  color: var(--kuy-text-muted);
  font-size: 14px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  transition: background var(--t-fast) var(--ease),
              color var(--t-fast) var(--ease);
  position: relative;
}

.nav-link:hover {
  background: var(--kuy-surface-3);
  color: #fff;
}

.nav-link.active {
  background: var(--kuy-accent-soft);
  color: #fff;
}

.nav-link.active::after {
  content: '';
  position: absolute;
  bottom: -13px;
  left: 14px;
  right: 14px;
  height: 2px;
  background: var(--kuy-accent);
  border-radius: 2px 2px 0 0;
}

/* =========================================================================
   Tables
   ========================================================================= */

.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--kuy-border);
  background: var(--kuy-surface);
}

table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  font-size: 13px;
}

th {
  background: var(--kuy-surface-3);
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--kuy-text-muted);
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 1;
  border-bottom: 1px solid var(--kuy-border);
  white-space: nowrap;
}

table.sortable th[data-sort] {
  cursor: pointer;
  user-select: none;
  transition: color var(--t-fast) var(--ease);
}

table.sortable th[data-sort]:hover {
  color: #fff;
}

th .sort-ind {
  display: inline-block;
  margin-left: 4px;
  font-size: 10px;
  opacity: 0.4;
  transition: opacity var(--t-fast) var(--ease);
}

td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--kuy-border);
  vertical-align: middle;
}

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

tbody tr {
  transition: background var(--t-fast) var(--ease);
}

tbody tr:hover td {
  background: var(--kuy-surface-2);
}

/* Empty state inside table */
.table-empty {
  padding: 48px 20px;
  text-align: center;
  color: var(--kuy-text-dim);
}

.table-empty-icon {
  font-size: 32px;
  margin-bottom: 8px;
  opacity: 0.4;
}

/* =========================================================================
   Loading indicators
   ========================================================================= */

.skeleton {
  background: linear-gradient(
    90deg,
    var(--kuy-surface-2) 25%,
    var(--kuy-surface-3) 50%,
    var(--kuy-surface-2) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
  border-radius: var(--radius-sm);
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--kuy-border-strong);
  border-top-color: var(--kuy-accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* Top progress bar — active during fetch */
#nprogress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--kuy-accent);
  z-index: 100;
  transform: scaleX(0);
  transform-origin: left;
  transition: transform var(--t-slow) var(--ease), opacity var(--t) var(--ease);
  opacity: 0;
  pointer-events: none;
}

#nprogress.active {
  opacity: 1;
  transform: scaleX(0.7);
}

#nprogress.done {
  transform: scaleX(1);
  opacity: 0;
}

/* =========================================================================
   Toasts
   ========================================================================= */

.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: calc(100vw - 32px);
}

.toast {
  pointer-events: auto;
  background: var(--kuy-surface);
  color: #fff;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--kuy-border);
  border-left: 3px solid var(--kuy-accent);
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 240px;
  max-width: 380px;
  animation: toast-in 200ms var(--ease);
}

.toast.leaving {
  animation: toast-out 200ms var(--ease) forwards;
}

.toast-success { border-left-color: var(--kuy-success); }
.toast-warn    { border-left-color: var(--kuy-warn); }
.toast-error   { border-left-color: var(--kuy-danger); }

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

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

/* =========================================================================
   Modals
   ========================================================================= */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
  animation: modal-fade-in 150ms var(--ease);
}

.modal-card {
  background: var(--kuy-surface);
  border: 1px solid var(--kuy-border);
  border-radius: var(--radius-xl);
  padding: 24px;
  max-width: 100%;
  box-shadow: var(--shadow-lg);
  animation: modal-slide-in 200ms var(--ease);
}

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

@keyframes modal-slide-in {
  from { transform: translateY(12px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

/* =========================================================================
   Empty states
   ========================================================================= */

.empty-state {
  padding: 48px 24px;
  text-align: center;
  color: var(--kuy-text-dim);
}

.empty-state-icon {
  font-size: 36px;
  margin-bottom: 12px;
  opacity: 0.5;
}

.empty-state-title {
  font-size: 15px;
  color: var(--kuy-text-muted);
  margin-bottom: 4px;
  font-weight: 500;
}

.empty-state-text {
  font-size: 13px;
  color: var(--kuy-text-dim);
  max-width: 400px;
  margin: 0 auto;
  line-height: 1.5;
}

/* =========================================================================
   Mobile nav
   ========================================================================= */

.mobile-nav-toggle {
  display: none;
  background: transparent;
  border: 1px solid var(--kuy-border);
  color: var(--kuy-text-muted);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.mobile-nav-drawer {
  display: none;
}

@media (max-width: 768px) {
  .nav-bar .nav-links-desktop { display: none; }

  .mobile-nav-toggle { display: inline-flex; align-items: center; }

  .mobile-nav-drawer {
    display: block;
    position: fixed;
    top: 56px;
    right: 0;
    bottom: 0;
    width: 260px;
    background: var(--kuy-surface);
    border-left: 1px solid var(--kuy-border);
    transform: translateX(100%);
    transition: transform var(--t) var(--ease);
    z-index: 40;
    padding: 16px;
    overflow-y: auto;
  }

  .mobile-nav-drawer.open { transform: translateX(0); }

  .mobile-nav-drawer .nav-link {
    display: block;
    padding: 12px 14px;
    font-size: 15px;
    margin-bottom: 4px;
  }

  .mobile-nav-drawer .nav-link.active::after { display: none; }

  .mobile-nav-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 39;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--t) var(--ease);
  }

  .mobile-nav-backdrop.open {
    opacity: 1;
    pointer-events: auto;
  }

  main { padding: 16px !important; }

  .card { border-radius: var(--radius); }

  table { font-size: 12px; }
  th, td { padding: 8px 10px; }
}

/* =========================================================================
   Utility
   ========================================================================= */

.text-muted { color: var(--kuy-text-muted); }
.text-dim   { color: var(--kuy-text-dim); }
.text-accent { color: var(--kuy-accent); }

.hr-thin {
  border: 0;
  border-top: 1px solid var(--kuy-border);
  margin: 16px 0;
}

/* Reduce motion — respect user preference (a11y) */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
