/* =====================================================
   mobile.css
   Centralized responsive rules for tablet and mobile.
   ===================================================== */

/* ---- Tablet ---- */
@media (max-width: 768px) {
  #authModal .modal {
    padding-top: 52px;
  }
  #authModal .modal-close {
    top: 10px;
    right: 10px;
    z-index: 4;
    border: 1px solid var(--border);
    background: var(--surface);
  }
  #authModal .modal-tabs {
    width: 100%;
    min-width: 0;
    margin: 0 0 12px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  #authModal .tab-btn {
    height: 34px;
    font-size: 12px;
    white-space: nowrap;
  }

  #dashboardHeader {
    padding: 8px 12px;
    gap: 10px;
  }
  .dashboard-title { font-size: 22px; }
  .dashboard-subtitle { font-size: 13px; }

  .results-bar {
    margin-bottom: 16px;
    justify-content: space-between;
    align-items: center;
  }
  .results-count {
    width: auto;
    white-space: nowrap;
  }

  .articles-grid,
  .loading-state {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .header-inner { padding: 0 12px; }
  .container { margin: -30px auto 0; }
  .logo-text { display: none; }
  .header-actions { gap: 6px; }
  .auth-buttons { gap: 6px; }
  .auth-buttons .btn { padding: 0 10px; }

  .filter-inner { padding: 0 12px; }

  .results-bar-right {
    width: auto;
    flex-wrap: nowrap;
    justify-content: flex-end;
    gap: 6px;
  }
  .view-toggle {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
  .toggle-btn {
    width: 100%;
    min-width: 0;
    padding: 5px 8px;
    font-size: 11px;
    text-align: center;
  }
  .availability-toggle {
    height: 30px;
    flex: 0 1 128px;
    max-width: 128px;
    padding: 0 8px;
    font-size: 11px;
  }
  .sort-select-wrap {
    flex: 0 1 132px;
    min-width: 120px;
  }
  .sort-select {
    width: 100%;
    height: 30px;
    font-size: 11px;
    padding: 0 24px 0 8px;
  }

  .form-grid-2 { grid-template-columns: 1fr; }
  .card-owner-actions { opacity: 1; }
  .card-owner-actions { gap: 4px; }
  .btn-sold-toggle { min-width: 78px; padding: 0 8px; }

  .card-seller {
    grid-template-columns: 24px minmax(0, 1fr);
    column-gap: 6px;
  }
  .card-seller-avatar {
    width: 24px;
    height: 24px;
    font-size: 11px;
  }
  .card-seller-name {
    font-size: 11px;
  }

  .card-handover.is-delivery,
  .card-handover.is-pickup {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
    width: 100%;
    align-self: stretch;
    box-sizing: border-box;
    height: 60px;
    min-height: 60px;
    gap: 2px;
  }

  .card-handover.is-delivery .card-handover-status {
    display: block;
    line-height: 1.2;
  }

  .card-handover.is-delivery .card-handover-details {
    margin-top: 0;
    line-height: 1.2;
  }

  /* Chat Modal - Tablet */
  .modal-chat {
    height: min(86vh, 760px);
    display: flex;
    flex-direction: column;
  }
  .chat-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr) auto;
    height: 100%;
    display: flex;
    flex-direction: column;
  }
  .chat-sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--border);
    order: 1;
  }
  .chat-sidebar h3 { padding: 10px 12px; }
  .chat-conversations {
    padding: 6px;
    gap: 5px;
    overflow-y: auto;
    max-height: 140px;
  }
  .chat-conversation-item {
    height: 40px;
    min-height: 40px;
    max-height: 40px;
  }
  .chat-main { 
    position: relative;
    order: 2;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
  }
  .chat-main-header { 
    padding: 10px 12px;
    flex-shrink: 0;
  }
  .chat-messages {
    flex: 1;
    padding: 10px;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  #chatForm {
    grid-template-columns: 1fr auto;
    align-items: center;
    flex-shrink: 0;
    padding: 8px 12px;
    background: var(--bg);
    border-top: 1px solid var(--border);
    order: 3;
  }
}

