/* ===========================
   RESPONSIVE — MOBILE FIRST
   breakpoints: 768px mobile, 1024px tablet
   =========================== */

/* Hamburger button — hidden on desktop */
.hamburger-btn {
  align-items: center;
  background: none;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: none;
  flex-direction: column;
  gap: 5px;
  height: 42px;
  justify-content: center;
  padding: 0 0.7rem;
  width: 46px;
}

.hamburger-btn span {
  background: var(--color-text);
  border-radius: 2px;
  display: block;
  height: 2px;
  transition: opacity 0.2s;
  width: 20px;
}

/* Sidebar close button — hidden on desktop */
.sidebar-close-btn {
  align-items: center;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  cursor: pointer;
  display: none;
  font-size: 1.25rem;
  height: 36px;
  justify-content: center;
  padding: 0;
  width: 36px;
}

.sidebar-header {
  align-items: center;
  display: flex;
  justify-content: space-between;
}

/* Overlay behind mobile sidebar */
.sidebar-overlay {
  background: rgba(15, 23, 42, 0.4);
  bottom: 0;
  display: none;
  left: 0;
  position: fixed;
  right: 0;
  top: 0;
  z-index: 45;
}

.sidebar-overlay.active {
  display: block;
}

/* Landing hamburger — hidden on desktop */
.landing-hamburger {
  display: none;
}

/* ===========================
   TABLET (769 – 1024px)
   =========================== */
@media (max-width: 1024px) and (min-width: 769px) {
  .dashboard-shell {
    grid-template-columns: 248px minmax(0, 1fr);
  }

  :root {
    --sidebar-w: 248px;
  }

  .hero-section {
    grid-template-columns: 1fr;
    padding: clamp(2rem, 5vw, 4rem) clamp(1rem, 3vw, 3rem);
  }

  .hero-card {
    display: none;
  }

  .hero-copy h1 {
    font-size: clamp(2rem, 4.5vw, 3.5rem);
  }

  .landing-cta {
    flex-direction: column;
    align-items: flex-start;
  }

  .landing-footer-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* ===========================
   MOBILE (≤ 768px)
   =========================== */
@media (max-width: 768px) {
  /* ── Landing page ── */

  .landing-header {
    position: sticky;
    top: 0;
    z-index: 50;
  }

  .landing-header nav.landing-nav {
    background: rgba(255, 255, 255, 0.98);
    border-top: 1px solid var(--color-border);
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.1);
    display: none;
    flex-direction: column;
    gap: 0.25rem;
    left: 0;
    padding: 0.75rem 1rem 1rem;
    position: absolute;
    right: 0;
    top: 100%;
    z-index: 100;
  }

  .landing-header nav.landing-nav.menu-open {
    display: flex;
  }

  .landing-hamburger {
    align-items: center;
    background: none;
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 5px;
    height: 42px;
    justify-content: center;
    padding: 0 0.7rem;
    width: 46px;
  }

  .landing-hamburger span {
    background: var(--color-text);
    border-radius: 2px;
    display: block;
    height: 2px;
    width: 20px;
  }

  .hero-section {
    grid-template-columns: 1fr;
    padding: 2.5rem 1.25rem;
  }

  .hero-card {
    display: none;
  }

  .hero-copy h1 {
    font-size: clamp(1.8rem, 7vw, 2.8rem);
  }

  .hero-actions {
    flex-direction: column;
    width: 100%;
  }

  .hero-actions .btn {
    justify-content: center;
    text-align: center;
    width: 100%;
  }

  .landing-section {
    padding: 0 1.25rem 3rem;
  }

  .feature-grid {
    grid-template-columns: 1fr;
  }

  .process-grid {
    grid-template-columns: 1fr;
  }

  .landing-cta {
    flex-direction: column;
    align-items: flex-start;
    margin: 0 1.25rem 3rem;
  }

  .landing-cta .btn {
    align-self: flex-start;
  }

  .landing-footer {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .landing-footer-grid {
    grid-template-columns: 1fr 1fr;
  }

  .landing-footer-bottom {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.4rem;
  }

  /* ── Dashboard ── */

  .dashboard-shell {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
  }

  .dashboard-sidebar {
    border-bottom: none;
    border-left: none;
    bottom: 0;
    box-shadow: -4px 0 24px rgba(15, 23, 42, 0.12);
    height: 100dvh;
    position: fixed;
    right: 0;
    top: 0;
    transform: translateX(105%);
    transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1), visibility 0.28s;
    visibility: hidden;
    width: 300px;
    z-index: 50;
  }

  .dashboard-sidebar.sidebar-open {
    transform: translateX(0);
    visibility: visible;
  }

  .sidebar-close-btn {
    display: flex;
  }

  .hamburger-btn {
    display: flex;
  }

  .dashboard-content {
    max-width: 100vw;
    padding: 1rem;
    width: 100%;
  }

  .dashboard-topbar {
    padding: 0.5rem 1rem;
    width: 100%;
  }

  .dashboard-topbar h1 {
    font-size: 1.1rem;
  }

  .topbar-date {
    display: none;
  }

  .topbar-user-meta {
    display: none;
  }

  /* ── Grids ── */

  .dashboard-grid,
  .card-grid {
    grid-template-columns: 1fr;
  }

  .split-panel {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }

  /* ── Section header ── */

  .section-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.75rem;
  }

  /* ── Tables ── */

  .table-wrap {
    -webkit-overflow-scrolling: touch;
    overflow-x: auto;
  }

  .data-table {
    min-width: 640px;
  }

  /* ── Forms ── */

  .form-grid {
    grid-template-columns: 1fr !important;
  }

  .action-row {
    flex-direction: column;
  }

  .action-row .btn {
    width: 100%;
  }

  /* ── Report card print ── */

  .report-card-actions {
    display: none;
  }

  /* ── Exam ── */

  .exam-layout {
    grid-template-columns: 1fr;
  }

  .exam-sidebar-panel {
    order: -1;
  }

  /* ── Usage chart ── */

  .usage-chart {
    height: 100px;
  }
}

