/**
 * Admin panel — mobil ve tablet uyumluluk
 * Breakpoints: 1024 (tablet shell), 960 (layout), 900 (inbox), 768 (phone), 480 (narrow)
 */

/* ── Tablet shell (1024px) ── */
@media (max-width: 1024px) {
  body {
    overflow-x: hidden;
  }

  .content-inner,
  .content-inner--full {
    max-width: 100%;
  }

  .mobile-toggle {
    display: inline-flex;
  }

  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }

  .sidebar.is-open {
    transform: translateX(0);
  }

  .sidebar-overlay.is-visible {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(45, 45, 45, 0.4);
    z-index: 35;
  }

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

  .topbar,
  .content {
    padding-left: var(--spacing-16);
    padding-right: var(--spacing-16);
  }

  .topbar-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
  }

  .topbar-left {
    flex: 1;
    min-width: 0;
  }

  .account-page-grid {
    grid-template-columns: 1fr;
  }
}

/* ── Layout grids (960px) ── */
@media (max-width: 960px) {
  .account-page-grid,
  .account-settings-grid {
    grid-template-columns: 1fr;
    gap: var(--spacing-24);
  }

  .account-settings-divider {
    width: 100%;
    height: 1px;
    align-self: auto;
  }

  .whatsapp-status-head,
  .dashboard-messages-head,
  .dashboard-latest-send-head,
  .history-toolbar,
  .history-detail-head,
  .history-failures-head,
  .history-recipients-head,
  .panel-users-head,
  .activity-log-head,
  .integration-status-head,
  .directory-detail-messages-head,
  .templates-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: var(--spacing-12);
  }

  .whatsapp-status-head .btn,
  .dashboard-messages-head .btn,
  .dashboard-latest-send-head .btn,
  .history-toolbar .btn,
  .panel-users-head .btn,
  .templates-toolbar .btn {
    align-self: flex-start;
  }

  .dashboard-messages-total {
    flex-wrap: wrap;
    gap: var(--spacing-8);
  }

  .directory-detail-messages-card {
    min-height: 420px;
  }
}

/* ── Inbox master/detail (900px) ── */
@media (max-width: 900px) {
  body.page-inbox .admin-main,
  .admin-main:has(.inbox-page) {
    height: auto;
    max-height: none;
    overflow: visible;
  }

  body.page-inbox .content,
  .content:has(.inbox-page) {
    overflow: visible;
    padding: var(--spacing-12) var(--spacing-16);
  }

  .content-inner--inbox,
  .inbox-page {
    min-height: auto;
  }

  .inbox-layout {
    display: flex;
    flex-direction: column;
    grid-template-columns: none;
    grid-template-rows: none;
    min-height: calc(100dvh - var(--topbar-height) - 32px);
    max-height: calc(100dvh - var(--topbar-height) - 32px);
    border-radius: var(--radius-cards);
    overflow: hidden;
  }

  .inbox-sidebar,
  .inbox-thread {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }

  .inbox-sidebar {
    border-right: 0;
    border-bottom: 0;
  }

  .inbox-thread-body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }

  .inbox-layout:not(.inbox-layout--thread-open) .inbox-thread {
    display: none;
  }

  .inbox-layout.inbox-layout--thread-open .inbox-sidebar {
    display: none;
  }

  .inbox-layout.inbox-layout--thread-open .inbox-thread {
    display: flex;
  }

  .inbox-thread-head {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas:
      "back contact"
      "actions actions";
    gap: var(--spacing-8);
    align-items: start;
  }

  .inbox-thread-back {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    grid-area: back;
    padding-left: 10px;
    padding-right: 10px;
  }

  .inbox-thread-back svg {
    width: 18px;
    height: 18px;
  }

  .inbox-thread-contact {
    grid-area: contact;
    min-width: 0;
  }

  .inbox-thread-actions {
    grid-area: actions;
    flex-wrap: wrap;
    width: 100%;
    gap: var(--spacing-8);
  }

  .inbox-thread-actions .btn {
    flex: 1 1 auto;
    min-width: 0;
    justify-content: center;
  }

  .inbox-compose-form {
    flex-direction: column;
    align-items: stretch;
  }

  .inbox-compose-send {
    width: 100%;
  }

  .inbox-diagnostics-list div {
    grid-template-columns: 1fr;
  }
}

.inbox-thread-back {
  display: none;
}

