/* Shared responsive layer — loaded after page styles.
   Covers desktop, laptop, tablet, and phone without removing features. */

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  overflow-x: hidden;
  max-width: 100%;
  min-width: 0;
}

img,
svg,
video,
canvas,
iframe,
embed,
object {
  max-width: 100%;
}

img,
svg,
video {
  height: auto;
}

.app,
.main-content,
.stats-grid,
.charts-row,
.chart-card,
.welcome-banner,
.quick-actions,
.table-section,
.table-container,
.table-wrapper,
.filter-form,
.form-grid,
.filter-card,
.card,
.page-title,
.top-bar,
.header-actions {
  min-width: 0;
  max-width: 100%;
}

.page-title {
  flex: 1;
  min-width: 0;
  text-align: left;
}
.page-title h1 {
  font-size: clamp(1.2rem, 4.2vw, 1.75rem);
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  line-height: 1.25;
  letter-spacing: -0.03em;
  text-align: left;
}
.page-title h1 i {
  flex-shrink: 0;
  font-size: clamp(1.05rem, 4vw, 1.45rem);
  line-height: 1;
}
.page-title h1 span {
  flex: 1;
  min-width: 0;
  overflow-wrap: break-word;
}
.page-title p {
  font-size: clamp(0.75rem, 3vw, 0.875rem);
  line-height: 1.45;
  max-width: 42rem;
  text-align: left;
  margin-top: 6px;
}

.hamburger,
.action-icon-btn,
.sidebar-toggle-btn,
.topbar__menu-btn,
.tf-menu-btn,
.close-modal {
  min-width: 44px;
  min-height: 44px;
  touch-action: manipulation;
}

input,
select,
textarea,
button,
a.btn,
.btn,
.btn-action,
.btn-filter,
.btn-reset,
.btn-primary,
.btn-secondary,
.quick-action,
.upload-btn {
  max-width: 100%;
  touch-action: manipulation;
}

