:root {
  --tm-color-bg-app: #0b1220;
  --tm-color-bg-canvas: #0f172a;
  --tm-color-surface-base: #111827;
  --tm-color-surface-panel: #161b22;
  --tm-color-surface-elevated: #1e293b;
  --tm-color-border-muted: #1e293b;
  --tm-color-border-default: #30363d;
  --tm-color-border-strong: #334155;
  --tm-color-text-primary: #f8fafc;
  --tm-color-text-secondary: #cbd5e1;
  --tm-color-text-muted: #94a3b8;
  --tm-color-text-disabled: #64748b;
  --tm-color-text-inverse: #06111f;
  --tm-color-accent-primary: #38bdf8;
  --tm-color-accent-primary-hover: #7dd3fc;
  --tm-color-accent-success: #22c55e;
  --tm-color-accent-warning: #f59e0b;
  --tm-color-accent-danger: #ef4444;
  --tm-color-accent-info: #60a5fa;
  --tm-font-body: Inter, Arial, sans-serif;
  --tm-font-display: 'Space Grotesk', Inter, Arial, sans-serif;
  --tm-font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --tm-radius-1: 4px;
  --tm-radius-2: 6px;
  --tm-radius-3: 8px;
  --tm-radius-4: 10px;
  --tm-radius-pill: 999px;
  --tm-focus-ring: 0 0 0 3px rgba(56, 189, 248, 0.28);
  --tm-shadow-sm: 0 4px 10px rgba(0, 0, 0, 0.18);
  --tm-shadow-md: 0 12px 28px rgba(0, 0, 0, 0.28);
  --tm-shadow-lg: 0 24px 80px rgba(0, 0, 0, 0.58);
}

*:focus-visible {
  outline: 2px solid var(--tm-color-accent-primary);
  outline-offset: 2px;
  box-shadow: var(--tm-focus-ring);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

.tm-container {
  width: min(100% - 32px, 1180px);
  margin-inline: auto;
}

.tm-prose {
  color: var(--tm-color-text-secondary);
  font-family: var(--tm-font-body);
  line-height: 1.65;
}

.tm-prose h1,
.tm-prose h2,
.tm-prose h3 {
  color: var(--tm-color-text-primary);
  font-family: var(--tm-font-display);
  line-height: 1.15;
  letter-spacing: 0;
}

.tm-surface,
.tm-card {
  background: var(--tm-color-surface-base);
  border: 1px solid var(--tm-color-border-muted);
  border-radius: var(--tm-radius-3);
  color: var(--tm-color-text-secondary);
}

.tm-card {
  padding: 16px;
}

.tm-btn,
.tm-icon-btn,
.tm-link-btn {
  align-items: center;
  border: 1px solid transparent;
  border-radius: var(--tm-radius-3);
  cursor: pointer;
  display: inline-flex;
  font-family: var(--tm-font-body);
  font-size: 12px;
  font-weight: 800;
  gap: 7px;
  justify-content: center;
  letter-spacing: 0;
  line-height: 1;
  min-height: 32px;
  min-width: 0;
  padding: 0 12px;
  text-decoration: none;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease, opacity 160ms ease;
  white-space: normal;
}

.tm-btn[disabled],
.tm-btn[aria-disabled="true"],
.tm-icon-btn[disabled],
.tm-icon-btn[aria-disabled="true"],
.tm-link-btn[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.54;
  pointer-events: none;
}

.tm-btn--primary {
  background: var(--tm-color-accent-primary);
  border-color: var(--tm-color-accent-primary);
  color: var(--tm-color-text-inverse);
}

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

.tm-btn--secondary,
.tm-link-btn {
  background: var(--tm-color-surface-elevated);
  border-color: var(--tm-color-border-strong);
  color: var(--tm-color-text-secondary);
}

.tm-btn--secondary:hover,
.tm-link-btn:hover {
  border-color: var(--tm-color-accent-primary);
  color: var(--tm-color-text-primary);
}

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

.tm-btn--ghost:hover {
  background: var(--tm-color-surface-elevated);
  color: var(--tm-color-text-primary);
}

.tm-btn--danger {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.38);
  color: #fecaca;
}

.tm-btn--danger:hover {
  background: rgba(239, 68, 68, 0.2);
}

.tm-btn--sm {
  min-height: 28px;
  padding-inline: 10px;
}

.tm-btn--lg {
  min-height: 40px;
  padding-inline: 16px;
}

.tm-btn.is-loading {
  color: transparent;
  position: relative;
}

.tm-btn.is-loading::after {
  animation: tm-spin 800ms linear infinite;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-top-color: transparent;
  border-radius: 50%;
  color: var(--tm-color-text-secondary);
  content: "";
  height: 14px;
  inset: calc(50% - 7px) auto auto calc(50% - 7px);
  position: absolute;
  width: 14px;
}

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

.tm-icon-btn {
  aspect-ratio: 1;
  min-height: 32px;
  padding: 0;
  width: 32px;
}

.tm-field {
  display: grid;
  gap: 6px;
}

