/*
 * modules_v3.css — Mobile-First Stitch Intelligence Hub Module UI (V3)
 *
 * Verträge:
 *  - Geladen über modules/page-grid.tpl via tenant_asset_url('css/modules_v3.css').
 *  - 0 rohe Hex-Literale (ausschließlich semantische Tokens über var(--color-*/--ts-*/--tsec-*)).
 *  - Hell-Modus ausschließlich über html[data-bs-theme="light"].
 *  - Touch-Targets >= 48px auf Mobilgeräten (WCAG / Mobile-First).
 *  - Kein horizontaler Overflow auf 390px Viewports (min-width: 0, overflow-x: clip).
 */

.ts-page-grid,
.cms-page-container {
  width: 100%;
  max-width: 100%;
  overflow-x: clip;
}

.ts-page-grid .col-main,
.ts-page-grid .sidebar-col {
  min-width: 0;
  container-type: inline-size;
}

.ts-module-shell {
  --tsec-mod-bg: var(--color-surface);
  --tsec-mod-bg-elev: var(--color-surface-elevated);
  --tsec-mod-border: var(--color-border);
  --tsec-mod-text: var(--color-text);
  --tsec-mod-muted: var(--color-text-muted);
  --tsec-mod-accent: var(--color-accent);
  --tsec-mod-accent-strong: var(--color-accent-hover);
  --tsec-mod-cyan: var(--color-accent-cyan);
  --tsec-mod-radius: var(--ts-radius-lg);
  --tsec-mod-radius-sm: var(--ts-radius-md);
  --tsec-mod-shadow: var(--ts-shadow-sm);
  --tsec-mod-shadow-hover: var(--ts-shadow-md);

  position: relative;
  min-width: 0;
  max-width: 100%;
  overflow-x: clip;
  background: var(--tsec-mod-bg);
  border: 1px solid var(--tsec-mod-border);
  border-radius: var(--tsec-mod-radius);
  color: var(--tsec-mod-text);
  padding: var(--ts-space-4);
  margin-bottom: var(--ts-space-4);
  box-shadow: var(--tsec-mod-shadow);
  font-family: var(--ts-font-sans);
  font-size: var(--ts-text-md);
  line-height: 1.6;
  transition: border-color var(--ts-transition-fast), box-shadow var(--ts-transition-fast);
}

@media (min-width: 768px) {
  .ts-module-shell {
    padding: var(--ts-space-6);
    margin-bottom: var(--ts-space-5);
  }
}

.ts-module-shell.cms-module-box--density-compact {
  padding: var(--ts-space-3);
  margin-bottom: var(--ts-space-3);
}

@media (min-width: 768px) {
  .ts-module-shell.cms-module-box--density-compact {
    padding: var(--ts-space-4);
  }
}

html[data-bs-theme="light"] .ts-module-shell {
  --tsec-mod-bg: var(--color-surface);
  --tsec-mod-bg-elev: var(--color-surface-elevated);
  --tsec-mod-border: var(--color-border);
  --tsec-mod-text: var(--color-text);
  --tsec-mod-muted: var(--color-text-muted);
  --tsec-mod-accent: var(--color-accent);
  --tsec-mod-accent-strong: var(--color-accent-hover);
  box-shadow: var(--ts-shadow-sm);
}

/* Typography & overflow safety inside modules */
.ts-module-shell h1,
.ts-module-shell h2,
.ts-module-shell h3,
.ts-module-shell h4,
.ts-module-shell .cms-brand-title {
  font-family: var(--ts-font-heading);
  color: var(--tsec-mod-text);
  line-height: 1.28;
  overflow-wrap: anywhere;
}

.ts-module-shell p,
.ts-module-shell li,
.ts-module-shell td,
.ts-module-shell th {
  overflow-wrap: anywhere;
}

.ts-module-shell img,
.ts-module-shell video,
.ts-module-shell iframe {
  max-width: 100%;
  height: auto;
}

