:root {
  --sidebar-width: 304px;
  --font-size-base: clamp(12.5px, 0.62vw + 10.6px, 14px);
  --font-size-h1: clamp(1.2rem, 0.95vw + 0.9rem, 1.65rem);
  --font-size-h2: clamp(1.08rem, 0.7vw + 0.84rem, 1.32rem);
  --font-size-h3: clamp(0.97rem, 0.42vw + 0.82rem, 1.1rem);
}

body {
  font-size: var(--font-size-base);
  line-height: 1.45;
  overflow-x: hidden;
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

img,
svg,
canvas {
  max-width: 100%;
}

h1 { font-size: var(--font-size-h1); }
h2 { font-size: var(--font-size-h2); }
h3 { font-size: var(--font-size-h3); }

main,
section,
article,
aside,
header,
footer,
.dashboard-shell,
.finance-wrap,
.table-responsive {
  min-width: 0;
}

h1, h2, h3, h4, h5, h6,
p {
  overflow-wrap: break-word;
  word-break: normal;
}

a,
label,
button {
  overflow-wrap: normal;
  word-break: normal;
}

.scrollbar-thin::-webkit-scrollbar {
  width: 8px;
}

.scrollbar-thin::-webkit-scrollbar-thumb {
  border-radius: 999px;
}

.table-zebra tbody tr {
  transition: background-color 0.2s ease;
}

.table-zebra {
  width: 100%;
}

[data-alert] {
  transition: opacity 0.3s ease;
}

[data-loading][disabled] {
  cursor: wait;
  opacity: 0.78;
}

@keyframes fadeSlideIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

main > * {
  animation: fadeSlideIn 0.25s ease;
}

.table-responsive {
  width: 100%;
  overflow: visible;
  -webkit-overflow-scrolling: auto;
}

.table-responsive > table {
  min-width: 0;
}

@media (max-width: 1024px) {
  .table-responsive > table {
    min-width: 0;
  }
}

@media (max-width: 768px) {
  form [class*="md:grid-cols-2"],
  form [class*="md:grid-cols-3"],
  form [class*="lg:grid-cols-2"],
  form [class*="lg:grid-cols-3"] {
    grid-template-columns: minmax(0, 1fr) !important;
  }
}

/* Global responsive hardening across modules */
@media (max-width: 768px) {
  .app-content-shell,
  .dashboard-shell,
  .finance-wrap,
  .finance-shell,
  .assembly-shell,
  .sports-shell {
    width: 100%;
    min-width: 0;
    overflow-x: hidden;
  }

  .app-content-shell [class*="rounded-2xl"],
  .app-content-shell [class*="rounded-xl"] {
    min-width: 0;
  }

  .app-content-shell .overflow-x-auto,
  .app-content-shell .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .app-content-shell .w-80,
  .app-content-shell .w-96 {
    max-width: 100%;
  }
}

/* Cross-module responsive safeguards */
@media (max-width: 960px) {
  .app-content-shell .overflow-x-auto,
  .app-content-shell .table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .app-content-shell table:not(.responsive-stack-mobile) {
    min-width: 680px;
  }

  .app-content-shell table:not(.responsive-stack-mobile) th,
  .app-content-shell table:not(.responsive-stack-mobile) td {
    white-space: nowrap;
  }
}

@media (max-width: 768px) {
  .app-content-shell [class*="md:grid-cols-2"],
  .app-content-shell [class*="md:grid-cols-3"],
  .app-content-shell [class*="md:grid-cols-4"],
  .app-content-shell [class*="lg:grid-cols-2"],
  .app-content-shell [class*="lg:grid-cols-3"],
  .app-content-shell [class*="lg:grid-cols-4"] {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .app-content-shell [class*="sm:flex-row"],
  .app-content-shell [class*="md:flex-row"],
  .app-content-shell [class*="lg:flex-row"] {
    flex-direction: column !important;
    align-items: stretch !important;
  }

  .app-content-shell .inline-flex,
  .app-content-shell button,
  .app-content-shell .btn {
    max-width: 100%;
  }
}

@media (max-width: 480px) {
  .app-content-shell table:not(.responsive-stack-mobile) {
    min-width: 560px;
  }
}

table.responsive-stack-mobile {
  width: 100%;
  table-layout: fixed;
}

table.responsive-stack-mobile td,
table.responsive-stack-mobile th {
  overflow-wrap: break-word;
  word-break: normal;
}

@media (max-width: 768px) {
  table.responsive-stack-mobile {
    border-collapse: separate;
    border-spacing: 0;
    table-layout: auto;
  }

  table.responsive-stack-mobile thead {
    display: none;
  }

  table.responsive-stack-mobile tbody {
    display: block;
    width: 100%;
  }

  table.responsive-stack-mobile tbody tr {
    display: block;
    width: 100%;
    margin-bottom: 0.8rem;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--card-bg);
    overflow: hidden;
    box-shadow: var(--shadow);
  }

  table.responsive-stack-mobile tbody tr:last-child {
    margin-bottom: 0;
  }

  table.responsive-stack-mobile tbody td {
    display: block;
    width: 100%;
    border-bottom: 1px solid var(--border) !important;
    padding: 0.72rem 0.82rem;
    white-space: normal !important;
    text-align: left;
  }

  table.responsive-stack-mobile tbody td::before {
    content: attr(data-label);
    display: block;
    text-align: left;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    line-height: 1.35;
    color: var(--text-muted);
    margin-bottom: 0.32rem;
  }

  table.responsive-stack-mobile tbody td a,
  table.responsive-stack-mobile tbody td span,
  table.responsive-stack-mobile tbody td strong {
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  table.responsive-stack-mobile tbody td.mobile-no-label::before {
    content: '';
    display: none;
  }

  table.responsive-stack-mobile tbody td.mobile-no-label {
    padding-top: 0.85rem;
  }

  table.responsive-stack-mobile tbody td.mobile-full-row {
    display: block;
    text-align: left;
    padding: 0.78rem 0.82rem;
  }

  table.responsive-stack-mobile tbody td:last-child {
    border-bottom: 0 !important;
  }
}

@media (min-width: 1280px) {
  body {
    font-size: 12.5px;
  }
}

/* Reusable SaaS UI utilities */
.ui-container {
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
}

.ui-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 1rem;
}

.ui-button-primary,
.ui-button-secondary,
.ui-button-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 40px;
  border-radius: 12px;
  padding: 0.55rem 0.95rem;
  font-weight: 600;
  border: 1px solid transparent;
  transition: background-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.ui-button-primary {
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
}

.ui-button-secondary {
  color: var(--text);
  border-color: var(--input-border);
  background: color-mix(in srgb, var(--surface), transparent 3%);
}

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

.ui-button-primary:hover,
.ui-button-secondary:hover,
.ui-button-ghost:hover {
  transform: translateY(-1px);
}

.ui-button-primary:focus-visible,
.ui-button-secondary:focus-visible,
.ui-button-ghost:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

.ui-input,
.ui-select,
.ui-textarea {
  width: 100%;
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--input-text);
  padding: 0.58rem 0.78rem;
}

