/* ═══════════════════════════════════════════════════════════
   Cards module — indigo accent, soft cool-grey background, same
   shadow-based elevation as Household Budget but with its own tokens.
   Isolated to #module-cards / .crd-* — no shared selectors with other
   modules. kitchen.css's blanket body.dark text rule excludes it.
   ═══════════════════════════════════════════════════════════ */
:root {
  --crd-bg:      #F1F2F9;
  --crd-card:    #FFFFFF;
  --crd-accent:  #5B5BD6;
  --crd-accent-dark: #4747B8;
  --crd-text:    #16172E;
  --crd-text-dim: #74748A;
  --crd-danger:  #E23744;
  --crd-shadow:  0 1px 2px rgba(20,21,43,0.04), 0 4px 16px rgba(20,21,43,0.06);
  --crd-dashed-border: rgba(20,21,43,0.18);
}

/* Scoped to body.dark (not #module-cards) because the modals are appended
   straight to <body>. */
body.dark {
  --crd-bg:      #0B0C16;
  --crd-card:    #1B1C2E;
  --crd-accent:  #7C7CF0;
  --crd-accent-dark: #6666DD;
  --crd-text:    #EDEDF4;
  --crd-text-dim: #8B8CA3;
  --crd-shadow:  0 1px 2px rgba(0,0,0,0.35), 0 4px 16px rgba(0,0,0,0.45);
  --crd-dashed-border: rgba(237,237,244,0.22);
}

#module-cards {
  background: var(--crd-bg);
  color: var(--crd-text);
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
}

/* ── Header (structure comes from shared .mod-header) ───── */
.crd-header {
  background: var(--crd-accent);
  border-radius: var(--r-xl);
  flex-shrink: 0;
  --mod-header-accent: rgba(255,255,255,0.55);
}
.crd-header .mod-header-title {
  font-family: var(--font-ui);
  font-weight: 800;
  color: #ffffff;
  letter-spacing: -0.01em;
}
.crd-header .mod-header-status {
  color: rgba(255,255,255,0.6);
  font-weight: 600;
}
.crd-header .home-btn {
  color: #ffffff;
  opacity: 0.85;
}

/* ── Joint / Individual toggle ──────────────────────────── */
.crd-view-toggle {
  display: flex;
  gap: 4px;
  background: var(--crd-card);
  border-radius: 999px;
  padding: 4px;
  margin: 0 var(--s4) var(--s4);
  box-shadow: var(--crd-shadow);
  flex-shrink: 0;
}
.crd-view-btn {
  flex: 1;
  border: none;
  background: none;
  border-radius: 999px;
  padding: var(--s2) 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--crd-text-dim);
  cursor: pointer;
  font-family: var(--font-ui);
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.crd-view-btn.active {
  background: var(--crd-accent);
  color: #ffffff;
}

/* ── Card carousel ───────────────────────────────────────────
   Real credit-card proportions (1.586:1) with native scroll-snap.
   Explicit height rather than aspect-ratio (see root CLAUDE.md). ── */
.crd-carousel {
  display: flex;
  flex-shrink: 0;
  gap: var(--s3);
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  padding: 0 var(--s4) var(--s4);
  -webkit-overflow-scrolling: touch;
}
.crd-carousel::-webkit-scrollbar { display: none; }

.crd-card {
  position: relative;
  flex: 0 0 auto;
  width: min(78vw, 300px);
  height: calc(min(78vw, 300px) / 1.586);
  scroll-snap-align: center;
  border-radius: var(--r-lg);
}
.crd-card-face {
  width: 100%;
  height: 100%;
  border-radius: var(--r-lg);
  padding: var(--s4);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  color: #ffffff;
  cursor: pointer;
  box-shadow: var(--crd-shadow);
  -webkit-tap-highlight-color: transparent;
}
.crd-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding-right: 38px; /* clears .crd-card-edit-date */
}
.crd-card-name { font-size: 16px; font-weight: 700; }
.crd-card-network {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  opacity: 0.7;
}
.crd-card-bottom { display: flex; flex-direction: column; gap: 2px; }
.crd-card-owing { font-size: 17px; font-weight: 800; }
.crd-card-recon-date { font-size: 13px; font-weight: 700; }
.crd-card-tap-hint { font-size: 11px; opacity: 0.6; }

