/**
 * DosiPlot v5.0 — Simulation Monte Carlo Interactive
 * © 2025 Pr. Yassine OULHOUQ
 * Université Mohammed Premier (UMP) — Oujda, Maroc
 * Module: Responsive — Media Queries, Mobile Drawer, Adaptive Grid
 */

/* ============================================
   LARGE SCREENS (1440px+)
   ============================================ */
@media (min-width: 1440px) {
  .main {
    grid-template-columns: 300px 1fr;
  }

  .sim-row {
    grid-template-columns: 380px 1fr;
  }

  .trs-row {
    grid-template-columns: 1fr 1fr;
    gap: 20px;
  }

  .cnt {
    padding: 20px;
    gap: 16px;
  }

  .chart-box {
    padding: 20px;
  }

  .phantom-box {
    padding: 18px;
  }

  .hdr {
    padding: 12px 36px;
  }

  .tabs {
    padding: 0 36px;
  }
}

/* ============================================
   DESKTOP (1024px - 1439px)
   ============================================ */
@media (min-width: 1024px) and (max-width: 1439px) {
  .main {
    grid-template-columns: 270px 1fr;
  }

  .sim-row {
    grid-template-columns: 340px 1fr;
  }
}

/* ============================================
   TABLET-DESKTOP TRANSITION (max-width: 1100px)
   ============================================ */
@media (max-width: 1100px) {
  .main {
    grid-template-columns: 240px 1fr;
  }

  .sim-row {
    grid-template-columns: 280px 1fr;
  }
}

/* ============================================
   TABLET (768px - 1023px)
   ============================================ */
@media (min-width: 768px) and (max-width: 1023px) {
  .main {
    grid-template-columns: 220px 1fr;
  }

  .sim-row {
    grid-template-columns: 1fr;
  }

  .trs-row {
    grid-template-columns: 1fr;
    max-height: none;
  }

  .hdr {
    padding: 10px 16px;
  }

  .tabs {
    padding: 0 16px;
  }

  /* Header adjustments */
  .hdr-l {
    gap: 10px;
  }

  .hdr-r {
    gap: 8px;
  }

  .app-t {
    font-size: 17px;
  }

  .linac-tree {
    display: none;
  }

  .logo {
    width: 38px;
    height: 38px;
    font-size: 14px;
  }

  /* Sidebar compact */
  .sb {
    padding: 12px;
  }

  .pnl-t {
    font-size: 8px;
    letter-spacing: 1.2px;
  }

  .pg {
    grid-template-columns: 1fr 1fr;
    gap: 4px;
  }

  .pc {
    padding: 6px;
  }

  .pc-v {
    font-size: 12px;
  }

  /* Chart box */
  .chart-box {
    padding: 12px;
  }

  .ct {
    font-size: 12px;
  }

  .cw {
    min-height: 250px;
  }

  /* TRS steps */
  .trs-steps {
    max-height: none;
    padding: 14px;
  }

  .trs-chart .cw {
    min-height: 220px;
    max-height: 350px;
  }
}

/* ============================================
   MOBILE (max-width: 767px)
   ============================================ */
