/* ============================================================
   DIABEETS — EXTENDED DESIGN SYSTEM v3.0
   Production-grade component library
   Extends theme.css — always load theme.css first
   ============================================================ */


/* ╔══════════════════════════════════════════════════════╗
   ║  EXTENDED TOKENS                                      ║
   ╚══════════════════════════════════════════════════════╝ */
:root {
  /* Z-index scale */
  --z-base:       1;
  --z-raised:     10;
  --z-dropdown:   200;
  --z-sticky:     400;
  --z-overlay:    600;
  --z-modal:      800;
  --z-toast:      1000;
  --z-progress:   2000;

  /* Focus ring */
  --focus-ring: 0 0 0 3px rgba(0, 212, 255, 0.45);

  /* Border radius scale */
  --radius-sm:    6px;
  --radius-md:    10px;
  --radius-lg:    16px;
  --radius-xl:    20px;
  --radius-2xl:   28px;
  --radius-full:  9999px;

  /* Spacing scale */
  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-5:  20px;
  --space-6:  24px;
  --space-8:  32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;
  --space-20: 80px;

  /* Skeleton shimmer */
  --skeleton-base:  rgba(255,255,255,0.05);
  --skeleton-shine: rgba(255,255,255,0.10);

  /* Status colours */
  --color-success:      #00E5A0;
  --color-success-dim:  rgba(0,229,160,0.12);
  --color-warning:      #FBBF24;
  --color-warning-dim:  rgba(251,191,36,0.12);
  --color-error:        #FF5C7C;
  --color-error-dim:    rgba(255,92,124,0.12);
  --color-info:         #00D4FF;
  --color-info-dim:     rgba(0,212,255,0.12);
}


/* ╔══════════════════════════════════════════════════════╗
   ║  ACCESSIBILITY                                        ║
   ╚══════════════════════════════════════════════════════╝ */

/* Skip link — first focusable element on every page */
.skip-link {
  position: fixed;
  top: -100%;
  left: 16px;
  z-index: var(--z-progress);
  padding: 8px 16px;
  background: var(--accent-blue);
  color: #000;
  font-size: 14px;
  font-weight: 700;
  border-radius: var(--radius-md);
  transition: top .2s ease;
  text-decoration: none;
}
.skip-link:focus { top: 16px; }

/* Visible focus rings for keyboard users */
*:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}

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

/* Respect prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}


/* ╔══════════════════════════════════════════════════════╗
   ║  SKELETON LOADERS                                     ║
   ╚══════════════════════════════════════════════════════╝ */

@keyframes skeletonPulse {
  0%   { background-position: -200% center; }
  100% { background-position:  200% center; }
}

.skeleton {
  background: linear-gradient(
    90deg,
    var(--skeleton-base) 0%,
    var(--skeleton-shine) 50%,
    var(--skeleton-base) 100%
  );
  background-size: 200% 100%;
  animation: skeletonPulse 1.6s ease infinite;
  border-radius: var(--radius-md);
  display: block;
}

.skeleton-text   { height: 16px; width: 100%; margin-bottom: 8px; }
.skeleton-text.w-3q { width: 75%; }
.skeleton-text.w-half { width: 50%; }
.skeleton-text.w-third { width: 33%; }
.skeleton-title  { height: 24px; width: 80%; margin-bottom: 12px; }
.skeleton-h1     { height: 40px; width: 70%; margin-bottom: 16px; }
.skeleton-badge  { height: 24px; width: 100px; border-radius: var(--radius-full); }
.skeleton-btn    { height: 44px; width: 140px; }
.skeleton-avatar { width: 48px; height: 48px; border-radius: 50%; flex-shrink: 0; }
.skeleton-img    { width: 100%; aspect-ratio: 16/9; border-radius: var(--radius-lg); }

/* Full article-card skeleton */
.skeleton-card {
  background: var(--gradient-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-xl);
  overflow: hidden;
  padding: 24px;
}
.skeleton-card-accent {
  height: 4px;
  margin: -24px -24px 24px;
  background: linear-gradient(
    90deg, var(--skeleton-base) 0%,
    var(--skeleton-shine) 50%,
    var(--skeleton-base) 100%
  );
  background-size: 200% 100%;
  animation: skeletonPulse 1.6s ease infinite;
}