.crd-card-edit-date {
  position: absolute;
  top: var(--s3);
  right: var(--s3);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.18);
  color: #ffffff;
  font-size: 14px;
  cursor: pointer;
}
.crd-card-date-input {
  position: absolute;
  bottom: 0;
  right: var(--s3);
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.crd-card-add {
  flex: 0 0 auto;
  width: min(78vw, 300px);
  height: calc(min(78vw, 300px) / 1.586);
  scroll-snap-align: center;
  border-radius: var(--r-lg);
  border: 2px dashed var(--crd-dashed-border);
  background: none;
  color: var(--crd-text-dim);
  font-size: 32px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Funds owing panel ─────────────────────────────────── */
.crd-owings {
  flex-shrink: 0;
  background: var(--crd-card);
  border-radius: var(--r-lg);
  box-shadow: var(--crd-shadow);
  margin: 0 var(--s4) var(--s5);
  padding: var(--s4);
}
.crd-owings-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--s3);
  margin-bottom: var(--s3);
}
.crd-owings-title { font-size: 16px; font-weight: 800; color: var(--crd-text); }
.crd-owings-sub { font-size: 12px; color: var(--crd-text-dim); margin-top: 2px; }
.crd-owings-total {
  font-size: 22px;
  font-weight: 800;
  color: var(--crd-accent);
  font-variant-numeric: tabular-nums;
}
.crd-empty {
  color: var(--crd-text-dim);
  font-size: 13px;
  padding: var(--s3) 0;
  text-align: center;
}
.crd-owing-row {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: var(--s2) 0;
  border-top: 1px solid var(--crd-bg);
}
.crd-owing-check { accent-color: var(--crd-accent); width: 18px; height: 18px; flex-shrink: 0; }
.crd-owing-desc {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  color: var(--crd-text);
  overflow-wrap: anywhere;
}
.crd-owing-amount {
  font-size: 14px;
  font-weight: 700;
  color: var(--crd-text);
  font-variant-numeric: tabular-nums;
}
.crd-owing-by {
  display: inline-block;
  margin-left: var(--s1);
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--crd-bg);
  color: var(--crd-text-dim);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
#crd-owing-by-input {
  min-width: 0;
  border: 1px solid var(--crd-bg);
  background: var(--crd-bg);
  border-radius: var(--r-sm);
  padding: var(--s2);
  font-size: 16px;
  font-family: var(--font-ui);
  color: var(--crd-text);
}
.crd-owing-row.cleared .crd-owing-desc,
.crd-owing-row.cleared .crd-owing-amount {
  text-decoration: line-through;
  color: var(--crd-text-dim);
}
.crd-owing-delete {
  background: none;
  border: none;
  color: var(--crd-text-dim);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: var(--s1) var(--s2);
  border-radius: var(--r-sm);
  flex-shrink: 0;
}
.crd-owing-delete:hover { background: var(--crd-bg); color: var(--crd-danger); }
.crd-owings-clear {
  background: none;
  border: none;
  color: var(--crd-text-dim);
  font-size: 12px;
  font-family: var(--font-ui);
  text-decoration: underline;
  cursor: pointer;
  padding: var(--s2) 0;
}

.crd-owing-form {
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  margin-top: var(--s3);
  padding-top: var(--s3);
  border-top: 1px solid var(--crd-bg);
}
.crd-owing-form input {
  min-width: 0; /* form controls keep an intrinsic min-width; see root CLAUDE.md */
  border: 1px solid var(--crd-bg);
  background: var(--crd-bg);
  border-radius: var(--r-sm);
  padding: var(--s2) var(--s3);
  font-size: 16px; /* >=16px stops iOS zooming on focus */
  font-family: var(--font-ui);
  color: var(--crd-text);
  outline: none;
}
.crd-owing-form input:focus { border-color: var(--crd-accent); }
.crd-owing-form-row { display: flex; gap: var(--s2); }
.crd-amount-field { flex: 1; min-width: 0; display: flex; align-items: center; gap: var(--s2); color: var(--crd-text-dim); }
.crd-amount-field input { flex: 1; width: 100%; }
#crd-owing-add-btn {
  background: var(--crd-accent);
  color: #ffffff;
  border: none;
  border-radius: 999px;
  padding: 0 var(--s5);
  font-size: 14px;
  font-weight: 800;
  font-family: var(--font-ui);
  cursor: pointer;
}
#crd-owing-add-btn:active { background: var(--crd-accent-dark); }

