/*
 * PCISS Design System v1.0
 * Unified design tokens + component classes for all dashboards.
 * Dark theme default (GitHub-dark based), light theme via data-theme="light".
 */

/* ── Global Setup ─────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--ds-surface-0);
  border-left: 1px solid var(--ds-border);
}
::-webkit-scrollbar-thumb {
  background: var(--ds-border-hover);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--ds-accent);
}

:root {
  /* Surfaces */
  --ds-bg: #0d1117;
  --ds-surface-0: #161b22;
  --ds-surface-1: #1c2128;
  --ds-surface-2: #21262d;

  /* Borders */
  --ds-border: #30363d;
  --ds-border-hover: #484f58;

  /* Text */
  --ds-text: #e6edf3;
  --ds-text-muted: #8b949e;
  --ds-text-dim: #6e7681;  /* WCAG AA compliant (4.5:1 on #0d1117) */

  /* Accent */
  --ds-accent: #58a6ff;
  --ds-accent-hover: #79c0ff;
  --ds-accent-bg: rgba(56, 139, 253, 0.1);

  /* Semantic */
  --ds-success: #3fb950;
  --ds-warning: #d29922;
  --ds-danger: #f85149;
  --ds-info: #79c0ff;

  /* Spacing (4px grid) */
  --ds-space-1: 4px;
  --ds-space-2: 8px;
  --ds-space-3: 12px;
  --ds-space-4: 16px;
  --ds-space-5: 20px;
  --ds-space-6: 24px;
  --ds-space-7: 32px;
  --ds-space-8: 48px;

  /* Radius */
  --ds-radius-sm: 4px;
  --ds-radius-md: 8px;
  --ds-radius-lg: 12px;

  /* Typography */
  --ds-font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --ds-font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;

  /* Font sizes */
  --ds-text-xs: 11px;
  --ds-text-sm: 12px;
  --ds-text-base: 13px;
  --ds-text-md: 14px;
  --ds-text-lg: 16px;
  --ds-text-xl: 20px;
  --ds-text-2xl: 24px;

  /* Transitions */
  --ds-transition: 150ms ease;

  /* Volumetric 3D Tokens (Phase 15) */
  --ds-glass-bg: rgba(13, 17, 23, 0.7);
  --ds-glass-border: rgba(255, 255, 255, 0.08);
  --ds-3d-shadow: 0 16px 32px rgba(0,0,0,0.6), 0 0 0 1px inset rgba(255,255,255,0.05);
  --ds-glow-shadow: 0 0 24px rgba(88,166,255,0.15);
  --ds-depth-blur: blur(12px);
  --ds-hologram-gradient: linear-gradient(145deg, rgba(88,166,255,0.05) 0%, rgba(0,0,0,0) 100%);
}

/* ── F8: Light Theme ───────────────────────────────────────────── */

:root[data-theme="light"] {
  --ds-bg: #ffffff;
  --ds-surface-0: #f6f8fa;
  --ds-surface-1: #eaeef2;
  --ds-surface-2: #d0d7de;

  --ds-border: #d0d7de;
  --ds-border-hover: #afb8c1;

  --ds-text: #1f2328;
  --ds-text-muted: #656d76;
  --ds-text-dim: #afb8c1;

  --ds-accent: #0969da;
  --ds-accent-hover: #0550ae;
  --ds-accent-bg: rgba(9, 105, 218, 0.08);

  --ds-success: #1a7f37;
  --ds-warning: #9a6700;
  --ds-danger: #cf222e;
  --ds-info: #0969da;

  /* Volumetric 3D Tokens (Phase 15) */
  --ds-glass-bg: rgba(255, 255, 255, 0.75);
  --ds-glass-border: rgba(0, 0, 0, 0.1);
  --ds-3d-shadow: 0 12px 24px rgba(0,0,0,0.1), 0 0 0 1px inset rgba(255,255,255,0.6);
  --ds-glow-shadow: 0 0 24px rgba(9,105,218,0.1);
  --ds-depth-blur: blur(16px);
  --ds-hologram-gradient: linear-gradient(145deg, rgba(255,255,255,0.8) 0%, rgba(240,246,252,0.4) 100%);
}

/* ── Component: Card ───────────────────────────────────────────── */

.ds-card {
  background: var(--ds-surface-0);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-md);
  padding: var(--ds-space-4);
}

/* 3D Holo-Glass Utilities (Phase 15/16) */
.ds-glass-panel {
  position: relative;
  overflow: hidden;
  background: var(--ds-glass-bg) !important;
  backdrop-filter: var(--ds-depth-blur);
  -webkit-backdrop-filter: var(--ds-depth-blur);
  border: 1px solid var(--ds-glass-border) !important;
  box-shadow: var(--ds-3d-shadow) !important;
  border-radius: var(--ds-radius-lg);
  background-image: var(--ds-hologram-gradient) !important;
}

