/* MailTrace authenticated product foundation.
   Ownership: product layout primitives, cards, panels, buttons, fields, tables,
   badges, focus, spacing, accessibility preferences, and utility states.
   Colors must come from theme.css tokens. Marketing pages must not import this. */

:root {
  --mt-font: Inter, Geist, "General Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mt-page-max: 1760px;
  --mt-content-padding: clamp(16px, 2vw, 28px);
  --mt-card-padding: 16px;
  --mt-section-gap: 18px;
  --mt-grid-gap: 14px;
  --mt-control-height: 40px;
  --mt-sidebar-width: 232px;
  --mt-gap: var(--mt-grid-gap);
  --mt-density-scale: 1;
  --mt-root-font-size: 14.5px;
  --mt-motion-duration: 0.16s;
}

:root[data-text-scale="large"] { --mt-root-font-size: 16px; }
:root[data-text-scale="extra_large"] { --mt-root-font-size: 17.25px; }
:root[data-density="compact"] {
  --mt-density-scale: 0.86;
  --mt-card-padding: 12px;
  --mt-control-height: 38px;
  --mt-section-gap: 14px;
  --mt-grid-gap: 10px;
  --mt-gap: var(--mt-grid-gap);
}
:root[data-density="spacious"] {
  --mt-density-scale: 1.14;
  --mt-card-padding: 22px;
  --mt-control-height: 46px;
  --mt-section-gap: 24px;
  --mt-grid-gap: 20px;
  --mt-gap: var(--mt-grid-gap);
}
:root[data-motion="reduced"] {
  scroll-behavior: auto;
  --mt-motion-duration: 0ms;
}
:root[data-contrast="high"] {
  --mt-border-subtle: var(--mt-border-strong);
  --mt-card-shadow: none;
}
:root[data-focus="enhanced"] {
  --mt-focus-ring: 0 0 0 4px color-mix(in srgb, var(--mt-accent-primary) 52%, transparent);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  scroll-behavior: smooth;
  font-size: var(--mt-root-font-size);
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    var(
      --shell-bg,
      radial-gradient(circle at top left, rgba(100, 115, 255, 0.14), transparent 34%),
      linear-gradient(180deg, #07101f, #0a1322 54%, #07101f)
    );
  color: var(--mt-text-primary);
  font-family: var(--mt-font);
  overflow-x: hidden;
  transition:
    background-color var(--mt-motion-duration) ease,
    color var(--mt-motion-duration) ease,
    background-image var(--mt-motion-duration) ease;
}

:root[data-motion="reduced"] *,
:root[data-motion="reduced"] *::before,
:root[data-motion="reduced"] *::after {
  animation-duration: 0.001ms !important;
  animation-iteration-count: 1 !important;
  scroll-behavior: auto !important;
  transition-duration: 0.001ms !important;
}

img,
svg,
video {
  max-width: 100%;
  height: auto;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled,
[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.62;
}

::placeholder {
  color: var(--mt-text-muted);
}

::selection {
  background: color-mix(in srgb, var(--mt-accent-primary) 24%, transparent);
}

:focus-visible {
  outline: none;
  box-shadow: var(--mt-focus-ring);
}

.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;
}

.is-hidden,
[hidden] {
  display: none !important;
}

/* Layout primitives */
.mt-app-shell,
.workspace-shell,
.case-shell,
.app-shell,
.case-app-shell {
  display: grid;
  grid-template-columns: var(--mt-sidebar-width) minmax(0, 1fr);
  min-height: 100vh;
}

.mt-sidebar,
.mt-global-sidebar,
.workspace-sidebar,
.case-sidebar,
.sidebar {
  position: sticky;
  top: 0;
  z-index: 20;
  width: var(--mt-sidebar-width);
  min-width: var(--mt-sidebar-width);
  height: 100vh;
  overflow: auto;
  padding: calc(24px * var(--mt-density-scale)) 18px;
  background: var(--mt-bg-sidebar);
  border-right: 1px solid var(--mt-border-subtle);
  color: var(--mt-sidebar-text);
}

.mt-main,
.workspace-main,
.case-main,
.main,
.main-area {
  min-width: 0;
  padding: var(--mt-content-padding) clamp(18px, 2.4vw, 34px) calc(var(--mt-content-padding) + 8px);
}

.mt-page,
.main-stack,
.workspace-stack,
.case-stack,
.page-wrap {
  width: 100%;
  max-width: var(--mt-page-max);
  margin-inline: 0;
  display: grid;
  gap: var(--mt-gap);
}

.mt-page-header,
.page-header,
.page-heading,
.mt-spread {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--mt-gap);
  min-width: 0;
}