/* ╔══════════════════════════════════════════════════════╗
   ║  BADGE                                                ║
   ╚══════════════════════════════════════════════════════╝ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  white-space: nowrap;
  line-height: 1;
}

.badge-blue   { background: var(--color-info-dim);    color: var(--color-info);    border: 1px solid rgba(0,212,255,0.25); }
.badge-green  { background: var(--color-success-dim); color: var(--color-success); border: 1px solid rgba(0,229,160,0.25); }
.badge-red    { background: var(--color-error-dim);   color: var(--color-error);   border: 1px solid rgba(255,92,124,0.25); }
.badge-amber  { background: var(--color-warning-dim); color: var(--color-warning); border: 1px solid rgba(251,191,36,0.25); }
.badge-purple { background: rgba(168,85,247,0.12);    color: var(--accent-purple); border: 1px solid rgba(168,85,247,0.25); }
.badge-gray   { background: rgba(255,255,255,0.06);   color: var(--text-secondary);border: 1px solid var(--border-light); }

.badge-dot::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}


/* ╔══════════════════════════════════════════════════════╗
   ║  ALERT / CALLOUT BANNER                              ║
   ╚══════════════════════════════════════════════════════╝ */

.alert {
  display: flex;
  gap: 16px;
  padding: 16px 20px;
  border-radius: var(--radius-lg);
  border: 1px solid;
  font-size: 14px;
  line-height: 1.6;
}
.alert-icon  { font-size: 18px; flex-shrink: 0; margin-top: 1px; }
.alert-body  { flex: 1; }
.alert-title { font-weight: 700; font-size: 14px; margin-bottom: 4px; }
.alert-close {
  background: none; border: none; cursor: pointer;
  color: currentColor; opacity: .6; font-size: 18px;
  padding: 0; flex-shrink: 0; line-height: 1;
  transition: opacity .2s;
}
.alert-close:hover { opacity: 1; }
.alert-info    { background: var(--color-info-dim);    border-color: rgba(0,212,255,0.3);  color: var(--color-info);    }
.alert-success { background: var(--color-success-dim); border-color: rgba(0,229,160,0.3);  color: var(--color-success); }
.alert-warning { background: var(--color-warning-dim); border-color: rgba(251,191,36,0.3); color: var(--color-warning); }
.alert-error   { background: var(--color-error-dim);   border-color: rgba(255,92,124,0.3); color: var(--color-error);   }
.alert p, .alert a { color: inherit; }


/* ╔══════════════════════════════════════════════════════╗
   ║  TOAST SYSTEM                                         ║
   ╚══════════════════════════════════════════════════════╝ */

.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: none;
  max-width: 380px;
  width: calc(100vw - 48px);
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px 20px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-medium);
  background: var(--surface-3);
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow-lg);
  pointer-events: all;
  animation: toastIn .4s var(--transition-bounce) both;
  position: relative;
  overflow: hidden;
}
.toast.toast-exit { animation: toastOut .3s ease forwards; }

@keyframes toastIn  {
  from { opacity: 0; transform: translateX(100%) scale(.92); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}
@keyframes toastOut {
  to   { opacity: 0; transform: translateX(110%) scale(.9); height: 0; padding: 0; margin: 0; }
}

.toast-progress {
  position: absolute;
  bottom: 0; left: 0;
  height: 2px;
  background: currentColor;
  opacity: .4;
  animation: toastProgress linear both;
}
@keyframes toastProgress { from { width: 100%; } to { width: 0; } }

.toast-icon  { font-size: 18px; flex-shrink: 0; margin-top: 1px; }
.toast-body  { flex: 1; min-width: 0; }
.toast-title { font-size: 14px; font-weight: 700; margin-bottom: 2px; color: var(--white); }
.toast-msg   { font-size: 13px; color: var(--text-secondary); }
.toast-close {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 16px;
  padding: 0; flex-shrink: 0; line-height: 1;
  transition: color .2s;
}
.toast-close:hover { color: var(--white); }
.toast-success { border-color: rgba(0,229,160,0.3);  color: var(--color-success); }
.toast-error   { border-color: rgba(255,92,124,0.3); color: var(--color-error);   }
.toast-warning { border-color: rgba(251,191,36,0.3); color: var(--color-warning); }
.toast-info    { border-color: rgba(0,212,255,0.3);  color: var(--color-info);    }


/* ╔══════════════════════════════════════════════════════╗
   ║  MODAL / DIALOG                                       ║
   ╚══════════════════════════════════════════════════════╝ */

.modal-backdrop {
  position: fixed; inset: 0; z-index: var(--z-overlay);
  background: rgba(7,11,20,0.82);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  opacity: 0; pointer-events: none;
  transition: opacity .25s ease;
}
.modal-backdrop.open { opacity: 1; pointer-events: all; }

.modal {
  background: var(--surface-elevation);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-lg), 0 0 80px rgba(0,0,0,.6);
  width: 100%; max-width: 560px; max-height: 90vh;
  overflow-y: auto;
  transform: scale(.95) translateY(16px);
  transition: transform .3s var(--transition-bounce);
  position: relative;
}
.modal-backdrop.open .modal { transform: scale(1) translateY(0); }
.modal-lg { max-width: 800px; }
.modal-sm { max-width: 400px; }