/* ── Phone (768px) ── */
@media (max-width: 768px) {
  :root {
    --card-padding: 16px;
    --topbar-height: 64px;
  }

  .topbar-user-meta {
    display: none;
  }

  .topbar-actions {
    gap: var(--spacing-8);
    flex-shrink: 0;
  }

  .topbar-actions .btn {
    padding-left: 12px;
    padding-right: 12px;
    font-size: 14px;
  }

  .content {
    padding-top: var(--spacing-16);
    padding-bottom: var(--spacing-16);
  }

  .card {
    padding: var(--card-padding);
  }

  /* Touch-friendly controls */
  .btn,
  .form-input,
  .form-select-trigger,
  .directory-page-btn,
  .directory-page-number,
  .trusted-device-action,
  .password-toggle {
    min-height: 44px;
  }

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

  /* Modals */
  .modal-overlay {
    padding: var(--spacing-12);
    align-items: flex-end;
  }

  .modal,
  .modal-lg,
  .modal-xl,
  .send-manual-modal,
  .contact-import-modal,
  .contact-form-modal {
    width: 100%;
    max-width: 100%;
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
    border-radius: var(--radius-cards) var(--radius-cards) 0 0;
  }

  .modal-actions {
    flex-direction: column-reverse;
    align-items: stretch;
    gap: var(--spacing-8);
  }

  .modal-actions .btn,
  .modal-actions form,
  .modal-actions form .btn {
    width: 100%;
  }

  /* Send message */
  .send-manual-label,
  .send-manual-modal .send-manual-label {
    grid-template-columns: auto 1fr;
    grid-template-areas:
      "check name"
      "check phone"
      "status status";
    gap: var(--spacing-8);
  }

  .send-manual-label input[type="checkbox"] {
    grid-area: check;
    align-self: start;
    margin-top: 4px;
  }

  .send-manual-name {
    grid-area: name;
  }

  .send-manual-phone {
    grid-area: phone;
  }

  .send-recipient-badge {
    grid-area: status;
    justify-self: start;
  }

  .send-preview-card:not(.is-collapsed) .send-preview-body {
    max-height: 280px;
  }

  .send-step-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .send-step-actions .btn {
    width: 100%;
  }

  /* Directory */
  .directory-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .directory-toolbar-filters {
    flex-direction: column;
    max-width: none;
  }

  .directory-toolbar-actions {
    flex-wrap: wrap;
  }

  .directory-toolbar-actions .btn {
    flex: 1 1 calc(50% - 4px);
    min-width: 140px;
  }

  .directory-toolbar-actions .btn-primary {
    flex: 1 1 100%;
  }

  .directory-opt-filter.form-select {
    width: 100%;
  }

  .directory-table-actions {
    flex-wrap: wrap;
    gap: 6px;
  }

  .directory-detail-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .directory-detail-actions .btn {
    width: 100%;
  }

  /* Tables — scroll + slimmer min-width */
  .directory-table-wrap,
  .templates-table-wrap,
  .history-table-wrap,
  .activity-log-table-wrap,
  .panel-users-table-wrap,
  .contact-import-preview-table-wrap,
  .history-recipients-list-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
    margin: 0 calc(-1 * var(--card-padding));
    padding: 0 var(--card-padding);
  }

  .templates-table {
    min-width: 720px;
  }

  .history-table {
    min-width: 640px;
  }

  .activity-log-table {
    min-width: 560px;
  }

  .panel-users-table {
    min-width: 520px;
  }

  /* Hide low-priority columns on phone */
  .activity-log-table th:nth-child(3),
  .activity-log-table td:nth-child(3),
  .activity-log-table th:nth-child(6),
  .activity-log-table td:nth-child(6) {
    display: none;
  }

  .history-table th:nth-child(5),
  .history-table td:nth-child(5),
  .history-table th:nth-child(6),
  .history-table td:nth-child(6),
  .history-table th:nth-child(7),
  .history-table td:nth-child(7) {
    display: none;
  }

  .templates-table th:nth-child(2),
  .templates-table td:nth-child(2),
  .templates-table th:nth-child(4),
  .templates-table td:nth-child(4),
  .templates-table th:nth-child(6),
  .templates-table td:nth-child(6),
  .templates-table th:nth-child(8),
  .templates-table td:nth-child(8) {
    display: none;
  }

  .panel-users-table th:nth-child(5),
  .panel-users-table td:nth-child(5) {
    display: none;
  }

  .panel-users-actions {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }

  .panel-users-actions .btn {
    width: 100%;
  }

  /* Pagination */
  .directory-pagination,
  .activity-log-pagination.directory-pagination {
    grid-template-columns: 1fr;
    justify-items: center;
    gap: var(--spacing-12);
  }

  .directory-pagination-nav--start,
  .directory-pagination-nav--end {
    justify-self: center;
  }

  .panel-users-pagination,
  .activity-log-pagination:not(.directory-pagination) {
    justify-content: center;
  }

  /* Activity log / panel users filters */
  .activity-log-filters {
    flex-direction: column;
  }

  .activity-log-filter {
    min-width: 0;
    width: 100%;
  }

  /* Integration */
  .integration-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .integration-actions .btn {
    width: 100%;
  }

  .integration-cron-code {
    font-size: 12px;
    overflow-x: auto;
  }

  /* Media */
  .media-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .media-toolbar-actions {
    flex-wrap: wrap;
  }

  .media-toolbar-actions .btn {
    flex: 1 1 auto;
  }

  .media-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }

  /* Trusted devices */
  .trusted-device-item {
    flex-direction: column;
    align-items: stretch;
  }

  .trusted-device-revoke-form {
    align-self: flex-end;
  }

  .trusted-devices-actions {
    gap: var(--spacing-8);
  }

  /* Contact import */
  .contact-import-modal {
    width: 100%;
    max-width: 100%;
  }

  .wix-import-file-row {
    flex-direction: column;
    align-items: stretch;
  }

  /* Login / OTP */
  .login-page {
    padding: var(--spacing-24) var(--spacing-16);
  }

  .login-card {
    padding: var(--card-padding);
  }

  .otp-boxes {
    gap: 6px;
  }

  .otp-box {
    width: 42px;
    height: 50px;
    font-size: 20px;
  }
}

/* ── Narrow phone (480px) ── */
@media (max-width: 480px) {
  .directory-toolbar-actions .btn {
    flex: 1 1 100%;
  }

  .inbox-thread-actions .btn {
    flex: 1 1 100%;
  }

  .dashboard-messages-summary {
    grid-template-columns: 1fr;
  }

  .stat-grid {
    grid-template-columns: 1fr;
  }

  .topbar-actions .btn-ghost:last-child {
    padding-left: 10px;
    padding-right: 10px;
  }
}