.table-section,
.table-container,
.table-wrapper,
.tf-table-container,
.result-section {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

.chart-container,
.chart-panel,
.horizontal-chart-container {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.horizontal-chart-container canvas {
  min-width: 0 !important;
  max-width: 100% !important;
}

.suggest-box {
  max-height: min(200px, 36vh);
  overflow-y: auto;
  overflow-x: hidden;
  max-width: 100%;
}

.pagination,
.pager {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* ----- Laptop ----- */
@media (max-width: 1100px) {
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .form-grid,
  .quick-actions,
  .charts-row {
    grid-template-columns: 1fr;
  }
}

/* ----- Tablet and below ----- */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    width: min(var(--sidebar-width, 280px), 86vw) !important;
    padding-top: env(safe-area-inset-top, 0px);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    padding: 16px calc(14px + env(safe-area-inset-right, 0px)) calc(24px + env(safe-area-inset-bottom, 0px)) calc(14px + env(safe-area-inset-left, 0px)) !important;
  }

  .sidebar-toggle-btn {
    display: none !important;
  }

  .mobile-header {
    display: flex !important;
    position: sticky;
    top: env(safe-area-inset-top, 0px);
    z-index: 50;
  }

  .top-bar,
  .page-header,
  .dept-stats-header,
  .table-header,
  .section-label,
  .filter-actions,
  .welcome-banner,
  .card-header,
  .card-header-flex {
    flex-wrap: wrap;
  }

  .welcome-banner {
    flex-direction: column;
    align-items: flex-start !important;
  }

  .welcome-banner h1 {
    overflow-wrap: anywhere;
  }

  .top-bar {
    flex-direction: column !important;
    align-items: stretch !important;
  }

  .page-title {
    width: 100%;
    text-align: left !important;
  }

  .page-title h1 {
    font-size: clamp(1.15rem, 5vw, 1.4rem) !important;
    flex-wrap: nowrap !important;
    justify-content: flex-start !important;
    text-align: left !important;
  }

  .page-title p {
    font-size: clamp(0.75rem, 3.4vw, 0.8125rem) !important;
    text-align: left !important;
  }

  .section-label {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 4px;
  }

  .welcome-banner__meta {
    width: 100%;
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .meta-chip {
    min-width: 0 !important;
    width: 100%;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .quick-actions,
  .charts-row,
  .filter-form,
  .form-grid,
  .detail-grid,
  .info-grid,
  .upload-grid,
  .row-2cols {
    grid-template-columns: 1fr !important;
  }

  .filter-card,
  .card,
  .table-section {
    padding-left: 16px !important;
    padding-right: 16px !important;
  }

  .filter-actions .btn-filter,
  .filter-actions .btn-reset,
  .filter-actions .btn,
  .filter-actions .btn-primary,
  .filter-actions .btn-secondary,
  .btn-add-modal,
  .upload-btn {
    width: 100%;
    justify-content: center;
    min-height: 44px;
  }

  .header-actions {
    width: 100%;
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="file"]),
  select,
  textarea {
    font-size: 16px !important;
    max-width: 100%;
  }

  .drop-zone,
  .upload-area,
  .file-drop,
  .pdf-drop {
    width: 100%;
    max-width: 100%;
  }

  /* Card-style tables when labels exist */
  table:has(td[data-label]),
  table:has(td[data-label]) thead,
  table:has(td[data-label]) tbody,
  table:has(td[data-label]) th,
  table:has(td[data-label]) td,
  table:has(td[data-label]) tr {
    display: block !important;
    width: 100% !important;
  }

  table:has(td[data-label]) thead {
    display: none !important;
  }

  table:has(td[data-label]) tr {
    margin-bottom: 14px;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    padding: 12px 14px;
    background: #fff;
    box-shadow: 0 8px 20px -16px rgba(15, 23, 42, 0.25);
  }

  table:has(td[data-label]) td {
    display: flex !important;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 8px 0 !important;
    border-bottom: 1px solid #f1f5f9 !important;
    background: transparent !important;
  }

  table:has(td[data-label]) td:last-child {
    border-bottom: none !important;
  }

  table:has(td[data-label]) td::before {
    content: attr(data-label);
    font-weight: 600;
    color: #64748b;
    font-size: 12px;
    flex-shrink: 0;
    min-width: 88px;
  }

  table:has(td[data-label]) td .action-buttons,
  table:has(td[data-label]) td .action-btn,
  table:has(td[data-label]) td .action-btns,
  table:has(td[data-label]) td .action-icons {
    justify-content: flex-end;
    flex-wrap: wrap;
    flex: 1;
  }

  .action-buttons,
  .action-btns,
  .action-icons {
    gap: 6px;
    flex-wrap: wrap;
  }

  .modal,
  .rejection-modal,
  .approval-modal,
  .modal-box,
  .modal-card,
  .modal-content {
    width: calc(100% - 24px) !important;
    max-width: 520px !important;
    margin: 16px auto !important;
    max-height: calc(100dvh - 32px);
    overflow-y: auto;
  }

  .modal-content-doc,
  .modal-doc {
    width: 98% !important;
    max-width: none !important;
    height: 95dvh !important;
    margin: 1% auto !important;
  }

  .modal-footer {
    flex-direction: column;
  }

  .modal-footer .btn-cancel,
  .modal-footer .btn-submit,
  .modal-footer .btn-primary,
  .modal-footer .btn-secondary,
  .modal-footer button,
  .modal-footer a {
    width: 100%;
    justify-content: center;
    min-height: 44px;
  }

  .chart-container {
    height: 220px !important;
  }

  .chart-container.chart-sm {
    height: 190px !important;
  }

  .info-table {
    display: block;
    width: 100%;
  }

  .info-table tr,
  .info-table th,
  .info-table td {
    display: block;
    width: 100%;
  }

  .info-table th {
    padding-bottom: 2px;
  }

  .location-badge {
    display: none !important;
  }

  .suggest-box {
    max-height: min(148px, 28vh);
  }
}

/* ----- Phone ----- */
@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;
  }

  .quick-actions {
    grid-template-columns: 1fr !important;
  }

  .welcome-banner h1 {
    font-size: 1.25rem !important;
  }

  .page-title h1 {
    font-size: clamp(1.05rem, 5.5vw, 1.25rem) !important;
    gap: 8px;
  }

  .page-title p {
    font-size: clamp(0.72rem, 3.6vw, 0.8rem) !important;
  }

  .meta-chip strong,
  .stat-number {
    font-size: 18px !important;
  }

  .stat-foot,
  .profile-btn span {
    display: none !important;
  }

  .btn-action {
    font-size: 11px;
  }

  .btn-icon,
  .btn-sm {
    min-width: 40px;
    min-height: 40px;
  }

  .submission-summary {
    white-space: normal !important;
  }

  .suggest-box {
    max-height: min(128px, 24vh);
  }

  .suggest-item {
    padding: 7px 10px;
    font-size: 12px;
  }

  .meta-grid,
  .row-2cols {
    grid-template-columns: 1fr !important;
  }

  .tf-search-row {
    flex-wrap: wrap;
    width: 100%;
  }

  .tf-search-row input {
    min-width: 0;
    flex: 1 1 100%;
    font-size: 16px !important;
  }
}

@media (max-width: 360px) {
  .stats-grid,
  .welcome-banner__meta {
    grid-template-columns: 1fr !important;
  }
}

@media (max-height: 500px) and (orientation: landscape) {
  .chart-container {
    height: 170px !important;
  }

  .brand-panel {
    min-height: 140px !important;
  }
}

/* Auth / landing */
@media (max-width: 768px) {
  .login-page,
  .auth-page,
  .register-page {
    min-height: 100dvh;
  }

  .form-panel,
  .login-card,
  .auth-card,
  .hero__card {
    width: 100%;
    max-width: 100%;
  }

  .hero__actions,
  .auth-actions {
    flex-wrap: wrap;
  }

  .hero__actions a,
  .hero__actions .btn,
  .auth-actions a,
  .auth-actions .btn {
    width: 100%;
    justify-content: center;
    text-align: center;
    min-height: 44px;
  }
}

/* Student shells */
@media (max-width: 768px) {
  .dashboard-wrapper,
  .page-main,
  .tf-main {
    padding-left: calc(1rem + env(safe-area-inset-left, 0px));
    padding-right: calc(1rem + env(safe-area-inset-right, 0px));
    grid-template-columns: 1fr !important;
    max-width: 100%;
  }

  .categories-sidebar,
  .tf-sidebar {
    position: static !important;
    max-height: none !important;
    width: 100% !important;
  }

  .journal-card,
  .info-grid,
  .tf-journal-band__inner,
  .tf-article__inner {
    grid-template-columns: 1fr !important;
  }

  .tf-journal-cover {
    display: none;
  }

  .tf-header__inner,
  .tf-breadcrumb__inner {
    flex-wrap: wrap;
    max-width: 100%;
  }

  .btn-read {
    width: 100%;
    justify-content: center;
    min-height: 44px;
  }
}