.modal-header {
  display: flex; align-items: flex-start; gap: 16px;
  padding: 24px 24px 20px;
  border-bottom: 1px solid var(--border-light);
}
.modal-title    { font-size: 18px; font-weight: 700; color: var(--white); flex: 1; }
.modal-subtitle { font-size: 14px; color: var(--text-muted); margin-top: 4px; }
.modal-close {
  background: rgba(255,255,255,0.06); border: 1px solid var(--border-light);
  border-radius: var(--radius-md); width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; cursor: pointer; color: var(--text-muted);
  transition: all .2s ease; flex-shrink: 0;
}
.modal-close:hover { background: rgba(255,255,255,0.1); color: var(--white); }

.modal-body   { padding: 24px; }
.modal-footer {
  padding: 20px 24px;
  border-top: 1px solid var(--border-light);
  display: flex; justify-content: flex-end; gap: 12px;
}
.modal::-webkit-scrollbar       { width: 4px; }
.modal::-webkit-scrollbar-track { background: transparent; }
.modal::-webkit-scrollbar-thumb { background: var(--border-medium); border-radius: 4px; }


/* ╔══════════════════════════════════════════════════════╗
   ║  TABS                                                 ║
   ╚══════════════════════════════════════════════════════╝ */

.tabs { display: flex; flex-direction: column; }
.tabs-list {
  display: flex; gap: 4px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 4px; width: fit-content; flex-wrap: wrap;
}
.tab-btn {
  padding: 8px 18px;
  border-radius: var(--radius-md);
  font-size: 14px; font-weight: 600;
  color: var(--text-secondary);
  background: none; border: none;
  cursor: pointer; transition: all .2s ease;
  white-space: nowrap; font-family: inherit;
}
.tab-btn:hover { color: var(--white); background: rgba(255,255,255,0.06); }
.tab-btn[aria-selected="true"] {
  background: var(--surface-3); color: var(--white);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-medium);
}
.tab-btn[aria-selected="true"].tab-accent {
  background: var(--accent-blue-dim); color: var(--accent-blue); border-color: var(--border-accent);
}

/* Underline variant */
.tabs-underline .tabs-list {
  background: none; border: none;
  border-bottom: 1px solid var(--border-light);
  border-radius: 0; padding: 0; gap: 0; width: 100%;
}
.tabs-underline .tab-btn { border-radius: 0; padding: 12px 20px; position: relative; background: none; border: none; box-shadow: none; }
.tabs-underline .tab-btn[aria-selected="true"] { color: var(--accent-blue); background: none; border: none; box-shadow: none; }
.tabs-underline .tab-btn[aria-selected="true"]::after {
  content: ''; position: absolute; bottom: -1px; left: 0; right: 0;
  height: 2px; background: var(--accent-blue); border-radius: 2px 2px 0 0;
}

.tab-panel        { display: none; padding-top: 24px; }
.tab-panel.active { display: block; }
.tab-panel:focus  { outline: none; }


/* ╔══════════════════════════════════════════════════════╗
   ║  PAGINATION                                           ║
   ╚══════════════════════════════════════════════════════╝ */