/* ===========================
   RESPONSIVE پایه — همه اندازه‌ها
   جلوگیری از اسکرول افقی ناخواسته و تطبیق تصاویر/جداول.
   =========================== */

img,
video,
canvas {
  height: auto;
  max-width: 100%;
}

.dashboard-content,
.dashboard-main,
.page-stack {
  min-width: 0;
}

/* شکستن متن‌های طولانی و لینک‌ها تا صفحه را نشکنند */
.panel-card h2,
.panel-card h3,
.metric-card,
.metric-card strong,
.empty-state p,
.module-disabled-message,
.module-disabled-hint,
.data-table td,
.data-table th {
  overflow-wrap: break-word;
  word-break: break-word;
}

/* ===========================
   موبایل (≤ 768px) — تکمیل‌ها
   =========================== */
@media (max-width: 768px) {
  /* جلوگیری از اسکرول افقی body */
  html,
  body {
    overflow-x: hidden;
  }

  /* توست — داخل عرض صفحه بگیرد و بیرون نزند */
  .toast-stack {
    left: 1rem;
    padding: 0.75rem;
    right: 1rem;
    top: 0.75rem;
  }

  .toast-item {
    max-width: 100%;
    min-width: 0;
    width: 100%;
  }

  /* تاپبار: فشرده‌تر و بدون سرریز */
  .dashboard-topbar {
    gap: 0.5rem;
    padding: 0.5rem 0.9rem;
  }

  .topbar-left {
    gap: 0.5rem;
    min-width: 0;
  }

  .topbar-right {
    flex: 1 1 auto;
    min-width: 0;
  }

  .topbar-avatar {
    height: 32px;
    width: 32px;
  }

  .topbar-theme-btn {
    height: 34px;
    width: 34px;
  }

  /* کارت‌های آماری: اعداد بزرگ نشکنند */
  .metric-card strong {
    font-size: 1.4rem;
    overflow-wrap: anywhere;
  }

  /* پدینگ محتوای فرم‌های داخل کارت */
  .panel-card {
    min-width: 0;
    padding: 1rem;
  }

  .metric-card {
    min-width: 0;
  }

  /* گرید آمار روی صفحه‌های خیلی کوچک تک‌ستونه */
  .stats-grid {
    grid-template-columns: 1fr;
  }

  /* سکشن هدر: دکمه‌ها تمام‌عرض */
  .section-header .btn,
  .section-header .action-row .btn {
    width: 100%;
  }

  /* جدول‌ها: حداقل عرض کمتر روی موبایل باریک */
  .data-table {
    min-width: 540px;
  }

  .super-schools-table {
    min-width: 980px;
  }

  .super-schools-table th:nth-child(9),
  .super-schools-table td:nth-child(9) {
    width: 240px;
  }

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

  .school-action-btn,
  .school-action-icon {
    font-size: 0.7rem;
    min-height: 32px;
    padding-inline: 0.35rem;
  }

  .news-composer {
    grid-template-columns: 1fr;
  }

  .news-preview-panel {
    position: static;
  }

  .news-form-grid,
  .news-form-grid--three {
    grid-template-columns: 1fr;
  }

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

  /* اعداد و ارقام تبولار در موبایل */
  .dashboard-topbar h1 {
    font-size: 1.05rem;
  }
}

