/* Mobilní optimalizace + čitelnost světlý/tmavý režim (SUZ, TK, admin, veřejný web) */

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

.page-body,
.admin-body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Čitelnost obsahu v obou režimech ── */
.site-page-body,
.prose,
.rich-text-body,
.shared-event-detail-desc-body {
  color: var(--ink);
  line-height: 1.65;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.site-page-body :where(h1, h2, h3, h4, h5, h6),
.prose :where(h1, h2, h3, h4, h5, h6),
.rich-text-body :where(h1, h2, h3, h4, h5, h6) {
  color: var(--text);
}

.site-page-body :where(p, li, td, th, label, figcaption),
.prose :where(p, li),
.rich-text-body :where(p, li) {
  color: var(--ink-soft);
}

.site-page-body a,
.prose a,
.rich-text-body a {
  color: var(--accent-link);
  text-decoration: underline;
  text-underline-offset: 0.12em;
}

.site-page-body code,
.prose code,
.rich-text-body code {
  background: var(--surface-chip);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 0.35rem;
  padding: 0.1em 0.35em;
  font-size: 0.92em;
}

html[data-theme="light"] .site-page-body blockquote,
html[data-theme="light"] .prose blockquote,
html[data-theme="light"] .rich-text-body blockquote {
  color: var(--text-muted);
  background: var(--bg-hover);
}

html:not([data-theme="light"]) .site-page-body blockquote,
html:not([data-theme="light"]) .prose blockquote,
html:not([data-theme="light"]) .rich-text-body blockquote {
  color: var(--text-soft);
  background: var(--surface-panel);
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--text-muted);
  opacity: 1;
}

.data-table th {
  color: var(--ink-muted);
}

.data-table td {
  color: var(--ink);
}

html[data-theme="light"] .data-table tbody tr:nth-child(even) {
  background: rgba(247, 247, 250, 0.85);
}

html:not([data-theme="light"]) .data-table tbody tr:nth-child(even) {
  background: rgba(148, 163, 184, 0.04);
}

.card,
.card-shadow,
.table-shell {
  color: var(--ink);
}

.text-ink-muted,
.page-lead {
  color: var(--ink-muted);
}

/* ── Horizontální tabulky — nápověda posunu ── */
.table-scroll-hint,
.challenge-activities-scroll,
.shared-event-admin-participants-scroll,
.table-shell:not(.table-shell--no-scroll) {
  position: relative;
}

@media (max-width: 767px) {
  .table-scroll-hint::after,
  .challenge-activities-scroll::after,
  .shared-event-admin-participants-scroll::after {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    width: 2rem;
    height: 100%;
    pointer-events: none;
    background: linear-gradient(90deg, transparent, var(--bg-card));
    opacity: 0.95;
  }
}

/* ── SUZ — tabulky aktivit (mobil i desktop) ── */
.suz-mobile-only {
  display: none !important;
}

.suz-my-activity-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
}

.suz-my-activity-card .card-body {
  padding: 1rem;
}

.suz-my-activity-card-km {
  font-size: 1.125rem;
  font-weight: 800;
  color: var(--brand);
  font-variant-numeric: tabular-nums;
}

.suz-my-activity-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.suz-all-activity-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  padding: 1rem;
}

.suz-all-activity-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
}

