/* ==========================================================================
   M222HP GLORY — Unified 20-Component UI Library
   ========================================================================== */

/* 1. BUTTONS (.m2-btn) */
.m2-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  max-width: 100%;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1.2;
  white-space: normal;
  text-align: center;
  user-select: none;
  transition:
    background-color var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-fast) var(--ease-out),
    transform var(--dur-fast) var(--ease-out);
}

.m2-btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.m2-btn:hover:not(:disabled) {
  background: var(--bg-card-hover);
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.m2-btn:active:not(:disabled) {
  transform: scale(0.98);
}

.m2-btn:disabled {
  opacity: 0.52;
  cursor: not-allowed;
  transform: none;
}

.m2-btn--primary {
  background: linear-gradient(135deg, var(--accent-light) 0%, var(--accent) 100%);
  color: var(--accent-ink);
  border-color: rgba(var(--accent-rgb), 0.75);
  font-weight: 700;
  box-shadow: var(--shadow-accent);
}

.m2-btn--primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #fff0bd 0%, var(--accent-light) 100%);
  border-color: var(--accent-light);
  box-shadow: 0 10px 28px -6px rgba(var(--accent-rgb), 0.48);
}

.m2-btn--violet {
  background: rgba(var(--accent-violet-rgb), 0.16);
  color: #ddd6fe;
  border-color: rgba(var(--accent-violet-rgb), 0.42);
}

.m2-btn--violet:hover:not(:disabled) {
  background: rgba(var(--accent-violet-rgb), 0.26);
  border-color: rgba(var(--accent-violet-rgb), 0.68);
}

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

.m2-btn--ghost:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--border);
  color: var(--text-primary);
}

.m2-btn--danger {
  background: rgba(var(--offline-rgb), 0.12);
  border-color: rgba(var(--offline-rgb), 0.35);
  color: #fca5a5;
}

.m2-btn--danger:hover:not(:disabled) {
  background: rgba(var(--offline-rgb), 0.22);
  border-color: rgba(var(--offline-rgb), 0.65);
  color: #fee2e2;
}

.m2-btn--success {
  background: rgba(var(--online-rgb), 0.12);
  border-color: rgba(var(--online-rgb), 0.35);
  color: #86efac;
}

.m2-btn--success:hover:not(:disabled) {
  background: rgba(var(--online-rgb), 0.22);
  border-color: rgba(var(--online-rgb), 0.65);
}

.m2-btn--sm {
  min-height: 32px;
  padding: 6px 10px;
  font-size: 0.75rem;
  gap: 6px;
}

.m2-btn--sm svg {
  width: 14px;
  height: 14px;
}

.m2-btn--lg {
  min-height: 46px;
  padding: 11px 20px;
  font-size: 0.875rem;
  border-radius: var(--radius-md);
}

.m2-btn--icon {
  min-width: 36px;
  min-height: 36px;
  padding: 0;
}

.m2-btn--icon.m2-btn--sm {
  min-width: 32px;
  min-height: 32px;
}

.m2-btn--block {
  width: 100%;
}

@media (pointer: coarse) {
  .m2-btn, .m2-btn--icon {
    min-height: 44px;
  }
  .m2-btn--icon {
    min-width: 44px;
  }
  .m2-btn--sm {
    min-height: 38px;
  }
}

/* 2. INPUTS & 3. SELECTS */
.m2-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.m2-field:last-child {
  margin-bottom: 0;
}

.m2-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.m2-label svg {
  width: 13px;
  height: 13px;
  color: var(--accent);
}

.m2-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.m2-input-icon {
  position: absolute;
  left: 13px;
  display: inline-flex;
  color: var(--text-muted);
  pointer-events: none;
  transition: color var(--dur-fast);
}

.m2-input-icon svg {
  width: 16px;
  height: 16px;
}

.m2-input,
.m2-select,
.m2-textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background-color: var(--bg-input);
  color: var(--text-primary);
  font-size: 0.875rem;
  line-height: 1.4;
  outline: none;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast), background-color var(--dur-fast);
}

@media (max-width: 767px) {
  .m2-input, .m2-select, .m2-textarea {
    font-size: max(1rem, 1em);
    min-height: 46px;
  }
}

.m2-input--has-icon {
  padding-left: 38px;
}

.m2-input--has-action {
  padding-right: 42px;
}

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

