/* ============================================================================
   mobile.css — Giao diện tối ưu điện thoại (dashboard + dùng chung)
   ============================================================================ */

/* Touch targets */
@media (max-width: 768px) {
  .btn {
    min-height: 44px;
    padding: 10px 14px;
  }
  .btn-sm {
    min-height: 40px;
    padding: 8px 12px;
    font-size: 13px;
  }
  .input, .select, .textarea {
    font-size: 16px; /* tránh zoom tự động iOS khi focus */
  }
}

/* ============== Dashboard ============== */
.devices-cards {
  display: none;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
}

.device-card {
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--sh-md);
  padding: 12px 14px;
}

.device-card-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
}

.device-card-title {
  flex: 1;
  min-width: 0;
}

.device-card-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-bottom: 10px;
}

.device-card-slot {
  font-size: 11px;
  color: var(--muted);
  font-family: var(--font-mono);
  margin-left: auto;
}

.device-card .actions-cell {
  max-width: none;
  gap: 8px;
}

.device-card .actions-cell .btn {
  flex: 1 1 calc(50% - 4px);
  justify-content: center;
  min-width: 0;
  white-space: normal;
  text-align: center;
  line-height: 1.2;
}

.devices-scroll {
  width: 100%;
}

@media (max-width: 768px) {
  body {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }

  .app-frame {
    margin: 8px auto;
    max-width: 100%;
    border-radius: 12px;
    overflow: visible;
  }

  .app-content {
    overflow: visible;
  }

  .app-titlebar {
    padding: 10px 12px;
    gap: 8px;
  }

  .app-titlebar .logo span:not(.logo-mark) {
    font-size: 16px;
  }

  .app-titlebar .version,
  .app-titlebar .window-btn {
    display: none;
  }

  .app-titlebar .actions {
    margin-left: 0;
    width: 100%;
    justify-content: flex-end;
  }

  .app-toolbar {
    padding: 10px 12px;
    gap: 8px;
  }

  .app-toolbar .help-link {
    width: 100%;
    margin-left: 0;
    text-align: center;
  }

  .devices-desktop {
    display: none !important;
  }

  .devices-cards {
    display: flex;
  }

  .view-screens-grid {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr));
    padding: 16px 12px 14px;
    gap: 18px 10px;
  }

  .iphone-frame .screen-label {
    font-size: 11px;
    padding: 4px 12px;
    top: -12px;
  }

  .view-screens-panel label input[type="range"] {
    width: 120px !important;
  }
}

/* Bảng: cuộn ngang trên tablet hẹp (768px–960px) nếu vẫn dùng desktop */
@media (min-width: 769px) and (max-width: 960px) {
  .devices-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .devices-table {
    min-width: 880px;
  }
}

/* ============== Modals (dashboard + chung) ============== */
@media (max-width: 768px) {
  .modal-backdrop {
    padding: 0 !important;
    align-items: stretch !important;
  }

  .modal,
  .modal.modal-wide {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
    height: 100%;
    border-radius: 0 !important;
    margin: 0 !important;
    display: flex;
    flex-direction: column;
  }

  .modal-body {
    flex: 1;
    max-height: none !important;
    -webkit-overflow-scrolling: touch;
  }

  .modal-header {
    padding: 12px 14px;
    flex-shrink: 0;
  }

  .modal-header h3 {
    font-size: 17px;
  }

  .modal-footer {
    flex-shrink: 0;
    flex-wrap: wrap;
    padding: 12px;
    gap: 8px;
  }

  .modal-footer .btn {
    flex: 1 1 auto;
    min-width: calc(50% - 4px);
  }

  .modal-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
    touch-action: pan-x;
    overscroll-behavior-x: contain;
  }

  .modal-tabs .modal-tab {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
  }

  .modal-backdrop {
    touch-action: none;
  }

  .modal .modal-body,
  .modal #data-content {
    touch-action: manipulation;
  }

  .modal-tab {
    flex-shrink: 0;
    font-size: 13px;
    padding: 8px 12px;
  }

  .cfg-card {
    margin-bottom: 10px;
  }

  .toast-container {
    left: 12px;
    right: 12px;
    top: auto;
    bottom: calc(12px + env(safe-area-inset-bottom));
    align-items: stretch;
  }

  .toast {
    min-width: 0;
    width: 100%;
  }
}

/* ============== Admin ============== */
@media (max-width: 768px) {
  .admin-frame {
    margin: 8px;
    border-radius: 12px;
  }

  .admin-titlebar {
    padding: 10px 12px;
  }

  .admin-content {
    padding: 12px !important;
  }

  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .table-wrap .table {
    min-width: 640px;
  }

  .tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
  }

  .tab {
    flex-shrink: 0;
  }
}

/* ============== Landing / auth ============== */
@media (max-width: 600px) {
  .container {
    padding: 0 16px;
  }

  h1 {
    font-size: 32px !important;
  }

  h2 {
    font-size: 24px !important;
  }

  .topbar-inner {
    gap: 8px;
  }

  .auth-wrap {
    padding: 24px 16px;
    align-items: flex-start;
    padding-top: max(24px, env(safe-area-inset-top));
  }
}