.suz-all-activity-card-km {
  font-weight: 800;
  color: var(--brand);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.suz-toolbar-sticky {
  background: color-mix(in srgb, var(--bg-page) 92%, transparent);
  backdrop-filter: blur(8px);
}

html[data-theme="light"] .suz-toolbar-sticky {
  background: color-mix(in srgb, var(--bg-page) 94%, transparent);
}

/* ── TK veřejný ── */
.page-tk .tk-page-tabs {
  scrollbar-gutter: stable;
  overscroll-behavior-x: contain;
}

@media (max-width: 767px) {
  .page-tk .tk-page-tabs {
    mask-image: linear-gradient(90deg, #000 92%, transparent);
  }
}

.page-tk .shared-event-detail-desc-body,
.page-tk .site-page-body {
  font-size: 1rem;
}

.page-tk .tk-hero-title,
.page-tk .tk-page-hero-title {
  text-wrap: balance;
}

/* ── Mobil (≤767px) ── */
@media (max-width: 767px) {
  .page-suz .suz-activities-table {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .page-suz .suz-activities-table .challenge-activities-scroll {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .page-suz .suz-activities-table .challenge-activities-scroll .data-table {
    width: max-content;
    min-width: 100%;
  }

  .form-input,
  .form-select,
  .form-textarea,
  input[type="search"].form-input {
    font-size: 16px;
    min-height: 2.75rem;
  }

  .btn,
  .btn-sm,
  .site-theme-toggle,
  .admin-shell-menu-toggle {
    min-height: 2.75rem;
  }

  .btn-sm {
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
  }

  .admin-page-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .admin-page-toolbar > .flex,
  .admin-page-toolbar .flex.flex-wrap {
    width: 100%;
  }

  .admin-page-toolbar .btn {
    flex: 0 1 auto;
    justify-content: center;
  }

  .admin-shell-content.page-main {
    padding: 1rem 0.75rem 2rem;
    padding-left: max(0.75rem, env(safe-area-inset-left));
    padding-right: max(0.75rem, env(safe-area-inset-right));
  }

  .admin-form-wide,
  .admin-form-grid {
    max-width: 100%;
  }

  .admin-form-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .suz-challenge-picker-row {
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.35rem 0.5rem;
  }

  .page-suz .suz-challenge-picker-label {
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--text-muted);
    flex: 0 0 auto;
  }

  .page-suz .suz-challenge-picker-row .form-input,
  .page-suz .suz-challenge-picker-select {
    width: auto;
    flex: 1 1 auto;
    min-width: 0;
    min-height: 2rem;
    padding: 0.15rem 1.75rem 0.15rem 0.45rem;
    font-size: 1rem;
    line-height: 1.25;
  }

  .page-suz .suz-challenge-picker--toolbar {
    padding: 0.35rem 0.5rem 0.4rem;
  }

  .page-suz .suz-toolbar-inner {
    padding: 0.4rem 0.5rem;
  }

  .page-suz .suz-toolbar-sticky {
    margin-bottom: 0.5rem;
    padding: 0.15rem 0;
  }

  .page-suz .suz-toolbar-actions {
    gap: 0.25rem 0.35rem;
  }

  .page-suz .suz-toolbar .btn,
  .page-suz .suz-toolbar .btn-sm {
    min-height: 1.75rem;
    padding: 0.2rem 0.45rem;
    font-size: 0.6875rem;
    line-height: 1.2;
    flex: 0 1 auto;
  }

  .page-suz .suz-page-brand {
    margin-bottom: 0.65rem !important;
  }

  .page-suz .suz-page-brand-logo {
    max-height: 2.25rem;
  }

  .page-suz .suz-page-brand-fallback {
    font-size: 1.125rem;
  }

  .suz-toolbar-sticky .flex.flex-wrap {
    gap: 0.35rem;
  }

  .page-suz .page-main,
  .page-tk .page-main,
  .page-body-dashboard .page-main {
    padding-bottom: max(2rem, env(safe-area-inset-bottom));
    max-width: 100%;
    min-width: 0;
    overflow-x: clip;
  }

  .page-tk .table-shell,
  .page-tk .records-table-scroll,
  .page-tk .tk-startlist-scroll,
  .page-tk .tk-editions-picker,
  .page-tk .shared-event-register-tabs {
    overscroll-behavior-x: contain;
  }

  .page-body-dashboard .dashboard-stat-card,
  .page-body-dashboard .dashboard-challenge-card {
    min-width: 0;
  }

  .flash {
    font-size: 0.9375rem;
    line-height: 1.45;
  }

  .admin-kpi-grid,
  .tk-payment-kpi-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .admin-list-table-card .data-table {
    min-width: 32rem;
  }

  .page-tk .tk-page-content.card-body {
    padding: 1rem 0.875rem;
  }

  .page-tk .shared-event-detail-register-form fieldset {
    padding: 0;
    border: 0;
  }

  .privacy-banner-inner {
    margin-bottom: env(safe-area-inset-bottom);
  }
}

@media (min-width: 768px) {
  .suz-mobile-only {
    display: none !important;
  }
}

/* ── Admin mobil (≤900px) ── */
@media (max-width: 1100px) {
  .admin-shell {
    --admin-sidebar-width: 14.5rem;
  }

  .admin-shell .page-title,
  .admin-page-title {
    font-size: clamp(1.25rem, 4vw, 1.75rem);
  }

  .admin-page-toolbar,
  .admin-page-header {
    gap: 0.75rem;
  }
}

@media (max-width: 900px) {
  .admin-body.admin-shell {
    overflow-x: clip;
  }

  .admin-shell-topbar {
    padding-left: max(0.75rem, env(safe-area-inset-left));
    padding-right: max(0.75rem, env(safe-area-inset-right));
    flex-wrap: wrap;
    height: auto;
    min-height: var(--admin-topbar-height);
    row-gap: 0.5rem;
  }

  .admin-shell-topbar-left {
    flex: 1 1 auto;
    min-width: 0;
  }

  .admin-shell-topbar-brand {
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: min(12rem, 42vw);
  }

  .admin-shell-topbar-right {
    flex: 0 1 auto;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.35rem 0.5rem;
    margin-left: auto;
  }

  .admin-shell-version-link {
    display: none;
  }

  .admin-shell-content.page-main {
    padding: 1rem max(0.75rem, env(safe-area-inset-left)) max(1.5rem, env(safe-area-inset-bottom)) max(0.75rem, env(safe-area-inset-right));
    max-width: 100%;
    min-width: 0;
    overflow-x: clip;
  }

  .admin-shell-user-chip-meta {
    display: none;
  }

  .admin-kpi-grid,
  .tk-payment-kpi-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .admin-stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .admin-form,
  .admin-form-wide,
  .admin-form-grid {
    max-width: 100%;
  }

  .admin-form-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .admin-shell .grid.gap-4,
  .admin-shell .grid.gap-6 {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .admin-shell .table-shell,
  .admin-shell .admin-list-table-shell,
  .admin-shell .records-table-scroll,
  .admin-shell .shared-event-admin-participants-scroll {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
  }

  .admin-shell .table-shell .data-table,
  .admin-shell .admin-list-table-shell .data-table,
  .admin-list-table-card .data-table {
    min-width: 32rem;
    width: max-content;
  }

  .shared-event-admin-participants-table .data-table {
    min-width: 40rem;
  }

  .admin-table-filter-row .form-input {
    font-size: 16px;
  }

  .admin-list-toolbar {
    padding: 0.85rem;
  }

  .admin-list-search {
    max-width: none;
    width: 100%;
  }

  .admin-list-filters {
    flex-direction: column;
    gap: 0.75rem;
  }

  .admin-fieldset,
  .admin-form .card-body {
    padding: 1rem;
  }

  .admin-crud-actions,
  .admin-row-actions,
  .admin-actions {
    flex-wrap: wrap;
    gap: 0.35rem;
  }
}

@media (max-width: 520px) {
  .admin-stat-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .admin-shell-web-link-label {
    display: none;
  }

  .admin-shell-user {
    padding: 0.35rem 0.5rem;
  }

  .admin-page-toolbar .flex.flex-wrap,
  .admin-page-header-actions {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }

  .admin-page-toolbar .btn,
  .admin-page-header-actions .btn,
  .admin-form-actions .btn {
    width: auto;
    max-width: 100%;
    flex: 0 0 auto;
  }
}

/* ── Dashboard — dlaždice v tmavém režimu ── */
html:not([data-theme="light"]) .page-body-dashboard .dashboard-stat-card,
html:not([data-theme="light"]) .page-body-dashboard .dashboard-challenge-card {
  border-color: var(--border-strong);
}

html[data-theme="light"] .page-body-dashboard .dashboard-stat-value,
html[data-theme="light"] .page-body-dashboard .dashboard-stat-label {
  color: var(--dashboard-heading);
}

/* ── Admin vždy světlý — kontrast prvků ── */
.admin-body .data-table td,
.admin-body .data-table th {
  color: var(--ink);
}

.admin-body .data-table th {
  color: var(--ink-muted);
}

.admin-body .form-label {
  color: var(--ink);
}

.admin-body .site-page-body,
.admin-body .rich-text-body {
  color: var(--ink-soft);
}

.admin-body .admin-empty {
  color: var(--ink-muted);
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
