/* ============================================================
   Valoex — Mobile First Component Overrides & Enhancements
   Applied on top of components.css, mobile-first approach
   ============================================================ */

/* ══════════════════════════════════════════
   GLOBAL TOUCH IMPROVEMENTS
   ══════════════════════════════════════════ */
* {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

input, select, textarea, button {
  -webkit-appearance: none;
  appearance: none;
  font-family: var(--font-family);
}

/* ══════════════════════════════════════════
   TYPOGRAPHY — MOBILE SCALE
   ══════════════════════════════════════════ */
:root {
  --mobile-title-xl:  700 28px/34px var(--font-family);
  --mobile-title-lg:  700 22px/28px var(--font-family);
  --mobile-title-md:  600 18px/24px var(--font-family);
  --mobile-title-sm:  600 15px/20px var(--font-family);
  --mobile-body-lg:   400 16px/24px var(--font-family);
  --mobile-body-md:   400 14px/20px var(--font-family);
  --mobile-body-sm:   400 12px/16px var(--font-family);
  --mobile-label-lg:  500 14px/20px var(--font-family);
  --mobile-label-md:  500 12px/16px var(--font-family);

  /* Touch target minimum size (WCAG 2.5.5) */
  --touch-target: 44px;
}

/* ══════════════════════════════════════════
   CARDS — MOBILE IMPROVEMENTS
   ══════════════════════════════════════════ */
.card {
  border-radius: var(--radius-2xl);
  border: 1px solid var(--border-color);
}

.card-p {
  padding: var(--space-4);
}

/* Hover only on pointer devices */
@media (hover: hover) {
  .card-elevated:hover {
    box-shadow: var(--elevation-2);
    transform: translateY(-2px);
  }
}

/* ══════════════════════════════════════════
   SUMMARY CARDS — MOBILE LAYOUT
   ══════════════════════════════════════════ */
.summary-card {
  padding: var(--space-4);
  border-radius: var(--radius-2xl);
  min-height: 100px;
}

.summary-card-value {
  font: 700 22px/28px var(--font-family);
  letter-spacing: -0.5px;
}

.summary-card-label {
  font: var(--mobile-label-md);
}

/* ══════════════════════════════════════════
   BUTTONS — LARGER TOUCH TARGETS
   ══════════════════════════════════════════ */
.btn {
  min-height: var(--touch-target);
  padding: var(--space-3) var(--space-5);
  font: var(--mobile-label-lg);
  border-radius: var(--radius-xl);
  touch-action: manipulation;
}

.btn-sm {
  min-height: 36px;
  padding: var(--space-2) var(--space-4);
}

.btn-lg {
  min-height: 52px;
  padding: var(--space-4) var(--space-6);
  font-size: 16px;
  border-radius: var(--radius-2xl);
}

/* Full-width CTA buttons on mobile */
.btn-block {
  width: 100%;
  justify-content: center;
}

/* ══════════════════════════════════════════
   FORMS — MOBILE FRIENDLY
   ══════════════════════════════════════════ */
.field-input,
.field-select,
.field-textarea {
  padding: 14px var(--space-4);
  font-size: 16px; /* prevents iOS zoom on focus */
  border-radius: var(--radius-xl);
  min-height: var(--touch-target);
  border: 1.5px solid var(--border-color);
  background: var(--md-surface-container);
}

.field-input:focus,
.field-select:focus,
.field-textarea:focus {
  border-color: var(--md-primary);
  border-width: 2px;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--md-primary) 15%, transparent);
}

