/* ==========================================================================
   DentCell — Mobil görünüm (sadece telefon / küçük tablet)
   Masaüstü tasarım değişmez: tüm kurallar max-width medya sorgularının içindedir.
   ========================================================================== */

@media (max-width: 768px) {
  html, body { overflow-x: hidden; }
  body { -webkit-text-size-adjust: 100%; }
  input, select, textarea { font-size: 16px !important; } /* iOS'ta odaklanınca yakınlaştırmayı önler */

  /* ---------- Genel: satır içi ızgaralar tek sütuna ---------- */
  [style*="grid-template-columns"] { grid-template-columns: 1fr !important; }
  [style*="grid-template-columns: repeat(4"],
  [style*="grid-template-columns: 1fr 1fr 1fr 1fr"] { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  [style*="justify-content: space-between"] { flex-wrap: wrap; row-gap: 10px; }
  /* Izgara/esnek öğeler içeriği (ör. geniş tablolar) yüzünden ekrandan taşmasın */
  [style*="grid-template-columns"] > *, [style*="display: grid"] > *, [style*="display: flex"] > * { min-width: 0; }
  .web-main-container, .web-content-body, .web-card { max-width: 100vw; }
  .stat-card-delta { font-size: .72rem !important; }
  .stat-card-delta span { font-size: inherit !important; }
  .web-card, .rad-card, .stk-card { padding: 16px !important; border-radius: 16px !important; }
  .web-table-wrapper, .stk-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; }
  .web-table-wrapper .web-table { min-width: 560px; }
  :not(.web-table-wrapper) > .web-table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; white-space: nowrap; max-width: 100%; }

  /* Tedavi planı ve teklif belgesi */
  .apple-plan-editor, .apple-doc-sheet { max-width: 100%; padding: 16px 12px !important; border-radius: 20px !important; min-height: 0 !important; overflow-x: hidden; }
  .apple-plan-editor table, .apple-doc-sheet table { display: block; overflow-x: auto; white-space: nowrap; max-width: 100%; }
  .apple-plan-header, .apple-doc-header { flex-wrap: wrap; gap: 10px; }
  .apple-doc-meta { text-align: left !important; }
  .anatomical-mouth-stage { padding: 8px 4px !important; border-radius: 20px !important; }
  .anatomical-mouth-stage svg { width: 100% !important; max-width: 100% !important; height: auto !important; }
  .mini-odonto { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  #btn-copy-proposal-link span, #btn-print-proposal-pdf span { display: none; }
  #btn-send-proposal-whatsapp { flex: 1; }
  h2:has(> span + span) { font-size: 1.1rem !important; flex-wrap: wrap; gap: 4px !important; }

  /* Takvim: hafta görünümü yatay kaydırılır */
  .calendar-grid-weekly { min-width: 640px; }
  .calendar-grid-weekly { grid-template-columns: 56px repeat(7, minmax(92px, 1fr)) !important; }
  .calendar-grid-weekly { min-width: 720px; }
  div:has(> .calendar-grid-weekly) { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Diş penceresi kapatma */
  .tooth-zoom-modal-card { position: relative; }
  #btn-close-tooth-zoom { position: absolute !important; top: 14px; right: 14px; z-index: 6; }
  #btn-close-tooth-zoom:empty::before { content: '✕'; font-size: .9rem; }
  .web-table th, .web-table td { padding: 10px 8px !important; font-size: .78rem; }
  h1, h2 { word-break: break-word; }
  .btn-web { padding: 10px 14px; }

  /* ---------- Tanıtım sitesi ---------- */
  .web-top-announcement { font-size: .7rem !important; padding: 6px 10px !important; gap: 6px !important; }
  .web-top-announcement > span:first-child { display: none; }
  .web-nav-container { padding: 0 14px !important; gap: 8px; height: 60px; }
  .web-brand-badge { display: none; }
  .web-brand-title { font-size: 1.05rem; }
  .web-nav-actions { gap: 6px; }
  .web-nav-actions .btn-web { padding: 8px 10px; font-size: .74rem; white-space: nowrap; }
  #btn-nav-open-trial span { display: none; }
  #btn-nav-open-trial::before { content: 'Satın Al'; }
  .web-hero-section { padding: 28px 16px 28px !important; gap: 24px !important; }
  .web-hero-title { font-size: 2rem !important; line-height: 1.15; }
  .web-hero-desc { font-size: .95rem; margin-bottom: 22px; }
  .web-hero-cta-group { flex-direction: column; align-items: stretch; gap: 10px; }
  .web-hero-cta-group .btn-web { width: 100%; justify-content: center; }
  .web-hero-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 26px; padding-top: 18px; }
  .web-stat-val { font-size: 1.2rem; }
  .web-stat-highlight-card { min-width: 0 !important; }
  .web-features-grid, .web-pricing-grid { grid-template-columns: 1fr !important; gap: 14px !important; }
  .web-footer-container { grid-template-columns: 1fr !important; gap: 24px !important; }
  section { scroll-margin-top: 70px; }

  /* ---------- Giriş / kayıt ---------- */
  .web-auth-card, .checkout-wizard-card { margin: 16px auto !important; padding: 20px 16px !important; border-radius: 20px !important; max-width: calc(100vw - 24px) !important; }
  .wizard-steps-header { overflow-x: auto; gap: 10px; padding-bottom: 16px; margin-bottom: 20px; }
  .wizard-step-node { flex-shrink: 0; font-size: .72rem; }

  /* ---------- Portal üst çubuğu ---------- */
  .web-topbar { height: auto !important; padding: 10px 12px !important; flex-wrap: wrap; gap: 8px; position: sticky; top: 0; z-index: 90; }
  .web-topbar > div:first-child { min-width: 0; flex: 1 1 100%; }
  .web-topbar > div:first-child > div:last-child { min-width: 0; }
  .web-topbar > div:first-child > div:last-child > div:last-child { flex-wrap: wrap; row-gap: 0; }
  .web-topbar > div:first-child > div:last-child > div:last-child strong { display: inline-block; max-width: 52vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
  .web-topbar > div:last-child { width: 100%; justify-content: space-between; gap: 6px !important; }
  .web-topbar > div:last-child > * { flex-shrink: 0; }
  .web-topbar .web-user-chip { display: none !important; }
  .web-topbar .btn-web { padding: 8px 10px !important; font-size: .74rem !important; }
  #btn-topbar-new-patient span, .web-topbar a[href="admin.html"] span, #btn-web-logout span { display: none; }
  #btn-topbar-new-appointment { flex: 1; }

  /* ---------- Portal içerik ---------- */
  .web-main-container { padding-bottom: 96px !important; }
  .web-content-body { padding: 14px 12px !important; }
  .web-stat-card { padding: 14px !important; }
  .stat-card-value { font-size: 1.25rem !important; }
  .stat-card-label { font-size: .72rem !important; }
  .stat-card-icon { width: 34px !important; height: 34px !important; }

  /* ---------- Alt menü: uygulama sekme çubuğu ---------- */
  .web-bottom-dock:not(.web-bottom-dock-collapsed), .web-sidebar:not(.web-bottom-dock-collapsed) {
    left: 0 !important; right: 0 !important; bottom: 0 !important; transform: none !important; max-width: none !important; width: 100% !important;
    border-radius: 20px 20px 0 0 !important; padding: 6px 6px calc(6px + env(safe-area-inset-bottom)) !important;
    justify-content: flex-start !important;
  }
  .web-bottom-dock-nav, .web-sidebar-nav { overflow-x: auto !important; overflow-y: hidden !important; gap: 2px !important; padding: 0 2px !important; margin: 0 !important; width: 100%; scroll-snap-type: x proximity; }
  .web-nav-btn { flex-direction: column !important; gap: 2px !important; padding: 6px 10px !important; min-width: 64px; font-size: .64rem !important; border-radius: 14px !important; scroll-snap-align: start; }
  .web-nav-btn .web-nav-label { font-size: .64rem !important; }
  .web-nav-btn:hover { transform: none !important; }
  .dock-center-slot { transform: none !important; margin: 0 !important; }
  .web-nav-btn.btn-center-clinic { padding: 6px 10px !important; }
  .btn-toggle-dock-close { flex-shrink: 0; }
  .web-bottom-dock.web-bottom-dock-collapsed { bottom: 14px !important; }
  #btn-web-fullscreen { display: none !important; }

  /* ---------- Ana ekran (Klinik) ---------- */
  .apple-home-container { padding: 16px !important; min-height: calc(100vh - 80px); }
  .apple-glass-master-card { padding: 28px 18px !important; border-radius: 26px !important; }
  .apple-glass-master-card > div[style*="font-size: 3.4rem"] { font-size: 2rem !important; gap: 8px !important; }
  .apple-glass-master-card > div[style*="font-size: 1.55rem"] { font-size: 1.1rem !important; margin-bottom: 22px !important; }
  .apple-logo-badge { width: 84px !important; height: 84px !important; }

  /* ---------- Hasta dosyası ---------- */
  .patient-profile-banner { flex-direction: column; align-items: flex-start !important; gap: 14px; padding: 18px 16px !important; }
  .patient-profile-banner h1 { font-size: 1.2rem !important; }
  .patient-profile-banner > div:first-child > div:last-child > div { flex-wrap: wrap; gap: 6px 10px !important; }
  .patient-avatar-badge { width: 52px !important; height: 52px !important; font-size: 1.1rem !important; }
  .patient-timeline-bar { overflow-x: auto; flex-wrap: nowrap !important; padding: 12px !important; }
  .patient-tab-nav { overflow-x: auto; flex-wrap: nowrap !important; -webkit-overflow-scrolling: touch; padding-bottom: 6px; }
  .patient-tab-btn { flex-shrink: 0; white-space: nowrap; }
  .anatomical-mouth-stage { margin: 0 -8px; }
  .dentition-switch-bar { flex-wrap: wrap; gap: 8px; }
  .dentition-btn small { display: none; }
  .bulk-bar { gap: 6px; }
  .bulk-apply { margin-left: 0; width: 100%; }
  .bulk-hint { display: none; }

  /* ---------- Pencereler: alttan açılan sayfa ---------- */
  .web-modal-backdrop { align-items: flex-end !important; padding: 0 !important; }
  .web-modal-box { width: 100% !important; max-width: 100% !important; margin: 0 !important; border-radius: 22px 22px 0 0 !important; max-height: 92vh; display: flex; flex-direction: column; animation: dcSheetUp .22s cubic-bezier(.16,1,.3,1); }
  .web-modal-box > form { display: flex; flex-direction: column; min-height: 0; }
  .web-modal-body { overflow-y: auto; max-height: none !important; padding: 16px !important; }
  .web-modal-header { padding: 16px !important; position: relative; }
  .web-modal-header::before { content: ''; position: absolute; top: 6px; left: 50%; width: 40px; height: 4px; border-radius: 4px; background: #cbd5e1; transform: translateX(-50%); }
  .web-modal-footer { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)) !important; position: sticky; bottom: 0; background: #fff; }
  .web-modal-footer .btn-web { flex: 1; }
  @keyframes dcSheetUp { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }

  /* Diş penceresi */
  .tooth-zoom-modal-backdrop { padding: 0 !important; align-items: flex-end !important; }
  .tooth-zoom-modal-card { width: 100% !important; max-width: 100% !important; height: auto !important; max-height: 94vh !important; border-radius: 22px 22px 0 0 !important; overflow-y: auto !important; padding: 16px 14px calc(14px + env(safe-area-inset-bottom)) !important; display: block !important; }
  .tooth-zoom-body { display: flex !important; flex-direction: column; gap: 14px; grid-template-columns: none !important; min-height: 0; overflow: visible !important; }
  .tooth-zoom-right, .tooth-zoom-left { width: 100% !important; max-height: none !important; overflow: visible !important; }
  .tooth-zoom-right .tx-picker { min-height: 60vh; }
  .tooth-zoom-save { position: sticky; bottom: 0; z-index: 5; }
  .tx-tree { max-height: 46vh; }
  .tx-pop { left: 0; right: 0; }

  /* Bildirim paneli ve toast */
  .notif-panel { left: 8px !important; right: 8px !important; width: auto !important; max-height: 75vh; }
  #toast-mount { left: 8px !important; right: 8px !important; top: 8px !important; }
  .toast-item { max-width: none !important; width: 100% !important; }

  /* ---------- Stok ---------- */
  .stk-head { flex-direction: column; align-items: stretch !important; gap: 12px; }
  .stk-actions { display: grid !important; grid-template-columns: 1fr 1fr; gap: 8px; }
  .stk-actions .stk-btn-ai { grid-column: 1 / -1; }
  .stk-stats { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .stk-toolbar { flex-direction: column; align-items: stretch !important; }
  .stk-toolbar > * { width: 100% !important; max-width: none !important; flex: none !important; }
  .stk-table { min-width: 1500px; }
  .stk-table-wrap { max-height: 70vh; }
  .stk-levels { display: flex; }
  .stk-levels button { flex: 1; }
  .stk-dialog { width: 100% !important; max-width: 100% !important; max-height: 94vh; border-radius: 22px 22px 0 0 !important; align-self: flex-end; }
  .stk-overlay { align-items: flex-end !important; padding: 0 !important; }

  /* ---------- WhatsApp sohbet ---------- */
  .wa-drawer { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .wa-side { max-height: 30vh; }
  .wa-profile-card { flex-direction: column; align-items: flex-start; }
  .wa-profile-card > div:last-child { width: 100%; }

  /* ---------- Radyoloji ---------- */
  .rad-top { padding: 10px 14px; }
  .rad-brand small { display: none; }
  .rad-user span { display: none; }
  .rad-logout span { display: none; }
  .rad-main { padding: 14px 12px 110px; }
  .rad-dock { left: 0; right: 0; bottom: 0; transform: none; border-radius: 20px 20px 0 0; justify-content: space-around; padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); }
  .rad-dock button { flex-direction: column; gap: 3px; padding: 8px 14px; font-size: .7rem; }
  .rad-dock button span { display: inline !important; }
  .rad-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .rad-stat b { font-size: 1.35rem; }
  .rad-table { min-width: 520px; }
  .rad-card { overflow-x: auto; }
  .rad-files { grid-template-columns: 1fr; }
  .rad-plist { position: static; height: auto; max-height: 52vh; }
  .rad-work { grid-template-columns: 1fr; }
  .rad-qitem { flex-wrap: wrap; }
  .rad-qitem img { width: 100%; height: 140px; }
  .rad-thumbs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rad-req-main .rad-teeth { align-self: flex-start; margin-left: 0; }
  .rad-req { flex-wrap: wrap; }
  .rad-req-act { flex-direction: row; flex-wrap: wrap; }
  .rad-del { opacity: 1; }

  /* Röntgen görüntüleyici */
  .rv-bar { padding: 4px 6px; }
  .rv-logo span { display: none; }
  .rv-tool { min-width: 50px; font-size: .58rem; padding: 5px 4px; }
  .rv-sliders { flex-direction: column; gap: 2px; padding: 0 6px; }
  .rv-sliders input { width: 80px; }
  .rv-series { display: none !important; }
  .rv-info { font-size: .62rem; }
}

@media (max-width: 420px) {
  .web-hero-title { font-size: 1.75rem !important; }
  .web-nav-actions #btn-nav-open-login span { display: none; }
  [style*="grid-template-columns: repeat(4"],
  [style*="grid-template-columns: 1fr 1fr 1fr 1fr"] { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
}

/* ===== Mobil uygulama içinde gömülü görünüm (web.html?embed=1) ===== */
.dc-embed .web-topbar,
.dc-embed .web-bottom-dock,
.dc-embed .web-sidebar,
.dc-embed #dc-imp-bar { display: none !important; }
.dc-embed body.web-body { background: transparent; }
.dc-embed .web-main-container { padding-top: 12px !important; padding-bottom: 32px !important; }

/* ===== Telefon: hasta dosyaları listesi kart görünümü ===== */
@media (max-width: 768px) {
  .pt-page { padding: 16px !important; }
  .pt-head h2 { font-size: 1.15rem !important; }
  .pt-head .btn-web { width: 100%; justify-content: center; }
  .pt-filters { grid-template-columns: 1fr 1fr !important; gap: 8px !important; }
  .pt-filters > div:first-child { grid-column: 1 / -1; }
  .pt-filters #sel-sort-patient { grid-column: 1 / -1; }
  .pt-filters .web-input-field { min-height: 42px; font-size: .86rem; }
  .pt-page .web-table-wrapper { border: 0; overflow: visible; background: transparent; box-shadow: none; margin: 0; }
  .pt-page .web-table-wrapper .web-table.pt-table { min-width: 0; white-space: normal; }
  .pt-table, .pt-table tbody { display: block; width: 100%; }
  .pt-table thead { display: none; }
  .pt-table tr.pt-row { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; padding: 14px; margin: 0 0 10px; background: #fff; border: 1px solid #e2e8f0; border-radius: 16px; box-shadow: 0 2px 10px rgba(15, 23, 42, .04); }
  .pt-table tr.pt-row td { display: block; padding: 0 !important; border: 0; font-size: .8rem !important; background: none !important; min-width: 0; }
  .pt-table td.pt-c-name { grid-column: 1; }
  .pt-table td.pt-c-status { grid-column: 2; grid-row: 1; text-align: right; }
  .pt-table tr.pt-row td.pt-c { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding-top: 7px !important; border-top: 1px solid #f1f5f9; color: #334155; }
  .pt-table td.pt-c::before { content: attr(data-label); color: #94a3b8; font-weight: 600; flex: none; }
  .pt-table td.pt-c > * { text-align: right; }
  .pt-table tr.pt-row td.pt-c-act { grid-column: 1 / -1; margin-top: 6px; }
  .pt-table td.pt-c-act .btn-web { width: 100%; justify-content: center; padding: 10px !important; font-size: .85rem !important; }
  .pt-table tr:not(.pt-row) td { display: block; }
}

/* ===== Telefon: ayarlar sekmeleri kaydırma yerine ızgara ===== */
@media (max-width: 760px) {
  .settings-subtabs { display: grid !important; grid-template-columns: repeat(3, 1fr); gap: 6px; overflow: visible; width: 100%; box-sizing: border-box; }
  .settings-subtab { flex-direction: column; justify-content: center; gap: 4px; padding: 10px 6px !important; font-size: .72rem !important; white-space: normal; text-align: center; line-height: 1.2; }
  .settings-subtab svg { width: 18px; height: 18px; }
  /* Kart içi form satırları ve buton grupları alt alta */
  .sec-inline { flex-direction: column; align-items: stretch !important; }
  .sec-inline > * { width: 100%; box-sizing: border-box; }
  .hid-head { flex-direction: column; }
  .fx-bar { gap: 8px; }
  .fx-seg { width: 100%; } .fx-btn { flex: 1; }
  .appt-bulk { width: 100%; } .appt-bulk .btn-web { flex: 1; }
  .cal-pop.cal-detail { width: calc(100vw - 24px); }
  .web-modal-box { max-width: calc(100vw - 20px) !important; }
  .web-modal-body [style*="grid-template-columns: 1.5fr 1fr 1fr"], .web-modal-body [style*="grid-template-columns: 1fr 1fr"] { grid-template-columns: 1fr 1fr !important; }
  .web-modal-footer { flex-wrap: wrap; gap: 8px; }
  .web-modal-footer .btn-web { flex: 1 1 auto; justify-content: center; }
}

/* ===== Telefon: ajanda üst kısmı ===== */
@media (max-width: 760px) {
  .badge-web { white-space: nowrap; }
  .cal-tools { display: grid !important; grid-template-columns: 1fr 1fr; gap: 8px; width: 100%; }
  .cal-tools > :last-child { grid-column: 1 / -1; justify-content: center; }
  .cal-tools select, .cal-tools .btn-web { width: 100%; box-sizing: border-box; min-height: 42px; font-size: .8rem !important; padding: 8px 10px !important; }
}
