/**
 * Track CCD - Responsive Stylesheet
 * Mobile-first responsive design for all devices
 * Author: IO Snack
 * Date: 2025
 */

/* ========================================
   TABLET LANDSCAPE (max-width: 1024px)
   ======================================== */
@media (max-width: 1024px) {
  .flex-container {
    padding: var(--spacing-md);
  }

  .half-span {
    flex-basis: 25%;
    min-width: 100px;
  }

  .half-span2 {
    flex-basis: 75%;
  }
}

/* ========================================
   TABLET PORTRAIT (max-width: 991px) - MOBILE LAYOUT
   ======================================== */
@media (max-width: 991px) {
  /* Reset desktop layout for mobile */
  .tracking-sidebar {
    position: relative !important;
    height: auto !important;
    width: 100% !important;
    border-right: none !important;
    padding: var(--spacing-md) !important;
    text-align: center;
  }

  .sidebar-content {
    position: relative !important;
    top: auto !important;
  }

  .conversation-container {
    margin-left: 0 !important;
    padding: var(--spacing-md) !important;
  }

  /* Footer on mobile */
  .conversation-container .invoice-footer {
    margin-top: var(--spacing-lg) !important;
  }

  .tracking-sidebar .tracking-info-list {
    text-align: center !important;
  }

  .tracking-sidebar .tracking-info-list li {
    border-bottom: none !important;
  }
}

@media (max-width: 768px) {
  :root {
    --font-base: 15px;
    --font-small: 13px;
    --font-large: 18px;
    --font-xlarge: 22px;
    --font-xxlarge: 24px;
    --spacing-lg: 20px;
    --spacing-xl: 28px;
  }

  body {
    font-size: var(--font-base);
  }

  /* Layout Adjustments */
  .flex-container {
    padding: var(--spacing-sm);
  }

  /* Logo */
  .invoice-logo img {
    width: 100px;
  }

  /* Tracking Info */
  .tracking-id-title {
    font-size: var(--font-xlarge);
  }

  /* Message Cards - Stack Content */
  .licontainer {
    flex-direction: column;
    gap: var(--spacing-xs);
  }

  .half-span,
  .half-span2 {
    flex-basis: 100%;
    width: 100%;
  }

  .half-span {
    min-width: unset;
    font-weight: 600;
  }

  /* Forms */
  .reply-form-row {
    flex-direction: column;
  }

  .reply-form-row > * {
    width: 100%;
    min-width: unset;
  }

  .form-control-compact {
    width: 100%;
    min-width: unset;
    margin: 4px 0;
  }

  /* Buttons - Full Width on Mobile */
  .btn-custom {
    width: 100%;
    margin: 4px 0;
  }

  /* Message Cards */
  .message-card {
    margin-bottom: var(--spacing-sm);
  }

  .message-header,
  .message-body {
    padding: var(--spacing-sm);
  }

  /* Footer */
  .invoice-footer {
    padding: var(--spacing-md);
  }
}

/* ========================================
   MOBILE LANDSCAPE (max-width: 640px)
   ======================================== */
@media (max-width: 640px) {
  :root {
    --font-base: 14px;
    --font-small: 12px;
    --font-xsmall: 11px;
    --font-large: 17px;
    --font-xlarge: 20px;
    --font-xxlarge: 22px;
  }

  .tracking-id-title {
    font-size: var(--font-xlarge);
  }

  /* Reduce padding on small screens */
  .flex-container {
    padding: var(--spacing-xs);
  }

  #hidereply {
    padding: var(--spacing-sm);
  }

  /* Status badges */
  .status-badge {
    font-size: var(--font-xsmall);
    padding: 3px 10px;
  }

  /* Message type badges */
  .message-type-badge {
    display: block;
    margin-top: var(--spacing-xs);
    margin-left: 0;
    width: fit-content;
  }
}

/* ========================================
   MOBILE PORTRAIT (max-width: 480px)
   ======================================== */