/* Responsive tables inside modules */
.ts-module-shell .ts-module-table-scroll,
.ts-module-shell .table-responsive {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Horizontal scrollable chip & filter bars on mobile */
.ts-module-chips,
.ts-module-filter-bar,
.ts-module-shell .rss-filter-views,
.ts-module-shell .nav-pills {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: var(--ts-space-2);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  max-width: 100%;
  padding-bottom: var(--ts-space-1);
}

.ts-module-chips::-webkit-scrollbar,
.ts-module-filter-bar::-webkit-scrollbar,
.ts-module-shell .rss-filter-views::-webkit-scrollbar,
.ts-module-shell .nav-pills::-webkit-scrollbar {
  display: none;
}

.ts-module-chips > *,
.ts-module-filter-bar > *,
.ts-module-shell .rss-filter-views > *,
.ts-module-shell .nav-pills > * {
  flex-shrink: 0;
}

@media (min-width: 768px) {
  .ts-module-chips,
  .ts-module-filter-bar,
  .ts-module-shell .rss-filter-views,
  .ts-module-shell .nav-pills {
    flex-wrap: wrap;
    overflow-x: visible;
    padding-bottom: 0;
  }
}

/* Touch targets >= 48px on mobile for module actions, chips, forms & popout */
.ts-module-shell .ts-module-action,
.ts-module-shell .ts-module-chip,
.ts-module-shell .cms-brand-footer .btn,
.ts-module-shell .acp-quick-toggle,
.ts-module-shell .btn,
.ts-module-shell .page-link,
.ts-module-shell .form-control,
.ts-module-shell .form-select {
  min-height: var(--ts-touch-target-min-mobile, 48px);
}

.ts-module-shell .cms-module-popout-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--ts-radius-pill);
  border: 1px solid var(--tsec-mod-border);
  background: var(--tsec-mod-bg-elev);
  color: var(--tsec-mod-text);
  transition: border-color var(--ts-transition-fast), background-color var(--ts-transition-fast);
}

@media (max-width: 767.98px) {
  .ts-module-shell .cms-module-popout-trigger {
    min-width: var(--ts-touch-target-min-mobile, 48px);
    min-height: var(--ts-touch-target-min-mobile, 48px);
  }
}

.ts-module-shell .cms-module-popout-trigger:hover,
.ts-module-shell .cms-module-popout-trigger:focus-visible {
  border-color: var(--tsec-mod-accent);
  box-shadow: var(--ts-focus-ring);
  outline: none;
}

@media (min-width: 768px) {
  .ts-module-shell .btn-sm,
  .ts-module-shell .acp-quick-toggle {
    min-height: 40px;
  }
}

/* Module cards grid helper */
.ts-module-cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--ts-space-3);
}

@media (min-width: 768px) {
  .ts-module-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--ts-space-4);
  }
}

@media (min-width: 1200px) {
  .ts-module-cards--3col {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.ts-module-card {
  background: var(--tsec-mod-bg-elev);
  border: 1px solid var(--tsec-mod-border);
  border-radius: var(--tsec-mod-radius-sm);
  padding: var(--ts-space-4);
  color: var(--tsec-mod-text);
  min-width: 0;
  transition: transform var(--ts-transition-fast), border-color var(--ts-transition-fast);
}

.ts-module-card:hover {
  border-color: var(--tsec-mod-accent);
}

/* Brand Header & Footer responsive polish */
.ts-module-shell .cms-brand-header {
  border-bottom-color: var(--tsec-mod-border);
}

.ts-module-shell .cms-brand-footer {
  border-top-color: var(--tsec-mod-border);
}

.ts-module-shell .mod-brand-badge {
  background: color-mix(in srgb, var(--tsec-mod-accent) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--tsec-mod-accent) 40%, transparent);
  color: var(--tsec-mod-cyan);
}

html[data-bs-theme="light"] .ts-module-shell .mod-brand-badge {
  background: color-mix(in srgb, var(--tsec-mod-accent) 10%, transparent);
  color: var(--tsec-mod-accent-strong);
}

/* Sidebar collapse toggle & upgrade teaser Light/Dark parity */
@media (max-width: 991.98px) {
  .ts-page-grid .sidebar-collapse-toggle {
    min-height: var(--ts-touch-target-min-mobile, 48px);
  }
}

.ts-page-grid .sidebar-collapse-toggle {
  background: var(--color-surface-elevated);
  border-color: var(--color-border);
  color: var(--color-text);
}

html[data-bs-theme="light"] .ts-page-grid .sidebar-collapse-toggle {
  background: var(--color-surface-elevated);
  border-color: var(--color-border);
  color: var(--color-text);
}

.ts-upgrade-teaser {
  background: var(--color-surface);
  color: var(--color-text);
  border-radius: var(--ts-radius-lg);
}

.ts-upgrade-teaser__title {
  color: var(--color-text);
}

.ts-upgrade-teaser__body {
  color: var(--color-text-muted);
  max-width: 520px;
}

.ts-upgrade-teaser__icon {
  font-size: 2.5rem;
  margin-bottom: var(--ts-space-2);
}

html[data-bs-theme="light"] .ts-upgrade-teaser {
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--ts-shadow-sm);
}

html[data-bs-theme="light"] .ts-upgrade-teaser__title {
  color: var(--color-text);
}

html[data-bs-theme="light"] .ts-upgrade-teaser__body {
  color: var(--color-text-muted);
}