.ds-glass-panel::after {
  content: '';
  position: absolute;
  top: -50%; left: -100%; width: 50%; height: 200%;
  background: linear-gradient(90deg, rgba(255,255,255,0) 0%, rgba(255,255,255,0.04) 50%, rgba(255,255,255,0) 100%);
  transform: skewX(-25deg);
  pointer-events: none;
  transition: left 0.7s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  z-index: 1;
}

.ds-glass-panel:hover::after {
  left: 150%;
}

.ds-glass-float {
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.3s;
}
.ds-glass-float:hover {
  transform: translateY(-4px) scale(1.01);
  box-shadow: var(--ds-3d-shadow), var(--ds-glow-shadow) !important;
  z-index: 10;
}

.ds-stat-card {
  background: var(--ds-surface-0);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-md);
  padding: var(--ds-space-4);
  display: flex;
  flex-direction: column;
  gap: var(--ds-space-1);
}

.ds-stat-card .ds-stat-value {
  font-size: var(--ds-text-2xl);
  font-weight: 700;
  font-family: var(--ds-font-mono);
  color: var(--ds-text);
  line-height: 1.2;
}

.ds-stat-card .ds-stat-label {
  font-size: var(--ds-text-xs);
  color: var(--ds-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ── Component: Button ─────────────────────────────────────────── */

.ds-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--ds-space-2);
  padding: var(--ds-space-2) var(--ds-space-3);
  font-size: var(--ds-text-sm);
  font-family: var(--ds-font-sans);
  font-weight: 500;
  border-radius: var(--ds-radius-sm);
  border: 1px solid var(--ds-border);
  background: var(--ds-surface-1);
  color: var(--ds-text);
  cursor: pointer;
  transition: background var(--ds-transition), border-color var(--ds-transition);
  line-height: 1.4;
}

.ds-btn:hover {
  background: var(--ds-surface-2);
  border-color: var(--ds-border-hover);
}

.ds-btn:focus-visible {
  outline: 2px solid var(--ds-accent);
  outline-offset: 2px;
}

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

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

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

.ds-btn-danger:hover {
  background: rgba(248, 81, 73, 0.1);
}

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

.ds-btn-ghost:hover {
  background: var(--ds-surface-1);
  color: var(--ds-text);
}

/* ── Component: Badge ──────────────────────────────────────────── */

.ds-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--ds-space-2);
  font-size: var(--ds-text-xs);
  font-weight: 600;
  border-radius: var(--ds-radius-sm);
  line-height: 1.4;
  background: var(--ds-surface-2);
  color: var(--ds-text-muted);
}

.ds-badge-success {
  background: rgba(63, 185, 80, 0.15);
  color: var(--ds-success);
}

.ds-badge-warning {
  background: rgba(210, 153, 34, 0.15);
  color: var(--ds-warning);
}

.ds-badge-danger {
  background: rgba(248, 81, 73, 0.15);
  color: var(--ds-danger);
}

.ds-badge-info {
  background: var(--ds-accent-bg);
  color: var(--ds-accent);
}

/* ── Component: Table ──────────────────────────────────────────── */

.ds-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--ds-text-sm);
}

.ds-table th {
  text-align: left;
  padding: var(--ds-space-2) var(--ds-space-3);
  font-weight: 600;
  color: var(--ds-text-muted);
  border-bottom: 1px solid var(--ds-border);
  font-size: var(--ds-text-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.ds-table td {
  padding: var(--ds-space-2) var(--ds-space-3);
  border-bottom: 1px solid var(--ds-border);
  color: var(--ds-text);
}

.ds-table tr:hover td {
  background: var(--ds-accent-bg);
}

/* ── Component: Form Controls ──────────────────────────────────── */

.ds-input,
.ds-select {
  padding: var(--ds-space-2) var(--ds-space-3);
  font-size: var(--ds-text-sm);
  font-family: var(--ds-font-sans);
  background: var(--ds-surface-0);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-sm);
  color: var(--ds-text);
  transition: border-color var(--ds-transition);
}

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

.ds-input::placeholder {
  color: var(--ds-text-dim);
}

/* ── Accessibility ─────────────────────────────────────────────── */

.ds-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* ── F10: Skeleton Loading ─────────────────────────────────────── */

@keyframes ds-skeleton-pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.8; }
}

.ds-skeleton {
  background: var(--ds-surface-2);
  border-radius: var(--ds-radius-sm);
  animation: ds-skeleton-pulse 1.5s ease-in-out infinite;
}