.mt-page-grid,
.workspace-grid,
.case-grid,
.dashboard-grid,
.overview-grid,
.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--mt-gap);
  align-items: start;
}

.mt-grid,
.metric-grid,
.stats-grid,
.case-stats-grid,
.summary-strip {
  display: grid;
  gap: var(--mt-gap);
}

.mt-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.mt-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.mt-grid-4,
.metric-grid,
.stats-grid,
.case-stats-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr));
}

.mt-row,
.mt-toolbar,
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  min-width: 0;
}

/* Typography */
h1,
h2,
h3,
h4,
p {
  overflow-wrap: anywhere;
}

h1,
.mt-title,
.mt-heading {
  margin: 0;
  color: var(--mt-text-primary);
  font-size: clamp(1.8rem, 2.5vw, 2.35rem);
  line-height: 1.08;
  letter-spacing: -0.04em;
}

h2,
.mt-subheading {
  margin: 0;
  color: var(--mt-text-primary);
  font-size: clamp(1.18rem, 1.45vw, 1.55rem);
  line-height: 1.18;
  letter-spacing: -0.025em;
}

h3 {
  margin: 0;
  color: var(--mt-text-primary);
  font-size: clamp(1rem, 1.1vw, 1.15rem);
  line-height: 1.25;
}

p,
.mt-copy {
  color: var(--mt-text-secondary);
  line-height: 1.5;
}

.mt-muted,
.muted,
.page-subtitle {
  color: var(--mt-text-muted);
}

.mt-small {
  font-size: 0.85rem;
  line-height: 1.5;
}

.mt-kicker,
.kicker {
  margin: 0 0 8px;
  color: var(--mt-accent-primary);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

/* Surfaces */
.mt-card,
.mt-panel,
.mt-surface,
.mt-stat-card,
.mt-kpi-card,
.card,
.panel,
.metric-card,
.stat-card,
.form-panel,
.welcome-card,
.quick-action-card,
.mailbox-card,
.summary-panel,
.investigation-card,
.settings-card,
.report-panel,
.rail-card {
  min-width: 0;
  border: 1px solid var(--mt-border-subtle);
  border-radius: var(--mt-radius-md);
  background: var(--card-gradient, var(--mt-bg-card));
  color: var(--mt-text-primary);
  box-shadow: var(--mt-card-shadow);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  position: relative;
  overflow: hidden;
}

.mt-card,
.mt-panel,
.mt-surface,
.card,
.panel,
.form-panel,
.welcome-card,
.quick-action-card,
.mailbox-card,
.summary-panel,
.investigation-card,
.settings-card,
.report-panel,
.rail-card {
  padding: var(--mt-card-padding);
}

.mt-surface {
  background: var(--mt-bg-surface);
}

.mt-card::before,
.mt-panel::before,
.mt-surface::before,
.card::before,
.panel::before,
.metric-card::before,
.stat-card::before,
.form-panel::before,
.welcome-card::before,
.quick-action-card::before,
.mailbox-card::before,
.summary-panel::before,
.investigation-card::before,
.settings-card::before,
.report-panel::before,
.rail-card::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), transparent 28%),
    radial-gradient(circle at top right, rgba(94, 216, 255, 0.08), transparent 34%),
    radial-gradient(circle at top left, rgba(154, 115, 255, 0.08), transparent 30%);
}

.mt-card *,
.mt-panel *,
.card *,
.panel *,
.metric-card *,
.stat-card *,
.investigation-card * {
  min-width: 0;
}

.mt-stat-card,
.mt-kpi-card,
.metric-card,
.stat-card {
  padding: var(--mt-card-padding);
}

