/* =========================================================
   Aresto CRM mobil katman
   Bu dosyadaki kurallar masaüstü görünümünü değiştirmemek için
   yalnızca telefon ve dokunmatik tablet kırılımlarında çalışır.
   ========================================================= */

.mobile-tabbar,
.mobile-product-list {
  display: none;
}

[hidden] {
  display: none !important;
}

/* ===================== Telefon kabuğu ===================== */
@media (max-width: 767.98px) {
  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  body {
    min-height: 100dvh;
    padding-bottom: calc(68px + env(safe-area-inset-bottom));
    overflow-x: hidden;
  }

  .app-shell {
    min-height: 100dvh;
  }

  .app-sidebar {
    z-index: 1050;
    width: min(86vw, 320px);
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
    box-shadow: 0 18px 50px rgba(15, 23, 42, .22);
  }

  .app-backdrop.show {
    z-index: 1044;
  }

  .app-sidebar-header {
    padding: 16px 18px;
  }

  .app-sidebar nav {
    padding: 12px;
  }

  .app-menu-item {
    min-height: 46px;
    font-size: 15px;
  }

  .app-main {
    margin-left: 0;
  }

  .app-topbar {
    height: 58px;
    padding: 0 12px;
    padding-top: env(safe-area-inset-top);
    gap: 8px;
  }

  .app-topbar > .d-flex {
    min-width: 0;
  }

  .app-topbar .app-search {
    display: none;
  }

  .app-topbar-actions {
    gap: 6px;
  }

  .app-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 42px;
    min-height: 42px;
  }

  .app-avatar {
    width: 36px;
    height: 36px;
  }

  .app-content {
    padding: 16px 12px 24px;
  }

  .app-footer {
    display: none;
  }

  .mobile-tabbar {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100vw;
    max-width: 100vw;
    z-index: 1045;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 2px;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    background: #fff;
    border-top: 1px solid var(--border-color);
    transition: transform .2s ease;
  }

  body.menu-open .mobile-tabbar {
    transform: translateY(110%);
  }

  .mobile-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 0;
    min-height: 52px;
    padding: 4px 2px;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: var(--text-gray);
    font-size: 10px;
    font-weight: 600;
    line-height: 1.15;
    text-decoration: none;
  }

  .mobile-tab i {
    font-size: 20px;
    line-height: 1;
  }

  .mobile-tab span {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-tab.active {
    color: var(--aresto);
    background: var(--aresto-soft);
  }

  .mobile-tab:focus-visible {
    outline: 3px solid rgba(34, 197, 94, .35);
    outline-offset: 1px;
  }

  /* iOS: yarı saydam, blur alt bar ve yumuşak yüzeyler */
  .platform-ios .app-topbar {
    background: rgba(255, 255, 255, .88);
    -webkit-backdrop-filter: saturate(180%) blur(18px);
    backdrop-filter: saturate(180%) blur(18px);
  }

  .platform-ios .mobile-tabbar {
    background: rgba(255, 255, 255, .88);
    -webkit-backdrop-filter: saturate(180%) blur(18px);
    backdrop-filter: saturate(180%) blur(18px);
    border-top: .5px solid rgba(15, 23, 42, .16);
  }

  .platform-ios .mobile-tab.active {
    background: rgba(31, 95, 64, .10);
  }

  .platform-ios .card,
  .platform-ios .mobile-card-table tbody tr {
    border-radius: 14px;
  }

  /* Android: Material benzeri yüzey, ripple ve yükseklik */
  .platform-android .mobile-tabbar {
    box-shadow: 0 -2px 12px rgba(15, 23, 42, .10);
  }

  .platform-android .mobile-tab {
    position: relative;
    overflow: hidden;
  }

  .platform-android .mobile-tab.active {
    color: var(--aresto-dark);
    background: #e8f4ed;
  }

  .platform-android .mobile-tab:active::after {
    position: absolute;
    inset: 0;
    content: "";
    background: rgba(31, 95, 64, .12);
  }

  .platform-android .card,
  .platform-android .mobile-card-table tbody tr {
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(15, 23, 42, .10);
  }

  /* Başlık ve sayfa aksiyonları */
  .page-header,
  .app-content > .d-flex.justify-content-between.align-items-center.mb-3,
  .app-content > .d-flex.justify-content-between.align-items-start.mb-3 {
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 16px !important;
  }

  .page-header > div:last-child,
  .app-content > .d-flex.justify-content-between > div:last-child {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
  }

  .page-header > div:last-child > form,
  .app-content > .d-flex.justify-content-between > div:last-child > form {
    flex: 1 1 100%;
  }

  .page-header > div:last-child > form .form-control,
  .app-content > .d-flex.justify-content-between > div:last-child > form .form-control {
    flex: 1 1 auto;
    min-width: 0;
    width: auto;
  }

  .page-header h1,
  .app-content > .d-flex.justify-content-between h1 {
    font-size: 1.45rem;
    line-height: 1.2;
  }

  .app-content > .d-flex.justify-content-between > .btn,
  .app-content > .d-flex.justify-content-between > div:last-child > .btn {
    flex: 1 1 auto;
  }

  .btn {
    min-height: 44px;
  }

  .btn-sm {
    min-height: 40px;
  }

  .form-control,
  .form-select {
    min-height: 44px;
    font-size: 16px;
  }

  .form-control-sm,
  .form-select-sm {
    min-height: 42px;
    font-size: 16px;
  }

  .card-body {
    padding: 1rem;
  }

  .card-body.p-4 {
    padding: 1rem !important;
  }

  .pagination {
    flex-wrap: wrap;
    gap: 4px;
  }

  .page-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    min-height: 40px;
  }

  /* Filtre kartları: telefonda alanlar alt alta */
  .app-content form.card .row.g-2 > [class*="col-"],
  .app-content form.card .row.g-3 > [class*="col-"] {
    flex: 0 0 100%;
    max-width: 100%;
  }

  /* ===================== Mobil kart tabloları ===================== */
  table.mobile-card-table {
    display: block;
    width: 100%;
    min-width: 0 !important;
    table-layout: auto !important;
    border-collapse: separate;
  }

  .mobile-card-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .mobile-card-table tbody {
    display: grid;
    gap: 10px;
  }

  .mobile-card-table tbody tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px 12px;
    padding: 14px;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 12px;
  }

  .mobile-card-table tbody tr.mobile-empty-row {
    display: block;
    padding: 18px;
  }

  .mobile-card-table tbody td {
    display: block;
    min-width: 0;
    padding: 0;
    border: 0;
    text-align: left !important;
    overflow-wrap: anywhere;
  }

  .mobile-card-table tbody td[data-label]::before {
    display: block;
    margin-bottom: 2px;
    color: var(--text-gray);
    font-size: 10px;
    font-weight: 600;
    content: attr(data-label);
  }

  .mobile-card-table tbody td[data-mobile-title] {
    grid-column: 1 / -1;
    font-size: 16px;
    font-weight: 700;
    line-height: 1.3;
  }

  .mobile-card-table tbody td[data-mobile-title]::before {
    display: none;
  }

  .mobile-card-table tbody td[data-mobile-title] a {
    color: var(--text-dark);
    text-decoration: none;
  }

  .mobile-card-table tbody td[data-mobile-full],
  .mobile-card-table tbody td[data-cell="description"] {
    grid-column: 1 / -1;
  }

  .mobile-card-table tbody td[data-mobile-actions] {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
    padding-top: 10px;
    border-top: 1px dashed var(--border-color);
  }

  .mobile-card-table tbody td[data-mobile-actions] form {
    display: contents;
  }

  .mobile-card-table tbody td[data-mobile-actions] .form-control {
    flex: 1 1 100%;
  }

  .mobile-card-table tbody td[data-mobile-hide] {
    display: none !important;
  }

  /* ===================== Ürün listesi ===================== */
  .desktop-product-table {
    display: none;
  }

  .mobile-product-list {
    display: grid;
    gap: 10px;
  }

  .mobile-product-card {
    display: block;
    padding: 14px;
    color: inherit;
    text-decoration: none;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 12px;
  }

  .mobile-product-card:active {
    background: var(--surface);
  }

  .mobile-product-name {
    margin-bottom: 8px;
    font-size: 16px;
    font-weight: 700;
    line-height: 1.3;
  }

  .mobile-product-facts {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 12px;
  }

  .mobile-product-fact span {
    display: block;
    color: var(--text-gray);
    font-size: 10px;
    font-weight: 600;
  }

  .mobile-product-fact strong {
    display: block;
    font-size: 15px;
    font-weight: 700;
  }

  .mobile-product-empty {
    padding: 18px;
    color: var(--text-gray);
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 12px;
  }

  /* ===================== Formlar ===================== */
  [data-mobile-form] .row > [class*="col-"] {
    flex: 0 0 100%;
    max-width: 100%;
  }

  [data-mobile-form] .card {
    margin-bottom: 12px;
  }

  [data-mobile-form] .form-text {
    font-size: .78rem;
  }

  [data-mobile-form] [data-tablet-actions],
  [data-mobile-form] [data-mobile-actions],
  [data-mobile-form] .mobile-form-actions,
  [data-mobile-form] .form-actions-sticky {
    position: sticky;
    right: 0;
    bottom: calc(66px + env(safe-area-inset-bottom));
    left: 0;
    z-index: 8;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 12px -12px -24px;
    padding: 10px 12px;
    background: rgba(244, 246, 248, .96);
    border-top: 1px solid var(--border-color);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
  }

  [data-mobile-form] [data-tablet-actions] .btn,
  [data-mobile-form] [data-mobile-actions] .btn,
  [data-mobile-form] .mobile-form-actions .btn {
    flex: 1 1 auto;
  }

  [data-mobile-form] table[data-product-table] {
    display: block;
    border-collapse: separate;
  }

  [data-mobile-form] table[data-product-table] thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  [data-mobile-form] table[data-product-table] tbody {
    display: grid;
    gap: 10px;
  }

  [data-mobile-form] table[data-product-table] tr[data-line-row] {
    position: relative;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px 12px;
    padding: 14px;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 12px;
  }

  [data-mobile-form] table[data-product-table] tr[data-line-row] > td {
    display: block;
    width: auto !important;
    padding: 0;
    border: 0;
  }

  [data-mobile-form] table[data-product-table] tr[data-line-row] > td[data-label]::before {
    display: block;
    margin-bottom: 4px;
    color: var(--text-gray);
    font-size: 10px;
    font-weight: 600;
    content: attr(data-label);
  }

  [data-mobile-form] table[data-product-table] tr[data-line-row] > td[data-cell="product"],
  [data-mobile-form] table[data-product-table] tr[data-line-row] > td[data-cell="description"],
  [data-mobile-form] table[data-product-table] tr[data-line-row] > td[data-cell="discounts"],
  [data-mobile-form] table[data-product-table] tr[data-line-row] > td[data-cell="total"],
  [data-mobile-form] table[data-product-table] tr[data-line-row] > td[data-cell="total-foreign"] {
    grid-column: 1 / -1;
  }

  [data-mobile-form] table[data-product-table] tr[data-line-row] > td[data-cell="product"]::before,
  [data-mobile-form] table[data-product-table] tr[data-line-row] > td[data-cell="remove"]::before {
    display: none;
  }

  [data-mobile-form] table[data-product-table] tr[data-line-row] > td[data-cell="remove"] {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 44px;
  }

  [data-mobile-form] table[data-product-table] tr[data-line-row] > td[data-cell="remove"] .btn {
    width: 44px;
    height: 44px;
  }

  [data-mobile-form] table[data-product-table] tr[data-line-row] > td[data-cell="total"] {
    padding-top: 8px;
    border-top: 1px dashed var(--border-color);
    font-size: 16px;
    font-weight: 600;
    text-align: right !important;
  }

  [data-mobile-form] table[data-product-table] tr[data-line-row] input,
  [data-mobile-form] table[data-product-table] tr[data-line-row] select,
  [data-mobile-form] table[data-product-table] tr[data-line-row] .rota-combo-input {
    width: 100% !important;
  }

  [data-mobile-form] [data-tablet-summary] {
    order: 20;
  }

  /* ===================== Detay ekranları ===================== */
  .app-content .row.g-4 > [class*="col-"] {
    flex: 0 0 100%;
    max-width: 100%;
  }

  .app-content dl.row dt,
  .app-content dl.row dd {
    flex: 0 0 100%;
    max-width: 100%;
  }

  .app-content dl.row dt {
    margin-top: .55rem;
    color: var(--text-gray);
    font-size: .78rem;
    font-weight: 600;
  }

  .app-content dl.row dd {
    margin-bottom: .35rem;
  }

  .app-content .nav-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
  }

  .app-content .nav-tabs .nav-link {
    white-space: nowrap;
  }

  .app-content .table-responsive {
    -webkit-overflow-scrolling: touch;
  }

  .app-content .alert {
    font-size: .9rem;
  }

  .rota-combo-list {
    max-height: min(48vh, 320px);
    overflow-y: auto;
  }

  .flatpickr-calendar {
    max-width: calc(100vw - 24px);
  }

  /* ===================== Giriş ekranı ===================== */
  .auth-body {
    padding-bottom: 0;
  }

  .auth-shell {
    min-height: 100dvh;
    padding: 18px;
  }

  .auth-split {
    grid-template-columns: 1fr;
    min-height: calc(100dvh - 36px);
  }

  .auth-right {
    display: none;
  }

  .auth-left {
    padding: 24px 18px;
  }

  .auth-brand {
    margin-bottom: 24px;
  }

  .auth-input .form-control {
    min-height: 48px;
  }
}

/* ===================== Dokunmatik tablet ===================== */
@media (min-width: 768px) and (max-width: 1199.98px) and (pointer: coarse) {
  .app-sidebar {
    z-index: 1050;
    width: min(38vw, 320px);
    transform: translateX(-100%);
  }

  .app-sidebar.open {
    transform: none;
  }

  .app-main {
    margin-left: 0;
  }

  .app-sidebar-toggle {
    display: inline-flex;
  }

  .app-backdrop.show {
    position: fixed;
    inset: 0;
    z-index: 1044;
    display: block;
    background: rgba(15, 23, 42, .4);
  }

  .app-content {
    padding: 22px;
  }

  .app-menu-item {
    min-height: 48px;
  }

  .form-control,
  .form-select {
    min-height: 44px;
    font-size: 16px;
  }

  .form-control-sm,
  .form-select-sm {
    min-height: 42px;
    font-size: 16px;
  }

  .btn-sm {
    min-height: 40px;
  }
}