.ds-skeleton-text {
  height: 14px;
  margin-bottom: var(--ds-space-2);
  width: 80%;
}

.ds-skeleton-text:last-child {
  width: 60%;
}

.ds-skeleton-card {
  height: 80px;
  border-radius: var(--ds-radius-md);
}

.ds-skeleton-row {
  height: 36px;
  margin-bottom: var(--ds-space-1);
}

/* ── F10: Empty State ──────────────────────────────────────────── */

.ds-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--ds-space-8) var(--ds-space-4);
  text-align: center;
  color: var(--ds-text-muted);
  gap: var(--ds-space-3);
}

.ds-empty-state .ds-empty-icon {
  font-size: 36px;
  opacity: 0.4;
}

.ds-empty-state .ds-empty-title {
  font-size: var(--ds-text-md);
  font-weight: 600;
  color: var(--ds-text);
}

.ds-empty-state .ds-empty-desc {
  font-size: var(--ds-text-sm);
  max-width: 320px;
}

/* ── F10: Error State ──────────────────────────────────────────── */

.ds-error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--ds-space-8) var(--ds-space-4);
  text-align: center;
  gap: var(--ds-space-3);
}

.ds-error-state .ds-error-icon {
  font-size: 36px;
  color: var(--ds-danger);
}

.ds-error-state .ds-error-title {
  font-size: var(--ds-text-md);
  font-weight: 600;
  color: var(--ds-danger);
}

.ds-error-state .ds-error-desc {
  font-size: var(--ds-text-sm);
  color: var(--ds-text-muted);
  max-width: 320px;
}

/* ── F10: Loading Overlay ──────────────────────────────────────── */

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

.ds-loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(13, 17, 23, 0.7);
  z-index: 50;
  border-radius: inherit;
}

:root[data-theme="light"] .ds-loading-overlay {
  background: rgba(255, 255, 255, 0.7);
}

.ds-spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--ds-border);
  border-top-color: var(--ds-accent);
  border-radius: 50%;
  animation: ds-spin 0.6s linear infinite;
}

/* ── F8: Theme Toggle ──────────────────────────────────────────── */

.ds-theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-sm);
  background: transparent;
  color: var(--ds-text-muted);
  cursor: pointer;
  transition: background var(--ds-transition), color var(--ds-transition);
  font-size: 16px;
  padding: 0;
  line-height: 1;
}

.ds-theme-toggle:hover {
  background: var(--ds-surface-1);
  color: var(--ds-text);
}

.ds-theme-toggle:focus-visible {
  outline: 2px solid var(--ds-accent);
  outline-offset: 2px;
}

/* ── SSE Connection Indicator (for F2) ─────────────────────────── */

.ds-connection-indicator {
  display: inline-flex;
  align-items: center;
  gap: var(--ds-space-2);
  font-size: var(--ds-text-xs);
  color: var(--ds-text-muted);
}

.ds-connection-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ds-text-dim);
  transition: background var(--ds-transition);
}

.ds-connection-dot[data-status="connected"] {
  background: var(--ds-success);
}

.ds-connection-dot[data-status="connecting"] {
  background: var(--ds-warning);
  animation: ds-skeleton-pulse 1s ease-in-out infinite;
}

.ds-connection-dot[data-status="disconnected"] {
  background: var(--ds-danger);
}

/* ── 1A: Transition Keyframes ─────────────────────────────────── */