.m2-input:focus,
.m2-select:focus,
.m2-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.14);
}

.m2-input-wrap:focus-within .m2-input-icon {
  color: var(--accent);
}

.m2-input:user-invalid,
.m2-input[aria-invalid="true"] {
  border-color: var(--offline);
  box-shadow: 0 0 0 3px rgba(var(--offline-rgb), 0.14);
}

.m2-input-action {
  position: absolute;
  right: 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  transition: color var(--dur-fast), background-color var(--dur-fast);
}

.m2-input-action:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
}

.m2-input-action svg {
  width: 16px;
  height: 16px;
}

.m2-select {
  appearance: none;
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238B95A7' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  background-size: 15px;
}

.m2-select option {
  background: var(--bg-card);
  color: var(--text-primary);
}

.m2-textarea {
  min-height: 96px;
  resize: vertical;
}

.m2-field-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.m2-field-err {
  min-height: 18px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #fca5a5;
}

/* 4. CHECKBOX & 5. SWITCH */
.m2-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.m2-check input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
  border-radius: 4px;
  cursor: pointer;
}

.m2-switch {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  user-select: none;
}

.m2-switch-input {
  position: relative;
  appearance: none;
  width: 42px;
  height: 24px;
  flex-shrink: 0;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-strong);
  background: var(--bg-input);
  cursor: pointer;
  transition: background-color var(--dur-fast), border-color var(--dur-fast);
}

.m2-switch-input::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--text-secondary);
  transition: transform var(--dur-fast) var(--ease-out), background-color var(--dur-fast);
}

.m2-switch-input:checked {
  background: rgba(var(--accent-rgb), 0.25);
  border-color: var(--accent);
}

.m2-switch-input:checked::after {
  transform: translateX(18px);
  background: var(--accent);
}

/* 6. MODAL & 20. CONFIRM DIALOG (<dialog>) */
/* Mandatory scroll containment on modal dialog & backdrop */
dialog.m2-dialog:modal {
  overscroll-behavior: contain;
}

dialog.m2-dialog::backdrop {
  overflow: hidden;
  overscroll-behavior: contain;
  background-color: rgba(4, 5, 9, 0);
  backdrop-filter: blur(0px);
  transition-property: background-color, backdrop-filter, display, overlay;
  transition-duration: 0.24s;
  transition-timing-function: ease-out;
  transition-behavior: allow-discrete;
}

dialog.m2-dialog {
  /* Closed / exit state — NEVER set display unconditionally on dialog */
  width: min(480px, calc(100vw - 24px));
  max-width: min(480px, calc(100vw - 24px));
  max-height: calc(100svh - 28px);
  margin: auto;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  background: linear-gradient(175deg, var(--bg-elevated) 0%, var(--bg-card) 100%);
  color: var(--text-primary);
  box-shadow: var(--shadow-dialog);
  overflow: hidden;
  opacity: 0;
  transition-property: opacity, transform, display, overlay;
  transition-duration: 0.24s;
  transition-timing-function: var(--ease-out);
  transition-behavior: allow-discrete;
}

dialog.m2-dialog--lg {
  width: min(640px, calc(100vw - 24px));
  max-width: min(640px, calc(100vw - 24px));
}

dialog.m2-dialog--sm {
  width: min(400px, calc(100vw - 24px));
  max-width: min(400px, calc(100vw - 24px));
}

@media (prefers-reduced-motion: no-preference) {
  dialog.m2-dialog {
    transform: translateY(10px) scale(0.97);
  }
}

/* Open state with :where(:not([data-closing])) for Firefox/Safari exit fallback */
dialog.m2-dialog[open]:where(:not([data-closing])) {
  display: flex;
  flex-direction: column;
  opacity: 1;
}

@media (prefers-reduced-motion: no-preference) {
  dialog.m2-dialog[open]:where(:not([data-closing])) {
    transform: translateY(0) scale(1);
    @starting-style {
      transform: translateY(10px) scale(0.97);
    }
  }
}

dialog.m2-dialog[open]:where(:not([data-closing])) {
  @starting-style {
    opacity: 0;
  }
}

dialog.m2-dialog[open]:where(:not([data-closing]))::backdrop {
  background-color: rgba(4, 5, 9, 0.78);
  backdrop-filter: blur(8px);
  @starting-style {
    background-color: rgba(4, 5, 9, 0);
    backdrop-filter: blur(0px);
  }
}

