/* One responsive layout layer for the school portal. Loaded for screen only. */
html { font-size: 16px; max-width: 100vw; overflow-x: hidden; }
body { min-height: 100svh; -webkit-tap-highlight-color: transparent; max-width: 100vw; overflow-x: hidden; }
.app-container { max-width: 100vw; overflow-x: hidden; min-width: 0; width: 100%; }
.main-wrapper { min-width: 0; max-width: 100%; width: 100%; padding: clamp(20px, 2.2vw, 40px); box-sizing: border-box; overflow-x: hidden; }
.main-wrapper > *, .tab-content, .tab-content > *, .charts-grid > *, .stats-grid > *, .form-grid > *, .dashboard-bottom-grid > * { min-width: 0; max-width: 100%; }

/* Hero Banner Baseline */
.dashboard-hero-banner { min-width: 0; max-width: 100%; width: 100%; box-sizing: border-box; }
.dashboard-bottom-grid { min-width: 0; max-width: 100%; width: 100%; box-sizing: border-box; }

.top-bar { padding: 14px 18px; gap: 16px; flex-wrap: wrap; border-color: #e2e8f0; background: #fff; border-radius: 18px; box-shadow: 0 5px 24px -12px #24345024; max-width: 100%; box-sizing: border-box; }
.top-bar-start { min-width: min(240px, 100%); }
.topbar-search-box { width: 100%; max-width: 430px; min-width: 0; background: #f8fafc; border-color: #e2e8f0; }
.topbar-search-box input { width: 100%; min-width: 0; }
.top-bar-actions { flex-wrap: wrap; gap: 10px; }
.topbar-user-badge { max-width: 210px; min-width: 0; }
.panel-card, .chart-card, .stat-card { border-radius: 18px; box-shadow: 0 4px 20px -10px #25364b22; min-width: 0; max-width: 100%; box-sizing: border-box; }
.panel-header { gap: 14px; flex-wrap: wrap; }
.stats-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; width: 100%; min-width: 0; }
.charts-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); width: 100%; min-width: 0; }
.stat-value { font-variant-numeric: tabular-nums; font-size: clamp(1.6rem, 2.5vw, 2.2rem); }
.form-grid { grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr)); }
.monitor-grid { grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); }
.filter-toolbar { flex-wrap: wrap; gap: 12px; }
.filter-toolbar > * { min-width: 0; }
.data-table-wrapper, .timetable-wrapper { width: 100%; max-width: 100%; min-width: 0; overflow-x: auto; overscroll-behavior-inline: contain; -webkit-overflow-scrolling: touch; border-radius: 12px; box-sizing: border-box; }
.data-table-wrapper:focus-visible, .timetable-wrapper:focus-visible { outline-offset: 2px; }
.sub-tabs { max-width: 100%; overflow-x: auto; flex-wrap: nowrap; gap: 8px; }
.sub-tabs > * { flex-shrink: 0; }
.btn, .topbar-round-btn, .topbar-logout-btn { min-height: 44px; }
.btn, .nav-item, .bottom-nav-item { transition: background .3s, color .3s, transform .3s; }
button, a, input, select, textarea { touch-action: manipulation; }
:is(button, a, input, select, textarea, [tabindex]):focus-visible { outline: 3px solid #2563eb; outline-offset: 3px; }
.app-sidebar :focus-visible { outline-color: #93c5fd; }
.modal-overlay { padding: 24px; overflow-y: auto; overscroll-behavior: contain; z-index: 3000; }
.modal-box { max-height: calc(100dvh - 48px) !important; overflow-y: auto; overscroll-behavior: contain; margin-block: auto; }
.toast-container { max-width: min(420px, calc(100vw - 32px)); }
.mobile-bottom-nav { background: #ffffffed; border-color: #e2e8f0; box-shadow: 0 -4px 24px #0f172a0a; backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.bottom-nav-item { color: #64748b; border-radius: 12px; margin: 4px; }
.bottom-nav-item.active { color: #c8102e; background: #fff1f3; }

/* Keep long stage names and large stage lists inside the distribution card. */
.donut-wrapper { min-width: 0; overflow: hidden; }
.donut-legend-list {
  min-width: 0;
  max-height: 190px;
  overflow-y: auto;
  overflow-x: hidden;
  padding-inline-end: 6px;
  scrollbar-width: thin;
}
.donut-legend-list .legend-item { min-width: 0; gap: 10px; }
.donut-legend-list .legend-item > span:first-child {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.donut-legend-list .legend-item > span:last-child {
  flex-shrink: 0;
  white-space: nowrap;
}

@media (min-width: 1800px) {
  .main-wrapper { padding-inline: clamp(36px, 4vw, 96px); }
  .stats-grid, .charts-grid { gap: 24px; }
}

@media (max-width: 1280px) {
  .top-bar-start { flex-basis: 100%; }
  .topbar-search-box { max-width: none; }
  .top-bar-actions { width: 100%; }
  .charts-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .charts-grid > :last-child:nth-child(odd) { grid-column: 1 / -1; }
  .dashboard-hero-banner { flex-wrap: wrap; }
  .hero-campus-photo-side { width: 280px; }
  .hero-greeting-side { flex-grow: 1; }
}

@media (max-width: 1024px) {
  .main-wrapper { margin-right: 0; width: 100%; padding: 18px; }
  .app-sidebar { width: min(310px, 88vw); z-index: 2000; padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); transform: translateX(105%); visibility: hidden; pointer-events: none; transition: transform .3s ease, visibility .3s; }
  .app-sidebar.open { transform: translateX(0); visibility: visible; pointer-events: auto; box-shadow: -20px 0 60px #0f172a40; }
  body.sidebar-open { overflow: hidden; }
  .app-sidebar .main-nav { overscroll-behavior: contain; }
  .sidebar-backdrop { display: block; position: fixed; inset: 0; background: #0f172a80; z-index: 1990; opacity: 0; visibility: hidden; transition: opacity .3s, visibility .3s; pointer-events: none; }
  .sidebar-backdrop.active { opacity: 1; visibility: visible; pointer-events: auto; }
  .mobile-menu-toggle-btn, .sidebar-close-btn { display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; width: 44px; height: 44px; border-radius: 12px; cursor: pointer; border: 1px solid #e2e8f0; background: #f8fafc; color: #0f172a; font-size: 1.1rem; }
  .sidebar-close-btn { margin-inline-start: auto; color: #f1f5f9; background: #ffffff0d; border-color: #ffffff20; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .top-bar-start { flex-basis: auto; }
  .topbar-search-box { flex: 1; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-bottom-grid { grid-template-columns: minmax(0, 1fr) !important; }
  .dashboard-bottom-grid > * { min-width: 0 !important; width: 100% !important; max-width: 100% !important; }
  .data-table { min-width: 580px; }
}

@media (max-width: 768px) {
  .main-wrapper { padding: 12px max(10px, env(safe-area-inset-right)) calc(84px + env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)); }
  .mobile-bottom-nav { display: flex; padding-inline: env(safe-area-inset-left) env(safe-area-inset-right); }
  .top-bar { gap: 12px; padding: 12px; border-radius: 16px; }
  .top-bar-start { width: 100%; }
  .top-bar-actions { display: flex; flex-wrap: wrap; width: 100%; gap: 8px; align-items: center; }
  .topbar-round-btn { width: 42px; height: 42px; flex-shrink: 0; }
  .topbar-user-badge { display: inline-flex; align-items: center; justify-content: center; padding: 0; background: none; border: 0; cursor: pointer; }
  .topbar-user-badge .user-avatar { width: 42px; height: 42px; }
  .topbar-user-badge .user-info { display: none; }
  .topbar-logout-btn { width: 42px; height: 42px; padding: 0; justify-content: center; flex-shrink: 0; }
  .topbar-logout-btn span { display: none; }
  .top-bar-actions > .btn { flex: 1 1 calc(50% - 8px); font-size: .85rem; padding: 10px 12px; min-height: 44px; }
  
  /* Hero Welcome Banner on Mobile */
  .dashboard-hero-banner { flex-direction: column; align-items: stretch; }
  .hero-campus-photo-side { width: 100% !important; min-width: 0 !important; max-width: 100% !important; height: 120px; min-height: 120px; }
  .hero-campus-photo-side img { width: 100%; height: 100%; object-fit: cover; }
  .hero-slogan-middle { width: 100% !important; min-width: 0 !important; padding: 14px 16px; }
  .hero-slogan-title { font-size: 1.2rem; justify-content: center; }
  .hero-greeting-side { width: 100% !important; min-width: 0 !important; padding: 14px 16px; flex-direction: column; align-items: stretch; gap: 12px; }
  .hero-greeting-side .greeting-text h2 { font-size: 1.35rem; }
  .hero-greeting-side .greeting-text p { font-size: .88rem; }
  .hero-date-box { width: 100% !important; min-width: 0 !important; box-sizing: border-box; }

  /* Grid layouts collapsed to single column on phone */
  .charts-grid, .monitor-grid, .form-grid, .form-row, .dashboard-bottom-grid { grid-template-columns: minmax(0, 1fr) !important; width: 100% !important; min-width: 0 !important; }
  .charts-grid > *, .dashboard-bottom-grid > * { grid-column: auto !important; min-width: 0 !important; max-width: 100% !important; width: 100% !important; box-sizing: border-box; }
  .panel-card, .chart-card { padding: 16px; min-width: 0 !important; max-width: 100% !important; width: 100% !important; box-sizing: border-box; overflow: hidden; }
  .panel-header { align-items: stretch; flex-direction: column; }
  .panel-header .btn { align-self: flex-start; }
  .filter-toolbar { flex-direction: column; align-items: stretch; }
  .filter-toolbar > *, .search-box { width: 100% !important; min-width: 0 !important; }
  
  /* Tables horizontally scrollable inside wrapper without expanding the card */
  .data-table-wrapper { width: 100% !important; max-width: 100% !important; min-width: 0 !important; overflow-x: auto !important; box-sizing: border-box; }
  .data-table { min-width: 520px; width: 100%; }
  .data-table th, .data-table td { padding: 12px 10px; font-size: .82rem; }
  
  .donut-wrapper { flex-direction: column; height: auto; align-items: center; gap: 14px; padding: 8px 0; }
  .donut-chart-box { width: 150px; height: 150px; }
  .donut-legend-list { width: 100%; min-width: 0; max-height: 180px; }

  .sub-tabs button { min-height: 44px; font-size: .82rem; }
  input:not([type=checkbox]):not([type=radio]), select, textarea { font-size: 16px !important; min-height: 48px; max-width: 100%; }
  .modal-overlay { padding: 10px; align-items: center; }
  .modal-box { width: 100% !important; max-width: 100% !important; margin: auto !important; border-radius: 22px; padding: 20px !important; max-height: calc(100dvh - 20px) !important; }
  .modal-box .form-grid > *, .form-grid > * { grid-column: auto !important; }
  .modal-actions { display: flex; flex-wrap: wrap; gap: 8px; }
  .modal-actions > .btn { flex: 1; }
  .toast-container { bottom: calc(84px + env(safe-area-inset-bottom)); }
  .monitor-metrics-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #billing-warning-banner { margin: 12px 0 !important; }
}

@media (max-width: 480px) {
  .main-wrapper { padding: 10px 8px calc(80px + env(safe-area-inset-bottom)) 8px; }
  .stats-grid { gap: 10px; }
  .stat-card { padding: 14px; min-width: 0; }
  .stat-value { font-size: 1.45rem; }
  .stat-label { font-size: .75rem; overflow-wrap: anywhere; }
  .stat-header { gap: 8px; flex-wrap: wrap; }
  .stat-icon { width: 36px; height: 36px; font-size: 1rem; }
  .page-title h1 { font-size: 1.25rem; }
  .page-title p { font-size: .78rem; }
  .modal-box { padding: 16px !important; }
  .chart-card { padding: 14px 12px; }
  .chart-header h3 { font-size: 1rem; }
}

@media (max-width: 350px) {
  .main-wrapper { padding: 8px 6px calc(76px + env(safe-area-inset-bottom)) 6px; }
  .stats-grid { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .stat-card { padding: 12px 10px; }
  .stat-value { font-size: 1.3rem; }
  .hero-slogan-title { font-size: 1.05rem; }
  .hero-greeting-side .greeting-text h2 { font-size: 1.15rem; }
  .top-bar { padding: 10px 8px; }
  .data-table { min-width: 480px; }
}