/* ===========================
   موبایل خیلی کوچک (≤ 380px)
   =========================== */
@media (max-width: 380px) {
  .dashboard-content {
    padding: 0.75rem;
  }

  .dashboard-topbar {
    padding: 0.45rem 0.7rem;
  }

  .dashboard-topbar h1 {
    font-size: 0.98rem;
  }

  .panel-card {
    padding: 0.85rem;
  }

  .metric-card strong {
    font-size: 1.2rem;
  }

  .dashboard-grid,
  .card-grid {
    gap: 0.6rem;
  }

  .data-table {
    min-width: 480px;
  }

  .super-schools-table {
    min-width: 900px;
  }

  .school-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .news-template-grid {
    grid-template-columns: 1fr;
  }

  .news-composer-head,
  .news-list-head,
  .news-label-row {
    align-items: flex-start;
    flex-direction: column;
  }
}

/* ===========================
   PRINT STYLES (report card)
   =========================== */
@media print {
  /* Hide navigation and UI chrome */
  .dashboard-sidebar,
  .dashboard-topbar,
  .report-card-actions,
  .section-header .btn,
  .section-header .action-row,
  .sidebar-overlay,
  .topbar-btn,
  nav,
  header,
  footer {
    display: none !important;
  }

  body {
    background: white !important;
    color: #111 !important;
    font-family: 'Estedad', 'Tahoma', sans-serif;
    font-size: 11pt;
    margin: 0;
    padding: 0;
    direction: rtl;
  }

  .dashboard-shell {
    display: block !important;
    min-height: unset;
  }

  .dashboard-main {
    padding: 1cm 1.5cm !important;
    max-width: 100% !important;
  }

  /* Page setup */
  @page {
    size: A4 portrait;
    margin: 1.5cm 2cm;
  }

  /* Card layout for print */
  .panel-card {
    box-shadow: none !important;
    border: 1px solid #bbb !important;
    background: white !important;
    border-radius: 0 !important;
    page-break-inside: avoid;
    break-inside: avoid;
    margin-bottom: 1rem;
  }

  /* Report card table */
  .data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 10pt;
  }

  .data-table th,
  .data-table td {
    border: 1px solid #999 !important;
    padding: 0.4rem 0.6rem;
    text-align: right;
  }

  .data-table th {
    background: #f5f5f5 !important;
    font-weight: 700;
    color: #111 !important;
  }

  .data-table tbody tr:nth-child(even) {
    background: #fafafa !important;
  }

  /* Metric cards in print */
  .metric-card {
    box-shadow: none !important;
    border: 1px solid #ccc !important;
    background: white !important;
    break-inside: avoid;
    border-radius: 0 !important;
  }

  .metric-card strong {
    font-size: 1.4rem !important;
    color: #111 !important;
  }

  /* Dashboard grid compact for print */
  .dashboard-grid {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 0.5rem !important;
  }

  /* Table wrap no overflow in print */
  .table-wrap {
    overflow: visible !important;
  }

  /* Section header in print */
  .section-header {
    margin-bottom: 1rem;
    border-bottom: 2px solid #111;
    padding-bottom: 0.5rem;
  }

  .section-header h2 {
    font-size: 14pt;
    color: #111 !important;
  }

  .section-header p {
    color: #555 !important;
    font-size: 10pt;
  }

  /* Links as plain text */
  a {
    color: #111 !important;
    text-decoration: none !important;
  }

  /* Status pills */
  .badge,
  .status-pill {
    border: 1px solid #999 !important;
    background: transparent !important;
    color: #111 !important;
    font-size: 9pt;
  }
}
