/* ═══════════════════════════════════════════════════════════════════════════
   SAPBridge Design System · Fruzco
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Fonts ─────────────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=Sora:wght@400;500;600;700;800&display=swap');

/* ── Design Tokens ─────────────────────────────────────────────────────── */
:root {
  /* Typography */
  --font-display: 'Sora', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;

  /* Radius */
  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-2xl: 28px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-xs: 0 1px 2px rgb(0 0 0/.04);
  --shadow-sm: 0 1px 3px rgb(0 0 0/.06), 0 1px 2px rgb(0 0 0/.04);
  --shadow-md: 0 4px 12px rgb(0 0 0/.07), 0 2px 4px rgb(0 0 0/.04);
  --shadow-lg: 0 12px 40px rgb(0 0 0/.1), 0 4px 12px rgb(0 0 0/.05);
  --shadow-xl: 0 20px 60px rgb(0 0 0/.12), 0 8px 20px rgb(0 0 0/.06);

  /* Timing */
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
  --duration-fast: 150ms;
  --duration-normal: 250ms;
  --duration-slow: 400ms;

  /* Colors – Light (default) */
  --color-surface: #f8fafc;
  --color-surface-elevated: #ffffff;
  --color-surface-sunken: #f1f5f9;
  --color-ink: #0f172a;
  --color-ink-secondary: #475569;
  --color-ink-muted: #94a3b8;
  --color-border: #e2e8f0;
  --color-border-subtle: #f1f5f9;
  --color-accent: #0d9488;
  --color-accent-soft: rgba(13, 148, 136, .08);
  --color-accent-hover: #0f766e;
  --color-success: #16a34a;
  --color-success-soft: rgba(22, 163, 74, .08);
  --color-warning: #d97706;
  --color-warning-soft: rgba(217, 119, 6, .08);
  --color-danger: #dc2626;
  --color-danger-soft: rgba(220, 38, 38, .08);
  --color-info: #2563eb;
  --color-info-soft: rgba(37, 99, 235, .08);

  /* Sidebar */
  --sidebar-bg: #0f172a;
  --sidebar-text: #e2e8f0;
  --sidebar-accent: #10b981;

  /* Top progress bar */
  --progress-height: 3px;
}

/* ── Dark Mode ─────────────────────────────────────────────────────────── */
[data-theme="dark"] {
  --color-surface: #0c1017;
  --color-surface-elevated: #151b27;
  --color-surface-sunken: #080c12;
  --color-ink: #e8ecf1;
  --color-ink-secondary: #94a3b8;
  --color-ink-muted: #64748b;
  --color-border: #1e293b;
  --color-border-subtle: #1a2332;
  --color-accent: #2dd4bf;
  --color-accent-soft: rgba(45, 212, 191, .1);
  --color-accent-hover: #5eead4;
  --color-success: #4ade80;
  --color-success-soft: rgba(74, 222, 128, .1);
  --color-warning: #fbbf24;
  --color-warning-soft: rgba(251, 191, 36, .1);
  --color-danger: #f87171;
  --color-danger-soft: rgba(248, 113, 113, .1);
  --color-info: #60a5fa;
  --color-info-soft: rgba(96, 165, 250, .1);
  --sidebar-bg: #080c12;
  --sidebar-text: #94a3b8;
  --sidebar-accent: #2dd4bf;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --color-surface: #0c1017;
    --color-surface-elevated: #151b27;
    --color-surface-sunken: #080c12;
    --color-ink: #e8ecf1;
    --color-ink-secondary: #94a3b8;
    --color-ink-muted: #64748b;
    --color-border: #1e293b;
    --color-border-subtle: #1a2332;
    --color-accent: #2dd4bf;
    --color-accent-soft: rgba(45, 212, 191, .1);
    --color-accent-hover: #5eead4;
    --color-success: #4ade80;
    --color-success-soft: rgba(74, 222, 128, .1);
    --color-warning: #fbbf24;
    --color-warning-soft: rgba(251, 191, 36, .1);
    --color-danger: #f87171;
    --color-danger-soft: rgba(248, 113, 113, .1);
    --color-info: #60a5fa;
    --color-info-soft: rgba(96, 165, 250, .1);
    --sidebar-bg: #080c12;
    --sidebar-text: #94a3b8;
    --sidebar-accent: #2dd4bf;
  }
}

/* ── Base Reset ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
  font-family: var(--font-body);
  color: var(--color-ink);
  background: var(--color-surface);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
}

/* ── Skip to content (a11y) ────────────────────────────────────────────── */
.ds-skip-link {
  position: absolute;
  top: -100%;
  left: 16px;
  z-index: 9999;
  padding: 8px 16px;
  background: var(--color-accent);
  color: #fff;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  transition: top var(--duration-fast) var(--ease-out);
}
.ds-skip-link:focus {
  top: 16px;
}