.pagination {
  display: flex; align-items: center; gap: 8px;
  flex-wrap: wrap; justify-content: center;
  padding: 32px 0 16px;
}
.page-btn {
  min-width: 40px; height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0 8px;
  border: 1px solid var(--border-light); border-radius: var(--radius-md);
  background: transparent; color: var(--text-secondary);
  font-size: 14px; font-weight: 600; cursor: pointer;
  text-decoration: none; transition: all .2s ease; font-family: inherit;
}
.page-btn:hover:not(:disabled) { border-color: var(--border-accent); color: var(--accent-blue); background: var(--accent-blue-dim); }
.page-btn.active { background: var(--accent-blue-dim); border-color: var(--border-accent); color: var(--accent-blue); }
.page-btn:disabled { opacity: .35; cursor: not-allowed; }
.page-btn.page-prev,
.page-btn.page-next { padding: 0 16px; gap: 8px; }
.page-ellipsis { color: var(--text-muted); padding: 0 8px; line-height: 40px; }


/* ╔══════════════════════════════════════════════════════╗
   ║  TOOLTIP                                              ║
   ╚══════════════════════════════════════════════════════╝ */

[data-tooltip] { position: relative; }
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px); left: 50%;
  transform: translateX(-50%) translateY(4px);
  background: var(--surface-3); border: 1px solid var(--border-medium);
  color: var(--white); font-size: 12px; font-weight: 600;
  white-space: nowrap; padding: 6px 10px;
  border-radius: var(--radius-md); box-shadow: var(--shadow-md);
  pointer-events: none; opacity: 0;
  transition: opacity .2s ease, transform .2s ease;
  z-index: var(--z-dropdown);
}
[data-tooltip]:hover::after { opacity: 1; transform: translateX(-50%) translateY(0); }


/* ╔══════════════════════════════════════════════════════╗
   ║  FORMS                                                ║
   ╚══════════════════════════════════════════════════════╝ */

.form-group   { display: flex; flex-direction: column; gap: 8px; }
.form-label   { font-size: 13px; font-weight: 700; color: var(--text-secondary); letter-spacing: .04em; text-transform: uppercase; }
.form-label .required { color: var(--color-error); margin-left: 3px; }

.form-input,
.form-textarea,
.form-select {
  width: 100%;
  background: var(--surface-elevation);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-lg);
  padding: 13px 16px;
  font-size: 15px; color: var(--white); font-family: inherit;
  outline: none; transition: all .25s ease;
  appearance: none; line-height: 1.5;
}
.form-input::placeholder,
.form-textarea::placeholder { color: var(--text-muted); }
.form-input:focus,
.form-textarea:focus,
.form-select:focus {
  border-color: var(--accent-blue);
  background: var(--surface-2);
  box-shadow: 0 0 0 3px var(--accent-blue-dim);
}
.form-input:disabled,
.form-textarea:disabled,
.form-select:disabled { opacity: .45; cursor: not-allowed; }

.form-group.is-valid   .form-input,
.form-group.is-valid   .form-textarea { border-color: var(--color-success); }
.form-group.is-invalid .form-input,
.form-group.is-invalid .form-textarea { border-color: var(--color-error); box-shadow: 0 0 0 3px var(--color-error-dim); }

.form-hint  { font-size: 12px; color: var(--text-muted); }
.form-error { font-size: 12px; color: var(--color-error); display: none; }
.form-group.is-invalid .form-error { display: block; }
.form-group.is-valid   .form-hint  { color: var(--color-success); }

.form-textarea    { min-height: 120px; resize: vertical; }

/* Select with custom arrow */
.form-select-wrap { position: relative; }
.form-select-wrap::after {
  content: '▾'; position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); pointer-events: none; font-size: 12px;
}
.form-select { padding-right: 36px; cursor: pointer; }
.form-select option { background: var(--surface-3); color: var(--white); }

/* Checkbox & Radio */
.form-check { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.form-check input[type="checkbox"],
.form-check input[type="radio"] {
  appearance: none; width: 18px; height: 18px; flex-shrink: 0;
  background: var(--surface-elevation); border: 1px solid var(--border-medium);
  border-radius: var(--radius-sm); cursor: pointer;
  transition: all .2s ease; position: relative;
}
.form-check input[type="radio"] { border-radius: 50%; }
.form-check input[type="checkbox"]:checked,
.form-check input[type="radio"]:checked { background: var(--accent-blue); border-color: var(--accent-blue); }
.form-check input[type="checkbox"]:checked::after {
  content: '✓'; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  color: #000; font-size: 11px; font-weight: 900; line-height: 1;
}
.form-check input[type="radio"]:checked::after {
  content: ''; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 8px; height: 8px; background: #000; border-radius: 50%;
}
.form-check-label { font-size: 14px; color: var(--text-secondary); user-select: none; }

/* Input with icon */
.input-icon-wrap { position: relative; }
.input-icon-wrap .form-input { padding-left: 46px; }
.input-icon-wrap .input-icon {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  font-size: 18px; color: var(--text-muted); pointer-events: none;
}
.input-icon-wrap .input-action {
  position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--text-muted); font-size: 16px;
  cursor: pointer; padding: 4px; transition: color .2s;
}
.input-icon-wrap .input-action:hover { color: var(--white); }


