/* ==========================================================================
   Finance PWA - Phase 4 shell stylesheet
   --------------------------------------------------------------------------
   Mobile-first dark-slate theme. No frameworks, no build step. The whole
   thing is intentionally tiny - it's a shell, not a design system. Real
   data layouts (charts, lists) get added in later phases.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Tokens
   -------------------------------------------------------------------------- */

:root {
  /* Dark slate palette (matches Tailwind's slate scale so any later
     additions stay coherent without us inventing new shades). */
  --c-bg-0: #020617;        /* slate-950 - app background, behind safe area */
  --c-bg-1: #0f172a;        /* slate-900 - main canvas */
  --c-bg-2: #1e293b;        /* slate-800 - cards */
  --c-bg-3: #334155;        /* slate-700 - card borders / dividers */
  --c-text:  #f1f5f9;       /* slate-100 - primary text */
  --c-text-dim:  #94a3b8;   /* slate-400 - secondary text */
  --c-text-muted: #64748b;  /* slate-500 - placeholders */
  --c-accent: #10b981;      /* emerald-500 - active tab + primary button */
  --c-accent-dim: #065f46;  /* emerald-800 - disabled accent */

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 18px;

  /* Tab bar height + gap so .app-main can reserve room for it without
     overlap, plus the iPhone home-indicator inset. */
  --tab-bar-height: 56px;

  /* System font stack: matches whatever the OS calls "default", giving
     us the iOS feel on iPhone and Roboto on Android with zero downloads. */
  --font-sans:
    -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono:
    ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

/* --------------------------------------------------------------------------
   Reset / globals
   -------------------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--c-bg-0);
  color: var(--c-text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  /* Disable iOS rubber-band on the document so the bottom tab bar stays
     visually anchored; individual scroll containers can still bounce. */
  overscroll-behavior: none;
  /* Prevent the iOS double-tap-to-zoom delay on tappable elements. */
  touch-action: manipulation;
}

body {
  min-height: 100vh;
  /* Fallback for browsers without dvh; modern iOS Safari handles this. */
  min-height: 100dvh;
  background: var(--c-bg-1);
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  /* iOS adds a tap highlight by default; we draw our own active styles. */
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* --------------------------------------------------------------------------
   App header
   -------------------------------------------------------------------------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding:
    calc(env(safe-area-inset-top, 0px) + 12px)
    16px
    12px
    16px;
  background: var(--c-bg-1);
  border-bottom: 1px solid var(--c-bg-3);
}

.app-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.header-action {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 1.25rem;
  color: var(--c-text-dim);
  transition: background 120ms ease;
}
.header-action:hover { background: var(--c-bg-2); }
.header-action:disabled { color: var(--c-text-muted); cursor: default; }

/* --------------------------------------------------------------------------
   Main scroll container
   -------------------------------------------------------------------------- */

.app-main {
  /* Reserve room for the fixed bottom tab bar plus the home indicator. */
  padding:
    16px
    16px
    calc(var(--tab-bar-height) + env(safe-area-inset-bottom, 0px) + 24px)
    16px;
  max-width: 720px;
  margin: 0 auto;
}

.screen {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* JS toggles the hidden attr; this is just defensive in case CSS loads
   before JS has a chance to set the active screen. */
.screen[hidden] { display: none; }

.screen-title {
  font-size: 1.5rem;
  margin-bottom: 4px;
}

/* --------------------------------------------------------------------------
   Cards
   -------------------------------------------------------------------------- */

.card {
  background: var(--c-bg-2);
  border: 1px solid var(--c-bg-3);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.card-hero { padding: 18px 20px; }

.card-row {
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
}

.card-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--c-text-dim);
}

