/* ========================================
   TRADES PAGE MOBILE OPTIMIZATIONS
   ======================================== */

@media (max-width: 768px) {

  /* ========================================
     ACTIONS BAR - Compact 2-column grid
     ======================================== */
  .actions-bar {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 0.5rem !important;
    position: relative;
    z-index: 10;
    margin-bottom: 1rem;
  }

  .actions-bar > div {
    display: contents !important;
  }

  /* Action buttons - smaller, 2-column */
  .actions-bar button {
    min-height: 38px !important;
    max-height: 38px !important;
    padding: 0 12px !important;
    font-size: 12px !important;
    justify-content: center;
    position: relative;
    z-index: 10;
    pointer-events: auto;
    touch-action: manipulation;
  }

  /* Primary button spans full width */
  .actions-bar button.btn-primary,
  .actions-bar button[style*="background: var(--brand)"],
  .actions-bar button[style*="background: linear-gradient"] {
    grid-column: 1 / -1 !important;
  }

  /* Search input full width */
  .actions-bar #searchInput,
  .actions-bar input[type="text"] {
    grid-column: 1 / -1 !important;
    min-height: 38px !important;
    font-size: 14px;
    padding: 8px 12px;
  }

  /* Hide secondary actions on mobile — keep Add Trade, Import, Filters */
  .actions-bar #importFromApiBtn,
  .actions-bar #syncBtn,
  .actions-bar #journalModeBtn,
  .actions-bar #privacyToggle {
    display: none !important;
  }

  /* Hide the separator line */
  .actions-bar > div > div[style*="width: 1px"] {
    display: none !important;
  }

  .actions-bar button svg {
    margin-right: 4px;
    flex-shrink: 0;
  }

  /* ========================================
     QUICK FILTERS BAR - Compact dropdowns
     ======================================== */
  .quick-filters-bar {
    gap: 0.5rem !important;
    margin-bottom: 0.75rem !important;
  }

  .quick-filters-bar > div {
    flex: 1 1 calc(50% - 0.25rem);
    min-width: 0;
  }

  .quick-filters-bar label {
    font-size: 10px !important;
    margin-bottom: 2px;
  }

  .quick-filters-bar select {
    min-width: unset !important;
    width: 100%;
    padding: 6px 8px !important;
    font-size: 12px !important;
    min-height: 32px !important;
  }

  /* ========================================
     FILTER CHIPS - Compact pill buttons
     ======================================== */
  .filter-chips {
    gap: 6px !important;
    margin-bottom: 0.75rem !important;
  }

  /* Hide label on mobile - saves space */
  .filter-chips-label {
    display: none !important;
  }

  /* Hide separators on mobile */
  .filter-chips-separator {
    display: none !important;
  }

  /* Stack all filter groups vertically - full width each */
  .filter-chips {
    display: flex !important;
    flex-direction: column !important;
    gap: 6px !important;
  }

  .filter-chip-group {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 6px !important;
    overflow: hidden;
    display: flex !important;
    width: 100%;
  }

  .filter-chip-group .filter-chip {
    padding: 8px 6px !important;
    font-size: 12px !important;
    flex: 1;
    text-align: center;
    min-height: 32px !important;
    border-radius: 0 !important;
    white-space: nowrap;
  }

  .filter-chip-group .filter-chip:first-child {
    border-top-left-radius: 5px !important;
    border-bottom-left-radius: 5px !important;
  }

  .filter-chip-group .filter-chip:last-child {
    border-top-right-radius: 5px !important;
    border-bottom-right-radius: 5px !important;
  }

  /* ========================================
     TRADES TABLE - Compact card rows on mobile
     ======================================== */

  /* Card container */
  .card {
    overflow: visible;
  }

  .card-body {
    padding: 0.5rem !important;
  }

  .trades-table-container,
  #tradesTableContainer {
    overflow-x: hidden !important;
    position: relative;
    z-index: 1;
    margin-top: 0.5rem;
    width: 100%;
  }

  /* Convert table to stacked cards */
  .trades-table {
    display: block !important;
    width: 100% !important;
    min-width: unset !important;
  }

  .trades-table thead {
    display: none !important;
  }

  .trades-table tbody {
    display: flex !important;
    flex-direction: column !important;
    gap: 0.5rem !important;
  }

  .trades-table tr {
    display: grid !important;
    grid-template-columns: auto 1fr auto auto !important;
    align-items: center !important;
    gap: 0.75rem !important;
    padding: 0.75rem !important;
    background: var(--bg-surface) !important;
    border-radius: var(--radius-md) !important;
    border: 1px solid var(--border) !important;
    min-height: unset !important;
    height: auto !important;
  }

  .trades-table td {
    display: block !important;
    padding: 0 !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border: none !important;
    background: transparent !important;
    height: auto !important;
    min-height: unset !important;
  }

  /* Hide less important columns */
  .trades-table td:nth-child(n+5) {
    display: none !important;
  }

  /* Show: date, symbol, side, P&L — hide size, entry, exit, fee, percent */
  .trades-table td:nth-child(1) { order: 0; font-size: 12px; color: var(--text-muted); } /* date */
  .trades-table td:nth-child(2) { order: 1; font-weight: 600; font-size: 14px; } /* symbol */
  .trades-table td:nth-child(3) { order: 2; } /* side badge */
  .trades-table td:nth-child(7) { display: flex !important; order: 3; font-weight: 600; font-size: 14px; } /* P&L — override the nth-child(n+5) hide */
  .trades-table td:nth-child(4) { display: none !important; } /* hide size */

  /* Make entire row clickable on mobile */
  .trades-table tr {
    cursor: pointer;
  }

  .trades-table tr:active {
    background: var(--bg-hover) !important;
  }

  /* Hide action buttons on mobile - row click handles it */
  .trade-actions {
    display: none !important;
  }

  /* ========================================
     PAGE TABS - Horizontal scroll
     ======================================== */
  .page-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 0.5rem;
    padding-bottom: 2px;
  }

  .page-tab {
    min-height: 44px;
    white-space: nowrap;
    padding: 12px 20px;
    font-size: 14px;
  }

  /* ========================================
     PAGINATION - Better spacing
     ======================================== */
  .pagination {
    flex-wrap: wrap;
    gap: 1rem !important;
    padding: 1rem 0;
  }

  .pagination button {
    min-width: 100px;
    min-height: 44px;
    font-size: 14px;
  }

  .page-info {
    font-size: 14px;
    padding: 8px 0;
  }

  /* ========================================
     MODALS - Full viewport on mobile
     ======================================== */
  .modal-content {
    max-width: 100% !important;
    width: 100vw !important;
    height: 100vh;
    border-radius: 0 !important;
    margin: 0;
  }

  .modal-header {
    padding: 1rem;
    position: sticky;
    top: 0;
    background: var(--bg-primary);
    z-index: 10;
    border-bottom: 1px solid var(--border);
  }

  .modal-header h2,
  .modal-header h3 {
    font-size: 18px;
  }

  .modal-close {
    min-width: 44px;
    min-height: 44px;
    font-size: 28px;
  }

  .modal-body {
    overflow-y: auto;
    max-height: calc(100vh - 140px);
    padding: 1rem;
  }

  .modal-footer {
    position: sticky;
    bottom: 0;
    background: var(--bg-primary);
    border-top: 1px solid var(--border);
    padding: 1rem !important;
  }

  /* ========================================
     TRADE FORM - Stack all fields
     ======================================== */
  .trade-form .form-grid,
  .modal-body .form-grid {
    grid-template-columns: 1fr !important;
    gap: 1rem;
  }

  .trade-form label,
  .modal-body label {
    display: block;
    width: 100%;
    margin-bottom: 1rem;
  }

  .trade-form input,
  .trade-form select,
  .trade-form textarea,
  .modal-body input,
  .modal-body select,
  .modal-body textarea {
    width: 100%;
    min-height: 44px;
    font-size: 16px;
    padding: 12px 16px;
  }

  .trade-form textarea {
    min-height: 120px;
  }

  /* Form buttons */
  .modal-footer button {
    min-height: 44px;
    padding: 12px 20px;
    font-size: 16px;
  }

  .modal-footer > div {
    gap: 0.75rem !important;
  }

  /* ========================================
     ADVANCED FILTER MODAL - Single column
     ======================================== */
  #advancedFilterModal .modal-body > div {
    grid-template-columns: 1fr !important;
    gap: 1.5rem;
  }

  #advancedFilterModal h3 {
    font-size: 16px;
    margin-bottom: 1rem;
  }

  #advancedFilterModal label {
    font-size: 14px;
    margin-bottom: 0.5rem;
  }

  #advancedFilterModal input,
  #advancedFilterModal select {
    min-height: 44px;
    font-size: 16px;
    padding: 12px;
  }

  /* Date quick filters - wrap properly */
  #advancedFilterModal .date-quick {
    min-height: 40px;
    padding: 8px 12px;
    font-size: 13px;
  }

  /* Filter modal footer */
  #advancedFilterModal .modal-footer {
    flex-direction: column;
    gap: 0.75rem;
  }

  #advancedFilterModal .modal-footer > div {
    width: 100%;
    justify-content: space-between;
  }

  #advancedFilterModal .modal-footer button {
    flex: 1;
    min-height: 44px;
  }

  /* ========================================
     QUICK ACTIONS GRID - Single column
     ======================================== */
  .quick-actions-grid {
    grid-template-columns: 1fr !important;
    gap: 1rem !important;
  }

  .quick-actions-grid .card {
    width: 100%;
  }

  .quick-actions-grid button {
    min-height: 44px;
    font-size: 15px;
    padding: 12px 16px;
  }

  /* ========================================
     PERFORMANCE METRICS - Stack
     ======================================== */
  .performance-grid {
    grid-template-columns: 1fr !important;
    gap: 1rem !important;
  }

  .performance-metric {
    padding: 1rem;
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
  }

  .metric-label {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
  }

  .metric-value {
    font-size: 20px;
    font-weight: 600;
  }

  /* ========================================
     JOURNAL ENTRY MODAL - Full screen
     ======================================== */
  .journal-create-modal .modal-content {
    max-width: 100vw !important;
    width: 100vw;
    height: 100vh;
    border-radius: 0;
  }

  /* Trade summary in journal modal */
  .trade-summary > div {
    grid-template-columns: 1fr 1fr !important;
    gap: 0.75rem !important;
    font-size: 12px;
  }

  /* Journal form fields */
  #journalEntryForm input,
  #journalEntryForm select,
  #journalEntryForm textarea {
    min-height: 44px;
    font-size: 16px;
    padding: 12px;
  }

  #journalEntryForm textarea {
    min-height: 150px;
  }

  /* Emotion slider */
  #journalEntryForm input[type="range"] {
    min-height: 44px;
    -webkit-appearance: none;
    appearance: none;
  }

  #journalEntryForm input[type="range"]::-webkit-slider-thumb {
    width: 24px;
    height: 24px;
  }

  /* Emotion and performance tags */
  #journalEntryForm label[style*="cursor: pointer"] {
    padding: 8px 12px !important;
    font-size: 13px !important;
    min-height: 40px;
    align-items: center;
  }

  #journalEntryForm input[type="checkbox"] {
    width: 20px;
    height: 20px;
  }

  /* ========================================
     JOURNAL MODE BANNER
     ======================================== */
  .journal-mode-banner {
    margin-bottom: 1rem;
  }

  .journal-mode-banner > div {
    flex-direction: column;
    text-align: center;
    padding: 1rem !important;
  }

  .journal-mode-banner h4 {
    font-size: 16px;
  }

  .journal-mode-banner p {
    font-size: 13px;
  }

  /* ========================================
     BADGES - Proper sizing
     ======================================== */
  .badge {
    font-size: 11px;
    padding: 4px 8px;
    white-space: nowrap;
  }

  .badge-success,
  .badge-error,
  .badge-warning {
    font-size: 11px;
  }

  /* ========================================
     EMPTY STATE - Better spacing
     ======================================== */
  .empty-state {
    padding: 2rem 1rem !important;
  }

  .empty-state-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
  }

  .empty-state-title {
    font-size: 18px;
    margin-bottom: 0.75rem;
  }

  .empty-state-description {
    font-size: 14px;
    margin-bottom: 1.5rem;
  }

  .empty-state button {
    min-height: 44px;
    font-size: 15px;
    padding: 12px 24px;
  }

  /* ========================================
     PAGE HEADER - Stack on mobile
     ======================================== */
  .page-header {
    padding: 1rem !important;
    flex-direction: column;
    gap: 1rem;
  }

  .page-title {
    font-size: 22px;
  }

  .page-subtitle {
    font-size: 14px;
  }

  .page-controls {
    width: 100%;
    flex-direction: column;
    gap: 0.75rem;
  }

  .mode-badge {
    padding: 8px 16px;
    font-size: 12px;
  }

  /* Demo toggle */
  .demo-toggle {
    width: 100%;
    padding: 12px 16px;
    min-height: 44px;
  }

  .toggle-label {
    font-size: 15px;
  }

  /* ========================================
     CARDS - Full width on mobile
     ======================================== */
  .card {
    margin-bottom: 1rem;
  }

  .card-header {
    padding: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .card-header h3 {
    font-size: 16px;
  }

  .card-body {
    padding: 1rem;
  }

  /* ========================================
     BUTTONS - Touch-friendly
     ======================================== */
  .btn,
  .btn-secondary,
  .btn-ghost {
    min-height: 44px;
    padding: 12px 20px;
    font-size: 15px;
  }

  .btn-sm {
    min-height: 36px;
    padding: 8px 12px;
    font-size: 13px;
  }

  .btn-full {
    width: 100%;
  }

  /* ========================================
     FILTER COUNT BADGE
     ======================================== */
  .filter-count {
    font-size: 11px !important;
    padding: 3px 7px !important;
    min-width: 20px;
    text-align: center;
  }

  /* ========================================
     SCROLLBAR STYLING (Mobile)
     ======================================== */
  .trades-table-container::-webkit-scrollbar,
  #tradesTableContainer::-webkit-scrollbar {
    height: 8px;
  }

  .trades-table-container::-webkit-scrollbar-track,
  #tradesTableContainer::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: 4px;
  }

  .trades-table-container::-webkit-scrollbar-thumb,
  #tradesTableContainer::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
  }

  .trades-table-container::-webkit-scrollbar-thumb:hover,
  #tradesTableContainer::-webkit-scrollbar-thumb:hover {
    background: var(--brand);
  }

  /* ========================================
     TRADE CHART MODAL (if exists)
     ======================================== */
  .trade-chart-modal .modal-content {
    width: 100vw !important;
    height: 100vh;
    border-radius: 0;
  }

  .trade-chart-modal canvas {
    width: 100% !important;
    height: 300px !important;
  }

  /* ========================================
     COMING SOON MESSAGE
     ======================================== */
  .coming-soon-message {
    padding: 1.5rem !important;
  }

  .coming-soon-message h4 {
    font-size: 16px;
  }

  .coming-soon-message p {
    font-size: 14px;
  }

  .coming-soon-message .badge {
    font-size: 11px;
    padding: 4px 8px;
  }

  /* ========================================
     ACTIVE TRADES COUNT
     ======================================== */
  #activeTradesCount {
    font-size: 12px;
    padding: 4px 10px;
  }
}

/* ========================================
   VERY SMALL MOBILE (< 375px)
   ======================================== */
@media (max-width: 375px) {

  .actions-bar button {
    font-size: 14px;
    padding: 10px 16px;
  }

  .page-tab {
    padding: 10px 16px;
    font-size: 13px;
  }

  .trades-table {
    font-size: 12px;
  }

  .modal-header h2,
  .modal-header h3 {
    font-size: 16px;
  }

  .trade-summary > div {
    grid-template-columns: 1fr !important;
    font-size: 11px;
  }

  #journalEntryForm label[style*="cursor: pointer"] {
    font-size: 12px !important;
    padding: 6px 10px !important;
  }
}
