/* ========================================================
   DueKeep Mobile Styles — 375px baseline (iPhone SE)
   ======================================================== */

/* ── 44px Tap Targets ─────────────────────────────────── */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="datetime-local"],
input[type="tel"],
input[type="url"],
input[type="search"],
textarea,
select {
  min-height: 44px;
  padding: 10px 12px;
  font-size: 16px; /* prevents iOS zoom on focus */
  -webkit-appearance: none;
  border-radius: var(--radius-sm, 6px);
}

/* Amount inputs — numeric keyboard */
input[type="number"][inputmode="decimal"],
input.amount-input {
  input-mode: decimal;
}

/* Label visibility — never placeholder-as-label */
.field label,
.form-card label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--fg-muted);
  margin-bottom: 6px;
}

/* Error messages appear below field */
.field-error {
  display: block;
  color: #f87171;
  font-size: 0.78rem;
  margin-top: 4px;
}

/* Submit buttons — full-width on mobile, 48px min height */
@media (max-width: 640px) {
  .btn-primary[onclick*="save"],
  .btn-primary[type="submit"],
  .btn-primary.submit-btn,
  form.ajax-form button[type="submit"],
  .mobile-submit-btn {
    width: 100%;
    min-height: 48px;
    font-size: 1rem;
    position: fixed;
    bottom: calc(70px + env(safe-area-inset-bottom, 0px));
    left: 16px;
    right: 16px;
    border-radius: 10px;
    z-index: 100;
    box-shadow: 0 4px 20px rgba(34, 214, 138, 0.4);
  }

  /* Also push the normal page bottom padding up */
  .invoice-builder-wrap,
  .page-wrap.narrow {
    padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  }
}

/* ── Bottom Tab Bar ────────────────────────────────────── */
.bottom-tab-bar {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(56px + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  z-index: 500;
  box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.25);
}

.bottom-tab-bar-inner {
  display: flex;
  align-items: center;
  justify-content: space-around;
  height: 56px;
}

.tab-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 6px 12px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--fg-muted);
  font-size: 0.68rem;
  font-weight: 500;
  transition: color 0.15s;
  cursor: pointer;
  min-width: 56px;
}

.tab-item:active { opacity: 0.7; transform: scale(0.95); }

.tab-item.active {
  color: #22d68a; /* Electric Green */
}

.tab-item svg {
  width: 22px;
  height: 22px;
  stroke-width: 1.75;
  flex-shrink: 0;
}

.tab-item.active svg {
  filter: drop-shadow(0 0 6px rgba(34, 214, 138, 0.5));
}

.tab-item--more {
  position: relative;
}

.tab-badge {
  position: absolute;
  top: 2px;
  right: 8px;
  background: #f87171;
  color: #fff;
  font-size: 0.6rem;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 100px;
  min-width: 16px;
  text-align: center;
}

/* More menu dropdown */
.tab-more-menu {
  display: none;
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
  min-width: 180px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.tab-more-menu.open { display: block; }

.tab-more-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  color: var(--fg);
  text-decoration: none;
  font-size: 0.88rem;
  border-radius: 8px;
  transition: background 0.1s;
}

.tab-more-item:hover { background: rgba(255,255,255,0.06); }
.tab-more-item svg { width: 18px; height: 18px; color: var(--fg-muted); }
.tab-more-divider { height: 1px; background: var(--border); margin: 4px 8px; }