@media (max-width: 480px) {
  :root {
    --font-base: 14px;
    --spacing-xs: 6px;
    --spacing-sm: 10px;
    --spacing-md: 14px;
    --spacing-lg: 18px;
    --input-height: 38px;
  }

  body {
    margin-top: 5px;
  }

  /* Logo */
  .invoice-logo img {
    width: 80px;
  }

  /* Tracking Info */
  .tracking-info-card {
    padding: var(--spacing-md);
  }

  .tracking-id-title {
    font-size: var(--font-large);
    word-break: break-word;
  }

  .tracking-detail-label,
  .tracking-detail-value {
    font-size: var(--font-small);
  }

  .tracking-detail-value strong {
    display: inline;
  }

  /* Forms */
  .form-control-custom {
    height: 38px;
    font-size: var(--font-base);
  }

  textarea.form-control-custom {
    min-height: 80px;
    font-size: var(--font-base);
  }

  /* Buttons */
  .btn-custom {
    height: 38px;
    line-height: 38px;
    padding: 0 var(--spacing-md);
    font-size: var(--font-base);
  }

  .btn-sm-custom {
    height: 32px;
    line-height: 32px;
    padding: 0 var(--spacing-sm);
    font-size: var(--font-small);
  }

  /* Message Cards */
  .message-header,
  .message-body {
    padding: var(--spacing-sm);
  }

  .message-date {
    font-size: var(--font-small);
  }

  .message-meta {
    font-size: var(--font-xsmall);
  }

  .message-content {
    font-size: var(--font-small);
  }

  /* Attachments */
  .message-attachments strong {
    font-size: var(--font-xsmall);
  }

  .attachment-button {
    display: block;
    width: 100%;
    margin: 4px 0;
    text-align: center;
    font-size: var(--font-xsmall);
  }

  .attachment-button i {
    font-size: 11px;
  }

  /* Footer */
  .text-disclaimer {
    font-size: 11px;
  }

  .invoice-footer p {
    font-size: var(--font-xsmall);
  }
}

/* ========================================
   EXTRA SMALL DEVICES (max-width: 360px)
   ======================================== */
@media (max-width: 360px) {
  :root {
    --font-base: 13px;
    --font-small: 11px;
    --font-xsmall: 10px;
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 12px;
    --spacing-lg: 16px;
  }

  .invoice-logo img {
    width: 70px;
  }

  .tracking-id-title {
    font-size: var(--font-large);
  }

  .flex-container {
    padding: var(--spacing-xs);
  }

  #hidereply {
    padding: var(--spacing-xs);
  }

  .form-control-custom,
  .btn-custom {
    height: 36px;
    line-height: 36px;
  }

  textarea.form-control-custom {
    min-height: 70px;
  }
}

/* ========================================
   LANDSCAPE ORIENTATION (Small Height)
   ======================================== */
@media (max-height: 500px) and (orientation: landscape) {
  .flex-container {
    padding: var(--spacing-xs);
  }

  .tracking-info-card,
  #hidereply {
    padding: var(--spacing-sm);
  }

  .message-card {
    margin-bottom: var(--spacing-xs);
  }

  .invoice-footer {
    padding: var(--spacing-sm);
  }
}

/* ========================================
   TOUCH DEVICE OPTIMIZATIONS
   ======================================== */
@media (hover: none) and (pointer: coarse) {
  /* Increase touch targets for better mobile UX */
  .btn-custom {
    min-height: 44px;
    line-height: 44px;
  }

  .form-control-custom {
    min-height: 44px;
  }

  .attachment-button {
    min-height: 44px;
    line-height: 44px;
  }

  /* Remove hover effects on touch devices */
  .btn-custom:hover {
    transform: none;
  }

  .message-card:hover {
    box-shadow: var(--shadow-sm);
  }

  /* Better tap highlighting */
  .btn-custom,
  .attachment-button,
  .form-control-custom {
    -webkit-tap-highlight-color: rgba(33, 150, 243, 0.2);
  }
}

/* ========================================
   HIGH CONTRAST MODE
   ======================================== */
@media (prefers-contrast: high) {
  :root {
    --border-color: #000;
    --text-secondary: #000;
    --text-muted: #333;
  }

  .form-control-custom,
  .btn-custom {
    border: 2px solid #000;
  }

  .status-badge,
  .message-type-badge {
    border: 1px solid currentColor;
  }
}

