/* ==========================================================================
   SafeDeal Escrow — Global Styles
   Design tokens: crimson (#B22222) as the single accent on a white/ink
   canvas. Everything else (grays, status colors) stays quiet so the
   accent keeps its authority — used only for actions and the "held in
   escrow" state, never as decoration.
   ========================================================================== */

:root {
    /* Brand */
    --crimson: #B22222;
    --crimson-dark: #8C1A1A;
    --crimson-light: #FBEAEA;

    /* Neutrals */
    --ink: #17181C;
    --ink-soft: #43454C;
    --gray-600: #6B6E76;
    --gray-400: #9A9CA5;
    --gray-200: #E4E4E8;
    --gray-100: #F1F1F4;
    --gray-50: #F8F8FA;
    --white: #FFFFFF;

    /* Status */
    --green: #1B8A5A;
    --green-bg: #E9F7F0;
    --amber: #B0700F;
    --amber-bg: #FCF3E1;
    --blue: #1C5FAD;
    --blue-bg: #E9F1FB;
    --red: #B22222;
    --red-bg: #FBEAEA;
    --gray-status: #5B5D66;
    --gray-status-bg: #EEEEF1;

    /* Type */
    --font-display: 'Fraunces', Georgia, serif;
    --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'IBM Plex Mono', ui-monospace, monospace;

    /* Type scale */
    --text-xs: 0.76rem;
    --text-sm: 0.85rem;
    --text-base: 0.95rem;
    --text-lg: 1.1rem;
    --text-xl: 1.35rem;
    --text-2xl: 1.75rem;
    --text-3xl: 2.4rem;

    /* Spacing scale (4px base) */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;

    /* Layout */
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 22px;
    --shadow-xs: 0 1px 2px rgba(23, 24, 28, 0.05);
    --shadow-sm: 0 1px 2px rgba(23, 24, 28, 0.06);
    --shadow-md: 0 8px 24px rgba(23, 24, 28, 0.08);
    --shadow-lg: 0 20px 48px rgba(23, 24, 28, 0.14);
    --shadow-ring: 0 0 0 3px var(--crimson-light);
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
    --max-width: 1180px;
}

* , *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    margin: 0;
    font-family: var(--font-body);
    font-size: var(--text-base);
    color: var(--ink);
    background: var(--white);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 {
    font-family: var(--font-display);
    font-weight: 600;
    line-height: 1.15;
    margin: 0 0 0.5em;
    letter-spacing: -0.01em;
    color: var(--ink);
}
h1 { font-size: var(--text-2xl); }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); }
h4 { font-size: var(--text-base); }

p { margin: 0 0 1em; color: var(--ink-soft); }

a { color: inherit; text-decoration: none; }

img, svg { display: block; max-width: 100%; }

ul, ol { padding-left: 1.2em; }

.container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 24px;
}

/* Reduced motion respect */
@media (prefers-reduced-motion: reduce) {
    * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
}

/* ---------------------------------- Buttons ---------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: var(--font-body);
    font-weight: 600;
    font-size: var(--text-base);
    padding: 12px 22px;
    border-radius: var(--radius-sm);
    border: 1.5px solid transparent;
    cursor: pointer;
    transition: transform 0.15s var(--ease), box-shadow 0.15s var(--ease), background-color 0.15s var(--ease), border-color 0.15s var(--ease), color 0.15s var(--ease), opacity 0.15s var(--ease);
    white-space: nowrap;
    position: relative;
}
.btn:focus-visible { outline: 3px solid var(--crimson-light); outline-offset: 2px; }
.btn:active { transform: translateY(0) scale(0.98); }

.btn-primary {
    background: var(--crimson);
    color: var(--white);
    box-shadow: var(--shadow-sm);
}
.btn-primary:hover { background: var(--crimson-dark); box-shadow: var(--shadow-md); transform: translateY(-1px); }

.btn-secondary {
    background: var(--white);
    color: var(--ink);
    border-color: var(--gray-200);
}
.btn-secondary:hover { border-color: var(--ink); background: var(--gray-50); }

.btn-ghost {
    background: transparent;
    color: var(--ink);
}
.btn-ghost:hover { background: var(--gray-100); }

.btn-danger {
    background: var(--white);
    color: var(--crimson);
    border-color: var(--red-bg);
}
.btn-danger:hover { background: var(--red-bg); border-color: var(--crimson); }

.btn-block { width: 100%; }
.btn-sm { padding: 8px 16px; font-size: var(--text-sm); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none !important; box-shadow: none !important; }

/* Button loading state — used while a form submits so people never wonder
   if their tap registered. The label stays in place (no layout jump); a
   spinner fades in beside it and the button becomes inert. */