.field-label {
  font: var(--mobile-label-md);
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.field-group {
  gap: 6px;
}

/* Amount input — bigger on mobile */
.amount-input {
  font: 700 32px/40px var(--font-family);
  letter-spacing: -1px;
}

.amount-currency {
  font: 600 20px/28px var(--font-family);
  padding-left: var(--space-4);
}

.amount-input-wrap {
  border-radius: var(--radius-xl);
  border-width: 2px;
  min-height: 64px;
}

/* ══════════════════════════════════════════
   SEGMENT CONTROL — LARGER
   ══════════════════════════════════════════ */
.segment-control {
  border-radius: var(--radius-2xl);
  padding: 4px;
}

.segment-btn {
  min-height: 44px;
  font: var(--mobile-label-lg);
  border-radius: var(--radius-xl);
  gap: var(--space-2);
}

/* ══════════════════════════════════════════
   TRANSACTION ITEMS — MOBILE TOUCH
   ══════════════════════════════════════════ */
.transaction-item {
  padding: var(--space-4) var(--space-4);
  min-height: 68px;
  border-radius: var(--radius-xl);
  gap: var(--space-3);
  transition: background var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.transaction-item:active {
  background: var(--md-surface-container-low);
  transform: scale(0.995);
}

.transaction-icon {
  width: 46px;
  height: 46px;
  border-radius: var(--radius-xl);
  font-size: 22px;
  flex-shrink: 0;
}

.transaction-name {
  font: var(--mobile-title-sm);
}

.transaction-amount {
  font: 700 15px/20px var(--font-family);
}

.transaction-meta {
  gap: var(--space-2);
  flex-wrap: wrap;
}

/* ══════════════════════════════════════════
   MODAL — BOTTOM SHEET ON MOBILE
   ══════════════════════════════════════════ */
.modal-backdrop {
  padding: 0;
  align-items: flex-end; /* Bottom sheet alignment on mobile */
}

.modal {
  border-radius: var(--radius-3xl) var(--radius-3xl) 0 0;
  max-width: 100%;
  width: 100%;
  max-height: 96dvh;
  animation: bottomSheetIn 320ms cubic-bezier(.2,0,0,1) both;
  /* Drag indicator */
  padding-top: 12px;
}

/* Drag handle for bottom sheet */
.modal::before {
  content: '';
  display: block;
  width: 36px;
  height: 4px;
  background: var(--md-outline-variant);
  border-radius: var(--radius-full);
  margin: 0 auto 4px;
}

.modal-header {
  padding: var(--space-4) var(--space-5) var(--space-3);
}

.modal-title {
  font: var(--mobile-title-md);
}

.modal-body {
  padding: 0 var(--space-5);
}

.modal-footer {
  padding: var(--space-4) var(--space-5);
  padding-bottom: max(var(--space-6), env(safe-area-inset-bottom, var(--space-6)));
  gap: var(--space-3);
  flex-direction: column-reverse; /* Primary action on top (more accessible) */
}

.modal-footer .btn {
  width: 100%;
}

.modal-footer .btn-text {
  width: 100%;
  text-align: center;
}

/* ══════════════════════════════════════════
   MODAL CONFIRM DIALOG — special handling
   ══════════════════════════════════════════ */
.modal[style*="max-width:400px"],
.modal[style*="max-width: 400px"],
.modal[style*="max-width:460px"],
.modal[style*="max-width: 460px"] {
  border-radius: var(--radius-3xl) var(--radius-3xl) 0 0;
}

/* ══════════════════════════════════════════
   SECTION HEADER — COMPACT ON MOBILE
   ══════════════════════════════════════════ */
.section-header {
  padding: var(--space-4) var(--space-4) var(--space-3);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-title {
  font: var(--mobile-title-sm);
  color: var(--text-primary);
}

.section-action {
  font: var(--mobile-label-md);
  color: var(--md-primary);
  cursor: pointer;
  padding: var(--space-2) 0;
  min-height: var(--touch-target);
  display: flex;
  align-items: center;
}

/* ══════════════════════════════════════════
   CHART CONTAINER — FULL WIDTH ON MOBILE
   ══════════════════════════════════════════ */
.chart-container {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-2xl);
  padding: var(--space-4);
  overflow: hidden;
}

/* ══════════════════════════════════════════
   TOAST — TOP OF SCREEN (ALWAYS ON TOP)
   ══════════════════════════════════════════ */
#toast-container {
  position: fixed;
  top: calc(var(--space-4) + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 2147483647 !important;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  pointer-events: none;
  width: max-content;
  max-width: calc(100vw - var(--space-6));
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--md-surface-container-highest);
  border-radius: var(--radius-2xl);
  font: var(--mobile-body-md);
  color: var(--text-primary);
  box-shadow: var(--elevation-3);
  pointer-events: all;
  animation: toastIn 280ms cubic-bezier(.2,0,0,1) both;
  border: 1px solid var(--border-color);
  min-height: 52px;
  cursor: pointer;
}

.toast svg { width: 18px; height: 18px; flex-shrink: 0; }
.toast.success { background: var(--color-income-bg); color: var(--color-income); border-color: rgba(27,133,84,0.2); }
.toast.error   { background: var(--color-expense-bg); color: var(--color-expense); border-color: rgba(186,26,26,0.2); }
.toast.warning { background: #FFF8E1; color: #F57F17; border-color: rgba(245,127,23,0.2); }

.toast.removing {
  animation: toastOut 250ms cubic-bezier(.4,0,1,1) forwards;
}

/* ══════════════════════════════════════════
   PAGE HEADER — MOBILE COMPACT
   ══════════════════════════════════════════ */
.page-header {
  margin-bottom: var(--space-4);
  gap: var(--space-3);
}

.page-header.flex {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

/* ══════════════════════════════════════════
   CHIPS / FILTERS — HORIZONTAL SCROLL
   ══════════════════════════════════════════ */
.chips-row {
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
  -ms-overflow-style: none;
}

.chips-row::-webkit-scrollbar { display: none; }

.chip {
  flex-shrink: 0;
  min-height: 36px;
  padding: var(--space-2) var(--space-4);
  font: var(--mobile-label-md);
  border-radius: var(--radius-xl);
  touch-action: manipulation;
}

/* ══════════════════════════════════════════
   AI INPUT BOX — MOBILE IMPROVEMENTS
   ══════════════════════════════════════════ */
.ai-input-box {
  background: linear-gradient(135deg,
    color-mix(in srgb, var(--md-primary) 8%, var(--bg-card)),
    color-mix(in srgb, var(--md-tertiary) 5%, var(--bg-card))
  );
  border: 1.5px solid color-mix(in srgb, var(--md-primary) 25%, transparent);
  border-radius: var(--radius-2xl);
  padding: var(--space-4);
}

.ai-input-label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
  font: var(--mobile-label-md);
  font-weight: 600;
  color: var(--md-primary);
}

.ai-input-label svg {
  width: 16px; height: 16px;
  color: var(--md-primary);
}

.ai-badge {
  background: var(--md-primary);
  color: var(--md-on-primary);
  font: 700 9px/12px var(--font-family);
  padding: 2px 6px;
  border-radius: var(--radius-full);
  letter-spacing: 0.5px;
}

.ai-text-input {
  width: 100%;
  background: var(--bg-card);
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: var(--space-3) var(--space-4);
  font: var(--mobile-body-md);
  color: var(--text-primary);
  resize: none;
  outline: none;
  min-height: 72px;
  transition: border-color var(--transition-fast);
  font-size: 16px; /* prevents iOS zoom */
}

.ai-text-input:focus {
  border-color: var(--md-primary);
}

.ai-preview-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.ai-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--md-primary-container);
  color: var(--md-on-primary-container);
  font: var(--mobile-label-md);
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 12px;
}

