/* Shared mobile component primitives for Phase 2+. */
:root {
  --tm-mobile-component-gap: 10px;
  --tm-mobile-sheet-radius: 18px;
}

.tm-card-expanded {
  display: block;
}

.tm-sheet {
  display: contents;
}

.tm-sheet__backdrop,
.tm-sheet__panel {
  display: none;
}

@media (min-width: 769px) {
  .tm-mobile-card-only,
  .tm-sticky-action-bar,
  .tm-mobile-page-header {
    display: none !important;
  }

  .tm-sheet__backdrop {
    position: fixed;
    inset: 0;
    z-index: 1290;
    background: rgba(15, 23, 42, 0.42);
    backdrop-filter: blur(2px);
  }

  .tm-sheet__panel {
    position: fixed;
    top: 50%;
    left: 50%;
    z-index: 1300;
    width: min(560px, 92vw);
    max-height: min(78vh, 820px);
    display: none;
    flex-direction: column;
    transform: translate(-50%, -50%);
    border: 1px solid var(--border);
    border-radius: var(--tm-mobile-sheet-radius);
    background: var(--panel);
    color: var(--fg);
    box-shadow: 0 18px 42px rgba(15, 23, 42, 0.24);
    overflow: hidden;
  }

  .tm-sheet.is-open .tm-sheet__backdrop,
  .tm-sheet.is-open .tm-sheet__panel {
    display: flex;
  }

  .tm-sheet__header {
    min-height: 56px;
    padding: 14px 16px 10px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    flex-shrink: 0;
  }

  .tm-sheet__body {
    min-height: 0;
    overflow-y: auto;
    padding: 14px 16px;
  }

  .tm-sheet__footer {
    padding: 10px 16px 14px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    flex-shrink: 0;
    background: var(--panel);
  }
}