/* ── View Transitions ──────────────────────────────────────────────────── */
.ds-view-enter {
  animation: ds-fadeSlideUp var(--duration-normal) var(--ease-out) both;
}

@keyframes ds-fadeSlideUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.ds-fade-in {
  animation: ds-fadeIn var(--duration-normal) ease-out both;
}

@keyframes ds-fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.ds-slide-in-right {
  animation: ds-slideRight var(--duration-normal) var(--ease-out) both;
}

@keyframes ds-slideRight {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ── Card Hover Elevation ──────────────────────────────────────────────── */
.ds-card-hover {
  transition: transform var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-fast) var(--ease-out);
}
.ds-card-hover:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

/* ── Skeleton Loading ──────────────────────────────────────────────────── */
.ds-skeleton {
  background: linear-gradient(90deg,
    var(--color-border-subtle) 25%,
    var(--color-border) 50%,
    var(--color-border-subtle) 75%);
  background-size: 200% 100%;
  animation: ds-shimmer 1.5s infinite ease-in-out;
  border-radius: var(--radius-sm);
}
.ds-skeleton-text {
  height: 14px;
  margin-bottom: 8px;
  width: 80%;
}
.ds-skeleton-text:last-child { width: 60%; }
.ds-skeleton-heading {
  height: 24px;
  width: 50%;
  margin-bottom: 12px;
}
.ds-skeleton-card {
  height: 100px;
  border-radius: var(--radius-lg);
}
.ds-skeleton-avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
}

@keyframes ds-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Top Progress Bar ──────────────────────────────────────────────────── */
.ds-progress-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--progress-height);
  z-index: 9998;
  background: transparent;
  pointer-events: none;
}
.ds-progress-bar-inner {
  height: 100%;
  background: linear-gradient(90deg, var(--color-accent), var(--color-info));
  border-radius: 0 var(--radius-full) var(--radius-full) 0;
  animation: ds-progressIndeterminate 1.8s ease-in-out infinite;
  transform-origin: left;
}
@keyframes ds-progressIndeterminate {
  0%   { transform: scaleX(0); translate: 0; }
  40%  { transform: scaleX(.4); translate: 20%; }
  100% { transform: scaleX(0); translate: 100%; }
}

/* ── Tables ────────────────────────────────────────────────────────────── */
.ds-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-variant-numeric: tabular-nums;
}
.ds-table thead th {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--color-surface-elevated);
  border-bottom: 1px solid var(--color-border);
  padding: 10px 12px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--color-ink-muted);
  white-space: nowrap;
  user-select: none;
}
.ds-table thead th.ds-sortable {
  cursor: pointer;
}
.ds-table thead th.ds-sortable:hover {
  color: var(--color-ink);
}
.ds-table tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--color-border-subtle);
  font-size: 13px;
  color: var(--color-ink-secondary);
  vertical-align: middle;
}
.ds-table tbody tr:hover td {
  background: var(--color-accent-soft);
}
.ds-table tbody td.ds-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.ds-table-scroll {
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--color-border) transparent;
}
.ds-table-scroll::-webkit-scrollbar { width: 6px; height: 6px; }
.ds-table-scroll::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: var(--radius-full);
}
.ds-table-scroll::-webkit-scrollbar-track { background: transparent; }

/* Table shadow on scroll */
.ds-table-scroll[data-scrolled] thead th {
  box-shadow: 0 2px 8px rgb(0 0 0/.06);
}

/* ── Toast Container ───────────────────────────────────────────────────── */
.ds-toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 10000;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  pointer-events: none;
  max-width: 400px;
}
.ds-toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 14px 18px;
  border-radius: var(--radius-lg);
  background: var(--color-surface-elevated);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  color: var(--color-ink);
  animation: ds-slideRight var(--duration-normal) var(--ease-out);
  position: relative;
  overflow: hidden;
}
.ds-toast-icon {
  font-size: 16px;
  line-height: 1;
  flex-shrink: 0;
  margin-top: 1px;
}
.ds-toast-body { flex: 1; min-width: 0; }
.ds-toast-title { font-weight: 600; font-size: 13px; }
.ds-toast-message { font-size: 12px; color: var(--color-ink-secondary); margin-top: 2px; }
.ds-toast-close {
  cursor: pointer;
  background: none;
  border: none;
  color: var(--color-ink-muted);
  font-size: 16px;
  padding: 0;
  line-height: 1;
  flex-shrink: 0;
}
.ds-toast-close:hover { color: var(--color-ink); }
.ds-toast-progress {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 3px;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  transform-origin: left;
  animation: ds-toastProgress 4s linear forwards;
}
.ds-toast.ds-toast-success .ds-toast-progress { background: var(--color-success); }
.ds-toast.ds-toast-error   .ds-toast-progress { background: var(--color-danger); }
.ds-toast.ds-toast-warning .ds-toast-progress { background: var(--color-warning); }
.ds-toast.ds-toast-info    .ds-toast-progress { background: var(--color-info); }
.ds-toast-exit {
  animation: ds-toastExit var(--duration-normal) var(--ease-out) forwards;
}
@keyframes ds-toastProgress {
  from { transform: scaleX(1); }
  to   { transform: scaleX(0); }
}
@keyframes ds-toastExit {
  to { opacity: 0; transform: translateX(80px); }
}

