/**
 * PWA & mobil — güvenli alan, dokunma ve taşma kontrolleri
 */

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: rgba(38, 166, 154, 0.15);
}

.login-body {
  padding-left: env(safe-area-inset-left, 0);
  padding-right: env(safe-area-inset-right, 0);
}

/* Çentikli telefonlar — yatay güvenli alan (mobil kabukta devre dışı) */
@supports (padding: max(0px)) {
  body:not(.layout-auth-mobile) {
    padding-left: env(safe-area-inset-left, 0);
    padding-right: env(safe-area-inset-right, 0);
  }

  .navbar.navbar-expand-lg.navbar-static {
    padding-top: max(0.35rem, env(safe-area-inset-top, 0));
    padding-left: max(0.5rem, env(safe-area-inset-left, 0));
    padding-right: max(0.5rem, env(safe-area-inset-right, 0));
  }

  .sidebar-main:not(.layout-auth-mobile .sidebar-main) {
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  body:not(.layout-auth-mobile) .content-inner {
    padding-bottom: max(1.25rem, env(safe-area-inset-bottom, 0));
  }
}

/* Mobil / tablet — daha rahat dokunma ve okuma */
@media (max-width: 991.98px) {
  .navbar .sidebar-mobile-main-toggle,
  .navbar .navbar-toggler {
    min-width: 44px;
    min-height: 44px;
    align-items: center;
    justify-content: center;
  }

  .nav-sidebar .nav-link {
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  .content-inner {
    padding-left: max(0.65rem, env(safe-area-inset-left, 0));
    padding-right: max(0.65rem, env(safe-area-inset-right, 0));
  }

  body.layout-auth-mobile .content-inner {
    padding-left: 0.65rem;
    padding-right: 0.65rem;
  }

  .container-fluid.px-3,
  .content .container-fluid {
    padding-left: max(0.75rem, env(safe-area-inset-left, 0)) !important;
    padding-right: max(0.75rem, env(safe-area-inset-right, 0)) !important;
  }

  .table-responsive {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }

  .btn:not(.btn-xs):not(.btn-link),
  .dropdown-item {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
  }

  .card {
    border-radius: 0.65rem;
  }
}

@media (max-width: 575.98px) {
  html {
    font-size: 15px;
  }

  .dropdown-menu {
    max-width: calc(100vw - 2rem - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
  }
}

/* Ana ekrana eklendiğinde (standalone) + iOS tam ekran */
@media all and (display-mode: standalone) {
  body.layout-auth-mobile {
    overscroll-behavior-y: none;
  }
}

/* iOS Safari / PWA — 100vh boşluk hatasına karşı */
@supports (-webkit-touch-callout: none) {
  @media (max-width: 991.98px) {
    html:has(body.layout-auth-mobile) {
      height: -webkit-fill-available;
    }

    body.layout-auth-mobile {
      min-height: 100vh;
      min-height: 100dvh;
      min-height: -webkit-fill-available;
    }
  }
}

/* Mobil kabuk — tam ekran, üst/alt boşluk yok */
@media (max-width: 991.98px) {
  html.layout-auth-mobile-root,
  html:has(body.layout-auth-mobile) {
    background-color: #16171a;
    height: 100%;
    height: 100dvh;
    height: -webkit-fill-available;
  }

  body.layout-auth-mobile {
    padding: 0 !important;
    margin: 0;
    background-color: #16171a;
    min-height: 100%;
    min-height: 100dvh;
    min-height: -webkit-fill-available;
  }

  body.layout-auth-mobile .page-content {
    padding-top: 0 !important;
    min-height: 100%;
    min-height: 100dvh;
    min-height: -webkit-fill-available;
    height: 100%;
    height: 100dvh;
    height: -webkit-fill-available;
    max-height: 100dvh;
    max-height: -webkit-fill-available;
  }

  body.layout-auth-mobile .content-wrapper {
    background-color: #f4f6f9;
    padding-top: env(safe-area-inset-top, 0px);
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
    box-sizing: border-box;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
    min-height: 100%;
    height: 100%;
  }

  body.layout-auth-mobile .page-content .content-inner {
    padding-bottom: calc(60px + env(safe-area-inset-bottom, 0px)) !important;
    padding-left: 0;
    padding-right: 0;
  }

  .dashboard-masonry,
  .table-responsive {
    touch-action: pan-y;
  }
}

/* iOS PWA — alt menü tam yapışık */
@supports (-webkit-touch-callout: none) {
  @media (max-width: 991.98px) {
    html.pwa-standalone.layout-auth-mobile-root,
    html.pwa-standalone:has(body.layout-auth-mobile) {
      background-color: #16171a;
    }

    .pwa-standalone .mobile-app-tabbar {
      bottom: 0;
      padding-bottom: constant(safe-area-inset-bottom);
      padding-bottom: env(safe-area-inset-bottom, 0px);
    }
  }
}

/* --------------------------------------------------------------------------
   Mobil uygulama kabuğu — alt sekme çubuğu + tam ekran menü (≤991px)
   -------------------------------------------------------------------------- */
@media (max-width: 991.98px) {
  /* page-content üst padding kaldırıldı — safe-area content-wrapper içinde */
  .layout-auth-mobile .sidebar-main {
    padding-top: env(safe-area-inset-top, 0);
    padding-left: env(safe-area-inset-left, 0);
    padding-right: env(safe-area-inset-right, 0);
  }

  .layout-auth-mobile .sidebar-main.sidebar-mobile-expanded {
    width: 100vw !important;
    max-width: 100vw !important;
    --sidebar-width: 100vw;
    left: 0 !important;
    box-shadow: none;
    border-right: 0;
  }

  .layout-auth-mobile .sidebar-main .sidebar-content {
    min-height: 0;
  }

  .layout-auth-mobile .sidebar-section-nav {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .mobile-app-tabbar {
    --mobile-tabbar-height: 60px;
    --mobile-tabbar-icon-size: 24px;
    --tabbar-safe-bottom: env(safe-area-inset-bottom, 0px);
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1030;
    box-sizing: border-box;
    width: 100%;
    max-width: 100vw;
    margin: 0;
    padding: 0;
    padding-bottom: constant(safe-area-inset-bottom);
    padding-bottom: var(--tabbar-safe-bottom);
    background-color: #16171a;
    border-top: 1px solid rgba(255, 255, 255, 0.07);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.2);
    transform: translateZ(0);
    -webkit-transform: translate3d(0, 0, 0);
  }

  .mobile-app-tabbar-row {
    display: flex;
    justify-content: space-between;
    align-items: stretch;
    gap: 0;
    width: 100%;
    height: var(--mobile-tabbar-height);
    min-height: var(--mobile-tabbar-height);
    max-height: var(--mobile-tabbar-height);
    padding: 0 max(0.2rem, env(safe-area-inset-left, 0px)) 0 max(0.2rem, env(safe-area-inset-right, 0px));
    box-sizing: border-box;
  }

  .mobile-tabbar-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    height: var(--mobile-tabbar-height);
    min-height: 0;
    max-height: var(--mobile-tabbar-height);
    max-width: 5.25rem;
    margin: 0 auto;
    padding: 0.35rem 0.08rem 0.28rem;
    border: 0;
    background: transparent;
    color: rgba(255, 255, 255, 0.62);
    font-size: 0.625rem;
    font-weight: 600;
    text-decoration: none;
    border-radius: 0.5rem;
    position: relative;
    -webkit-tap-highlight-color: transparent;
    line-height: 1;
    overflow: hidden;
  }

  .mobile-tabbar-item i {
    font-size: var(--mobile-tabbar-icon-size);
    width: var(--mobile-tabbar-icon-size);
    height: var(--mobile-tabbar-icon-size);
    line-height: var(--mobile-tabbar-icon-size);
    opacity: 0.88;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .mobile-tabbar-item.active {
    color: #fff;
    background: rgba(255, 255, 255, 0.07);
  }

  .mobile-tabbar-item.active i {
    opacity: 1;
    color: #7dd3c0;
  }

  .mobile-tabbar-menu-btn {
    cursor: pointer;
    font-family: inherit;
  }

  .mobile-tabbar-item-profile .mobile-tabbar-avatar {
    width: var(--mobile-tabbar-icon-size);
    height: var(--mobile-tabbar-icon-size);
    border-radius: 50%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.14);
    font-size: 0.55rem;
    font-weight: 700;
    color: #fff;
  }

  .mobile-tabbar-item-profile .mobile-tabbar-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .mobile-tabbar-badge {
    position: absolute;
    top: 6px;
    right: 50%;
    transform: translateX(1.45rem);
    min-width: 1rem;
    height: 1rem;
    padding: 0 0.28rem;
    border-radius: 999px;
    background: #ef5350;
    color: #fff;
    font-size: 0.52rem;
    font-weight: 700;
    line-height: 1rem;
    text-align: center;
    pointer-events: none;
  }

  .mobile-sidebar-quick {
    padding: 0.85rem 1rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(0, 0, 0, 0.18);
    flex-shrink: 0;
  }

  .mobile-sidebar-quick__title {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.72rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.48);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.65rem;
  }

  .mobile-sidebar-quick__title i {
    font-size: 1rem;
    opacity: 0.85;
  }

  .mobile-sidebar-quick__actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.55rem;
  }

  .mobile-sidebar-quick__btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.68rem 0.8rem;
    border-radius: 0.85rem;
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
    text-decoration: none;
    font-size: 0.88rem;
    font-weight: 600;
    border: 1px solid rgba(255, 255, 255, 0.09);
    min-height: 48px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  }

  .mobile-sidebar-quick__btn i:first-child {
    font-size: 1.28rem;
    opacity: 0.92;
  }

  .mobile-sidebar-quick__avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    overflow: hidden;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.14);
    font-size: 0.62rem;
    font-weight: 700;
    flex-shrink: 0;
    color: #fff;
  }

  .mobile-sidebar-quick__avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
}