/* ╔══════════════════════════════════════════════════════╗
   ║  DROPDOWN MENU                                        ║
   ╚══════════════════════════════════════════════════════╝ */

.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
  position: absolute; top: calc(100% + 8px); right: 0;
  min-width: 200px; background: var(--surface-3);
  border: 1px solid var(--border-medium); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); padding: 8px;
  z-index: var(--z-dropdown); opacity: 0; pointer-events: none;
  transform: translateY(-8px) scale(.97); transform-origin: top right;
  transition: all .2s var(--transition-smooth);
}
.dropdown-menu.open { opacity: 1; pointer-events: all; transform: translateY(0) scale(1); }
.dropdown-item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 10px 12px; border-radius: var(--radius-md);
  font-size: 14px; color: var(--text-secondary);
  text-decoration: none; cursor: pointer;
  background: none; border: none; font-family: inherit;
  transition: all .15s ease; text-align: left;
}
.dropdown-item:hover  { background: rgba(255,255,255,0.06); color: var(--white); }
.dropdown-item.active { color: var(--accent-blue); background: var(--accent-blue-dim); }
.dropdown-item.danger { color: var(--color-error); }
.dropdown-item.danger:hover { background: var(--color-error-dim); }
.dropdown-divider  { height: 1px; background: var(--border-light); margin: 8px 0; }
.dropdown-header   { padding: 8px 12px 4px; font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted); }


/* ╔══════════════════════════════════════════════════════╗
   ║  EMPTY STATE                                          ║
   ╚══════════════════════════════════════════════════════╝ */

.empty-state {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 64px 32px; text-align: center;
}
.empty-state-icon  { font-size: 56px; margin-bottom: 20px; filter: grayscale(.4); opacity: .7; }
.empty-state-title { font-size: 20px; font-weight: 700; color: var(--white); margin-bottom: 12px; }
.empty-state-body  { font-size: 15px; color: var(--text-muted); max-width: 380px; line-height: 1.7; margin-bottom: 24px; }
.empty-state-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }

/* In-card variant */
.empty-card {
  background: var(--gradient-card);
  border: 1px dashed var(--border-medium);
  border-radius: var(--radius-xl);
  padding: 64px 32px;
}


/* ╔══════════════════════════════════════════════════════╗
   ║  SPINNER / LOADING                                    ║
   ╚══════════════════════════════════════════════════════╝ */

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

.spinner {
  display: inline-block;
  width: 24px; height: 24px;
  border: 2.5px solid var(--border-medium);
  border-top-color: var(--accent-blue);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}
.spinner-sm { width: 16px; height: 16px; border-width: 2px; }
.spinner-lg { width: 40px; height: 40px; border-width: 3px; }

.loading-overlay {
  position: absolute; inset: 0; z-index: var(--z-raised);
  background: rgba(7,11,20,0.6); backdrop-filter: blur(4px);
  border-radius: inherit;
  display: flex; align-items: center; justify-content: center;
  gap: 12px; font-size: 14px; color: var(--text-muted);
}


/* ╔══════════════════════════════════════════════════════╗
   ║  DATA TABLE                                           ║
   ╚══════════════════════════════════════════════════════╝ */

.table-wrap {
  background: var(--gradient-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-xl);
  overflow: hidden;
}
.table-scroll { overflow-x: auto; }
.table-scroll::-webkit-scrollbar       { height: 4px; }
.table-scroll::-webkit-scrollbar-track { background: transparent; }
.table-scroll::-webkit-scrollbar-thumb { background: var(--border-medium); border-radius: 4px; }

