/* ==========================================================================
   Staff Cooperative — mobile-first UI
   ========================================================================== */

:root {
  --bg:        #faf9f5;
  --surface:   #ffffff;
  --surface-2: #f3f1ec;
  --ink:       #1a1a1a;
  --ink-2:     #3f3f3f;
  --muted:     #6e6e6e;
  --subtle:    #a1a1a1;
  --line:      #e7e5e0;
  --line-2:    #efece6;

  --brand:     #c8102e;
  --brand-ink: #8f0a1f;
  --success:   #0b7a3e;
  --warn:      #c2410c;

  --radius:    16px;
  --radius-lg: 20px;
  --radius-sm: 10px;

  --shadow-1: 0 1px 2px rgba(26,26,26,0.04), 0 2px 8px rgba(26,26,26,0.04);
  --shadow-2: 0 2px 6px rgba(26,26,26,0.06), 0 8px 24px rgba(26,26,26,0.06);

  --safe-top:    env(safe-area-inset-top, 0);
  --safe-bottom: env(safe-area-inset-bottom, 0);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
}

#app { min-height: 100vh; }

/* --- Layout shell ---------------------------------------------------------- */
.shell {
  max-width: 520px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 16px) 20px calc(var(--safe-bottom) + 24px);
  min-height: 100vh;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.top .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.brand-mark {
  width: 32px; height: 32px;
  border-radius: 9px;
  background: var(--brand);
  color: white;
  display: grid; place-items: center;
  font-weight: 700;
  font-size: 15px;
}
.top .link-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 14px;
  padding: 8px;
  cursor: pointer;
}
.top .link-btn:hover { color: var(--ink); }