.ui-input:focus,
.ui-select:focus,
.ui-textarea:focus {
  outline: none;
  box-shadow: var(--ring);
  border-color: var(--primary);
}

.ui-table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--card-border);
  border-radius: 12px;
  overflow: hidden;
}

.ui-table thead th {
  background: var(--table-header-bg);
  color: var(--text-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
}

.ui-table th,
.ui-table td {
  padding: 0.72rem 0.8rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.ui-table tbody tr:hover {
  background: var(--table-row-hover);
}

.records-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.85rem;
}

.records-grid.records-grid-4 {
  grid-template-columns: minmax(0, 1fr);
}

.records-grid.records-grid-3 {
  grid-template-columns: minmax(0, 1fr);
}

.record-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 0.95rem;
  min-width: 0;
}

.record-card__title {
  font-weight: 700;
  color: var(--text);
  font-size: 1rem;
  line-height: 1.25;
}

.record-card__meta {
  margin-top: 0.2rem;
  color: var(--text-muted);
  font-size: 0.83rem;
}

.record-card__grid {
  margin-top: 0.7rem;
  display: grid;
  gap: 0.45rem;
}

.record-card__line {
  display: flex;
  justify-content: space-between;
  gap: 0.7rem;
  align-items: flex-start;
}

.record-card__line span {
  color: var(--text-muted);
  font-size: 0.78rem;
}

.record-card__line strong {
  color: var(--text);
  font-size: 0.88rem;
  text-align: right;
  overflow-wrap: anywhere;
  max-width: 60%;
}

.record-card__actions {
  margin-top: 0.75rem;
  padding-top: 0.7rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.record-card__actions a {
  font-weight: 600;
  font-size: 0.86rem;
}

.js-reveal {
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 220ms ease, transform 220ms ease;
  will-change: opacity, transform;
}

.js-reveal.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.js-micro-lift {
  transition: transform 180ms ease, box-shadow 180ms ease, opacity 180ms ease;
}

.js-micro-lift:hover,
.js-micro-lift:focus-visible {
  transform: translateY(-1px);
}

.js-micro-lift:active {
  transform: translateY(0);
}

.desktop-table-only {
  display: block;
}

.mobile-cards-only {
  display: none;
}

@media (min-width: 640px) {
  .records-grid.records-grid-4,
  .records-grid.records-grid-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1024px) {
  .records-grid.records-grid-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .records-grid.records-grid-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 768px) {
  .desktop-table-only {
    display: none;
  }

  .mobile-cards-only {
    display: grid;
  }

  .record-card__line {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.2rem;
  }

  .record-card__line strong {
    text-align: left;
    max-width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .js-reveal,
  .js-micro-lift {
    transition: none !important;
    transform: none !important;
    opacity: 1 !important;
  }
}
