/* SecurePay design system
   Refined editorial aesthetic: cream backgrounds, deep navy text, emerald accents.
   Fraunces serif display + Manrope body + Geist Mono for codes.
*/

@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,500;9..144,600;9..144,700&family=Manrope:wght@400;500;600;700&family=Geist+Mono:wght@400;500;700&display=swap');

:root {
  /* Palette */
  --bg: #FBF9F4;
  --bg-elev: #FFFFFF;
  --bg-sunken: #F4F1EA;
  --ink: #1A1F2E;
  --ink-muted: #5C6275;
  --ink-faint: #A39E96;
  --border: #E8E3DA;
  --border-strong: #D7D1C4;
  --accent: #0F5132;
  --accent-soft: #E6EFEA;
  --accent-hover: #0a3d24;
  --warn: #B45439;
  --warn-soft: #FBE9E1;
  --warn-strong: #8a3e26;
  --gold: #B08A3E;

  /* Typography */
  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Manrope', system-ui, sans-serif;
  --font-mono: 'Geist Mono', 'SF Mono', Menlo, monospace;

  /* Spacing scale */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;
  --s-6: 32px;
  --s-7: 48px;
  --s-8: 64px;
  --s-9: 96px;

  --radius: 8px;
  --radius-lg: 14px;
  --shadow-card: 0 1px 2px rgba(26,31,46,.04), 0 8px 24px -8px rgba(26,31,46,.08);
  --shadow-pop: 0 4px 12px rgba(26,31,46,.06), 0 24px 48px -16px rgba(26,31,46,.16);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Subtle paper grain on the cream background */
body {
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.1 0 0 0 0 0.12 0 0 0 0 0.18 0 0 0 0.025 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 500; letter-spacing: -0.01em; margin: 0; }
h1 { font-size: 2.25rem; font-variation-settings: 'opsz' 96; line-height: 1.1; }
h2 { font-size: 1.5rem; font-variation-settings: 'opsz' 36; line-height: 1.2; }
h3 { font-size: 1.125rem; font-variation-settings: 'opsz' 14; line-height: 1.3; font-family: var(--font-body); font-weight: 600; }

p { margin: 0 0 var(--s-4); }
a { color: var(--accent); text-decoration: none; border-bottom: 1px solid transparent; transition: border-color .15s; }
a:hover { border-bottom-color: var(--accent); }

/* ---------- Layout primitives ---------- */
.container { max-width: 560px; margin: 0 auto; padding: 0 var(--s-5); }
.container-wide { max-width: 1180px; margin: 0 auto; padding: 0 var(--s-6); }

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--s-6);
  box-shadow: var(--shadow-card);
}

.divider { height: 1px; background: var(--border); margin: var(--s-5) 0; border: none; }

.label {
  font-family: var(--font-body);
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.muted { color: var(--ink-muted); }
.faint { color: var(--ink-faint); }

/* ---------- Forms ---------- */
.field { margin-bottom: var(--s-5); }
.field label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--ink-muted);
  margin-bottom: var(--s-2);
  text-transform: uppercase;
}

.input, .select, .textarea {
  display: block;
  width: 100%;
  padding: 14px 16px;
  font-family: var(--font-body);
  font-size: 1rem;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  color: var(--ink);
  transition: border-color .15s, box-shadow .15s, background .15s;
  -webkit-appearance: none;
  appearance: none;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(26,31,46,.08);
}
.input::placeholder { color: var(--ink-faint); }
.input.mono { font-family: var(--font-mono); letter-spacing: 0.05em; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-4); }
@media (max-width: 480px) { .field-row { grid-template-columns: 1fr; } }

.select {
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%231A1F2E' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
  padding-right: 44px;
}

/* Checkbox */
.checkbox {
  display: flex;
  gap: var(--s-3);
  align-items: flex-start;
  padding: var(--s-4);
  background: var(--bg-sunken);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  cursor: pointer;
}
.checkbox input[type=checkbox] { margin-top: 3px; width: 18px; height: 18px; accent-color: var(--accent); flex-shrink: 0; }
.checkbox span { font-size: .9375rem; line-height: 1.5; color: var(--ink); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  padding: 14px 24px;
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .15s, transform .05s, box-shadow .15s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { border-bottom-color: transparent; }
.btn-primary { background: var(--ink); color: var(--bg); }
.btn-primary:hover { background: #2a3144; }
.btn-primary:active { transform: translateY(1px); }
.btn-accent { background: var(--accent); color: white; }
.btn-accent:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--border-strong); }
.btn-ghost:hover { background: var(--bg-sunken); }
.btn-danger { background: var(--warn); color: white; }
.btn-danger:hover { background: var(--warn-strong); }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 14px; font-size: .875rem; }