@media (prefers-reduced-motion: reduce) {
  dialog.m2-dialog,
  dialog.m2-dialog::backdrop {
    transition-duration: 0.1s;
  }
}

.m2-dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.m2-dialog-title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.m2-dialog-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: rgba(var(--accent-rgb), 0.12);
  border: 1px solid rgba(var(--accent-rgb), 0.28);
  color: var(--accent);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.m2-dialog-icon--danger {
  background: rgba(var(--offline-rgb), 0.12);
  border-color: rgba(var(--offline-rgb), 0.35);
  color: var(--offline);
}

.m2-dialog-icon svg {
  width: 17px;
  height: 17px;
}

.m2-dialog-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.m2-dialog-body {
  padding: 18px 20px;
  overflow-y: auto;
  flex: 1 1 auto;
}

.m2-dialog-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.22);
  flex-shrink: 0;
}

/* 7. DROPDOWN POPOVER */
[popover].m2-popover-menu {
  margin: 0;
  padding: 6px;
  min-width: 210px;
  max-width: min(280px, calc(100vw - 24px));
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  color: var(--text-primary);
  box-shadow: var(--shadow-dialog);
  opacity: 0;
  transition: opacity 0.16s ease-out, display 0.16s, overlay 0.16s;
  transition-behavior: allow-discrete;
}

[popover].m2-popover-menu:is(:popover-open, .\:popover-open) {
  display: block;
  opacity: 1;
  @starting-style {
    opacity: 0;
  }
}

@supports not selector(:popover-open) {
  [popover]:not(.\:popover-open) {
    display: none;
  }
}

.m2-menu-header {
  padding: 8px 10px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.m2-menu-header strong {
  display: block;
  color: var(--text-primary);
  font-size: 0.8125rem;
}

.m2-menu-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-primary);
  font-size: 0.8125rem;
  font-weight: 500;
  text-align: left;
  transition: background-color var(--dur-fast), color var(--dur-fast);
}

.m2-menu-item:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--accent-light);
}

.m2-menu-item--danger:hover {
  background: rgba(var(--offline-rgb), 0.14);
  color: #fca5a5;
}

.m2-menu-item svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

/* 8. TOOLTIP */
[data-tooltip] {
  position: relative;
}

/* Floating helper tooltip (collapsed sidebar + explicit buttons) */
.m2-tooltip-box {
  position: fixed;
  z-index: 9000;
  padding: 5px 9px;
  border-radius: 7px;
  background: #0c0e14;
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.55);
  opacity: 0;
  transform: translateY(2px);
  transition: opacity 0.14s ease, transform 0.14s ease;
}

.m2-tooltip-box.show {
  opacity: 1;
  transform: translateY(0);
}

/* 9. BADGE & 18. STATUS INDICATOR */
.m2-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-secondary);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.m2-badge--gold {
  background: rgba(var(--accent-rgb), 0.12);
  border-color: rgba(var(--accent-rgb), 0.32);
  color: var(--accent-light);
}

.m2-badge--violet {
  background: rgba(var(--accent-violet-rgb), 0.14);
  border-color: rgba(var(--accent-violet-rgb), 0.35);
  color: #ddd6fe;
}

.m2-badge--online {
  background: rgba(var(--online-rgb), 0.12);
  border-color: rgba(var(--online-rgb), 0.32);
  color: #86efac;
}

.m2-badge--offline {
  background: rgba(var(--offline-rgb), 0.12);
  border-color: rgba(var(--offline-rgb), 0.35);
  color: #fca5a5;
}

.m2-badge--warning {
  background: rgba(var(--warning-rgb), 0.12);
  border-color: rgba(var(--warning-rgb), 0.35);
  color: #fcd34d;
}

.m2-badge--info {
  background: rgba(var(--info-rgb), 0.12);
  border-color: rgba(var(--info-rgb), 0.35);
  color: #7dd3fc;
}

.m2-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.m2-dot--online {
  color: var(--online);
  box-shadow: 0 0 8px rgba(var(--online-rgb), 0.7);
}

@media (prefers-reduced-motion: no-preference) {
  .m2-dot--pulse {
    animation: m2Pulse 2s ease-in-out infinite;
  }
}

@keyframes m2Pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.42; transform: scale(0.86); }
}