/* ========================================
   REDUCED MOTION
   ======================================== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .loading-spinner {
    animation: none;
    border-color: var(--primary);
  }
}

/* ========================================
   DARK MODE SUPPORT (Optional)
   ======================================== */
@media (prefers-color-scheme: dark) {
  /* Uncomment if you want automatic dark mode support */
  /*
  :root {
    --text-primary: #e0e0e0;
    --text-secondary: #b0b0b0;
    --text-muted: #808080;
    --bg-main: #121212;
    --bg-white: #1e1e1e;
    --bg-response: rgba(33, 150, 243, 0.15);
    --border-color: #333;
    --border-light: #2a2a2a;
  }

  body {
    background: var(--bg-main);
    color: var(--text-primary);
  }

  .message-header {
    background: #2a2a2a;
  }

  .form-control-custom {
    background: #2a2a2a;
    color: var(--text-primary);
    border-color: #444;
  }

  .form-control-custom:disabled {
    background: #1a1a1a;
  }
  */
}

/* ========================================
   FOCUS VISIBLE (Keyboard Navigation)
   ======================================== */
@media (hover: hover) {
  /* Enhanced focus for keyboard users */
  .btn-custom:focus-visible,
  .form-control-custom:focus-visible,
  .attachment-button:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
  }
}

/* ========================================
   DESKTOP LAYOUT - TWO COLUMN DESIGN
   ======================================== */
@media (min-width: 992px) {
  /* Container adjustments */
  .container-fluid {
    padding: 0;
  }

  .container-fluid > .row {
    margin: 0;
  }

  /* LEFT SIDEBAR - Fixed/Sticky Position */
  .tracking-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    overflow-y: auto;
    background: var(--bg-white);
    border-right: 2px solid var(--border-light);
    padding: var(--spacing-lg);
    z-index: 100;
  }

  .sidebar-content {
    position: sticky;
    top: var(--spacing-md);
  }

  /* RIGHT COLUMN - Conversation List */
  .conversation-container {
    margin-left: 33.333333%; /* Offset for fixed left column (col-lg-4) */
    padding: var(--spacing-lg);
    min-height: 100vh;
  }

  /* Footer in conversation column */
  .conversation-container .invoice-footer {
    margin-top: var(--spacing-xl);
  }

  /* Logo in sidebar */
  .tracking-sidebar .invoice-logo {
    margin-bottom: var(--spacing-lg);
  }

  .tracking-sidebar .invoice-logo img {
    width: 120px;
  }

  /* Tracking info in sidebar */
  .tracking-sidebar .tracking-info-list {
    text-align: left;
    margin-bottom: var(--spacing-lg);
  }

  .tracking-sidebar .tracking-info-list li {
    padding: var(--spacing-sm) 0;
    border-bottom: 1px solid var(--border-light);
  }

  .tracking-sidebar .tracking-info-list li:last-child {
    border-bottom: none;
  }

  /* Reply button in sidebar */
  .tracking-sidebar .btn-custom {
    width: 100%;
    margin-top: var(--spacing-md);
  }

  /* Message cards in conversation */
  .conversation-container .message-card {
    margin-bottom: var(--spacing-lg);
  }
}

/* ========================================
   WIDE SCREEN OPTIMIZATION (min-width: 1400px)
   ======================================== */
@media (min-width: 1400px) {
  .tracking-sidebar {
    padding: var(--spacing-xl);
  }

  .conversation-container {
    padding: var(--spacing-xl);
  }

  .conversation-container .message-card {
    max-width: 900px;
    margin-left: auto;
    margin-right: auto;
    margin-bottom: var(--spacing-xl);
  }
}

/* ========================================
   CONTAINER QUERIES (Progressive Enhancement)
   ======================================== */
@supports (container-type: inline-size) {
  .message-card {
    container-type: inline-size;
    container-name: messageCard;
  }

  @container messageCard (max-width: 500px) {
    .licontainer {
      flex-direction: column;
    }

    .half-span,
    .half-span2 {
      flex-basis: 100%;
    }
  }
}