/* ── Mobile Invoice Cards ──────────────────────────────── */
@media (max-width: 640px) {
  /* Convert table rows to cards */
  .invoice-row {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 16px;
    border-left: none;
    border-bottom: 1px solid var(--border);
    position: relative;
    overflow: hidden;
    background: var(--bg-card);
    margin-bottom: 0;
    border-radius: 0;
  }

  .invoice-row > span.inv-number { display: none; }
  .invoice-row > div.inv-client {
    flex-direction: row;
    align-items: center;
    gap: 8px;
  }
  .client-name-text { font-size: 1rem; font-weight: 600; }
  .client-email-text { display: none; }
  .inv-amount {
    position: absolute;
    top: 16px;
    right: 70px;
    font-size: 1.05rem;
    font-weight: 700;
  }
  .inv-due-date { display: none; }
  .inv-status {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
  }
  .inv-status .badge {
    font-size: 0.78rem;
    padding: 4px 10px;
  }

  /* Swipe action container */
  .invoice-row {
    position: relative;
  }
  .swipe-action {
    position: absolute;
    top: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0;
    font-size: 0.8rem;
    font-weight: 600;
    transition: all 0.2s;
    min-width: 80px;
  }
  .swipe-action--send {
    right: 0;
    background: #22d68a;
    color: #0a0f1a;
    padding: 0 16px;
    opacity: 0;
    transform: translateX(80px);
    pointer-events: none;
  }
  .invoice-row.swiped .swipe-action--send {
    opacity: 1;
    transform: translateX(0);
    pointer-events: auto;
  }

  /* Header row hidden on mobile */
  .table-header-row { display: none; }

  /* Kebab on mobile — always visible */
  .inv-actions { justify-content: flex-end; }
  .btn-kebab { display: flex; }

  /* Count label */
  .invoice-count-label { font-size: 0.78rem; }

  /* New Invoice FAB */
  .invoice-fab {
    display: flex;
  }

  /* Filter bar */
  .invoice-filter-bar {
    margin-bottom: 12px;
  }
  .filter-tabs {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 4px;
  }
  .filter-tabs::-webkit-scrollbar { display: none; }
  .filter-count { font-size: 0.7rem; }

  /* Page header */
  .page-header {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  .page-title { font-size: 1.4rem; }
  .header-actions { display: none; } /* FAB replaces this on mobile */
}

/* FAB */
.invoice-fab {
  display: none;
  position: fixed;
  bottom: calc(66px + env(safe-area-inset-bottom, 0px));
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #22d68a;
  color: #0a0f1a;
  font-size: 1.6rem;
  font-weight: 700;
  border: none;
  box-shadow: 0 4px 16px rgba(34, 214, 138, 0.5);
  align-items: center;
  justify-content: center;
  cursor: pointer;
  text-decoration: none;
  z-index: 300;
  line-height: 1;
}

.invoice-fab:hover { opacity: 0.9; transform: scale(1.05); }
.invoice-fab:active { transform: scale(0.95); }

/* Page wrap — ensure bottom padding for tab bar + FAB */
@media (max-width: 640px) {
  .page-wrap { padding-bottom: calc(100px + env(safe-area-inset-bottom, 0px)); }
  .invoice-table-wrap { border-radius: 8px; }
}

/* ── Dashboard Mobile ──────────────────────────────────── */
@media (max-width: 640px) {
  .dash-greeting {
    flex-direction: column;
    gap: 12px;
    align-items: stretch;
  }
  .dash-greeting-h1 { font-size: 1.4rem; }
  .dash-greeting-actions { display: none; }

  .dash-main-row { flex-direction: column; }
  .dash-right-col { display: none; } /* hide activity on mobile */

  .metric-cards-grid {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }
  .metric-card--success { grid-column: 1 / -1; }

  /* Override: hide header actions, show mobile greeting actions */
  .dash-greeting-actions { display: flex; }
  .dash-greeting-actions .btn-primary {
    padding: 10px 20px;
    font-size: 0.9rem;
  }

  /* Overdue table → card list */
  .overdue-table-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
  }
  .overdue-table-header { display: none; }
  .overdue-table-num { display: none; }
  .overdue-table-client { font-size: 0.95rem; font-weight: 600; }
  .overdue-table-amount { font-size: 1rem; font-weight: 700; color: #f87171; }
  .overdue-table-due { display: none; }
  .overdue-table-badge { font-size: 0.75rem; color: #f87171; background: rgba(248,113,113,0.1); padding: 2px 8px; border-radius: 4px; display: inline-block; width: fit-content; }
  .overdue-table-action { display: none; }

  .cash-flow-wrap { overflow-x: auto; }
}

/* ── Clients Mobile ────────────────────────────────────── */
@media (max-width: 640px) {
  .client-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
  }
  .client-card-avatar {
    width: 44px;
    height: 44px;
    min-width: 44px;
    border-radius: 50%;
    background: var(--accent-dim);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--accent);
  }
  .client-card-info { flex: 1; min-width: 0; }
  .client-card-name { font-weight: 600; font-size: 0.95rem; margin-bottom: 2px; }
  .client-card-email { font-size: 0.78rem; color: var(--fg-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .client-card-balance { font-weight: 600; font-size: 0.92rem; color: var(--fg); }
  .client-card-actions { display: flex; gap: 8px; margin-top: 8px; }
}

/* ── Forms Mobile ──────────────────────────────────────── */
@media (max-width: 640px) {
  .form-card { padding: 16px; border-radius: 10px; }
  .form-row { gap: 0; }
  .form-card .field { margin-bottom: 16px; }

  /* Builder layout */
  .builder-layout { grid-template-columns: 1fr !important; }
  .builder-preview-col { order: -1; }
  .preview-sticky { position: static; }

  /* Full-width on mobile */
  input[type="text"],
  input[type="email"],
  input[type="date"],
  input[type="number"],
  input[type="datetime-local"],
  textarea,
  select {
    width: 100%;
  }

  /* Line items — simpler mobile layout */
  .line-items-header { display: none; }
  .line-item-row {
    display: grid !important;
    grid-template-columns: 1fr 80px !important;
    gap: 8px;
    padding: 8px 0;
  }
  .li-col-qty,
  .li-col-price,
  .li-col-total,
  .li-col-action {
    display: none;
  }
  .li-qty,
  .li-price-wrap,
  .li-total { display: none; }
  .li-delete { display: flex; }

  /* Header actions hidden on mobile (FAB takes over) */
  .header-actions { display: none; }
}

/* ── Skeleton screens ──────────────────────────────────── */
@media (max-width: 640px) {
  .skeleton-row {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  .skeleton-row .skel {
    height: 16px;
    border-radius: 4px;
  }
  .skeleton-row .skel-title {
    height: 20px;
    width: 60%;
  }
  .skeleton-row .skel-sub {
    height: 14px;
    width: 40%;
  }
}

/* ── Command palette on mobile ─────────────────────────── */
@media (max-width: 640px) {
  .cmd-palette { padding-top: 20px; }
  .cmd-inner { max-width: 100%; border-radius: 12px; margin: 0; }
  .cmd-results { max-height: 280px; }
}

/* ── Toast on mobile ───────────────────────────────────── */
@media (max-width: 640px) {
  .toast-container {
    bottom: calc(70px + env(safe-area-inset-bottom, 0px));
    left: 16px;
    right: 16px;
  }
  .toast {
    width: 100%;
    min-width: 0;
    border-radius: 10px;
  }
}

/* ── Show bottom tab bar on mobile ────────────────────── */
@media (max-width: 1023px) {
  .bottom-tab-bar { display: block; }
  .app-content { padding-bottom: calc(66px + env(safe-area-inset-bottom, 0px)); }

  /* Push FAB up above tab bar */
  .invoice-fab {
    bottom: calc(66px + 20px + env(safe-area-inset-bottom, 0px));
  }
}

/* ── Disable hover states on touch devices ────────────── */
@media (hover: none) and (pointer: coarse) {
  .btn-primary:hover { opacity: 1; }
  .card-hover:hover { transform: none; box-shadow: var(--shadow-sm); }
  .btn-ghost:hover { color: var(--fg-muted); border-color: var(--border); }
}

/* ── Dark theme accent overrides ───────────────────────── */
:root {
  --accent-green: #22d68a;
}