@media (max-width: 767px) {
  /* Layout: single column */
  .main {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .sim-row {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .trs-row {
    grid-template-columns: 1fr;
    gap: 10px;
    max-height: none;
  }

  /* Header mobile layout */
  .hdr {
    padding: 8px 12px;
    flex-wrap: wrap;
    gap: 8px;
  }

  .hdr-l {
    flex: 1;
    min-width: 0;
    gap: 10px;
  }

  .hdr-r {
    width: 100%;
    justify-content: flex-end;
    gap: 6px;
    flex-wrap: wrap;
  }

  .app-t {
    font-size: 16px;
  }

  .app-st {
    font-size: 8px;
    letter-spacing: 0.5px;
  }

  .app-author {
    font-size: 10px;
  }

  .linac-tree {
    display: none;
  }

  .logo {
    width: 36px;
    height: 36px;
    font-size: 13px;
    border-radius: 8px;
  }

  /* Hide elements on mobile */
  .hdr-r > span {
    display: none;
  }

  /* Tabs: horizontal scroll */
  .tabs {
    padding: 0 10px;
    gap: 0;
    -webkit-overflow-scrolling: touch;
  }

  .tab {
    padding: 10px 14px;
    font-size: 10px;
  }

  /* ========================
     MOBILE SIDEBAR — INLINE PANEL
     ======================== */
  .sb {
    position: relative;
    width: 100%;
    height: auto;
    z-index: auto;
    transform: none;
    padding: 10px 12px;
    overflow-y: visible;
    box-shadow: none;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .sb.drawer-open {
    transform: none;
  }

  /* Compact: inline controls layout */
  .sb .pnl {
    margin-bottom: 6px;
  }

  .sb .pnl-t {
    display: none;
  }

  .sb .fg {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
    margin-right: 8px;
  }

  .sb .fl {
    display: inline;
    margin-bottom: 0;
    white-space: nowrap;
    font-size: 10px;
  }

  .sb select {
    width: auto;
    min-width: 90px;
    padding: 6px 24px 6px 8px;
    font-size: 11px;
  }

  .sb .btn-grp {
    margin-top: 4px;
    margin-bottom: 0;
  }

  .sb .btn-run {
    padding: 8px 16px;
    font-size: 11px;
  }

  /* Hide results and extras on mobile — keep only inputs + simulate */
  .sb .teacher-only,
  .sb .sep,
  .sb .btn-s,
  .sb .empirical-panel,
  .sb .eprof-depth-note,
  .sb .mv-note {
    display: none;
  }

  /* Drawer overlay — still available but not needed for inline panel */
  .drawer-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 199;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
  }

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

  /* Drawer toggle — hide since panel is always visible */
  .drawer-toggle {
    display: none;
  }

  /* Content area full width */
  .cnt {
    padding: 10px;
    gap: 10px;
  }

  /* Chart box mobile */
  .chart-box {
    padding: 10px;
    border-radius: 10px;
  }

  .ch {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  .ct {
    font-size: 12px;
  }

  .cw {
    min-height: 220px;
  }

  /* Phantom box mobile */
  .phantom-box {
    padding: 10px;
    border-radius: 10px;
  }

  .phantom-title {
    font-size: 10px;
  }

  /* TRS mobile */
  .trs-chart {
    border-radius: 10px;
    padding: 12px;
  }

  .trs-steps {
    border-radius: 10px;
    padding: 12px;
    max-height: none;
  }

  .trs-chart .cw {
    min-height: 200px;
    max-height: 300px;
  }

  .step {
    padding: 10px;
    border-radius: 8px;
  }

  .step-formula {
    font-size: 10px;
    padding: 8px;
  }

  .trs-result-val {
    font-size: 20px;
  }

  /* Result cards mobile */
  .pg {
    grid-template-columns: 1fr 1fr;
    gap: 4px;
  }

  .pc {
    padding: 6px;
  }

  .pc-l {
    font-size: 7px;
  }

  .pc-v {
    font-size: 12px;
  }

  /* Buttons mobile */
  .btn-run {
    padding: 11px;
    font-size: 11px;
  }

  .btn-s {
    padding: 8px;
    font-size: 10px;
  }

  /* Data table mobile */
  .dtc {
    max-height: 150px;
    padding: 8px;
  }

  .dt th,
  .dt td {
    padding: 4px;
    font-size: 8px;
  }

  /* Toast mobile */
  .toast {
    bottom: 10px;
    right: 10px;
    left: 10px;
    text-align: center;
  }

  /* TP mobile */
  .tp-input-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .tp-input-row label {
    min-width: auto;
  }

  .tp-input {
    width: 100%;
  }

  .tp-phase {
    padding: 10px;
  }

  /* Comparison mobile */
  .cmp-guidance {
    padding: 10px 12px;
    font-size: 11px;
  }

  /* Password modal mobile */
  .pw-box {
    width: calc(100% - 32px);
    max-width: 340px;
    padding: 20px;
  }

  /* Mode toggle */
  .mode-toggle {
    padding: 8px;
  }

  .mode-label {
    font-size: 8px;
  }

  /* Lang selector */
  .lang-sel {
    height: 28px;
  }

  .lang-btn {
    padding: 0 8px;
    font-size: 8px;
  }

  /* Theme button */
  .theme-btn {
    width: 32px;
    height: 32px;
    font-size: 16px;
  }

  /* Gloss tips position fix on mobile */
  .gloss-tip {
    min-width: 160px;
    max-width: 220px;
    margin-left: -80px;
    font-size: 10px;
  }

  /* Scrollbar narrower on mobile */
  ::-webkit-scrollbar {
    width: 4px;
    height: 4px;
  }
}

/* ============================================
   SMALL MOBILE (max-width: 480px)
   ============================================ */
@media (max-width: 480px) {
  .hdr {
    padding: 6px 10px;
  }

  .app-t {
    font-size: 14px;
  }

  .app-author {
    display: none;
  }

  .logo {
    width: 32px;
    height: 32px;
    font-size: 12px;
  }

  .tabs {
    padding: 0 6px;
  }

  .tab {
    padding: 8px 10px;
    font-size: 9px;
  }

  .cnt {
    padding: 8px;
    gap: 8px;
  }

  .sb {
    width: 100%;
    padding: 8px 10px;
  }

  .chart-box {
    padding: 8px;
  }

  .cw {
    min-height: 180px;
  }

  .pg {
    grid-template-columns: 1fr 1fr;
    gap: 3px;
  }

  .pc {
    padding: 4px;
  }

  .pc-v {
    font-size: 11px;
  }

  .pc-l {
    font-size: 6px;
  }
}

/* ============================================
   DESKTOP-ONLY ELEMENTS
   ============================================ */
.drawer-toggle {
  display: none;
}

.drawer-overlay {
  display: none;
}

@media (max-width: 767px) {
  .drawer-toggle {
    display: flex;
  }
}

/* ============================================
   LANDSCAPE MOBILE
   ============================================ */
@media (max-width: 767px) and (orientation: landscape) {
  .hdr {
    padding: 4px 12px;
  }

  .logo {
    width: 28px;
    height: 28px;
    font-size: 11px;
  }

  .tabs {
    padding: 0 8px;
  }

  .tab {
    padding: 6px 12px;
    font-size: 9px;
  }

  .main {
    min-height: auto;
  }

  .cw {
    min-height: 160px;
  }
}

/* ============================================
   HIGH DPI DISPLAYS
   ============================================ */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .logo {
    image-rendering: -webkit-optimize-contrast;
  }

  ::-webkit-scrollbar-thumb {
    background: rgba(100, 160, 255, 0.18);
  }
}

/* ============================================
   TOUCH DEVICES
   ============================================ */
@media (hover: none) and (pointer: coarse) {
  /* Larger touch targets */
  .btn-run {
    padding: 15px;
    min-height: 48px;
  }

  .btn-pause {
    min-height: 48px;
  }

  .btn-s {
    padding: 12px;
    min-height: 44px;
  }

  .tab {
    padding: 14px 18px;
  }

  select {
    padding: 12px 32px 12px 14px;
    min-height: 44px;
  }

  .mode-toggle {
    padding: 12px;
    min-height: 48px;
  }

  .theme-btn {
    width: 40px;
    height: 40px;
  }

  .lang-btn {
    padding: 0 12px;
    min-height: 36px;
  }

  .tp-btn-check {
    padding: 6px 16px;
    min-height: 36px;
  }

  .tp-input {
    padding: 8px 10px;
    min-height: 36px;
  }

  /* Disable hover effects on touch */
  .btn-run:hover {
    transform: none;
  }

  .pc:hover {
    border-color: var(--border);
    box-shadow: none;
  }

  .hover-lift:hover {
    transform: none;
  }

  .hover-scale:hover {
    transform: none;
  }
}

/* ============================================
   PRINT RESPONSIVE OVERRIDES
   ============================================ */
@media print {
  .main {
    display: block;
  }

  .sb {
    display: none !important;
  }

  .tabs {
    display: none !important;
  }

  .hdr {
    display: none !important;
  }

  .chart-box,
  .phantom-box,
  .trs-chart,
  .trs-steps {
    break-inside: avoid;
    page-break-inside: avoid;
    box-shadow: none;
    border: 1px solid #ddd;
  }

  .cnt {
    padding: 0;
  }
}