.mt-stat-value,
.metric-value,
.stat-value {
  display: block;
  max-width: 100%;
  color: var(--mt-text-primary);
  font-size: clamp(1.35rem, 2vw, 1.85rem);
  font-weight: 850;
  line-height: 1;
  letter-spacing: -0.05em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric-label,
.stat-label {
  margin: 0 0 8px;
  color: var(--mt-text-muted);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.metric-footnote,
.stat-footnote,
.metric-meta {
  margin: 8px 0 0;
  color: var(--mt-text-muted);
  font-size: 0.8rem;
  line-height: 1.45;
}

/* Buttons */
.mt-button,
.mt-button-primary,
.mt-button-secondary,
.mt-button-ghost,
.mt-icon-button,
.primary-action,
.secondary-action,
.primary-button,
.secondary-button,
.ghost-button,
.text-button,
.icon-button,
.filter-chip,
button.primary,
button.secondary,
button.ghost {
  min-height: var(--mt-control-height);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 1px solid var(--mt-border-subtle);
  border-radius: var(--mt-radius-md);
  background: color-mix(in srgb, var(--mt-field-bg) 82%, transparent);
  color: var(--mt-text-primary);
  padding: 0 16px;
  font-size: 0.95rem;
  font-weight: 750;
  line-height: 1;
  transition:
    transform var(--mt-motion-duration) ease,
    border-color var(--mt-motion-duration) ease,
    background-color var(--mt-motion-duration) ease;
}

.mt-button:hover,
.mt-button-primary:hover,
.mt-button-secondary:hover,
.mt-button-ghost:hover,
.mt-icon-button:hover,
.primary-action:hover,
.secondary-action:hover,
.primary-button:hover,
.secondary-button:hover,
.ghost-button:hover,
.text-button:hover,
.icon-button:hover,
.filter-chip:hover {
  transform: translateY(-1px);
  border-color: var(--mt-border-strong);
}

.mt-button-primary,
.mt-button.primary,
.primary-action,
.primary-button,
button.primary {
  border-color: transparent;
  background: var(--mt-button-primary-bg);
  color: var(--mt-button-primary-text);
  box-shadow: 0 14px 34px rgba(99, 115, 255, 0.24);
}

.mt-button-ghost,
.ghost-button,
.text-button,
button.ghost {
  background: transparent;
}

.mt-icon-button,
.icon-button {
  width: var(--mt-control-height);
  min-width: var(--mt-control-height);
  padding: 0;
}

/* Fields */
.mt-field,
label {
  display: grid;
  gap: 8px;
  color: var(--mt-text-muted);
  font-size: 0.82rem;
}

.mt-input,
.mt-select,
.mt-search,
input,
select,
textarea,
.search-input,
.target-input {
  width: 100%;
  min-width: 0;
  min-height: var(--mt-control-height);
  border: 1px solid var(--mt-border-subtle);
  border-radius: var(--mt-radius-md);
  background: color-mix(in srgb, var(--mt-field-bg) 88%, transparent);
  color: var(--mt-text-primary);
  padding: 0 14px;
  font-size: 0.95rem;
  outline: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

textarea {
  min-height: 120px;
  padding-block: 14px;
  resize: vertical;
}

/* Shared progress loader states */
.mt-loader-steps {
  --mt-loader-line: rgba(148, 163, 184, 0.22);
  --mt-loader-complete-glow: 0 0 28px rgba(51, 209, 201, 0.42);
  --mt-loader-active-glow: 0 0 34px rgba(124, 77, 255, 0.55);
  position: relative;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
  margin: 42px 0 34px;
  padding: 0;
  list-style: none;
}

.mt-loader-steps::before {
  content: "";
  position: absolute;
  top: 28px;
  left: 8%;
  right: 8%;
  height: 2px;
  background: var(--mt-loader-line);
  z-index: 0;
}

.mt-loader-step {
  position: relative;
  z-index: 1;
  display: grid;
  justify-items: center;
  text-align: center;
  gap: 8px;
  color: var(--mt-text-muted);
}

.mt-step-number {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.24);
  background: rgba(15, 23, 42, 0.7);
  color: #9fb1ca;
  font-size: 20px;
  font-weight: 800;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.mt-loader-step strong {
  color: #dde7ff;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.35;
}

.mt-loader-step small {
  max-width: 130px;
  color: #8ea0bd;
  font-size: 13px;
  line-height: 1.4;
}

.mt-loader-step.is-complete .mt-step-number {
  border-color: rgba(51, 209, 201, 0.72);
  background: linear-gradient(135deg, #1ea7ff, #33d1c9);
  color: #fff;
  box-shadow:
    var(--mt-loader-complete-glow),
    inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.mt-loader-step.is-active .mt-step-number {
  border-color: rgba(124, 77, 255, 0.78);
  background: linear-gradient(135deg, #7c4dff, #1ea7ff);
  color: #fff;
  box-shadow:
    var(--mt-loader-active-glow),
    0 0 52px rgba(30, 167, 255, 0.24),
    inset 0 1px 0 rgba(255, 255, 255, 0.18);
  animation: mt-loader-step-pulse 1.45s ease-in-out infinite;
}

.mt-loader-step.is-error .mt-step-number {
  border-color: rgba(239, 68, 68, 0.55);
  background: rgba(239, 68, 68, 0.13);
  color: #fca5a5;
  box-shadow: 0 0 28px rgba(239, 68, 68, 0.28);
}

@keyframes mt-loader-step-pulse {
  0%,
  100% {
    transform: scale(1);
    box-shadow:
      0 0 28px rgba(124, 77, 255, 0.42),
      0 0 44px rgba(30, 167, 255, 0.18);
  }

  50% {
    transform: scale(1.08);
    box-shadow:
      0 0 42px rgba(124, 77, 255, 0.66),
      0 0 68px rgba(30, 167, 255, 0.3);
  }
}

@media (max-width: 720px) {
  .mt-loader-steps {
    grid-template-columns: 1fr;
    gap: 16px;
    margin: 32px 0;
  }

  .mt-loader-steps::before {
    display: none;
  }

  .mt-loader-step {
    grid-template-columns: 52px 1fr;
    justify-items: start;
    text-align: left;
    column-gap: 14px;
  }

  .mt-step-number {
    width: 52px;
    height: 52px;
    grid-row: span 2;
  }

  .mt-loader-step small {
    max-width: none;
  }
}

:root[data-motion="reduced"] .mt-loader-step.is-active .mt-step-number {
  animation: none;
}

.mt-input:focus,
.mt-select:focus,
.mt-search:focus,
input:focus,
select:focus,
textarea:focus {
  border-color: var(--mt-border-strong);
  box-shadow: var(--mt-focus-ring);
}

/* Tables */
.mt-table-wrap,
.table-wrap,
.email-table-wrap,
.workspace-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--mt-border-subtle);
  border-radius: var(--mt-radius-lg);
}

.mt-table,
table,
.email-table,
.workspace-table,
.evidence-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

.mt-table th,
.mt-table td,
table th,
table td,
.email-table th,
.email-table td,
.workspace-table th,
.workspace-table td,
.evidence-table th,
.evidence-table td {
  padding: calc(13px * var(--mt-density-scale)) 14px;
  border-bottom: 1px solid var(--mt-border-subtle);
  text-align: left;
  vertical-align: top;
}

.mt-table th,
table th,
.email-table th,
.workspace-table th,
.evidence-table th {
  color: var(--mt-text-muted);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.mt-table td,
table td,
.email-table td,
.workspace-table td,
.evidence-table td {
  color: var(--mt-text-secondary);
  font-size: 0.9rem;
}

/* Badges and states */
.mt-badge,
.mt-pill,
.status-badge,
.status-pill,
.badge,
.chip,
.pill,
.type-pill,
.person-pill,
.status-chip {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  width: fit-content;
  gap: 6px;
  padding: 0 10px;
  border: 1px solid var(--mt-border-subtle);
  border-radius: 999px;
  background: var(--mt-surface-soft);
  color: var(--mt-text-secondary);
  font-size: 0.75rem;
  font-weight: 800;
}

.mt-badge.success,
.badge.success,
.status-chip-done,
.workspace-pill.success {
  color: var(--mt-status-success-text);
  background: var(--mt-status-success-bg);
  border-color: color-mix(in srgb, var(--mt-accent-success) 36%, transparent);
}

.mt-badge.warning,
.badge.warning,
.workspace-pill.warning {
  color: var(--mt-status-warning-text);
  background: var(--mt-status-warning-bg);
  border-color: color-mix(in srgb, var(--mt-accent-warning) 36%, transparent);
}

.mt-badge.danger,
.badge.danger {
  color: var(--mt-status-danger-text);
  background: var(--mt-status-danger-bg);
  border-color: color-mix(in srgb, var(--mt-accent-danger) 36%, transparent);
}

.mt-empty-state,
.mt-error-state,
.mt-loading-state,
.mt-state,
.empty-card,
.workspace-empty {
  border: 1px solid var(--mt-border-subtle);
  border-radius: var(--mt-radius-lg);
  background: var(--mt-bg-card);
  color: var(--mt-text-secondary);
  padding: var(--mt-card-padding);
}

.mt-error-state,
.mt-state-error {
  border-color: color-mix(in srgb, var(--mt-accent-danger) 44%, var(--mt-border-subtle));
}

.mt-empty-state strong,
.mt-error-state strong,
.mt-loading-state strong,
.mt-state strong,
.workspace-empty strong {
  display: block;
  margin-bottom: 6px;
  color: var(--mt-text-primary);
}

/* Sidebar helpers used by shared shell */
.mt-sidebar-brand,
.sidebar-brand,
.brand-block,
.brand {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-width: 0;
}

.mt-sidebar-brand-mark,
.brand-mark,
.avatar {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: var(--mt-radius-md);
  background: var(--mt-button-primary-bg);
  color: var(--mt-button-primary-text);
  font-weight: 850;
}

.mt-sidebar-brand-mark {
  width: 38px;
  height: 38px;
}

.mt-sidebar-brand-mark-image {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  display: block;
}

.mt-sidebar-brand strong,
.brand-title,
.brand-name {
  display: block;
  color: var(--mt-sidebar-text);
  font-weight: 850;
  letter-spacing: -0.04em;
}

.mt-sidebar-brand small,
.brand-copy,
.brand-subtitle {
  display: block;
  margin-top: 4px;
  color: var(--mt-sidebar-muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.mt-sidebar-section,
.sidebar-nav-section,
.sidebar-section {
  display: grid;
  gap: 10px;
  margin-top: 22px;
}

.mt-sidebar-section-title,
.sidebar-section-title,
.sidebar-label,
.sidebar-section-head {
  margin: 0;
  color: var(--mt-sidebar-muted);
  font-size: 0.7rem;
  font-weight: 850;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.mt-sidebar-new,
.sidebar-cta {
  width: 100%;
  min-height: 46px;
  margin-top: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border-radius: var(--mt-radius-md);
  background: var(--mt-button-primary-bg);
  color: var(--mt-button-primary-text);
  font-weight: 800;
}

.mt-sidebar-link,
.nav-link,
.workspace-nav-link,
.domain-case-link,
.case-link,
.active-case-link {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: var(--mt-radius-md);
  color: var(--mt-sidebar-muted);
  overflow: hidden;
}

.mt-sidebar-link span,
.nav-link span,
.domain-case-link span,
.case-link span,
.active-case-link span,
.mt-cluster-link span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mt-sidebar-link:hover,
.nav-link:hover,
.workspace-nav-link:hover,
.domain-case-link:hover,
.case-link:hover,
.active-case-link:hover,
.mt-investigation-parent:hover,
.mt-cluster-link:hover {
  background: color-mix(in srgb, var(--mt-sidebar-text) 8%, transparent);
  color: var(--mt-sidebar-text);
}

.mt-sidebar-link.is-active,
.nav-link.is-active,
.nav-link.active,
.workspace-nav-link.is-active,
.domain-case-link.is-active,
.domain-case-link.active,
.case-link.is-active,
.case-link.active,
.active-case-link.is-active,
.active-case-link.active {
  background: var(--mt-nav-active-bg);
  border-color: color-mix(in srgb, var(--mt-accent-primary) 44%, transparent);
  color: var(--mt-sidebar-text);
}

.mt-investigation-tree {
  display: grid;
  gap: 8px;
}

.mt-investigation-group {
  border: 1px solid color-mix(in srgb, var(--mt-sidebar-text) 10%, transparent);
  border-radius: var(--mt-radius-md);
  background: color-mix(in srgb, var(--mt-sidebar-text) 4%, transparent);
  overflow: hidden;
}

.mt-investigation-group.is-current {
  border-color: color-mix(in srgb, var(--mt-accent-primary) 62%, transparent);
}

.mt-investigation-head,
.mt-investigation-parent,
.mt-investigation-toggle,
.mt-cluster-link {
  min-width: 0;
  display: flex;
  align-items: center;
}

.mt-investigation-head {
  justify-content: space-between;
  gap: 8px;
}

.mt-investigation-parent {
  flex: 1;
  gap: 10px;
  min-height: 42px;
  padding: 0 10px;
  color: var(--mt-sidebar-text);
  font-weight: 800;
}

.mt-investigation-toggle {
  width: 36px;
  height: 36px;
  justify-content: center;
  border: 0;
  background: transparent;
  color: var(--mt-sidebar-muted);
}

.mt-cluster-list {
  display: grid;
  gap: 4px;
  padding: 0 8px 10px 28px;
}

.mt-cluster-link {
  position: relative;
  gap: 8px;
  min-height: 34px;
  padding: 0 8px;
  border-radius: 10px;
  color: var(--mt-sidebar-muted);
  font-size: 0.82rem;
}

.mt-cluster-link.is-active {
  background: var(--mt-nav-active-bg);
  color: var(--mt-sidebar-text);
}

.mt-sidebar-empty {
  margin: 0;
  padding: 8px 10px;
  color: var(--mt-sidebar-muted);
  font-size: 0.82rem;
}

.mt-sidebar-case {
  border: 1px solid color-mix(in srgb, var(--mt-sidebar-text) 10%, transparent);
  border-radius: 13px;
  background: color-mix(in srgb, var(--mt-sidebar-text) 4%, transparent);
  padding: 8px;
}

.mt-sidebar-case + .mt-sidebar-case {
  margin-top: 8px;
}

.mt-sidebar-case-link {
  display: grid;
  gap: 2px;
  color: var(--mt-sidebar-text);
  text-decoration: none;
}

.mt-sidebar-case-link strong {
  font-size: 13px;
}

.mt-sidebar-case-link span {
  color: var(--mt-sidebar-muted);
  font-size: 11px;
}

.mt-sidebar-issues {
  display: grid;
  gap: 5px;
  margin-top: 8px;
}

.mt-sidebar-issue {
  display: grid;
  grid-template-columns: 8px minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px;
  min-height: 28px;
  border-radius: 9px;
  padding: 0 7px;
  color: var(--mt-sidebar-muted);
  text-decoration: none;
}

.mt-sidebar-issue:hover,
.mt-sidebar-issue.is-active {
  background: color-mix(in srgb, var(--mt-sidebar-text) 9%, transparent);
  color: var(--mt-sidebar-text);
}

.mt-sidebar-issue span:not(.mt-sidebar-issue-dot) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
}

.mt-sidebar-issue small {
  color: inherit;
  font-size: 10px;
  opacity: 0.76;
}

.mt-sidebar-issue-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--mt-accent-primary);
}

.mt-sidebar-user,
.sidebar-user,
.sidebar-footer {
  margin-top: 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 12px;
  border: 1px solid color-mix(in srgb, var(--mt-sidebar-text) 10%, transparent);
  border-radius: var(--mt-radius-lg);
  background: color-mix(in srgb, var(--mt-sidebar-text) 5%, transparent);
}

.mt-sidebar-avatar,
.avatar {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  overflow: hidden;
}

.mt-sidebar-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.mt-sidebar-avatar span {
  display: grid;
  place-items: center;
}

.mt-sidebar-user-copy,
.sidebar-user div {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.mt-sidebar-user-copy strong,
.sidebar-user strong,
.sidebar-user p {
  margin: 0;
  color: var(--mt-sidebar-text);
  font-weight: 800;
}

.mt-sidebar-user-copy span,
.sidebar-user span {
  color: var(--mt-sidebar-muted);
  font-size: 0.78rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mt-sidebar-signout {
  width: fit-content;
  min-height: auto;
  border: 0;
  background: transparent;
  color: var(--mt-accent-secondary);
  padding: 2px 0;
  font-size: 0.76rem;
}

/* Toasts, drawers, quota, mobile sidebar */
.mt-toast-root {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 80;
  display: grid;
  gap: 10px;
  max-width: min(420px, calc(100vw - 32px));
}

.mt-toast {
  border: 1px solid var(--mt-border-subtle);
  border-left: 4px solid var(--mt-accent-primary);
  border-radius: var(--mt-radius-md);
  background: var(--mt-bg-card-elevated);
  color: var(--mt-text-primary);
  box-shadow: var(--mt-card-shadow);
  padding: 12px 14px;
}

.mt-toast-success { border-left-color: var(--mt-accent-success); }
.mt-toast-error { border-left-color: var(--mt-accent-danger); }
.mt-toast-warning { border-left-color: var(--mt-accent-warning); }
.mt-toast.is-hiding {
  opacity: 0;
  transform: translateY(4px);
  transition: opacity var(--mt-motion-duration) ease, transform var(--mt-motion-duration) ease;
}

.mt-skeleton-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--mt-accent-primary);
  animation: mt-pulse 1.2s ease-in-out infinite;
}

@keyframes mt-pulse {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}

.mt-quota-meter {
  display: grid;
  gap: 8px;
  width: 100%;
}

.mt-quota-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: color-mix(in srgb, var(--mt-text-muted) 22%, transparent);
}

.mt-quota-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--mt-accent-primary), var(--mt-accent-success));
}

.mt-drawer-shell {
  position: fixed;
  inset: 0;
  z-index: 70;
  pointer-events: none;
}

.mt-drawer-shell.is-open {
  pointer-events: auto;
}

.mt-drawer-overlay {
  position: absolute;
  inset: 0;
  background: var(--mt-overlay);
  opacity: 0;
  transition: opacity var(--mt-motion-duration) ease;
}

.mt-drawer-shell.is-open .mt-drawer-overlay {
  opacity: 1;
}

.mt-drawer {
  position: absolute;
  top: 0;
  right: 0;
  width: min(460px, 100vw);
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: var(--mt-bg-card-elevated);
  border-left: 1px solid var(--mt-border-subtle);
  box-shadow: var(--mt-card-shadow);
  transform: translateX(100%);
  transition: transform var(--mt-motion-duration) ease;
}

.mt-drawer-shell.is-open .mt-drawer {
  transform: translateX(0);
}

.mt-drawer header,
.mt-drawer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--mt-border-subtle);
}

