/* ═══════════════════════════════════════════════════════════
   SHARED UI — Toast, Spinner, Animations, Tables, Polish
   Mobile-first: base styles = phone, scale up with min-width
   ═══════════════════════════════════════════════════════════ */

/* ── Toast Notification System ── */
.toast-container {
  position: fixed; bottom: 12px; left: 12px; right: 12px; z-index: 99999;
  display: flex; flex-direction: column-reverse; gap: 8px;
  pointer-events: none; align-items: center;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-radius: 10px;
  font-size: 13px; font-weight: 600; font-family: inherit;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  width: 100%; max-width: 420px;
  animation: toastInMobile 0.3s ease-out forwards;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.toast.removing { animation: toastOutMobile 0.2s ease-in forwards; }
.toast-success { background: rgba(34,197,94,0.15); border: 1px solid rgba(34,197,94,0.3); color: #22c55e; }
.toast-error   { background: rgba(244,63,94,0.15); border: 1px solid rgba(244,63,94,0.3); color: #f43f5e; }
.toast-info    { background: rgba(59,130,246,0.15); border: 1px solid rgba(59,130,246,0.3); color: #3b82f6; }
.toast-warning { background: rgba(245,158,11,0.15); border: 1px solid rgba(245,158,11,0.3); color: #f59e0b; }
.toast-icon { font-size: 16px; flex-shrink: 0; }
.toast-msg { flex: 1; min-width: 0; line-height: 1.4; }
.toast-close {
  margin-left: auto; background: none; border: none; color: inherit;
  cursor: pointer; font-size: 18px; opacity: 0.5; padding: 4px 4px;
  min-width: 28px; min-height: 28px; display: flex; align-items: center; justify-content: center;
}
.toast-close:hover { opacity: 1; }
body.light .toast { box-shadow: 0 8px 24px rgba(0,0,0,0.12); }

/* Mobile: slide from bottom */
@keyframes toastInMobile {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}
@keyframes toastOutMobile {
  from { transform: translateY(0); opacity: 1; }
  to   { transform: translateY(100%); opacity: 0; }
}

/* Desktop: reposition to bottom-right, slide from right */
@media (min-width: 481px) {
  .toast-container {
    left: auto; right: 24px; bottom: 24px; align-items: flex-end;
  }
  .toast {
    width: auto; min-width: 280px; max-width: 420px;
    animation-name: toastInDesktop;
  }
  .toast.removing { animation-name: toastOutDesktop; }
  @keyframes toastInDesktop {
    from { transform: translateX(100%); opacity: 0; }
    to   { transform: translateX(0); opacity: 1; }
  }
  @keyframes toastOutDesktop {
    from { transform: translateX(0); opacity: 1; }
    to   { transform: translateX(100%); opacity: 0; }
  }
}

/* ── Loading Spinner ── */
.spinner-overlay {
  position: absolute; inset: 0; display: flex;
  align-items: center; justify-content: center;
  background: rgba(15,17,23,0.5); border-radius: 12px; z-index: 10;
  backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px);
}
body.light .spinner-overlay { background: rgba(245,245,247,0.6); }
.spinner {
  width: 32px; height: 32px;
  border: 3px solid rgba(255,255,255,0.1);
  border-top-color: var(--accent, #22c55e);
  border-radius: 50%; animation: spin 0.7s linear infinite;
}
body.light .spinner { border-color: rgba(0,0,0,0.1); border-top-color: var(--accent, #22c55e); }
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 481px) {
  .spinner { width: 36px; height: 36px; }
}

/* ── Sort Direction Indicators ── */
th.sortable { cursor: pointer; user-select: none; }
th.sort-asc::after  { content: ' \25B2'; font-size: 8px; opacity: 0.8; }
th.sort-desc::after { content: ' \25BC'; font-size: 8px; opacity: 0.8; }
th.sortable:not(.sort-asc):not(.sort-desc)::after {
  content: ' \25B4'; font-size: 7px; opacity: 0.25;
}
@media (min-width: 481px) {
  th.sort-asc::after, th.sort-desc::after { font-size: 9px; }
  th.sortable:not(.sort-asc):not(.sort-desc)::after { font-size: 8px; }
}

/* ── Button Hover — desktop only ── */
@media (hover: hover) {
  .btn:hover { transform: translateY(-1px); filter: brightness(1.1); }
  .btn:active { transform: translateY(0); filter: brightness(0.95); }
}

/* ── Modal Transitions ── */
.modal-overlay {
  transition: opacity 0.25s ease, visibility 0.25s ease;
}
.modal-overlay .modal-content,
.modal-overlay .modal {
  transform: translateY(16px) scale(0.98);
  transition: transform 0.25s ease, opacity 0.25s ease;
  opacity: 0;
}
.modal-overlay.open .modal-content,
.modal-overlay.open .modal {
  transform: translateY(0) scale(1);
  opacity: 1;
}

/* ── View/Tab Fade ── */
.view { transition: opacity 0.2s ease-in-out; }

/* ── Table Zebra Striping ── */
.tbl tbody tr:nth-child(even) td { background: rgba(255,255,255,0.02); }
body.light .tbl tbody tr:nth-child(even) td { background: rgba(0,0,0,0.02); }

/* ── Progress Bar Animation ── */
.progress-fill {
  transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1) !important;
}

/* ── KPI Entrance Animation ── */
@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Empty State Enhancements ── */
.empty-state { text-align: center; padding: 48px 16px; }
.empty-state-icon {
  font-size: 48px; margin-bottom: 12px;
  animation: emptyBounce 2.5s ease-in-out infinite;
}
.empty-state-title {
  font-size: 18px; font-weight: 700; margin-bottom: 8px;
}
.empty-state-text {
  font-size: 13px; color: var(--text-muted, #71717a);
  margin-bottom: 20px; max-width: 400px; margin-left: auto; margin-right: auto;
  line-height: 1.6;
}
.empty-state-btn {
  background: rgba(59,130,246,0.2); color: var(--blue, #3b82f6); border: 1px solid rgba(59,130,246,0.3);
  border-radius: 10px; padding: 12px 28px; font-size: 15px; font-weight: 600;
  cursor: pointer; font-family: inherit; transition: all 0.2s;
}
.empty-state-btn:hover { background: rgba(59,130,246,0.3); transform: translateY(-2px); }
.empty-state-hint {
  font-size: 11px; color: var(--text-muted, #71717a);
  margin-top: 12px; opacity: 0.6;
}
@keyframes emptyBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

@media (min-width: 481px) {
  .empty-state { padding: 60px 20px; }
  .empty-state-icon { font-size: 64px; margin-bottom: 16px; }
  .empty-state-title { font-size: 20px; }
  .empty-state-text { font-size: 14px; max-width: 500px; }
  .empty-state-hint { font-size: 12px; }
  .empty-state-btn { font-size: 16px; padding: 14px 32px; }
}

/* ── Card Hover — desktop only ── */
@media (hover: hover) {
  .card:hover { border-color: rgba(255,255,255,0.1); }
  body.light .card:hover { border-color: rgba(0,0,0,0.15); }
  .kpi, .insight-card, .trip-card, .delta-card {
    transition: transform 0.15s ease, box-shadow 0.15s ease;
  }
  .kpi:hover, .insight-card:hover, .trip-card:hover, .delta-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  }
}

/* ══════════════════════════════════════════════════════
   HEADER NAVIGATION & AUTH — Mobile-first
   ══════════════════════════════════════════════════════ */

/* ── Header Nav Container (Groceries, Expenses right side) ── */
.header-nav {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}

/* ── Nav Pill Links ── */
.nav-pill {
  font-size: 13px; text-decoration: none; font-weight: 600;
  padding: 6px 14px; border-radius: 8px; transition: all 0.2s;
  white-space: nowrap; line-height: 1.4;
}
.nav-pill-blue { color: var(--blue, #3b82f6); border: 1px solid rgba(59,130,246,0.3); background: rgba(59,130,246,0.08); }
.nav-pill-purple { color: #a855f7; border: 1px solid rgba(168,85,247,0.3); background: rgba(168,85,247,0.08); }
.nav-pill-green { color: var(--green, #22c55e); border: 1px solid rgba(34,197,94,0.3); background: rgba(34,197,94,0.08); }
.nav-pill-orange { color: #f97316; border: 1px solid rgba(249,115,22,0.3); background: rgba(249,115,22,0.08); }

/* ── Firebase Auth Container ── */
.fb-auth-container {
  display: flex; align-items: center; gap: 8px;
}
.fb-sync-status {
  font-size: 12px; color: #71717a;
}
.fb-auth-btn {
  background: rgba(249,115,22,0.15); color: #f97316;
  border: 1px solid rgba(249,115,22,0.3); border-radius: 8px;
  padding: 6px 14px; font-size: 12px; font-weight: 600;
  cursor: pointer; font-family: inherit; transition: all .2s;
}
.fb-user-info {
  font-size: 12px; color: #a1a1aa;
  display: inline-flex; align-items: center; gap: 4px;
}
.fb-user-email {
  max-width: 200px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; display: inline-block; vertical-align: middle;
}
.fb-signout-btn {
  background: none; border: none; color: #71717a; cursor: pointer;
  font-size: 11px; margin-left: 2px; text-decoration: underline;
  font-family: inherit; white-space: nowrap;
}

/* ── Mobile: Header + Controls responsive ── */
@media (max-width: 480px) {

  /* ── Header nav: full-width, wrap into sub-rows via order ── */
  .header-nav {
    width: 100%; display: flex; flex-wrap: wrap;
    justify-content: center; gap: 6px;
    border-top: 1px solid var(--card-border, #2a2b35);
    padding-top: 8px; margin-top: 4px;
  }

  /* Theme toggle: compact, first sub-row */
  .theme-toggle { order: 0; font-size: 14px; padding: 5px 8px; }

  /* Auth: same sub-row as theme toggle */
  .fb-auth-container {
    order: 1; width: auto !important;
    justify-content: center !important;
    padding-top: 0 !important; margin-top: 0 !important;
    border-top: none !important;
  }
  .fb-auth-btn { font-size: 10px; padding: 4px 10px; }
  .fb-user-info { font-size: 10px; }
  .fb-user-email { max-width: 120px; font-size: 10px; }
  .fb-signout-btn { font-size: 9px; }

  /* Invisible flex line break between auth-row and pills-row */
  .header-nav::after {
    content: ''; flex-basis: 100%; height: 0; order: 5;
  }

  /* Nav pills: second sub-row */
  .nav-pill { order: 10; font-size: 11px; padding: 5px 10px; }

  /* ── Month nav: stacked, full-width select + equal buttons ── */
  .month-nav { flex-wrap: wrap; gap: 8px; }
  .month-nav select {
    width: 100%; font-size: 14px; padding: 10px 14px; order: -1;
  }
  .month-nav-btn {
    flex: 1 1 0; text-align: center;
    font-size: 11px; padding: 8px 6px; min-height: 36px; white-space: nowrap;
  }

  /* ── Budget header-right: centered row ── */
  .header-right {
    position: static !important;
    width: 100%; display: flex; justify-content: center;
    flex-wrap: wrap; gap: 6px;
  }

  /* Scanner header-links wrap */
  .header-links { flex-wrap: wrap; gap: 8px; }
  .header-links a { font-size: 11px; }
}

/* ── Tablet+ ── */
@media (min-width: 481px) {
  .fb-user-email {
    max-width: 240px;
  }
}

/* ── Hover states for nav pills — desktop only ── */
@media (hover: hover) {
  .nav-pill:hover { transform: translateY(-1px); filter: brightness(1.15); }
  .fb-auth-btn:hover { background: rgba(249,115,22,0.25); }
  .fb-signout-btn:hover { color: #f43f5e; }
}

/* ══════════════════════════════════════════════════════
   UNDO TOAST — Mobile-first
   ══════════════════════════════════════════════════════ */
.undo-toast {
  position: fixed; bottom: 12px; left: 12px; right: 12px; z-index: 100000;
  background: var(--card, #1a1b2e); border: 1px solid var(--blue, #3b82f6);
  border-radius: 12px; padding: 14px 16px;
  display: flex; align-items: center; gap: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  transform: translateY(120%); opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  overflow: hidden;
}
.undo-toast.visible { transform: translateY(0); opacity: 1; }
.undo-toast.hiding { transform: translateY(120%); opacity: 0; }
body.light .undo-toast {
  background: #fff; border-color: #3b82f6;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
}
.undo-toast-icon { font-size: 16px; flex-shrink: 0; }
.undo-toast-msg {
  flex: 1; min-width: 0; font-size: 13px; font-weight: 600;
  color: var(--text, #e2e8f0); line-height: 1.4;
}
body.light .undo-toast-msg { color: #1e293b; }
.undo-btn {
  background: var(--blue, #3b82f6); color: #fff; border: none;
  border-radius: 8px; padding: 8px 18px; font-size: 13px;
  font-weight: 700; cursor: pointer; font-family: inherit;
  white-space: nowrap; min-height: 38px;
  transition: background 0.2s;
}
.undo-btn:hover { background: #2563eb; }
.undo-btn:active { background: #1d4ed8; }
.undo-toast-close {
  background: none; border: none; color: var(--text-muted, #71717a);
  cursor: pointer; font-size: 18px; padding: 4px; min-width: 32px;
  min-height: 32px; display: flex; align-items: center; justify-content: center;
}
.undo-progress {
  position: absolute; bottom: 0; left: 0; height: 3px;
  background: var(--blue, #3b82f6); width: 100%;
  transition: width 6s linear;
  border-radius: 0 0 12px 12px;
}

/* Desktop: center and constrain width */
@media (min-width: 481px) {
  .undo-toast {
    left: 50%; right: auto; transform: translateX(-50%) translateY(120%);
    max-width: 480px; width: auto; min-width: 320px;
    bottom: 24px; padding: 14px 20px;
  }
  .undo-toast.visible { transform: translateX(-50%) translateY(0); }
  .undo-toast.hiding { transform: translateX(-50%) translateY(120%); }
}

/* ══════════════════════════════════════════════════════
   BULK ACTION BAR — Mobile-first
   ══════════════════════════════════════════════════════ */
.bulk-bar {
  position: fixed; bottom: 12px; left: 12px; right: 12px; z-index: 9999;
  background: var(--card, #1a1b2e); border: 1px solid var(--blue, #3b82f6);
  border-radius: 12px; padding: 12px 16px;
  display: none; align-items: center; gap: 8px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  animation: toastInMobile 0.3s ease-out forwards;
}
.bulk-bar.active { display: flex; flex-wrap: wrap; }
body.light .bulk-bar {
  background: #fff; box-shadow: 0 8px 32px rgba(0,0,0,0.15);
}
.bulk-count {
  font-size: 13px; font-weight: 700; color: var(--blue, #3b82f6);
  white-space: nowrap;
}
.bulk-bar button {
  border: none; border-radius: 8px; padding: 8px 14px;
  font-size: 12px; font-weight: 600; cursor: pointer;
  font-family: inherit; min-height: 36px; white-space: nowrap;
}
.bulk-bar .bulk-recat { background: rgba(59,130,246,0.15); color: var(--blue, #3b82f6); }
.bulk-bar .bulk-delete { background: rgba(239,68,68,0.15); color: #ef4444; }
.bulk-bar .bulk-cancel { background: rgba(113,113,122,0.15); color: var(--text-muted, #71717a); margin-left: auto; }

/* Checkbox styling — hidden by default, shown in select mode */
.tx-check { width: 18px; height: 18px; cursor: pointer; accent-color: var(--blue, #3b82f6); }
.tx-check-col { display: none; width: 0; padding: 0 !important; overflow: hidden; }
.select-mode .tx-check-col { display: table-cell; width: 32px; padding: 8px !important; }

/* Select mode toggle button */
.btn-select-mode {
  border: 1px solid var(--card-border, #2a2b35); border-radius: 8px;
  background: rgba(255,255,255,0.04); color: var(--text-muted, #71717a);
  padding: 8px 16px; font-size: 13px; font-weight: 600; cursor: pointer;
  font-family: inherit; transition: all 0.2s; min-height: 38px;
}
.btn-select-mode:hover { border-color: var(--blue, #3b82f6); color: var(--blue, #3b82f6); }
.btn-select-mode.active {
  background: rgba(59,130,246,0.12); border-color: var(--blue, #3b82f6);
  color: var(--blue, #3b82f6);
}
body.light .btn-select-mode {
  background: rgba(0,0,0,0.03); border-color: #e4e4e7; color: #71717a;
}
body.light .btn-select-mode:hover { border-color: var(--blue, #3b82f6); color: var(--blue, #3b82f6); }
body.light .btn-select-mode.active { background: rgba(59,130,246,0.08); }

@media (min-width: 481px) {
  .btn-select-mode { padding: 6px 12px; font-size: 12px; min-height: auto; }
  .bulk-bar {
    left: 50%; right: auto; transform: translateX(-50%);
    max-width: 520px; width: auto; min-width: 360px;
    bottom: 24px; padding: 12px 20px; flex-wrap: nowrap;
  }
  .tx-check { width: 16px; height: 16px; }
}