/* ── Modals (appended to <body>, so not nested under the module) ── */
.crd-modal-sheet .modal-sheet-title {
  font-family: var(--font-ui);
  font-weight: 800;
  color: var(--crd-text);
}
.crd-modal-sheet .modal-close-btn {
  background: var(--crd-bg);
  color: var(--crd-text-dim);
}
.crd-modal-sheet .modal-sheet-sub {
  color: var(--crd-text-dim);
  font-family: var(--font-ui);
}
.crd-modal-sheet .modal-confirm-btn {
  background: var(--crd-accent);
  color: #ffffff;
  font-family: var(--font-ui);
  font-weight: 800;
  border-radius: 999px;
}
/* kitchen.css's `body.dark .modal-confirm-btn` (0,2,1) would otherwise win
   in dark mode, turning Save Kitchen-green. Same fix Finance uses. */
body.dark .crd-modal-sheet .modal-confirm-btn { background: var(--crd-accent); }
body.dark .crd-modal-sheet .modal-confirm-btn:active { background: var(--crd-accent-dark); }

.crd-settings-nav-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: var(--s3) 0;
  background: none;
  border: none;
  border-top: 1px solid var(--crd-bg);
  cursor: pointer;
  text-align: left;
  font-family: var(--font-ui);
  font-size: 15px;
  color: var(--crd-text);
}
.crd-settings-nav-row:first-of-type { border-top: none; }
.crd-settings-nav-row:active { background: var(--crd-bg); }
.crd-settings-nav-chevron { font-size: 20px; color: var(--crd-text-dim); line-height: 1; }

#crd-reminder-time-input {
  border: 1px solid var(--crd-bg);
  background: var(--crd-bg);
  border-radius: var(--r-sm);
  padding: var(--s2) var(--s3);
  font-size: 16px;
  font-family: var(--font-ui);
  color: var(--crd-text);
  outline: none;
  margin-bottom: var(--s3);
}

/* ── Card manager ─────────────────────────────────────── */
.crd-mgr-row {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: var(--s2) 0;
  border-bottom: 1px solid var(--crd-bg);
  flex-wrap: wrap;
}
.crd-mgr-input {
  flex: 1 1 120px;
  min-width: 0;
  border: none;
  border-bottom: 1px solid var(--crd-bg);
  font-size: 15px;
  font-family: var(--font-ui);
  color: var(--crd-text);
  background: transparent;
  padding: 4px 0;
  outline: none;
}
.crd-mgr-network,
.crd-mgr-scope {
  border: 1px solid var(--crd-bg);
  background: var(--crd-bg);
  border-radius: var(--r-sm);
  padding: 4px var(--s2);
  font-size: 12px;
  color: var(--crd-text);
  font-family: var(--font-ui);
}
.crd-mgr-delete {
  background: none;
  border: none;
  color: var(--crd-text-dim);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: var(--s1) var(--s2);
  border-radius: var(--r-sm);
  flex-shrink: 0;
}
.crd-mgr-delete:hover { background: var(--crd-bg); color: var(--crd-danger); }
.crd-mgr-add-row { display: flex; gap: var(--s2); margin-top: var(--s2); }
.crd-mgr-add-row input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--crd-bg);
  background: var(--crd-bg);
  border-radius: var(--r-sm);
  padding: var(--s2) var(--s3);
  font-size: 14px;
  font-family: var(--font-ui);
  color: var(--crd-text);
  outline: none;
}
.crd-mgr-add-row button {
  background: var(--crd-accent);
  color: #ffffff;
  border: none;
  border-radius: var(--r-sm);
  width: 40px;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
}