@keyframes ds-fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes ds-slide-right {
  from { transform: translateX(16px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

@keyframes ds-slide-up {
  from { transform: translateY(8px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

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

@keyframes ds-pulse-glow {
  0%, 100% { box-shadow: 0 0 4px var(--ds-accent); }
  50%      { box-shadow: 0 0 12px var(--ds-accent); }
}

/* ── 1B: Animation Utility Classes ────────────────────────────── */

.ds-animate-fade {
  animation: ds-fade-in 200ms ease-out both;
}

.ds-animate-slide {
  animation: ds-slide-up 250ms ease-out both;
}

.ds-animate-scale {
  animation: ds-scale-in 300ms ease-out both;
}

.ds-animate-slide-right {
  animation: ds-slide-right 250ms ease-out both;
}

/* ── 1B.2: Staggered Entry Pipeline ───────────────────────────── */
.ds-stagger {
  animation: ds-slide-up 400ms cubic-bezier(0.16, 1, 0.3, 1) both;
}
.ds-stagger-1 { animation-delay: 50ms; }
.ds-stagger-2 { animation-delay: 100ms; }
.ds-stagger-3 { animation-delay: 150ms; }
.ds-stagger-4 { animation-delay: 200ms; }
.ds-stagger-5 { animation-delay: 250ms; }

/* ── 1C: Disabled States ──────────────────────────────────────── */

.ds-disabled,
.ds-btn:disabled,
.ds-input:disabled,
.ds-select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
  filter: grayscale(30%);
  border-style: dashed;
}

/* ── 1D: Focus Ring (global) ──────────────────────────────────── */

.ds-focusable:focus-visible,
.ds-input:focus-visible,
.ds-select:focus-visible {
  outline: 2px solid var(--ds-accent);
  outline-offset: 2px;
}

/* ── 1E: Responsive Breakpoints ───────────────────────────────── */

@media (max-width: 1024px) {
  :root {
    --ds-space-8: 32px;
  }
}

@media (max-width: 480px) {
  :root {
    --ds-space-7: 24px;
    --ds-space-8: 24px;
    --ds-text-2xl: 20px;
    --ds-text-xl: 18px;
  }
}

@media (max-width: 320px) {
  :root {
    --ds-space-4: 12px;
    --ds-space-6: 16px;
    --ds-space-7: 20px;
    --ds-space-8: 20px;
    --ds-text-2xl: 18px;
    --ds-text-xl: 16px;
    --ds-text-lg: 14px;
  }
}

/* ── 1F: Toast Notification ───────────────────────────────────── */

.ds-toast-container {
  position: fixed;
  bottom: var(--ds-space-4);
  right: var(--ds-space-4);
  z-index: 9999;
  display: flex;
  flex-direction: column-reverse;
  gap: var(--ds-space-2);
  pointer-events: none;
}

.ds-toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: var(--ds-space-3);
  padding: var(--ds-space-3) var(--ds-space-4);
  background: var(--ds-surface-1);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-md);
  font-size: var(--ds-text-sm);
  color: var(--ds-text);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  animation: ds-slide-up 250ms ease-out both;
  max-width: 380px;
}

.ds-toast-success { border-left: 3px solid var(--ds-success); }
.ds-toast-error   { border-left: 3px solid var(--ds-danger); }
.ds-toast-info    { border-left: 3px solid var(--ds-accent); }
.ds-toast-warning { border-left: 3px solid var(--ds-warning); }

.ds-toast-icon {
  font-size: 16px;
  flex-shrink: 0;
}

.ds-toast-close {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--ds-text-muted);
  cursor: pointer;
  padding: var(--ds-space-1);
  font-size: 14px;
  line-height: 1;
}

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

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

.ds-toast-exit {
  animation: ds-toast-out 200ms ease-in forwards;
}

/* ── 1G: Modal/Dialog ─────────────────────────────────────────── */

.ds-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ds-modal {
  background: var(--ds-surface-0);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-lg);
  padding: var(--ds-space-6);
  max-width: 480px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  animation: ds-scale-in 200ms ease-out both;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.ds-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--ds-space-4);
}

.ds-modal-title {
  font-size: var(--ds-text-lg);
  font-weight: 600;
  color: var(--ds-text);
}

.ds-modal-body {
  margin-bottom: var(--ds-space-4);
}

.ds-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--ds-space-2);
  padding-top: var(--ds-space-4);
  border-top: 1px solid var(--ds-border);
}

/* ── 1H: Connection Indicator (enhanced) ──────────────────────── */

.ds-connection-label {
  font-size: var(--ds-text-xs);
  color: var(--ds-text-muted);
}

.ds-connection-label[data-status="connected"] {
  color: var(--ds-success);
}

.ds-connection-label[data-status="connecting"] {
  color: var(--ds-warning);
}

.ds-connection-label[data-status="disconnected"] {
  color: var(--ds-danger);
}

/* ── Inline Spinner (for buttons) ─────────────────────────────── */

.ds-spinner-inline {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: ds-spin 0.6s linear infinite;
  vertical-align: middle;
}

/* ── Form Validation ──────────────────────────────────────────── */

.ds-input[aria-invalid="true"],
.ds-select[aria-invalid="true"] {
  border-color: var(--ds-danger);
}

.ds-input[aria-invalid="true"]:focus,
.ds-select[aria-invalid="true"]:focus {
  box-shadow: 0 0 0 3px rgba(248, 81, 73, 0.15);
}

.ds-field-error {
  font-size: var(--ds-text-xs);
  color: var(--ds-danger);
  margin-top: var(--ds-space-1);
}

/* ── Touch Target (mobile a11y) ───────────────────────────────── */

@media (max-width: 480px) {
  .ds-btn,
  .ds-touch-target {
    min-height: 44px;
    min-width: 44px;
  }
}