/* ══════════════════════════════════════════
   LIST ITEMS — MOBILE TOUCH FRIENDLY
   ══════════════════════════════════════════ */
.list-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  min-height: 64px;
  cursor: pointer;
  transition: background var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}

.list-item:hover, .list-item:active {
  background: var(--md-surface-container-low);
}

.list-item + .list-item {
  border-top: 1px solid var(--border-color);
}

/* ══════════════════════════════════════════
   GOALS CARD — MOBILE
   ══════════════════════════════════════════ */
.goal-card {
  padding: var(--space-4);
  border-radius: var(--radius-2xl);
}

/* ══════════════════════════════════════════
   DASHBOARD — MONTH NAV MOBILE
   ══════════════════════════════════════════ */
.month-nav {
  display: flex;
  align-items: center;
  background: var(--md-surface-container);
  border-radius: var(--radius-2xl);
  padding: var(--space-1);
  gap: 0;
  align-self: stretch;
}

.month-nav-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-xl);
  color: var(--text-secondary);
  transition: background var(--transition-fast), color var(--transition-fast);
  cursor: pointer;
  flex-shrink: 0;
}

.month-nav-btn:not(:disabled):hover { background: var(--bg-card); color: var(--text-primary); }
.month-nav-btn:disabled { opacity: 0.3; cursor: not-allowed; }