table { width: 100%; border-collapse: collapse; }
thead { background: rgba(255,255,255,0.03); border-bottom: 1px solid var(--border-light); }
th {
  padding: 14px 20px; font-size: 12px; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-muted); text-align: left; white-space: nowrap;
}
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover   { color: var(--white); }
th.sorted-asc::after  { content: ' ↑'; color: var(--accent-blue); }
th.sorted-desc::after { content: ' ↓'; color: var(--accent-blue); }
td {
  padding: 16px 20px; font-size: 14px; color: var(--text-secondary);
  border-bottom: 1px solid var(--border-light); vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tbody tr { transition: background .15s ease; }
tbody tr:hover { background: rgba(255,255,255,0.03); }


/* ╔══════════════════════════════════════════════════════╗
   ║  CARD VARIANTS                                        ║
   ╚══════════════════════════════════════════════════════╝ */

/* Metric / stat card */
.metric-card {
  background: var(--gradient-card); border: 1px solid var(--border-light);
  border-radius: var(--radius-xl); padding: 24px;
  display: flex; flex-direction: column; gap: 8px;
  transition: all .3s var(--transition-smooth);
}
.metric-card:hover { border-color: var(--border-accent); transform: translateY(-4px); box-shadow: var(--shadow-glow-blue); }
.metric-label  { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted); }
.metric-value  { font-size: 40px; font-weight: 900; letter-spacing: -.04em; line-height: 1; color: var(--white); }
.metric-delta  { font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 4px; }
.metric-delta.up   { color: var(--color-success); }
.metric-delta.down { color: var(--color-error);   }
.metric-sub    { font-size: 13px; color: var(--text-muted); }

/* Feature card */
.feature-card {
  background: var(--gradient-card); border: 1px solid var(--border-light);
  border-radius: var(--radius-xl); padding: 24px;
  transition: all .3s var(--transition-smooth);
}
.feature-card:hover { border-color: var(--border-accent); transform: translateY(-6px); box-shadow: var(--shadow-md), var(--shadow-glow-blue); }
.feature-card-icon  { width: 52px; height: 52px; border-radius: var(--radius-lg); display: flex; align-items: center; justify-content: center; font-size: 24px; margin-bottom: 16px; }
.feature-card h3    { font-size: 18px; font-weight: 700; color: var(--white); margin-bottom: 8px; }
.feature-card p     { font-size: 14px; color: var(--text-muted); line-height: 1.6; }

/* List card */
.list-card { background: var(--gradient-card); border: 1px solid var(--border-light); border-radius: var(--radius-xl); overflow: hidden; }
.list-card-header { padding: 20px 24px; border-bottom: 1px solid var(--border-light); font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted); }
.list-card-item {
  display: flex; align-items: center; gap: 16px;
  padding: 16px 24px; border-bottom: 1px solid var(--border-light);
  text-decoration: none; transition: background .15s ease;
}
.list-card-item:last-child { border-bottom: none; }
.list-card-item:hover { background: rgba(255,255,255,0.03); }
.list-card-item-title { font-size: 14px; font-weight: 600; color: var(--white); flex: 1; }
.list-card-item-meta  { font-size: 12px; color: var(--text-muted); }


/* ╔══════════════════════════════════════════════════════╗
   ║  TABLE OF CONTENTS (Article sidebar)                 ║
   ╚══════════════════════════════════════════════════════╝ */

.toc-card {
  background: var(--gradient-card); border: 1px solid var(--border-light);
  border-radius: var(--radius-xl); padding: 24px;
  position: sticky; top: 90px;
}
.toc-title {
  font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: var(--text-muted); margin-bottom: 16px;
  padding-bottom: 12px; border-bottom: 1px solid var(--border-light);
}
.toc-list  { list-style: none; display: flex; flex-direction: column; gap: 2px; }
.toc-link  {
  display: block; font-size: 13px; color: var(--text-muted);
  text-decoration: none; padding: 6px 10px;
  border-radius: var(--radius-md); border-left: 2px solid transparent;
  transition: all .2s ease; line-height: 1.5;
}
.toc-link:hover { color: var(--white); background: rgba(255,255,255,0.04); }
.toc-link.active { color: var(--accent-blue); border-color: var(--accent-blue); background: var(--accent-blue-dim); }
.toc-link.toc-h3 { padding-left: 22px; font-size: 12px; }


/* ╔══════════════════════════════════════════════════════╗
   ║  SEARCH DROPDOWN                                      ║
   ╚══════════════════════════════════════════════════════╝ */