.btn.is-loading { pointer-events: none; color: transparent !important; }
.btn.is-loading::after {
    content: '';
    position: absolute;
    width: 16px; height: 16px;
    border-radius: 50%;
    border: 2px solid currentColor;
    border-top-color: transparent;
    color: var(--white);
    animation: btn-spin 0.65s linear infinite;
}
.btn-secondary.is-loading::after,
.btn-ghost.is-loading::after,
.btn-danger.is-loading::after { color: var(--ink); }
@keyframes btn-spin { to { transform: rotate(360deg); } }

/* ---------------------------------- Forms ---------------------------------- */

.field { margin-bottom: 20px; }

.field label {
    display: block;
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--ink);
    margin-bottom: 6px;
}

.field .hint { font-size: var(--text-xs); color: var(--gray-400); margin-top: 6px; }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="tel"],
input[type="number"],
input[type="date"],
select,
textarea {
    width: 100%;
    font-family: var(--font-body);
    font-size: var(--text-base);
    padding: 12px 14px;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-sm);
    background: var(--white);
    color: var(--ink);
    transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease), background-color 0.15s var(--ease);
}

input:hover, select:hover, textarea:hover { border-color: var(--gray-400); }

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--crimson);
    box-shadow: var(--shadow-ring);
}

input:disabled, select:disabled, textarea:disabled {
    background: var(--gray-50);
    color: var(--gray-400);
    cursor: not-allowed;
}

textarea { resize: vertical; min-height: 100px; }

.input-prefix {
    position: relative;
}
.input-prefix span {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gray-400);
    font-weight: 600;
}
.input-prefix input { padding-left: 32px; }

/* ---------------------------------- Read/edit toggle pattern ----------------------------------
   Used anywhere a person views their own saved data and may want to change
   it. Default state is a quiet, read-only summary; tapping "Edit" swaps in
   the live form. Keeps pages calm until someone actually intends to change
   something, and makes editing an explicit, reversible action. */

.static-list { display: flex; flex-direction: column; }
.static-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 16px;
    padding: 14px 0;
    border-bottom: 1px solid var(--gray-100);
}
.static-row:last-child { border-bottom: none; }
.static-row .static-label { font-size: var(--text-sm); color: var(--gray-400); font-weight: 600; flex-shrink: 0; }
.static-row .static-value { font-size: var(--text-base); font-weight: 500; color: var(--ink); text-align: right; word-break: break-word; }
.static-row .static-value.is-muted { color: var(--gray-400); font-weight: 400; font-style: italic; }

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
}
.section-head h2, .section-head h3 { margin-bottom: 2px; }
.section-head .section-sub { font-size: var(--text-xs); color: var(--gray-400); }

.btn-edit {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 14px;
    border-radius: 100px;
    border: 1.5px solid var(--gray-200);
    background: var(--white);
    color: var(--ink-soft);
    font-size: var(--text-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    cursor: pointer;
    transition: border-color 0.15s var(--ease), color 0.15s var(--ease), background 0.15s var(--ease);
}
.btn-edit:hover { border-color: var(--crimson); color: var(--crimson); background: var(--crimson-light); }
.btn-edit svg { width: 13px; height: 13px; }

.edit-form-actions { display: flex; gap: 10px; margin-top: 4px; }

/* ---------------------------------- Password visibility toggle ---------------------------------- */

.password-field { position: relative; }
.password-field input[type="password"],
.password-field input[type="text"] { padding-right: 44px; }
.password-toggle {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--gray-400);
    cursor: pointer;
    padding: 0;
}
.password-toggle:hover { color: var(--ink); background: var(--gray-100); }
.password-toggle:focus-visible { outline: 2px solid var(--crimson-light); outline-offset: 1px; }
.password-toggle svg { display: block; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 640px) { .form-row { grid-template-columns: 1fr; } }

.form-card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    padding: 36px;
    box-shadow: var(--shadow-sm);
}
@media (max-width: 560px) { .form-card { padding: 24px; } }

/* ---------------------------------- Cards & surfaces ---------------------------------- */

.card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    padding: 24px;
}

.card-hover { transition: box-shadow 0.15s var(--ease), transform 0.15s var(--ease), border-color 0.15s var(--ease); }
.card-hover:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); border-color: var(--gray-200); }

/* Ticket-stub — the one deliberate flourish in this system. A perforated
   edge, borrowed from a claim stub, marks the one surface where a real
   sum of someone else's money is sitting: it should feel like a receipt
   you'd keep, not a dashboard widget. Used sparingly (escrow amount box). */