/* ---- Mobile ---- */
@media (max-width: 480px) {
  #dashboardHeader {
    padding: 8px 10px;
    gap: 8px;
  }
  .dashboard-title { font-size: 18px; }
  .dashboard-subtitle { font-size: 12px; }

  .results-bar {
    margin-bottom: 12px;
    justify-content: space-between;
    align-items: center;
  }

  .articles-grid,
  .loading-state {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  html,
  body {
    overflow-x: hidden;
    height: 100dvh;
  }

  .header-inner {
    gap: 8px;
    padding: 0 10px;
  }
  .header-search input { height: 36px; }

  .chat-bell-btn {
    width: 34px;
    height: 34px;
  }

  .btn { height: 34px; padding: 0 12px; }
  .auth-buttons .btn {
    padding: 0 8px;
    font-size: 12px;
  }

  .results-bar { gap: 8px; }
  .results-count {
    width: auto;
    white-space: nowrap;
    font-size: 12px;
  }
  .results-bar-right {
    width: auto;
    flex-wrap: nowrap;
    justify-content: flex-end;
    gap: 4px;
    max-width: 100%;
    overflow-x: auto;
  }
  .view-toggle {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
  .toggle-btn {
    width: 100%;
    padding: 5px 8px;
    font-size: 11px;
    text-align: center;
  }
  .availability-toggle {
    height: 30px;
    flex: 0 1 116px;
    max-width: 116px;
    padding: 0 8px;
    font-size: 11px;
  }
  .sort-select-wrap {
    flex: 0 1 120px;
    min-width: 110px;
  }
  .sort-select {
    width: 100%;
    height: 30px;
    font-size: 11px;
    padding: 0 24px 0 8px;
  }

  .card-owner-actions {
    top: 6px;
    right: 6px;
  }
  .card-action-btn {
    width: 28px;
    height: 28px;
  }
  .btn-sold-toggle {
    min-width: 72px;
    height: 28px;
    font-size: 10px;
  }

  .card-title { font-size: 16px; }
  .card-price { font-size: 19px; }

  .card-handover {
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 34px;
    padding: 6px 8px;
  }
  .card-handover.is-delivery,
  .card-handover.is-pickup {
    width: 100%;
    align-self: stretch;
    box-sizing: border-box;
    height: 60px;
    min-height: 60px;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
    gap: 2px;
  }
  .card-handover-status,
  .card-handover-details {
    line-height: 1.2;
  }
  .card-handover-details {
    margin-top: 0;
  }

  .card-contact-actions {
    gap: 4px;
    max-width: 100%;
  }
  .card-contact-actions .btn-contact,
  .card-contact-actions .btn-chat {
    height: 26px;
    padding: 0 8px;
    font-size: 11px;
    border-radius: 6px;
  }

  .modal-overlay {
    padding: 10px;
    height: 100dvh;
    display: flex;
    align-items: flex-start;
  }
  .modal-overlay#chatModal {
    align-items: flex-end;
  }
  .modal {
    width: 100%;
    max-width: calc(100vw - 20px);
    padding: 14px 12px;
    overflow-x: hidden;
  }
  #authModal .modal {
    padding-top: 50px;
  }
  #authModal .modal-close {
    top: 8px;
    right: 8px;
    width: 30px;
    height: 30px;
  }
  #authModal .modal-tabs {
    width: 100%;
    min-width: 0;
    margin: 0 0 10px;
    padding-right: 0;
  }
  #authModal .tab-btn {
    height: 32px;
    font-size: 12px;
  }
  #loginForm,
  #registerForm,
  #phoneForm {
    width: 100%;
    max-width: 100%;
  }
  .auth-form,
  .form-group,
  .phone-input-wrap {
    min-width: 0;
  }
  .form-group input,
  .form-group select,
  .form-group textarea,
  .btn-full,
  .btn-google {
    width: 100%;
    max-width: 100%;
  }
  .phone-country-select {
    width: 75px !important;
  }
  .phone-input-wrap input[type=tel] {
    min-width: 0;
  }

  /* Mobile Chat - Vollbild Layout */
  .modal-chat {
    --chat-modal-top-gap: 20px;
    width: calc(100vw - 24px);
    height: calc(100dvh - (var(--chat-modal-top-gap) + 12px));
    max-width: calc(100vw - 24px);
    max-height: calc(100dvh - (var(--chat-modal-top-gap) + 12px));
    margin: var(--chat-modal-top-gap) 12px 12px;
    border-radius: 14px;
    padding: 0;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .modal-chat .modal-close {
    top: 12px;
    right: 12px;
    z-index: 20;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid var(--border);
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.14);
  }

  .chat-layout {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    min-width: 0;
  }

  /* Header fixiert oben */
  .chat-main-header {
    flex-shrink: 0;
    z-index: 10;
    padding: 12px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    column-gap: 8px;
    gap: 6px;
  }

  #chatTitle {
    grid-column: 1;
    margin: 0;
  }

  #chatSubTitle,
  .chat-conversation-select {
    grid-column: 1 / -1;
  }

  /* Chat Messages über gesamten verfügbaren Bereich */
  .chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    position: relative;
  }

  .chat-sidebar {
    display: none;
  }

  .chat-conversation-select {
    display: block;
    flex-shrink: 0;
    padding: 8px 12px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
  }
  .chat-conversation-select.hidden {
    display: none;
  }

  .chat-delete-selected {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    grid-column: 2;
    margin: 0 44px 0 0;
    align-self: center;
    justify-self: end;
  }

  .chat-messages {
    flex: 1;
    padding: 12px;
    overflow-y: auto;
    overscroll-behavior: contain;
    scroll-behavior: smooth;
    min-width: 0;
  }

  .chat-form {
    margin: 10px 10px calc(10px + env(safe-area-inset-bottom));
    border-radius: 16px;
    height: 58px;
    padding: 0 10px;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
    width: calc(100% - 20px);
    align-self: center;
    box-sizing: border-box;
    grid-template-columns: minmax(0, 1fr) auto;
    overflow: hidden;
  }

  .chat-form input {
    height: 38px;
    min-width: 0;
  }

  .chat-form .btn {
    height: 38px;
    min-width: 0;
    width: auto;
    padding: 0 14px;
    white-space: nowrap;
    justify-self: end;
  }

  .chat-conversation-item {
    padding: 6px 7px;
    height: 40px;
    min-height: 40px;
    max-height: 40px;
    gap: 4px;
  }
  .chat-message {
    max-width: 86%;
  }

  .zoom-nav {
    width: 42px;
    height: 56px;
    font-size: 22px;
  }
  .zoom-gallery-main {
    --zoom-nav-inset: 8px;
  }
  .zoom-thumb {
    width: 74px;
    height: 54px;
  }
}