.month-nav-label {
  font: 600 13px/18px var(--font-family);
  color: var(--text-primary);
  text-transform: capitalize;
  text-align: center;
  min-width: 130px;
  padding: 0 var(--space-2);
}

/* ══════════════════════════════════════════
   SUCCESS OVERLAY — MOBILE CENTERED
   ══════════════════════════════════════════ */
.success-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-toast);
  padding: var(--space-6);
  animation: fadeIn 200ms both;
}

.success-card {
  background: var(--bg-card);
  border-radius: var(--radius-3xl);
  padding: var(--space-8) var(--space-6);
  text-align: center;
  max-width: 320px;
  width: 100%;
  animation: scaleInSpring 400ms cubic-bezier(.34,1.56,.64,1) both;
  box-shadow: var(--elevation-5);
}

.success-icon {
  width: 72px;
  height: 72px;
  background: var(--color-income-bg);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto var(--space-4);
  animation: successScale 500ms cubic-bezier(.34,1.56,.64,1) both;
}

.success-icon svg {
  width: 36px;
  height: 36px;
  color: var(--color-income);
  stroke-dasharray: 100;
  stroke-dashoffset: 100;
  animation: checkDraw 400ms 200ms ease-out both;
}

.success-title {
  font: var(--mobile-title-md);
  color: var(--text-primary);
  margin-bottom: var(--space-2);
}

.success-subtitle {
  font: var(--mobile-body-md);
  color: var(--text-secondary);
}

/* ══════════════════════════════════════════
   STAT CARD — MOBILE
   ══════════════════════════════════════════ */
.stat-card {
  padding: var(--space-4);
  gap: var(--space-3);
}

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-lg);
  flex-shrink: 0;
}

/* ══════════════════════════════════════════
   PILL NAV (secondary navigation)
   ══════════════════════════════════════════ */
.pill-nav {
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.pill-nav::-webkit-scrollbar { display: none; }

.pill-nav-item {
  flex-shrink: 0;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-full);
  font: var(--mobile-label-md);
  color: var(--text-secondary);
  background: var(--md-surface-container);
  cursor: pointer;
  min-height: 36px;
  display: flex;
  align-items: center;
  transition: all var(--transition-fast);
  border: 1px solid transparent;
}

.pill-nav-item.active {
  background: var(--md-primary-container);
  color: var(--md-on-primary-container);
  font-weight: 600;
  border-color: var(--md-primary);
}

/* ══════════════════════════════════════════
   SEARCH PAGE — MOBILE
   ══════════════════════════════════════════ */
.search-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-input-wrap input {
  padding-left: 44px;
  height: 52px;
  font-size: 16px;
  border-radius: var(--radius-2xl);
}

.search-input-wrap svg {
  position: absolute;
  left: 14px;
  width: 20px;
  height: 20px;
  color: var(--text-secondary);
  pointer-events: none;
}

/* ══════════════════════════════════════════
   DASHBOARD HERO CARD — MOBILE FIRST
   ══════════════════════════════════════════ */
.dashboard-hero {
  background: linear-gradient(135deg, var(--md-primary), var(--brand-secondary));
  border-radius: var(--radius-3xl);
  padding: var(--space-6) var(--space-5);
  color: white;
  margin-bottom: var(--space-4);
  position: relative;
  overflow: hidden;
}

.dashboard-hero::before {
  content: '';
  position: absolute;
  top: -40px; right: -40px;
  width: 200px; height: 200px;
  border-radius: 50%;
  background: rgba(255,255,255,0.08);
  pointer-events: none;
}

