/* KLİNİK — Windows, dikey tablet ve telefon için ortak responsive katman */

html, body, #app, .main, .content { max-width: 100%; }
.main, .content, .card, .card-body, .page-head, .row, .grid2, .grid3 { min-width: 0; }
.page-head { flex-wrap: wrap; }
.card { max-width: 100%; }
img, video, canvas, svg { max-width: 100%; }

/* Uzun listelerde ekran dışında kalan kartların çizimini tarayıcı ihtiyaç anına erteler. */
.report-mobile-card, .photo, .harita-kart, .oneri-satir {
  content-visibility: auto;
  contain-intrinsic-size: auto 150px;
}

/* Orta genişlikte yatay ekranlarda menü içerikten gereksiz alan almasın. */
@media (min-width: 901px) and (max-width: 1300px) and (orientation: landscape) {
  :root { --sidebar-w: 220px; }
  .sidebar { padding-inline: 10px; }
  .content { padding-inline: 18px; }
}

/* iPad dikey görünümü: 1024px genişlik artık masaüstü değil tablet kabul edilir. */
@media (orientation: portrait) and (max-width: 1180px) {
  body { overflow-x: hidden; }
  .sidebar { display: none !important; }
  .main { width: 100%; }
  .content {
    width: 100%;
    max-width: none;
    padding: 18px 18px calc(92px + env(safe-area-inset-bottom));
  }
  .topbar {
    gap: 12px;
    padding: max(10px, env(safe-area-inset-top)) 18px 10px;
  }
  .topbar .search { min-width: 0; max-width: none; }
  .topbar .search input { min-width: 0; font-size: 16px; }
  .topbar .who { flex: 0 0 auto; }
  .topbar .who .r { display: none; }

  .bottom-nav {
    display: flex;
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 60;
    justify-content: space-around;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--stroke-soft);
    background: var(--surface-lowest);
  }
  .bottom-nav .nav-item {
    width: auto;
    min-width: 0;
    min-height: 54px;
    flex: 1 1 0;
    flex-direction: column;
    gap: 3px;
    padding: 6px 5px;
    color: var(--on-surface-variant);
    font-size: 10px;
  }
  .bottom-nav .nav-item.active { color: var(--primary); }
  .bottom-nav .nav-item svg { width: 21px; height: 21px; }

  .dash-cols { grid-template-columns: minmax(0, 1fr) !important; }
  .page-head > .grow { flex: 1 1 100%; }
  .tabs { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { flex: 0 0 auto; }

  /* Rapor tablosu yerine dokunmaya uygun, kesilmeyen kartlar. */
  .report-desktop-table { display: none !important; }
  .report-mobile-list {
    display: grid !important;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 12px;
    padding: 12px;
  }
  .report-list-card { overflow: visible; }
  .report-mobile-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 9px 12px;
    min-width: 0;
    padding: 14px;
    border: 1px solid var(--stroke-soft);
    border-radius: 14px;
    background: var(--surface-lowest);
    box-shadow: 0 2px 10px rgba(23, 35, 49, .05);
  }
  .report-mobile-patient {
    min-width: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--on-surface);
    text-align: left;
  }
  .report-mobile-patient b,
  .report-mobile-patient small,
  .report-mobile-topic small { display: block; }
  .report-mobile-patient b { overflow: hidden; font-size: 15px; text-overflow: ellipsis; white-space: nowrap; }
  .report-mobile-patient small,
  .report-mobile-topic small { margin-top: 4px; color: var(--outline); font-size: 10px; }
  .report-mobile-date { align-self: start; color: var(--outline); font: 10px var(--font-mono); white-space: nowrap; }
  .report-mobile-topic { min-width: 0; }
  .report-mobile-topic .chip { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: normal; }
  .report-mobile-status { justify-self: end; }
  .report-mobile-actions {
    grid-column: 1 / 3;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 8px;
    padding-top: 3px;
  }
  .report-mobile-actions .btn { width: 100%; min-width: 0; margin: 0; }
  .page-head:has(#rapor-ara) {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
  }
  .page-head:has(#rapor-ara) .grow { grid-column: 1 / -1; }
  .page-head:has(#rapor-ara) .search { width: 100%; min-width: 0 !important; }

  /* Mobil karşılığı olmayan geniş tablolar güvenli biçimde yatay kaydırılabilir. */
  table:not(.report-desktop-table) {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
  }

  .modal-bg { min-height: 100dvh; padding: max(14px, env(safe-area-inset-top)) 14px; }
  .modal, .modal.wide { width: 100%; max-width: min(760px, 96vw); max-height: calc(100dvh - 28px); }
}

/* Telefon: tek sütun, büyük dokunma hedefleri ve güvenli alt menü. */
@media (max-width: 720px) {
  .content { padding: 14px 10px calc(92px + env(safe-area-inset-bottom)); }
  .topbar { padding-inline: 10px; }
  .topbar .who { display: none; }
  .grid2, .grid3 { grid-template-columns: minmax(0, 1fr) !important; }
  .report-mobile-list { grid-template-columns: minmax(0, 1fr); padding: 8px; }
  .report-mobile-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .report-mobile-actions .btn:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .page-head:has(#rapor-ara) { grid-template-columns: minmax(0, 1fr); }
  .page-head:has(#rapor-ara) .grow,
  .page-head:has(#rapor-ara) .search,
  .page-head:has(#rapor-ara) #btn-rapor-yeni { grid-column: 1; width: 100%; }
  .modal, .modal.wide { max-width: 100%; border-radius: 14px; }
  .modal-foot { flex-direction: column-reverse; }
  .modal-foot .btn { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