/* ---------- Flash messages ---------- */
.flash { padding: var(--s-3) var(--s-4); border-radius: var(--radius); margin-bottom: var(--s-4); font-size: .9375rem; }
.flash-error { background: var(--warn-soft); color: var(--warn-strong); border: 1px solid #f0d2c2; }
.flash-success { background: var(--accent-soft); color: var(--accent); border: 1px solid #d0e1d7; }

/* ---------- Status badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.badge-pending { background: #FFF6E5; color: #8A6A14; }
.badge-opened { background: #FFF1D6; color: #8A6A14; }
.badge-submitted { background: var(--accent-soft); color: var(--accent); }
.badge-complete { background: var(--bg-sunken); color: var(--ink-muted); }
.badge-expired, .badge-cancelled { background: #F0EDE6; color: var(--ink-faint); }
.badge-dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
.badge-pending .badge-dot { background: #D89F12; }
.badge-opened .badge-dot { background: #D89F12; animation: pulse 1.4s ease-in-out infinite; }
.badge-submitted .badge-dot { background: var(--accent); }
.badge-complete .badge-dot, .badge-expired .badge-dot, .badge-cancelled .badge-dot { background: var(--ink-faint); }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(1.4); }
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(26,31,46,0.5);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: var(--s-4);
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--bg-elev);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow: auto;
  box-shadow: var(--shadow-pop);
  animation: modal-pop .2s ease-out;
}
@keyframes modal-pop {
  from { opacity: 0; transform: scale(.96) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-header { padding: var(--s-5) var(--s-6); border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: var(--s-6); }
.modal-footer { padding: var(--s-4) var(--s-6); border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: var(--s-3); background: var(--bg-sunken); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.modal-close { background: none; border: none; cursor: pointer; color: var(--ink-muted); font-size: 1.5rem; padding: 0; line-height: 1; }

/* ---------- Tables ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: var(--s-3) var(--s-4); text-align: left; border-bottom: 1px solid var(--border); }
.table th { font-size: .75rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-muted); }
.table tbody tr { transition: background .1s; }
.table tbody tr:hover { background: var(--bg-sunken); cursor: pointer; }

/* ---------- Utilities ---------- */
.stack { display: flex; flex-direction: column; }
.stack-2 > * + * { margin-top: var(--s-2); }
.stack-3 > * + * { margin-top: var(--s-3); }
.stack-4 > * + * { margin-top: var(--s-4); }
.stack-5 > * + * { margin-top: var(--s-5); }
.row { display: flex; align-items: center; }
.row-between { display: flex; align-items: center; justify-content: space-between; }
.gap-2 { gap: var(--s-2); }
.gap-3 { gap: var(--s-3); }
.gap-4 { gap: var(--s-4); }
.mt-2 { margin-top: var(--s-2); }
.mt-3 { margin-top: var(--s-3); }
.mt-4 { margin-top: var(--s-4); }
.mt-5 { margin-top: var(--s-5); }
.mt-6 { margin-top: var(--s-6); }
.mb-2 { margin-bottom: var(--s-2); }
.mb-3 { margin-bottom: var(--s-3); }
.mb-4 { margin-bottom: var(--s-4); }
.mb-5 { margin-bottom: var(--s-5); }
.mb-6 { margin-bottom: var(--s-6); }
.text-center { text-align: center; }
.text-mono { font-family: var(--font-mono); }
.small { font-size: .875rem; }
.tiny { font-size: .75rem; }

/* ---------- iOS form quirks ---------- */
input, select, textarea { font-size: 16px !important; } /* prevents iOS zoom on focus */

/* ---------- Carrier multiselect ---------- */
.carrier-multiselect {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-elev);
  max-height: 240px;
  overflow-y: auto;
}
.carrier-row {
  display: flex !important;
  align-items: center;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  font-size: .9375rem !important;
  text-transform: none !important;
  letter-spacing: 0 !important;
  margin: 0 !important;
  font-weight: 400 !important;
  color: var(--ink) !important;
}
.carrier-row:last-child { border-bottom: none; }
.carrier-row:hover { background: var(--bg-sunken); }
.carrier-row input[type=checkbox] {
  margin: 0 12px 0 0;
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  flex-shrink: 0;
}
.carrier-row input[type=checkbox]:checked ~ span {
  font-weight: 600;
  color: var(--ink);
}