/* ── Module Switcher (Cmd+K) ──────────────────────────────────────────── */
.ds-switcher-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0, 0, 0, .5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 15vh;
  animation: ds-fadeIn var(--duration-fast) ease-out;
}
.ds-switcher {
  background: var(--color-surface-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 520px;
  overflow: hidden;
  animation: ds-switcherIn var(--duration-normal) var(--ease-spring);
}
@keyframes ds-switcherIn {
  from { opacity: 0; transform: scale(.96) translateY(-8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.ds-switcher-input {
  width: 100%;
  border: none;
  outline: none;
  padding: 18px 22px;
  font-size: 16px;
  font-family: var(--font-body);
  background: transparent;
  color: var(--color-ink);
  border-bottom: 1px solid var(--color-border);
}
.ds-switcher-input::placeholder {
  color: var(--color-ink-muted);
}
.ds-switcher-list {
  max-height: 340px;
  overflow-y: auto;
  padding: 8px;
}
.ds-switcher-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--duration-fast);
  text-decoration: none;
  color: var(--color-ink);
}
.ds-switcher-item:hover,
.ds-switcher-item.ds-active {
  background: var(--color-accent-soft);
}
.ds-switcher-item-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.ds-switcher-item-label {
  font-size: 14px;
  font-weight: 500;
}
.ds-switcher-item-desc {
  font-size: 11px;
  color: var(--color-ink-muted);
  margin-top: 1px;
}
.ds-switcher-footer {
  padding: 10px 18px;
  border-top: 1px solid var(--color-border);
  font-size: 11px;
  color: var(--color-ink-muted);
  display: flex;
  gap: 16px;
}
.ds-switcher-footer kbd {
  display: inline-flex;
  align-items: center;
  padding: 1px 5px;
  background: var(--color-surface-sunken);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-size: 10px;
  font-family: var(--font-body);
}

/* ── Empty State ───────────────────────────────────────────────────────── */
.ds-empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--color-ink-muted);
}
.ds-empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: .4;
}
.ds-empty-title {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  color: var(--color-ink-secondary);
  margin-bottom: 6px;
}
.ds-empty-desc {
  font-size: 13px;
  max-width: 320px;
  margin: 0 auto 16px;
  line-height: 1.5;
}
.ds-empty-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 20px;
  border-radius: var(--radius-full);
  background: var(--color-accent);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: background var(--duration-fast);
}
.ds-empty-action:hover { background: var(--color-accent-hover); }

/* ── Dark mode toggle button ───────────────────────────────────────────── */
.ds-theme-toggle {
  cursor: pointer;
  background: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: var(--color-ink-secondary);
  transition: background var(--duration-fast), color var(--duration-fast);
}
.ds-theme-toggle:hover {
  background: var(--color-accent-soft);
  color: var(--color-ink);
}

/* ── Filter Chips ──────────────────────────────────────────────────────── */
.ds-filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: var(--radius-full);
  background: var(--color-accent-soft);
  color: var(--color-accent);
  font-size: 12px;
  font-weight: 500;
}
.ds-filter-chip-remove {
  cursor: pointer;
  background: none;
  border: none;
  color: inherit;
  font-size: 14px;
  padding: 0;
  line-height: 1;
  opacity: .6;
}
.ds-filter-chip-remove:hover { opacity: 1; }

/* ── Result Counter ────────────────────────────────────────────────────── */
.ds-result-count {
  font-size: 12px;
  color: var(--color-ink-muted);
  font-variant-numeric: tabular-nums;
}

/* ── Reduced Motion ────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── Print ─────────────────────────────────────────────────────────────── */
@media print {
  .ds-toast-container,
  .ds-switcher-overlay,
  .ds-progress-bar,
  .ds-theme-toggle,
  .ds-skip-link,
  nav, aside { display: none !important; }

  body {
    background: #fff !important;
    color: #000 !important;
  }
}

/* ── Custom Scrollbars ─────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-track { background: transparent; }
html { scrollbar-width: thin; scrollbar-color: var(--color-border) transparent; }