.tm-label {
  color: var(--tm-color-text-muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.tm-input,
.tm-textarea,
.tm-select,
.tm-search {
  background: var(--tm-color-surface-elevated);
  border: 1px solid var(--tm-color-border-strong);
  border-radius: var(--tm-radius-3);
  color: var(--tm-color-text-primary);
  font-family: var(--tm-font-body);
  font-size: 13px;
  min-height: 34px;
  min-width: 0;
  padding: 0 11px;
  width: 100%;
}

.tm-textarea {
  min-height: 88px;
  padding-block: 9px;
  resize: vertical;
}

.tm-input::placeholder,
.tm-search::placeholder,
.tm-textarea::placeholder {
  color: var(--tm-color-text-disabled);
}

.tm-input:disabled,
.tm-textarea:disabled,
.tm-select:disabled {
  cursor: not-allowed;
  opacity: 0.56;
}

.tm-check,
.tm-radio,
.tm-switch {
  align-items: center;
  color: var(--tm-color-text-secondary);
  display: inline-flex;
  gap: 8px;
  min-width: 0;
}

.tm-switch input {
  inline-size: 38px;
}

.tm-badge,
.tm-chip,
.tm-tag {
  align-items: center;
  border: 1px solid var(--tm-color-border-strong);
  border-radius: var(--tm-radius-pill);
  display: inline-flex;
  font-size: 11px;
  font-weight: 800;
  gap: 5px;
  min-height: 24px;
  padding: 0 9px;
  white-space: nowrap;
}

.tm-badge {
  background: rgba(56, 189, 248, 0.12);
  color: var(--tm-color-accent-primary);
}

.tm-chip {
  background: var(--tm-color-surface-elevated);
  color: var(--tm-color-text-muted);
}

.tm-chip[aria-pressed="true"],
.tm-chip.is-active {
  border-color: var(--tm-color-accent-primary);
  color: var(--tm-color-accent-primary);
}

.tm-tooltip {
  background: #020817;
  border: 1px solid var(--tm-color-border-default);
  border-radius: var(--tm-radius-2);
  box-shadow: var(--tm-shadow-md);
  color: var(--tm-color-text-secondary);
  font-size: 12px;
  max-width: min(280px, calc(100vw - 24px));
  padding: 7px 9px;
  z-index: 4000;
}

.tm-modal-overlay,
.tm-drawer-overlay {
  background: rgba(2, 8, 23, 0.72);
  display: flex;
  inset: 0;
  padding: 16px;
  position: fixed;
  z-index: 9999;
}

.tm-modal {
  background: var(--tm-color-surface-base);
  border: 1px solid var(--tm-color-border-default);
  border-radius: var(--tm-radius-4);
  box-shadow: var(--tm-shadow-lg);
  color: var(--tm-color-text-secondary);
  margin: auto;
  max-height: min(720px, calc(100vh - 32px));
  max-width: min(560px, calc(100vw - 32px));
  overflow: auto;
  padding: 22px;
  width: 100%;
}

.tm-drawer {
  background: var(--tm-color-surface-base);
  border: 1px solid var(--tm-color-border-default);
  border-radius: var(--tm-radius-4) var(--tm-radius-4) 0 0;
  box-shadow: var(--tm-shadow-lg);
  margin: auto auto 0;
  max-height: min(82vh, 720px);
  overflow: auto;
  padding: 16px;
  width: min(100%, 680px);
}

.tm-tabs,
.tm-segmented,
.tm-filter-toolbar,
.tm-cta-group {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

.tm-table-wrap {
  border: 1px solid var(--tm-color-border-muted);
  border-radius: var(--tm-radius-3);
  overflow: auto;
}

.tm-table {
  border-collapse: collapse;
  font-size: 13px;
  width: 100%;
}

.tm-table th {
  color: var(--tm-color-text-disabled);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-align: start;
  text-transform: uppercase;
}

.tm-table th,
.tm-table td {
  border-bottom: 1px solid var(--tm-color-border-muted);
  padding: 7px 9px;
}

.tm-skeleton {
  animation: tm-pulse 1.4s ease-in-out infinite;
  background: linear-gradient(90deg, #162033, #22324a, #162033);
  background-size: 220% 100%;
  border-radius: var(--tm-radius-2);
  min-height: 12px;
}

@keyframes tm-pulse {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

.tm-empty-state,
.tm-inline-notice,
.tm-alert {
  border: 1px solid var(--tm-color-border-default);
  border-radius: var(--tm-radius-3);
  color: var(--tm-color-text-secondary);
  padding: 12px;
}

.tm-inline-notice {
  background: rgba(96, 165, 250, 0.08);
  border-color: rgba(96, 165, 250, 0.24);
}

.tm-alert--danger {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.3);
}

.tm-stat-card {
  background: var(--tm-color-surface-base);
  border: 1px solid var(--tm-color-border-muted);
  border-radius: var(--tm-radius-3);
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 12px;
}

.tm-stat-card__value {
  color: var(--tm-color-text-primary);
  font-family: var(--tm-font-display);
  font-size: 24px;
  font-weight: 800;
  line-height: 1;
}

.tm-stat-card__label {
  color: var(--tm-color-text-muted);
  font-size: 12px;
}

[dir="rtl"] .tm-btn,
[dir="rtl"] .tm-link-btn,
[dir="rtl"] .tm-chip,
[dir="rtl"] .tm-badge,
[dir="rtl"] .tm-check,
[dir="rtl"] .tm-radio {
  flex-direction: row-reverse;
}

@media (max-width: 700px) {
  .tm-container {
    width: min(100% - 24px, 1180px);
  }

  .tm-filter-toolbar {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .tm-btn,
  .tm-link-btn {
    min-height: 36px;
  }
}