/* 10. CARDS */
.m2-card {
  position: relative;
  min-width: 0;
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  padding: 20px;
  transition: border-color var(--dur-med) var(--ease-out), background-color var(--dur-med);
}

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

.m2-card--gold {
  border-color: rgba(var(--accent-rgb), 0.28);
  background: linear-gradient(155deg, rgba(var(--accent-rgb), 0.05) 0%, var(--bg-card) 48%);
}

.m2-card--gold:hover {
  border-color: rgba(var(--accent-rgb), 0.45);
}

.m2-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.m2-card-title-group {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.m2-card-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: rgba(var(--accent-rgb), 0.1);
  border: 1px solid rgba(var(--accent-rgb), 0.22);
  color: var(--accent);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.m2-card-icon--violet {
  background: rgba(var(--accent-violet-rgb), 0.12);
  border-color: rgba(var(--accent-violet-rgb), 0.26);
  color: var(--accent-violet);
}

.m2-card-icon svg {
  width: 17px;
  height: 17px;
}

.m2-card-title {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--text-primary);
}

.m2-card-sub {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.m2-kpi {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
}

.m2-kpi-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.m2-kpi-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.m2-kpi-value {
  font-family: var(--font-display);
  font-size: clamp(1.375rem, 2.2vw, 1.85rem);
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}

.m2-kpi-value--gold { color: var(--accent-light); }
.m2-kpi-value--online { color: var(--online); }
.m2-kpi-value--violet { color: #c4b5fd; }

.m2-kpi-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

/* 11. RESPONSIVE SORTABLE DATA TABLE */
.m2-table-wrap {
  position: relative;
  overflow: auto;
  max-inline-size: 100%;
  max-block-size: min(560px, 72svh);
  container-type: inline-size;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: rgba(8, 9, 13, 0.45);
}

.m2-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  text-align: left;
  font-size: 0.8125rem;
}

.m2-table caption {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

.m2-table thead th {
  position: sticky;
  inset-block-start: 0;
  z-index: 2;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  padding: 11px 14px;
}

.m2-table thead th:has(> button.m2-sort-btn) {
  padding: 0;
}

.m2-sort-btn {
  width: 100%;
  min-height: 38px;
  padding: 10px 14px;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-align: left;
  transition: color var(--dur-fast), background-color var(--dur-fast);
}

.m2-sort-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.03);
}

.m2-sort-icon {
  display: inline-flex;
  opacity: 0.4;
  transition: opacity var(--dur-fast), transform var(--dur-fast);
}

.m2-sort-icon svg {
  width: 13px;
  height: 13px;
}

th[aria-sort] .m2-sort-btn {
  color: var(--accent-light);
}

th[aria-sort] .m2-sort-icon {
  opacity: 1;
  color: var(--accent);
}

th[aria-sort="descending"] .m2-sort-icon {
  transform: rotate(180deg);
}

.m2-table tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.045);
  vertical-align: middle;
  color: var(--text-primary);
}

.m2-table tbody tr:last-child td {
  border-bottom: 0;
}

.m2-table tbody tr {
  transition: background-color var(--dur-fast);
}

.m2-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

.m2-table tbody tr.is-selected {
  background: rgba(var(--accent-rgb), 0.07);
}

/* Container query stacked card layout on narrow widths */
@container (width < 640px) {
  .m2-table-wrap {
    border: 0;
    background: transparent;
    max-block-size: none;
    overflow: visible;
  }
  .m2-table, .m2-table tbody, .m2-table tr, .m2-table td {
    display: block;
    width: 100%;
  }
  .m2-table thead {
    display: none;
  }
  .m2-table tbody tr {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 10px 14px;
    margin-bottom: 10px;
  }
  .m2-table tbody tr:last-child {
    margin-bottom: 0;
  }
  .m2-table tbody td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 7px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    text-align: right;
  }
  .m2-table tbody td:last-child {
    border-bottom: 0;
    padding-top: 10px;
    justify-content: flex-end;
  }
  .m2-table tbody td[data-label]::before {
    content: attr(data-label);
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
    text-align: left;
    flex-shrink: 0;
  }
  .m2-table tbody td.m2-td-main {
    justify-content: flex-start;
    text-align: left;
  }
  .m2-table tbody td.m2-td-main::before {
    display: none;
  }
}