@media (max-width: 768px) {
  body.tm-sheet-open {
    overflow: hidden;
    touch-action: none;
  }

  .tm-mobile-page-header,
  .page-header-bar,
  .portfolio-header,
  .decision-board-header,
  .analytics-header,
  .user-settings-header,
  .watchlists-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    margin: 0 0 12px;
  }

  .tm-mobile-page-header h1,
  .page-header-bar h1,
  .portfolio-header h1,
  .decision-board-header h1,
  .analytics-header h1,
  .user-settings-header h1,
  .watchlists-header h1 {
    margin: 0;
    font-size: 22px;
    line-height: 1.15;
  }

  .tm-mobile-page-header p,
  .page-header-bar p,
  .portfolio-header p,
  .decision-board-header p,
  .analytics-header p,
  .user-settings-header p,
  .watchlists-header p {
    margin: 4px 0 0;
    font-size: 13px;
    line-height: 1.45;
    color: var(--muted);
  }

  .tm-mobile-card-list,
  .mobile-cards {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--tm-mobile-component-gap);
  }

  .tm-mobile-card,
  .mobile-card {
    position: relative;
    min-width: 0;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--panel);
    color: var(--fg);
    box-shadow: var(--shadow-sm);
  }

  .tm-mobile-card--interactive,
  .mobile-card[role="button"],
  .mobile-card[data-symbol] {
    cursor: pointer;
  }

  .tm-mobile-card--interactive:active,
  .mobile-card:active {
    border-color: var(--accent);
  }

  .tm-mobile-card--success {
    border-left: 3px solid var(--success);
  }

  .tm-mobile-card--warning {
    border-left: 3px solid var(--warning);
  }

  .tm-mobile-card--danger {
    border-left: 3px solid var(--danger);
  }

  .tm-mobile-card__eyebrow {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  .tm-mobile-card__title,
  .mobile-card-header {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    margin-bottom: 8px;
  }

  .tm-mobile-card__title strong,
  .mobile-card-sym {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--fg-strong);
    font-size: 15px;
    font-weight: 800;
  }

  .tm-mobile-card__subtitle,
  .mobile-card-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--muted);
    font-size: 12px;
  }

  .tm-mobile-card__metrics {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    margin: 8px 0;
  }

  .tm-mobile-card__metric {
    display: grid;
    gap: 1px;
  }

  .tm-mobile-card__metric span,
  .mobile-card-cell .mc-label {
    color: var(--muted);
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 0.05em;
    text-transform: uppercase;
  }

  .tm-mobile-card__metric strong,
  .mobile-card-cell .mc-value {
    color: var(--fg-strong);
    font-size: 13px;
    font-weight: 750;
    font-variant-numeric: tabular-nums;
  }

  .tm-mobile-card__grid,
  .mobile-card-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px 10px;
  }

  .tm-mobile-card__actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 10px;
  }

  .tm-mobile-card__actions .btn {
    flex: 1 1 120px;
  }

  .tm-mobile-card__details,
  .mobile-card-detail {
    display: none;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: 13px;
    line-height: 1.45;
  }

  .tm-mobile-card.is-expanded .tm-mobile-card__details,
  .mobile-card.expanded .mobile-card-detail {
    display: block;
  }

  .tm-filter-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 12px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .tm-filter-bar::-webkit-scrollbar {
    display: none;
  }

  .tm-filter-chip,
  .tm-filter-trigger {
    min-height: 36px;
    padding: 7px 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    flex: 0 0 auto;
    background: var(--panel);
    color: var(--fg);
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
  }

  .tm-filter-chip.is-active,
  .tm-filter-trigger.is-active {
    border-color: rgba(15, 118, 110, 0.28);
    background: var(--accent-light);
    color: var(--accent);
  }

  .tm-filter-summary {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.45;
  }

  .tm-filter-section {
    display: grid;
    gap: 8px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
  }

  .tm-filter-section:last-child {
    border-bottom: none;
  }

  .tm-sheet__backdrop {
    position: fixed;
    inset: 0;
    z-index: 1290;
    background: rgba(15, 23, 42, 0.46);
    backdrop-filter: blur(2px);
  }

  .tm-sheet__panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1300;
    max-height: 85dvh;
    display: none;
    flex-direction: column;
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: var(--tm-mobile-sheet-radius) var(--tm-mobile-sheet-radius) 0 0;
    background: var(--panel);
    color: var(--fg);
    box-shadow: 0 -18px 42px rgba(15, 23, 42, 0.24);
    overflow: hidden;
  }

  .tm-sheet.is-open .tm-sheet__backdrop,
  .tm-sheet.is-open .tm-sheet__panel {
    display: flex;
  }

  .tm-sheet__header {
    min-height: 54px;
    padding: 14px 16px 10px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    flex-shrink: 0;
  }

  .tm-sheet__header h2,
  .tm-sheet__header h3 {
    margin: 0;
    color: var(--fg-strong);
    font-size: 17px;
    line-height: 1.2;
  }

  .tm-sheet__header p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.45;
  }

  .tm-sheet__body {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 14px 16px;
  }

  .tm-sheet__footer {
    padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    flex-shrink: 0;
    background: var(--panel);
  }

  .tm-sheet__footer .btn,
  .tm-sheet__footer button {
    flex: 1 1 120px;
  }

  .tm-sticky-action-bar {
    position: sticky;
    bottom: calc(var(--tm-mobile-bottomnav-h, 66px) + env(safe-area-inset-bottom) + 8px);
    z-index: 900;
    display: flex;
    gap: 8px;
    align-items: center;
    margin: 12px 0 0;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: color-mix(in srgb, var(--panel) 96%, transparent);
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(12px);
  }

  .tm-sticky-action-bar .btn,
  .tm-sticky-action-bar button {
    flex: 1 1 0;
  }

  .tm-sticky-action-bar--decision {
    border-color: rgba(15, 118, 110, 0.24);
  }

  .tm-sticky-action-bar--danger {
    border-color: rgba(239, 68, 68, 0.26);
    background: color-mix(in srgb, var(--danger-bg) 46%, var(--panel));
  }

  .tm-mobile-table-scroll,
  .table-responsive,
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .tm-mobile-card-only {
    display: grid;
  }

  .tm-desktop-table-only {
    display: none !important;
  }

  html[data-theme='dark'] .tm-sheet__panel,
  html[data-theme='dark'] .tm-sticky-action-bar {
    box-shadow: 0 -18px 42px rgba(0, 0, 0, 0.34);
  }
}