.card-value {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.card-hero .card-value {
  font-size: 2rem;
}

.card-meta {
  font-size: 0.86rem;
  color: var(--c-text-dim);
}

/* Skeleton-ish state for unloaded data: muted color signals "not yet". */
.placeholder {
  color: var(--c-text-muted);
}

/* --------------------------------------------------------------------------
   Grid
   -------------------------------------------------------------------------- */

.grid {
  display: grid;
  gap: 12px;
}

.grid-2 {
  grid-template-columns: repeat(2, 1fr);
}

/* On wider screens (iPad portrait, desktop hosting) move to a 4-up row
   so the hero card doesn't look lonely on the left. Width chosen so an
   iPhone Pro Max in landscape stays in the 2-up layout. */
@media (min-width: 600px) {
  .grid-2 { grid-template-columns: repeat(4, 1fr); }
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */

.btn {
  width: 100%;
  min-height: 48px;
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 600;
  display: grid;
  place-items: center;
  transition: background 120ms ease, color 120ms ease;
}

.btn-primary {
  background: var(--c-accent);
  color: var(--c-bg-0);
}
.btn-primary:disabled { background: var(--c-accent-dim); color: var(--c-text-dim); }

.btn-ghost {
  background: var(--c-bg-2);
  color: var(--c-text);
  border: 1px solid var(--c-bg-3);
}
.btn-ghost:disabled { color: var(--c-text-muted); }

/* --------------------------------------------------------------------------
   Empty state
   -------------------------------------------------------------------------- */

.empty-state {
  background: var(--c-bg-2);
  border: 1px dashed var(--c-bg-3);
  border-radius: var(--radius-md);
  padding: 32px 20px;
  text-align: center;
}
.empty-title {
  font-weight: 600;
  margin: 0 0 6px 0;
}
.empty-body {
  margin: 0;
  color: var(--c-text-dim);
  font-size: 0.95rem;
}

.footnote {
  margin: 16px 4px 0 4px;
  font-size: 0.8rem;
  color: var(--c-text-muted);
  text-align: center;
}

/* --------------------------------------------------------------------------
   Bottom tab bar
   -------------------------------------------------------------------------- */

.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: rgba(15, 23, 42, 0.92);
  /* Backdrop blur gives the iOS-translucent feel when content scrolls
     under it. Falls back to opaque on browsers without backdrop-filter. */
  -webkit-backdrop-filter: saturate(140%) blur(14px);
  backdrop-filter: saturate(140%) blur(14px);
  border-top: 1px solid var(--c-bg-3);
  /* Add the home-indicator inset so the visible tab area stays above the
     iPhone's bottom indicator strip. */
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  height: var(--tab-bar-height);
  color: var(--c-text-dim);
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  transition: color 120ms ease;
}

.tab[aria-selected="true"] {
  color: var(--c-accent);
}

.tab-icon {
  font-size: 1.1rem;
  line-height: 1;
}

.tab:active {
  /* Subtle press feedback - we don't want a full background flash. */
  transform: scale(0.97);
}

/* --------------------------------------------------------------------------
   Phase 5 additions: transactions list, modal, error toast, loading veil
   -------------------------------------------------------------------------- */

/* ---- Transactions ------------------------------------------------------ */

.txn-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.txn-section-header {
  margin: 12px 4px 4px 4px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--c-text-dim);
}
.txn-section-header:first-child {
  margin-top: 0;
}

.txn-row {
  background: var(--c-bg-2);
  border: 1px solid var(--c-bg-3);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.txn-left {
  flex: 1 1 auto;
  min-width: 0;
}
.txn-name {
  font-size: 0.95rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.txn-meta {
  font-size: 0.78rem;
  color: var(--c-text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.txn-amount {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  flex: 0 0 auto;
}
.txn-amount.pos { color: var(--c-accent); }    /* income, +$ */
.txn-amount.neg { color: var(--c-text); }      /* spend, -$ - default text colour, no red */

/* ---- Modal ------------------------------------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal[hidden] { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.7);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 420px;
  background: var(--c-bg-2);
  border: 1px solid var(--c-bg-3);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  /* Slide up + fade in - keeps the entrance feeling intentional. */
  animation: modalIn 180ms ease-out;
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0)    scale(1); }
}

.modal-title {
  font-size: 1.1rem;
  margin: 0;
}
.modal-body {
  margin: 0;
  font-size: 0.9rem;
  color: var(--c-text-dim);
  line-height: 1.45;
}
.modal-body code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--c-bg-1);
  border: 1px solid var(--c-bg-3);
  padding: 1px 6px;
  border-radius: 4px;
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.modal-label {
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--c-text-dim);
}
.modal-form input[type="password"] {
  width: 100%;
  background: var(--c-bg-1);
  color: var(--c-text);
  border: 1px solid var(--c-bg-3);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  /* >= 16px on iOS prevents the page from auto-zooming on focus. */
  font-size: 16px;
  font-family: var(--font-mono);
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.modal-form input[type="password"]:focus {
  border-color: var(--c-accent);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.18);
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 4px;
}
.modal-actions .btn {
  /* Modal buttons are tighter than full-width form buttons. */
  min-height: 44px;
}

/* ---- Error toast ------------------------------------------------------- */

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(var(--tab-bar-height) + env(safe-area-inset-bottom, 0px) + 16px);
  z-index: 60;
  background: #7f1d1d;          /* red-900 - distinct from emerald accent */
  color: #fee2e2;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid #991b1b;
  font-size: 0.92rem;
  text-align: center;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}
.toast.visible {
  opacity: 1;
  transform: translateY(0);
}
.toast:empty { display: none; }

/* ---- Loading veil ------------------------------------------------------ */

.loading-veil {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(2, 6, 23, 0.55);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}
html.is-loading .loading-veil {
  display: flex;
}

.spinner {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid var(--c-bg-3);
  border-top-color: var(--c-accent);
  animation: spin 800ms linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