.mt-drawer-actions {
  justify-content: flex-end;
  border-top: 1px solid var(--mt-border-subtle);
  border-bottom: 0;
}

.mt-drawer-body {
  overflow: auto;
  padding: 16px;
}

.mt-sidebar-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 65;
  width: 42px;
  height: 42px;
  border: 1px solid var(--mt-border-subtle);
  border-radius: var(--mt-radius-md);
  background: var(--mt-bg-card-elevated);
  color: var(--mt-text-primary);
}

.mt-sidebar-overlay {
  display: none;
}

@media (max-width: 1180px) {
  :root { --mt-sidebar-width: 260px; }
  .dashboard-grid,
  .overview-grid,
  .content-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 980px) {
  .mt-app-shell,
  .workspace-shell,
  .case-shell,
  .app-shell,
  .case-app-shell {
    display: block;
  }

  .mt-main,
  .workspace-main,
  .case-main,
  .main,
  .main-area {
    padding: calc(var(--mt-content-padding) + 48px) 18px 28px;
  }

  .mt-sidebar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .mt-sidebar,
  .mt-global-sidebar,
  .workspace-sidebar,
  .case-sidebar,
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 64;
    width: min(300px, 88vw);
    min-width: 0;
    height: 100vh;
    transform: translateX(-105%);
    transition: transform var(--mt-motion-duration) ease;
  }

  .is-sidebar-open .mt-sidebar,
  .is-sidebar-open .mt-global-sidebar,
  .is-sidebar-open .workspace-sidebar,
  .is-sidebar-open .case-sidebar,
  .is-sidebar-open .sidebar {
    transform: translateX(0);
  }

  .mt-sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 63;
    background: var(--mt-overlay);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--mt-motion-duration) ease;
  }

  .is-sidebar-open .mt-sidebar-overlay {
    opacity: 1;
    pointer-events: auto;
  }

  .mt-page-header,
  .page-header,
  .page-heading,
  .mt-spread,
  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (max-width: 720px) {
  .mt-main,
  .workspace-main,
  .case-main,
  .main,
  .main-area {
    padding-inline: 16px;
  }

  .mt-grid-2,
  .mt-grid-3,
  .mt-grid-4,
  .metric-grid,
  .stats-grid,
  .case-stats-grid {
    grid-template-columns: 1fr;
  }

  .mt-button,
  .mt-button-primary,
  .mt-button-secondary,
  .primary-action,
  .secondary-action,
  .primary-button,
  .secondary-button {
    width: 100%;
  }
}