/* 12. TABS (WCAG 1.4.1 underline + color) */
.m2-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: 1px solid var(--border);
}

.m2-tabs::-webkit-scrollbar {
  display: none;
}

.m2-tab {
  position: relative;
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 14px;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.8125rem;
  font-weight: 600;
  white-space: nowrap;
  transition: color var(--dur-fast);
}

.m2-tab:hover {
  color: var(--text-primary);
}

.m2-tab[aria-selected="true"],
.m2-tab.is-active {
  color: var(--accent-light);
}

.m2-tab[aria-selected="true"]::after,
.m2-tab.is-active::after {
  content: "";
  position: absolute;
  inset: auto 8px 0;
  border-block-end: 2px solid var(--accent);
}

/* Segmented pills (filters / auth switch) */
.m2-pills {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.m2-pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 5px 11px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  transition: all var(--dur-fast);
}

.m2-pill-btn:hover {
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.m2-pill-btn[aria-pressed="true"],
.m2-pill-btn.is-active {
  background: rgba(var(--accent-rgb), 0.14);
  border-color: rgba(var(--accent-rgb), 0.45);
  color: var(--accent-light);
}

/* 13. PROGRESS & SPINNER */
.m2-progress {
  width: 100%;
  height: 7px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.05);
  overflow: hidden;
}

.m2-progress-bar {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent-deep), var(--accent), var(--accent-light));
  transition: width 0.45s var(--ease-out);
}

.m2-progress-bar--online {
  background: linear-gradient(90deg, #16a34a, var(--online));
}

.m2-progress-bar--violet {
  background: linear-gradient(90deg, #6d28d9, var(--accent-violet));
}

progress.m2-spinner {
  --size: 20px;
  --thickness: 2.5px;
  --spinner-color: var(--accent);
  --track-color: rgba(255, 255, 255, 0.12);
  --_dur: 0.9s;
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  appearance: none;
  border: 0;
  background: conic-gradient(from 0deg, var(--spinner-color) 140deg, transparent 0) var(--track-color);
  animation: m2Spin var(--_dur) linear infinite;
}

progress.m2-spinner::-webkit-progress-bar,
progress.m2-spinner::-webkit-progress-value {
  background: none;
}

progress.m2-spinner::-moz-progress-bar {
  background: none;
}

@supports (background-clip: border-area) {
  progress.m2-spinner {
    background-clip: border-area;
    border: var(--thickness) solid transparent;
    background-origin: border-box;
  }
}

@supports not (background-clip: border-area) {
  progress.m2-spinner {
    mask-image: radial-gradient(farthest-side, transparent calc(100% - var(--thickness)), #000 calc(100% - var(--thickness)));
  }
}

@media (prefers-reduced-motion: reduce) {
  progress.m2-spinner {
    --_dur: 6s;
  }
}

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

/* 14. TOAST NOTIFICATIONS */
.m2-toast-region {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 9500;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(360px, calc(100vw - 24px));
  pointer-events: none;
}

.m2-toast {
  position: relative;
  inset: auto;
  margin: 0;
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.55);
  font-size: 0.8125rem;
  font-weight: 600;
  opacity: 1;
  transition: opacity 0.2s ease, transform 0.2s var(--ease-out), display 0.2s, overlay 0.2s;
  transition-behavior: allow-discrete;
}

.m2-toast[popover] {
  position: relative;
  inset: auto;
}

.m2-toast--success { border-color: rgba(var(--online-rgb), 0.42); }
.m2-toast--success .m2-toast-ic { color: var(--online); }
.m2-toast--error { border-color: rgba(var(--offline-rgb), 0.45); }
.m2-toast--error .m2-toast-ic { color: var(--offline); }
.m2-toast--warning { border-color: rgba(var(--warning-rgb), 0.45); }
.m2-toast--warning .m2-toast-ic { color: var(--warning); }
.m2-toast--info { border-color: rgba(var(--accent-rgb), 0.4); }
.m2-toast--info .m2-toast-ic { color: var(--accent); }

.m2-toast-ic {
  display: inline-flex;
  margin-top: 1px;
  flex-shrink: 0;
}

.m2-toast-ic svg {
  width: 16px;
  height: 16px;
}

.m2-toast-msg {
  flex: 1;
  min-width: 0;
  word-break: break-word;
}

.m2-toast-close {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  padding: 2px;
  border-radius: 5px;
  display: inline-flex;
}

.m2-toast-close:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.08);
}