.ticket-stub {
    position: relative;
    --scallop: 13px;
    -webkit-mask-image:
        radial-gradient(circle at var(--scallop) 0, transparent var(--scallop), #000 calc(var(--scallop) + 0.5px)),
        radial-gradient(circle at var(--scallop) 100%, transparent var(--scallop), #000 calc(var(--scallop) + 0.5px));
    -webkit-mask-size: calc(var(--scallop) * 2) 100%;
    -webkit-mask-repeat: repeat-x;
    -webkit-mask-position: left top, left bottom;
    -webkit-mask-composite: source-in, source-in;
    mask-image:
        radial-gradient(circle at var(--scallop) 0, transparent var(--scallop), #000 calc(var(--scallop) + 0.5px)),
        radial-gradient(circle at var(--scallop) 100%, transparent var(--scallop), #000 calc(var(--scallop) + 0.5px));
    mask-size: calc(var(--scallop) * 2) 100%;
    mask-repeat: repeat-x;
    mask-position: left top, left bottom;
    mask-composite: intersect;
}
.ticket-stub::before {
    content: '';
    position: absolute;
    top: var(--scallop); bottom: var(--scallop); left: 0; right: 0;
    border-top: 1.5px dashed var(--gray-200);
    border-bottom: 1.5px dashed var(--gray-200);
    pointer-events: none;
}

/* ---------------------------------- Badges ---------------------------------- */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: var(--text-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 5px 10px;
    border-radius: 100px;
    border: 1px solid transparent;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }

.badge-green { background: var(--green-bg); color: var(--green); }
.badge-amber { background: var(--amber-bg); color: var(--amber); }
.badge-blue { background: var(--blue-bg); color: var(--blue); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-gray { background: var(--gray-status-bg); color: var(--gray-status); }

/* ---------------------------------- Alerts / flash messages ---------------------------------- */

.alert {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 18px;
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    margin-bottom: 20px;
    border: 1px solid transparent;
    border-left-width: 3px;
}
.alert-error { background: var(--red-bg); color: var(--crimson-dark); border-color: #F3CACA; border-left-color: var(--crimson); }
.alert-success { background: var(--green-bg); color: var(--green); border-color: #C6EAD9; border-left-color: var(--green); }
.alert-info { background: var(--blue-bg); color: var(--blue); border-color: #C9DFF6; border-left-color: var(--blue); }

/* ---------------------------------- Tables ---------------------------------- */

.table-wrap { overflow-x: auto; border: 1px solid var(--gray-200); border-radius: var(--radius-md); }
table { width: 100%; border-collapse: collapse; font-size: var(--text-base); }
thead th {
    text-align: left;
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--gray-400);
    background: var(--gray-50);
    padding: 12px 16px;
    border-bottom: 1px solid var(--gray-200);
    white-space: nowrap;
}
tbody td { padding: 14px 16px; border-bottom: 1px solid var(--gray-100); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.1s var(--ease); }
tbody tr:hover { background: var(--gray-50); }

/* ---------------------------------- Skeleton loading states ---------------------------------- */

@keyframes skeleton-shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}
.skeleton {
    background: linear-gradient(90deg, var(--gray-100) 25%, var(--gray-200) 37%, var(--gray-100) 63%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.4s ease-in-out infinite;
    border-radius: var(--radius-sm);
    color: transparent !important;
    pointer-events: none;
    user-select: none;
}
.skeleton * { visibility: hidden; }
.skeleton-text { height: 0.9em; border-radius: 4px; margin-bottom: 6px; }
.skeleton-text:last-child { margin-bottom: 0; }
.skeleton-circle { border-radius: 50%; }

[data-skeleton] .skeleton-layer { display: block; }
[data-skeleton] .real-layer { display: none; }
[data-skeleton].is-loaded .skeleton-layer { display: none; }
[data-skeleton].is-loaded .real-layer { display: block; }
noscript ~ [data-skeleton] .skeleton-layer,
.no-js [data-skeleton] .skeleton-layer { display: none; }
.no-js [data-skeleton] .real-layer { display: block; }

/* ---------------------------------- Utility ---------------------------------- */

.text-muted { color: var(--gray-400); }
.text-crimson { color: var(--crimson); }
.text-center { text-align: center; }
.mt-0 { margin-top: 0; }
.flex { display: flex; align-items: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.stack { display: flex; flex-direction: column; }
.hidden { display: none !important; }

.empty-state {
    text-align: center;
    padding: 56px 24px;
    color: var(--gray-400);
}
.empty-state svg { margin: 0 auto 16px; }
.empty-state h3 { color: var(--ink); margin-bottom: 6px; }

/* ---------------------------------- Site header (shared) ---------------------------------- */

.site-header {
    position: sticky;
    top: 0;
    z-index: 40;
    background: rgba(255, 255, 255, 0.72);
    backdrop-filter: blur(14px) saturate(160%);
    -webkit-backdrop-filter: blur(14px) saturate(160%);
    border-bottom: 1px solid rgba(228, 228, 232, 0.7);
}
.site-header .container { display: flex; align-items: center; justify-content: space-between; height: 72px; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; }
.brand-mark {
    width: 32px; height: 32px; border-radius: 9px;
    background: var(--crimson);
    display: flex; align-items: center; justify-content: center;
    color: var(--white);
    font-family: var(--font-display);
    font-weight: 700;
}

.site-nav { display: flex; align-items: center; gap: 28px; font-weight: 500; font-size: 0.92rem; }
.site-nav a { transition: color 0.15s var(--ease); }
.site-nav a:hover { color: var(--crimson); }
.header-actions { display: flex; align-items: center; gap: 12px; }

.nav-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    color: var(--ink);
    width: 34px;
    height: 34px;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
}
.nav-toggle:hover { background: var(--gray-100); }

/* Mobile menu: main.js does nothing but
   `mobileMenu.classList.toggle('hidden')`, so every open/close state is
   just the presence or absence of the shared .hidden utility (display:
   none !important). This block only supplies what it looks like once
   that class is gone. */
.mobile-menu {
    position: fixed;
    top: 72px;
    left: 0;
    right: 0;
    z-index: 39;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(20px) saturate(160%);
    -webkit-backdrop-filter: blur(20px) saturate(160%);
    border-bottom: 1px solid var(--gray-200);
    box-shadow: var(--shadow-lg);
    max-height: calc(100vh - 72px);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 18px 24px 26px;
}
.mobile-menu a:not(.btn) {
    padding: 12px 4px;
    font-weight: 600;
    font-size: 1rem;
    border-bottom: 1px solid var(--gray-100);
    color: var(--ink);
}
.mobile-menu a:not(.btn):last-of-type { border-bottom: none; }
.mobile-menu .btn { margin-top: 8px; }

@media (max-width: 860px) {
    .site-nav { display: none; }
    .header-actions .btn-secondary { display: none; }
    .header-actions .btn-primary.btn-sm { display: none; }
    .nav-toggle { display: flex; }
}
@media (min-width: 861px) {
    .mobile-menu { display: none !important; }
}

/* ---------------------------------- Footer (shared) ---------------------------------- */

.site-footer { background: var(--ink); color: var(--gray-200); padding: 64px 0 28px; margin-top: 96px; }
.site-footer a { color: var(--gray-200); }
.site-footer a:hover { color: var(--white); }
.footer-grid { display: grid; grid-template-columns: 1.4fr 1fr 1fr 1fr; gap: 40px; padding-bottom: 40px; border-bottom: 1px solid rgba(255,255,255,0.12); }
.footer-grid h4 { color: var(--white); font-family: var(--font-body); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 16px; }
.footer-grid ul { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 10px; font-size: 0.9rem; }
.footer-bottom { display: flex; justify-content: space-between; align-items: center; padding-top: 24px; font-size: 0.82rem; color: var(--gray-400); flex-wrap: wrap; gap: 12px; }
@media (max-width: 760px) { .footer-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 480px) { .footer-grid { grid-template-columns: 1fr; } }

/* ---------------------------------- Auth pages ---------------------------------- */

.auth-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1fr 1fr;
}
.auth-visual {
    background: var(--ink);
    color: var(--white);
    padding: 56px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    position: relative;
    overflow: hidden;
}
.auth-form-side {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 24px;
}
.auth-form-wrap { width: 100%; max-width: 420px; }
.auth-form-wrap .brand { margin-bottom: 32px; }
.auth-switch { text-align: center; margin-top: 24px; font-size: 0.9rem; color: var(--gray-600); }
.auth-switch a { color: var(--crimson); font-weight: 600; }
.role-tabs { display: flex; gap: 8px; background: var(--gray-100); padding: 4px; border-radius: 10px; margin-bottom: 28px; }
.role-tabs a { flex: 1; text-align: center; padding: 9px; border-radius: 7px; font-weight: 600; font-size: 0.88rem; color: var(--gray-600); }
.role-tabs a.active { background: var(--white); color: var(--ink); box-shadow: var(--shadow-sm); }

@media (max-width: 900px) {
    .auth-shell { grid-template-columns: 1fr; }
    .auth-visual { display: none; }
}