.search-results-dropdown {
  position: absolute; top: calc(100% + 8px); left: 0; right: 0;
  background: var(--surface-3); border: 1px solid var(--border-medium);
  border-radius: var(--radius-xl); box-shadow: var(--shadow-lg);
  max-height: 440px; overflow-y: auto;
  z-index: var(--z-dropdown); display: none;
}
.search-results-dropdown.open { display: block; }
.search-result-group-label    { padding: 12px 20px 8px; font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted); }
.search-result-item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 20px; text-decoration: none;
  transition: background .15s ease; cursor: pointer;
}
.search-result-item:hover,
.search-result-item.highlighted { background: rgba(255,255,255,0.05); }
.search-result-icon  { font-size: 18px; flex-shrink: 0; margin-top: 2px; }
.search-result-title { font-size: 14px; font-weight: 600; color: var(--white); line-height: 1.4; }
.search-result-meta  { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.search-result-divider { height: 1px; background: var(--border-light); margin: 8px 0; }
.search-empty { padding: 40px 32px; text-align: center; color: var(--text-muted); font-size: 14px; }
.search-empty strong { display: block; font-size: 16px; color: var(--white); margin-bottom: 8px; }
.search-results-dropdown::-webkit-scrollbar       { width: 4px; }
.search-results-dropdown::-webkit-scrollbar-track { background: transparent; }
.search-results-dropdown::-webkit-scrollbar-thumb { background: var(--border-medium); border-radius: 4px; }


/* ╔══════════════════════════════════════════════════════╗
   ║  CHIP / FILTER PILLS                                  ║
   ╚══════════════════════════════════════════════════════╝ */

.chip-group { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px; border: 1px solid var(--border-light);
  border-radius: var(--radius-full); font-size: 13px; font-weight: 600;
  color: var(--text-secondary); background: transparent;
  cursor: pointer; transition: all .2s ease; font-family: inherit; white-space: nowrap;
}
.chip:hover { border-color: var(--border-medium); color: var(--white); background: rgba(255,255,255,0.05); }
.chip.active { background: var(--accent-blue-dim); border-color: var(--border-accent); color: var(--accent-blue); }
.chip-dismiss {
  width: 16px; height: 16px; border-radius: 50%;
  background: rgba(255,255,255,0.1); display: flex; align-items: center;
  justify-content: center; font-size: 10px; cursor: pointer;
  transition: background .2s; border: none; color: inherit; padding: 0; font-family: inherit;
}
.chip-dismiss:hover { background: rgba(255,255,255,0.2); }


/* ╔══════════════════════════════════════════════════════╗
   ║  CALLOUT / TIP BOX                                    ║
   ╚══════════════════════════════════════════════════════╝ */

.callout {
  display: flex; gap: 16px; padding: 20px 24px;
  border-radius: var(--radius-xl); border-left: 4px solid;
  background: rgba(255,255,255,0.03); margin: 24px 0;
}
.callout-tip     { border-color: var(--accent-blue);   background: var(--color-info-dim); }
.callout-warning { border-color: var(--color-warning); background: var(--color-warning-dim); }
.callout-danger  { border-color: var(--color-error);   background: var(--color-error-dim); }
.callout-success { border-color: var(--color-success); background: var(--color-success-dim); }
.callout-icon    { font-size: 22px; flex-shrink: 0; margin-top: 2px; }
.callout-body h4 { font-size: 15px; font-weight: 700; color: var(--white); margin-bottom: 8px; }
.callout-body p  { font-size: 14px; color: var(--text-secondary); margin: 0; line-height: 1.7; }


/* ╔══════════════════════════════════════════════════════╗
   ║  AVATAR                                               ║
   ╚══════════════════════════════════════════════════════╝ */

.avatar {
  border-radius: 50%; object-fit: cover; flex-shrink: 0;
  background: var(--surface-3); border: 2px solid var(--border-medium);
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-weight: 700;
}
.avatar-sm { width: 32px; height: 32px; font-size: 13px; }
.avatar-md { width: 48px; height: 48px; font-size: 18px; }
.avatar-lg { width: 64px; height: 64px; font-size: 24px; }

.author-block {
  display: flex; align-items: center; gap: 16px;
  padding: 20px 24px; background: var(--gradient-card);
  border: 1px solid var(--border-light); border-radius: var(--radius-xl);
}
.author-name { font-size: 15px; font-weight: 700; color: var(--white); }
.author-role { font-size: 13px; color: var(--text-muted); margin-top: 2px; }


/* ╔══════════════════════════════════════════════════════╗
   ║  KBD / KEYBOARD HINT                                  ║
   ╚══════════════════════════════════════════════════════╝ */

.kbd {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 24px; height: 24px; padding: 0 6px;
  background: var(--surface-3); border: 1px solid var(--border-medium);
  border-bottom-width: 2px; border-radius: var(--radius-sm);
  font-size: 11px; font-weight: 700; color: var(--text-muted);
  font-family: 'SF Mono', 'Fira Code', monospace; letter-spacing: .02em;
}


/* ╔══════════════════════════════════════════════════════╗
   ║  READING PROGRESS                                     ║
   ╚══════════════════════════════════════════════════════╝ */

.reading-progress { height: 3px; background: var(--border-light); border-radius: var(--radius-full); overflow: hidden; }
.reading-progress-fill { height: 100%; background: var(--gradient-brand); border-radius: var(--radius-full); transition: width .3s ease; }


/* ╔══════════════════════════════════════════════════════╗
   ║  CODE BLOCK                                           ║
   ╚══════════════════════════════════════════════════════╝ */

.code-block {
  background: var(--surface-2); border: 1px solid var(--border-light);
  border-radius: var(--radius-lg); padding: 16px 20px;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 14px; color: var(--accent-green); overflow-x: auto; line-height: 1.7;
}


/* ╔══════════════════════════════════════════════════════╗
   ║  UTILITY CLASSES                                      ║
   ╚══════════════════════════════════════════════════════╝ */

.divider { height: 1px; background: var(--border-light); margin: 24px 0; }
.divider-label {
  display: flex; align-items: center; gap: 16px;
  font-size: 12px; font-weight: 700; color: var(--text-muted); letter-spacing: .08em; text-transform: uppercase;
}
.divider-label::before, .divider-label::after { content: ''; flex: 1; height: 1px; background: var(--border-light); }

/* Text */
.text-white     { color: var(--white) !important; }
.text-muted     { color: var(--text-muted) !important; }
.text-secondary { color: var(--text-secondary) !important; }
.text-blue      { color: var(--accent-blue) !important; }
.text-green     { color: var(--accent-green) !important; }
.text-red       { color: var(--accent-red) !important; }
.text-purple    { color: var(--accent-purple) !important; }
.text-amber     { color: var(--accent-amber) !important; }
.text-sm        { font-size: 13px; }
.text-xs        { font-size: 11px; }
.text-lg        { font-size: 18px; }
.font-bold      { font-weight: 700; }
.font-heavy     { font-weight: 900; }
.text-center    { text-align: center; }
.uppercase      { text-transform: uppercase; letter-spacing: .08em; }
.truncate       { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Layout */
.w-full  { width: 100%; }
.h-full  { height: 100%; }
.overflow-hidden { overflow: hidden; }
.cursor-pointer { cursor: pointer; }
.opacity-50     { opacity: .5; }
.opacity-75     { opacity: .75; }

/* Rounded */
.rounded-full { border-radius: var(--radius-full) !important; }
.rounded-xl   { border-radius: var(--radius-xl) !important; }
.rounded-lg   { border-radius: var(--radius-lg) !important; }


/* ╔══════════════════════════════════════════════════════╗
   ║  RESPONSIVE                                           ║
   ╚══════════════════════════════════════════════════════╝ */

@media (max-width: 768px) {
  .hide-mobile { display: none !important; }
  .toast-container { bottom: 16px; right: 16px; left: 16px; max-width: 100%; width: auto; }
  .tabs-list { width: 100%; }
  .pagination { gap: 4px; }
  .page-btn   { min-width: 36px; height: 36px; font-size: 13px; }
  .modal { margin: 8px; max-width: calc(100% - 16px); }
  .empty-state { padding: 48px 20px; }
}
@media (min-width: 769px) {
  .hide-desktop { display: none !important; }
}


/* ╔══════════════════════════════════════════════════════╗
   ║  JS-DRIVEN STATES (toggled by scripts)               ║
   ╚══════════════════════════════════════════════════════╝ */

[hidden], .hidden { display: none !important; }
[aria-expanded="false"] + .collapsible { display: none; }
[aria-expanded="true"]  + .collapsible { display: block; }