/* --- Cards ---------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-1);
}

.card + .card { margin-top: 14px; }

.card-title {
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.card-title + .value { margin-top: 6px; }

/* --- Hero card (available credit) ----------------------------------------- */
.hero {
  background: linear-gradient(155deg, #1a1a1a 0%, #2a1213 100%);
  color: #fff;
  border: none;
  padding: 26px 24px 22px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2);
}
.hero .label {
  color: rgba(255,255,255,0.64);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.hero .amount {
  margin: 6px 0 4px;
  font-size: 36px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.hero .sub {
  color: rgba(255,255,255,0.7);
  font-size: 14px;
}
.hero .cta {
  margin-top: 18px;
  width: 100%;
}

/* --- Meta row (key-value strip) ------------------------------------------- */
.meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 14px;
}
.meta-item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.meta-item .k {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.meta-item .v {
  margin-top: 4px;
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.01em;
}

/* --- Forms ----------------------------------------------------------------- */
.field {
  display: block;
  margin-bottom: 14px;
}
.field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
  margin-bottom: 6px;
}
.field .hint {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}
.input, .select, .textarea {
  width: 100%;
  padding: 14px 14px;
  font-size: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(200,16,46,0.12);
}
.textarea { resize: vertical; min-height: 80px; }

.input-tel {
  letter-spacing: 0.06em;
  font-variant-numeric: tabular-nums;
}

.pin-input {
  text-align: center;
  letter-spacing: 0.5em;
  font-size: 24px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: 18px 12px;
}

.btn {
  -webkit-appearance: none;
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 18px;
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  color: #fff;
  background: var(--brand);
  border: 1px solid var(--brand);
  border-radius: var(--radius-sm);
  cursor: pointer;
  min-height: 48px;
  transition: transform 0.08s, background 0.15s, opacity 0.15s;
}
.btn:hover { background: var(--brand-ink); border-color: var(--brand-ink); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.full { width: 100%; }
.btn.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}
.btn.ghost:hover { background: var(--surface-2); border-color: var(--line); }
.btn.subtle {
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--line-2);
}
.btn.subtle:hover { background: #ebe8e1; }
.btn.dark {
  background: #fff;
  color: #1a1a1a;
  border: 1px solid rgba(255,255,255,0.2);
}

/* --- Section titles -------------------------------------------------------- */
.section-title {
  margin: 28px 0 10px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.screen-title {
  margin: 6px 0 18px;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.screen-sub {
  margin: -10px 0 20px;
  color: var(--muted);
  font-size: 15px;
}

/* --- Loan list / rows ----------------------------------------------------- */
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  gap: 12px;
}
.row + .row { margin-top: 10px; }
.row:hover { background: var(--surface-2); }
.row .row-main { min-width: 0; }
.row .row-title {
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.01em;
}
.row .row-sub {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}
.row .row-right {
  text-align: right;
  flex-shrink: 0;
}
.row .row-amount {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.chev::after {
  content: "›";
  font-size: 22px;
  color: var(--subtle);
  margin-left: 6px;
}

/* --- Status pills ---------------------------------------------------------- */
.pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 999px;
  letter-spacing: 0.01em;
  text-transform: capitalize;
}
.pill-pending   { background: #fff4e5; color: #9a4a00; }
.pill-approved  { background: #e8f4ff; color: #0b4a8c; }
.pill-disbursed { background: #e7f6ec; color: var(--success); }
.pill-repaying  { background: #e7f6ec; color: var(--success); }
.pill-rejected  { background: #fde8ea; color: #9a102b; }
.pill-completed { background: var(--surface-2); color: var(--muted); }
.pill-cancelled { background: var(--surface-2); color: var(--muted); }

/* --- Schedule table ------------------------------------------------------- */
.schedule {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}
.schedule-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  font-size: 14px;
}
.schedule-row + .schedule-row { border-top: 1px solid var(--line-2); }
.schedule-row .k { color: var(--ink-2); }
.schedule-row .v { font-weight: 600; font-variant-numeric: tabular-nums; }
.schedule-row.is-confirmed .k::before { content: "✓ "; color: var(--success); font-weight: 700; }

/* --- Empty states --------------------------------------------------------- */
.empty {
  text-align: center;
  padding: 44px 22px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.empty h3 {
  margin: 0 0 6px;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.empty p {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 14px;
}

/* --- Auth screens --------------------------------------------------------- */
.auth {
  max-width: 420px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 40px) 22px calc(var(--safe-bottom) + 24px);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.auth .auth-head {
  margin-bottom: 28px;
}
.auth .auth-brand {
  width: 46px; height: 46px;
  border-radius: 12px;
  background: var(--brand);
  color: white;
  display: grid; place-items: center;
  font-weight: 700;
  font-size: 22px;
  margin-bottom: 18px;
}
.auth h1 {
  margin: 0 0 6px;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.auth p.lead {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
}
.auth .alt {
  margin-top: 18px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}
.auth .alt button {
  background: none; border: none;
  color: var(--ink);
  font-weight: 600;
  cursor: pointer;
  padding: 4px 2px;
}

/* --- Error message -------------------------------------------------------- */
.err {
  background: #fde8ea;
  border: 1px solid #f7c9cf;
  color: #7a0b1b;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 14px;
}

/* --- Toast ---------------------------------------------------------------- */
.toast {
  position: fixed;
  left: 50%; bottom: calc(var(--safe-bottom) + 24px);
  transform: translateX(-50%) translateY(16px);
  background: #1a1a1a;
  color: #fff;
  font-size: 14px;
  padding: 12px 18px;
  border-radius: 999px;
  box-shadow: var(--shadow-2);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: 92%;
  text-align: center;
  z-index: 50;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* --- Spinners / loading --------------------------------------------------- */
.boot {
  min-height: 100vh;
  display: grid;
  place-items: center;
}
.spinner {
  width: 26px; height: 26px;
  border: 2.5px solid var(--line);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.btn .spinner {
  width: 16px; height: 16px;
  border-width: 2px;
  border-color: rgba(255,255,255,0.35);
  border-top-color: #fff;
}
.btn.ghost .spinner { border-color: var(--line); border-top-color: var(--ink); }

/* --- Segmented control (term months) -------------------------------------- */
.seg {
  display: grid;
  grid-template-columns: repeat(var(--cols, 3), 1fr);
  gap: 8px;
}
.seg label {
  display: block;
  text-align: center;
  padding: 12px 6px;
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  color: var(--ink-2);
}
.seg input { display: none; }
.seg input:checked + span {
  color: var(--brand);
}
.seg label:has(input:checked) {
  background: #fff;
  border-color: var(--brand);
  color: var(--brand);
  box-shadow: 0 0 0 3px rgba(200,16,46,0.08);
}

/* --- Preview card --------------------------------------------------------- */
.preview {
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-top: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
}
.preview .k { color: var(--muted); }
.preview .v { font-weight: 700; font-size: 18px; font-variant-numeric: tabular-nums; }

/* --- Responsive tweaks ---------------------------------------------------- */
@media (min-width: 720px) {
  .shell { padding-top: calc(var(--safe-top) + 36px); }
  .hero .amount { font-size: 42px; }
}

/* ==========================================================================
   Papa's Grill branding — auth logo, glow, staggered reveal, shimmer
   ========================================================================== */

/* Warm radial wash on auth screens only */
body:has(.auth) {
  background:
    radial-gradient(70% 52% at 25% -5%, rgba(200,16,46,0.07), rgba(200,16,46,0) 70%),
    radial-gradient(60% 46% at 105% 12%, rgba(200,16,46,0.05), rgba(200,16,46,0) 70%),
    var(--bg);
}

/* Logo badge + glow */
.auth-logo-wrap {
  position: relative;
  width: 96px;
  height: 96px;
  margin: 0 0 24px;
  display: inline-flex;
  border-radius: 22px;
}
.auth-logo {
  position: relative;
  z-index: 1;
  display: block;
  width: 96px;
  height: 96px;
  border-radius: 22px;
  box-shadow:
    0 10px 24px rgba(200,16,46,0.28),
    0 2px 6px rgba(26,26,26,0.08);
  animation: breathe 5s ease-in-out 1200ms infinite;
  transform-origin: center;
}
.auth-logo-glow {
  position: absolute;
  inset: -20px;
  border-radius: 44px;
  background: radial-gradient(closest-side,
    rgba(200,16,46,0.38),
    rgba(200,16,46,0) 72%);
  filter: blur(10px);
  z-index: 0;
  animation: halo 3.6s ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.035); }
}
@keyframes halo {
  0%, 100% { opacity: 0.55; transform: scale(0.94); }
  50%      { opacity: 0.95; transform: scale(1.08); }
}

/* Staggered entrance */
.reveal {
  opacity: 0;
  transform: translateY(14px);
  animation: rise 560ms cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}
.reveal-1 { animation-delay:  80ms; }
.reveal-2 { animation-delay: 200ms; }
.reveal-3 { animation-delay: 320ms; }
.reveal-4 { animation-delay: 440ms; }
.reveal-5 { animation-delay: 560ms; }

/* Logo lands with a scale + rise */
.auth-logo-wrap.reveal {
  transform: translateY(14px) scale(0.86);
  animation: landLogo 700ms cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
  animation-delay: 80ms;
}
@keyframes rise {
  to { opacity: 1; transform: translateY(0); }
}
@keyframes landLogo {
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Button shimmer sweep */
.btn.shimmer { position: relative; overflow: hidden; isolation: isolate; }
.btn.shimmer::after {
  content: "";
  position: absolute;
  top: 0; left: -120%;
  width: 60%; height: 100%;
  background: linear-gradient(120deg,
    rgba(255,255,255,0) 0%,
    rgba(255,255,255,0.38) 50%,
    rgba(255,255,255,0) 100%);
  transform: skewX(-18deg);
  animation: shimmer 3.6s ease-in-out 1.4s infinite;
  pointer-events: none;
  z-index: 0;
}
@keyframes shimmer {
  0%   { left: -120%; }
  55%  { left: 140%; }
  100% { left: 140%; }
}

/* Input focus gets a soft brand glow on auth screens */
.auth .input:focus {
  box-shadow:
    0 0 0 3px rgba(200,16,46,0.14),
    0 6px 14px rgba(200,16,46,0.08);
}

/* Respect reduced-motion preferences */
@media (prefers-reduced-motion: reduce) {
  .reveal,
  .auth-logo-wrap.reveal { opacity: 1; transform: none; animation: none; }
  .auth-logo,
  .auth-logo-glow { animation: none; }
  .btn.shimmer::after { display: none; }
}