.m2-toast-close svg {
  width: 14px;
  height: 14px;
}

.m2-toast.is-leaving {
  opacity: 0;
  transform: translateX(12px);
}

/* 15. SKELETON LOADING */
.m2-skeleton {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.05);
}

.m2-skeleton--line { height: 14px; }
.m2-skeleton--title { height: 24px; width: 45%; }
.m2-skeleton--card { height: 112px; border-radius: var(--radius-lg); }

@media (prefers-reduced-motion: no-preference) {
  .m2-skeleton::after {
    content: "";
    position: absolute;
    inset: 0;
    transform: translateX(-100%);
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.06), transparent);
    animation: m2Shimmer 1.5s infinite;
  }
}

@keyframes m2Shimmer {
  100% { transform: translateX(100%); }
}

/* 16. EMPTY STATE & 17. ERROR STATE */
.m2-empty,
.m2-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 36px 20px;
  border-radius: var(--radius-md);
  border: 1px dashed var(--border-strong);
  background: rgba(255, 255, 255, 0.015);
  gap: 8px;
}

.m2-error {
  border-color: rgba(var(--offline-rgb), 0.35);
  background: rgba(var(--offline-rgb), 0.05);
}

.m2-empty-icon,
.m2-error-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  display: grid;
  place-items: center;
  margin-bottom: 4px;
}

.m2-error-icon {
  background: rgba(var(--offline-rgb), 0.12);
  border-color: rgba(var(--offline-rgb), 0.3);
  color: var(--offline);
}

.m2-empty-icon svg,
.m2-error-icon svg {
  width: 20px;
  height: 20px;
}

.m2-empty-title,
.m2-error-title {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--text-primary);
}

.m2-empty-copy,
.m2-error-copy {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  max-width: 360px;
}

/* 19. CHART & COPY BUTTON */
.m2-copy-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  min-height: 28px;
  padding: 4px 7px;
  gap: 5px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-secondary);
  font-size: 0.75rem;
  transition: all var(--dur-fast);
}

.m2-copy-btn:hover {
  border-color: var(--accent);
  color: var(--accent-light);
}

.m2-copy-btn[data-copied] {
  border-color: rgba(var(--online-rgb), 0.5);
  color: var(--online);
  background: rgba(var(--online-rgb), 0.1);
}

.m2-copy-btn svg {
  width: 13px;
  height: 13px;
}

.m2-chart-shell {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.m2-chart-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.m2-chart-canvas {
  position: relative;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: rgba(8, 9, 13, 0.55);
  padding: 14px 12px 10px;
}

.m2-chart-canvas svg {
  width: 100%;
  height: 170px;
  display: block;
  overflow: visible;
  touch-action: pan-y;
}

.m2-chart-tooltip {
  position: absolute;
  top: 10px;
  right: 12px;
  padding: 8px 11px;
  border-radius: 9px;
  background: rgba(12, 14, 20, 0.94);
  border: 1px solid var(--border-strong);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.55);
  font-size: 0.75rem;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s ease;
  z-index: 4;
}

.m2-chart-tooltip.is-visible {
  opacity: 1;
}

/* Inline Alerts */
.m2-alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.m2-alert svg {
  width: 16px;
  height: 16px;
  margin-top: 2px;
  flex-shrink: 0;
}

.m2-alert--warning {
  background: rgba(var(--warning-rgb), 0.08);
  border-color: rgba(var(--warning-rgb), 0.3);
  color: #fde68a;
}

.m2-alert--warning svg { color: var(--warning); }

.m2-alert--success {
  background: rgba(var(--online-rgb), 0.09);
  border-color: rgba(var(--online-rgb), 0.32);
  color: #bbf7d0;
}

.m2-alert--success svg { color: var(--online); }

.m2-alert--error {
  background: rgba(var(--offline-rgb), 0.1);
  border-color: rgba(var(--offline-rgb), 0.35);
  color: #fecaca;
}

.m2-alert--error svg { color: var(--offline); }

.m2-alert--info {
  background: rgba(var(--accent-violet-rgb), 0.09);
  border-color: rgba(var(--accent-violet-rgb), 0.28);
  color: #ddd6fe;
}

.m2-alert--info svg { color: var(--accent-violet); }