.dashboard-hero-label {
  font: var(--mobile-label-md);
  opacity: 0.85;
  margin-bottom: var(--space-2);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.dashboard-hero-value {
  font: 700 38px/44px var(--font-family);
  letter-spacing: -1.5px;
  margin-bottom: var(--space-4);
}

.dashboard-hero-row {
  display: flex;
  gap: var(--space-4);
  flex-wrap: wrap;
}

.dashboard-hero-stat {
  flex: 1;
  min-width: 120px;
}

.dashboard-hero-stat-label {
  font: var(--mobile-body-sm);
  opacity: 0.75;
  margin-bottom: 2px;
}

.dashboard-hero-stat-value {
  font: 600 16px/22px var(--font-family);
}

/* ══════════════════════════════════════════
   RESPONSIVE OVERRIDES FOR TABLET+
   ══════════════════════════════════════════ */
@media (min-width: 600px) {
  .card-p { padding: var(--space-5); }

  .modal-backdrop { padding: var(--space-6); align-items: center; }

  .modal {
    border-radius: var(--radius-3xl);
    max-width: 560px;
    max-height: 92dvh;
    animation: modalIn 280ms cubic-bezier(.2,0,0,1) both;
  }

  .modal::before { display: none; } /* Remove drag handle on tablet */

  .modal-footer {
    flex-direction: row;
    justify-content: flex-end;
    padding-bottom: var(--space-6);
  }

  .modal-footer .btn,
  .modal-footer .btn-text {
    width: auto;
  }

  .summary-card-value {
    font: 700 26px/32px var(--font-family);
  }

  .amount-input {
    font: 700 36px/44px var(--font-family);
  }
}

@media (min-width: 1024px) {
  .modal-backdrop { padding: var(--space-8); }

  .btn {
    min-height: 40px;
    padding: var(--space-3) var(--space-6);
  }

  .btn-lg {
    min-height: 48px;
    padding: var(--space-3) var(--space-8);
  }

  .transaction-item {
    padding: var(--space-4) var(--space-5);
  }

  .field-input,
  .field-select,
  .field-textarea {
    font-size: 14px;
    padding: var(--space-3) var(--space-4);
    min-height: 40px;
  }
}

/* ══════════════════════════════════════════
   UTILITY — MOBILE HELPERS
   ══════════════════════════════════════════ */
.mobile-only { display: block; }
.desktop-only { display: none; }

@media (min-width: 1024px) {
  .mobile-only { display: none; }
  .desktop-only { display: block; }
}

/* Full-width on mobile */
@media (max-width: 599px) {
  .mobile-full { width: 100% !important; }

  /* Force single column on very small screens */
  .grid-4 { grid-template-columns: repeat(2, 1fr) !important; }

  /* Reduce premium page hero padding */
  .premium-page-hero {
    padding: var(--space-6) var(--space-4) !important;
    border-radius: var(--radius-2xl) !important;
  }

  .premium-page-title {
    font-size: 24px !important;
    line-height: 30px !important;
  }

  .premium-page-benefits-grid {
    grid-template-columns: 1fr !important;
  }

  .premium-modal {
    border-radius: var(--radius-3xl) var(--radius-3xl) 0 0 !important;
    max-width: 100% !important;
  }

  /* Confirm dialog full-width */
  .modal-backdrop .modal {
    max-width: 100% !important;
    border-radius: var(--radius-3xl) var(--radius-3xl) 0 0 !important;
  }

  /* section headers */
  .section-header { padding: var(--space-4) var(--space-4) var(--space-2); }

  /* upsell content stack */
  .premium-upsell-content { flex-direction: column; align-items: flex-start; }
  .premium-upsell-btn { width: 100%; text-align: center; }
}

/* ══════════════════════════════════════════
   HAPTIC FEEDBACK SIMULATION (active states)
   ══════════════════════════════════════════ */
@media (hover: none) {
  /* Active press effect for touch */
  .btn:active { transform: scale(0.96); }
  .transaction-item:active { background: var(--md-surface-container); }
  .nav-item:active { background: var(--md-surface-container); }
  .bottom-nav-item:active .bottom-nav-item-icon { transform: scale(0.9); }
  .chip:active { transform: scale(0.96); }
}

/* ══════════════════════════════════════════
   FLEX UTILITIES (used extensively in pages)
   ══════════════════════════════════════════ */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }
.flex-1 { flex: 1; }
.min-w-0 { min-width: 0; }
.w-full { width: 100%; }
.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-5 { margin-bottom: var(--space-5); }
.mb-6 { margin-bottom: var(--space-6); }
.mb-8 { margin-bottom: var(--space-8); }
.text-sm { font: var(--text-body-sm); }
.text-secondary { color: var(--text-secondary); }
.text-primary-color { color: var(--md-primary); }
.text-income  { color: var(--color-income); }
.text-expense { color: var(--color-expense); }
.font-bold { font-weight: 700; }
.font-medium { font-weight: 500; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
