/*
 * Application styles.
 *
 * One stylesheet, no framework: the strict Content-Security-Policy forbids
 * remote origins, and the whole UI is small enough that a single file loads
 * faster than any build pipeline would.
 */

:root {
    --bg: #f5f7fb;
    --surface: #ffffff;
    --border: #dfe4ee;
    --text: #17202f;
    --muted: #61708a;
    --brand: #d0362f;
    --brand-dark: #a72a24;
    --accent: #1f6feb;
    --success: #17794a;
    --warning: #9a6100;
    --danger: #b3261e;
    --radius: 12px;
    --shadow: 0 1px 2px rgba(23, 32, 47, .06), 0 8px 24px rgba(23, 32, 47, .06);
    --wrap: 1400px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: clamp(1.75rem, 1.2rem + 1.6vw, 2.5rem); letter-spacing: -.02em; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; color: var(--muted); font-weight: 600; }
p { margin: 0 0 1rem; }
a { color: var(--accent); }
code { font: .9em ui-monospace, "SFMono-Regular", Consolas, monospace; background: rgba(31, 111, 235, .08); padding: .1em .35em; border-radius: 4px; }
small { font-size: .85em; }

.wrap { width: 100%; max-width: var(--wrap); margin: 0 auto; padding: 0 1.25rem; }
.lede { color: var(--muted); font-size: 1.05rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.contents { display: contents; }

.skip-link {
    position: absolute; left: -999px; top: 0; background: var(--surface);
    padding: .75rem 1rem; z-index: 100; border-radius: 0 0 var(--radius) 0;
}
.skip-link:focus { left: 0; }

/* ------------------------------------------------------------- header -- */

.site-header, .admin-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 40;
}

.header-inner { display: flex; align-items: center; gap: 1rem; min-height: 68px; }

.brand { display: flex; align-items: center; gap: .6rem; text-decoration: none; color: inherit; font-weight: 700; }
.brand-mark {
    background: var(--brand); color: #fff; font-size: .75rem; letter-spacing: .04em;
    padding: .35rem .5rem; border-radius: 8px;
}
.brand-name { white-space: nowrap; }
.brand-logo { height: 40px; width: auto; max-width: 220px; object-fit: contain; display: block; }

/* branding + company details */
.logo-settings { display: grid; gap: 1.25rem; grid-template-columns: auto 1fr; align-items: start; }
.logo-preview {
    display: grid; gap: .5rem; justify-items: center; align-content: center; min-width: 180px; min-height: 100px;
    padding: 1rem; border: 1px dashed var(--border); border-radius: var(--radius); background: var(--bg);
}
.logo-preview img { max-height: 80px; max-width: 240px; object-fit: contain; }
.logo-preview small { color: var(--muted); text-align: center; }
.auth-brand { display: grid; gap: .4rem; justify-items: center; margin-bottom: 1rem; }
.auth-logo { max-height: 64px; max-width: 240px; object-fit: contain; }
.auth-company { margin: 0; color: var(--muted); font-weight: 600; }
.footer-company { display: grid; gap: .2rem; justify-items: center; color: var(--muted); font-size: .875rem; }
.footer-company strong { color: var(--text); font-size: .95rem; }
.footer-contact { display: flex; gap: 1rem; flex-wrap: wrap; justify-content: center; }
.footer-contact a { color: var(--muted); text-decoration: none; }
.footer-contact a:hover { color: var(--text); }
@media (max-width: 600px) { .logo-settings { grid-template-columns: 1fr; } }

.site-nav { display: flex; gap: .25rem; margin-left: 1rem; flex: 1; }
.nav-group { position: relative; }
.nav-trigger {
    background: none; border: 0; font: inherit; color: var(--text);
    padding: .55rem .75rem; border-radius: 8px; cursor: pointer;
}
.nav-trigger:hover, .nav-trigger[aria-expanded="true"] { background: var(--bg); }
.nav-menu {
    display: none; position: absolute; top: calc(100% + .35rem); left: 0;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: .4rem; min-width: 230px; max-height: 70vh; overflow: auto;
}
.nav-group.open .nav-menu { display: block; }
.nav-menu a { display: block; padding: .5rem .65rem; border-radius: 8px; text-decoration: none; color: var(--text); font-size: .95rem; }
.nav-menu a:hover { background: var(--bg); }

.admin-nav { display: flex; gap: .25rem; flex: 1; margin-left: 1rem; }
.admin-nav a { padding: .5rem .7rem; border-radius: 8px; text-decoration: none; color: var(--text); }
.admin-nav a:hover { background: var(--bg); }

.header-actions { display: flex; align-items: center; gap: .5rem; }
.inline-form { display: inline; }

.nav-toggle { display: none; background: none; border: 0; cursor: pointer; padding: .5rem; }
.nav-toggle span { display: block; width: 22px; height: 2px; background: var(--text); margin: 4px 0; }

/* ------------------------------------------------------------ buttons -- */

.button {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    background: var(--brand); color: #fff; border: 1px solid transparent;
    padding: .55rem 1rem; border-radius: 10px; font: inherit; font-weight: 600;
    text-decoration: none; cursor: pointer; transition: background .15s, box-shadow .15s;
}
.button:hover { background: var(--brand-dark); }
.button.primary { background: var(--brand); }
.button.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.button.ghost:hover { background: var(--bg); }
.button.danger { background: var(--danger); }
.button.large { padding: .8rem 1.6rem; font-size: 1.05rem; border-radius: 12px; }
.button.small { padding: .35rem .7rem; font-size: .875rem; }
.button:disabled { opacity: .5; cursor: not-allowed; }
.button.active { background: var(--bg); }

/* -------------------------------------------------------------- alerts -- */

.alert { border-radius: var(--radius); padding: .85rem 1rem; margin: 1rem 0; border: 1px solid; font-size: .95rem; }
.alert-success { background: #eaf7f0; border-color: #b9e3cc; color: var(--success); }
.alert-error   { background: #fdeceb; border-color: #f5c2be; color: var(--danger); }
.alert-warning { background: #fdf4e3; border-color: #f0d9a8; color: var(--warning); }
.alert-info    { background: #eef3fd; border-color: #c6d8f8; color: #1a4fa0; }

/* ---------------------------------------------------------------- hero -- */

.hero { padding: 3rem 0 1.5rem; text-align: center; }
.hero .lede { max-width: 640px; margin: 0 auto 1rem; }
.hero-privacy { color: var(--muted); font-size: .9rem; max-width: 620px; margin: 0 auto; }

/* ----------------------------------------------------------- tool grid -- */

.tool-section { margin: 2.5rem 0; }
.tool-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }

.tool-card {
    display: flex; gap: .9rem; align-items: flex-start;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 1rem; text-decoration: none; color: inherit;
    transition: transform .12s, box-shadow .12s, border-color .12s;
}
.tool-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: #c9d3e4; }
.tool-card.is-unavailable { opacity: .55; }
.tool-body { display: flex; flex-direction: column; gap: .15rem; }
.tool-name { font-weight: 650; }
.tool-description { color: var(--muted); font-size: .88rem; line-height: 1.45; }
.tool-flag { color: var(--warning); font-size: .78rem; margin-top: .25rem; }

.tool-icon {
    display: inline-flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; flex: 0 0 40px;
    border-radius: 10px; background: rgba(208, 54, 47, .08); color: var(--brand);
}
.tool-icon.large { width: 56px; height: 56px; flex-basis: 56px; }
.icon { width: 22px; height: 22px; }
.tool-icon.large .icon { width: 30px; height: 30px; }

/* ----------------------------------------------------------- tool page -- */

.tool-page, .result-page, .dashboard, .admin-page, .auth-page { padding: 2rem 0 3rem; }
.tool-header { display: flex; gap: 1rem; align-items: center; margin-bottom: 1.5rem; }

.panel {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1.25rem;
}
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: .75rem; }
.panel h2 { margin-bottom: .75rem; }

.dropzone {
    border: 2px dashed #c4cddd; text-align: center; padding: 2.5rem 1rem;
    cursor: pointer; transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone:focus, .dropzone.dragover { border-color: var(--brand); background: rgba(208, 54, 47, .03); outline: none; }
.dropzone-title { font-size: 1.1rem; font-weight: 600; margin-bottom: .25rem; }
.dropzone-hint { color: var(--muted); font-size: .9rem; margin: 0; }
.dropzone .link { color: var(--accent); text-decoration: underline; }

.file-list { list-style: none; margin: 0 0 1.25rem; padding: 0; display: grid; gap: .5rem; }
.file-list li {
    display: flex; align-items: center; gap: .75rem;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 10px; padding: .6rem .8rem;
}
.file-list .file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-list .file-size { color: var(--muted); font-size: .85rem; }
.file-list .drag-handle { cursor: grab; color: var(--muted); }
.file-list li.dragging { opacity: .5; }
.file-remove { background: none; border: 0; color: var(--muted); font-size: 1.1rem; cursor: pointer; line-height: 1; }
.file-remove:hover { color: var(--danger); }

/* -------------------------------------------------------------- fields -- */

.field-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); align-items: start; }
.field { display: flex; flex-direction: column; gap: .35rem; font-size: .95rem; }
.field.wide, .field-grid > .field-note, .field-grid > fieldset { grid-column: 1 / -1; }
.field > span, .field-label { font-weight: 600; display: flex; flex-direction: column; }
.field > span small, .field-label small { font-weight: 400; color: var(--muted); }

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="file"], select, textarea {
    font: inherit; color: inherit; background: var(--surface);
    border: 1px solid var(--border); border-radius: 10px; padding: .55rem .7rem; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(31, 111, 235, .35); outline-offset: 1px; border-color: var(--accent); }
input[type="color"] { padding: .2rem; height: 42px; width: 100%; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
textarea { resize: vertical; }

.field.checkbox, .checkbox-grid label { flex-direction: row; align-items: flex-start; gap: .6rem; font-weight: 400; }
.field.checkbox input, .checkbox-grid input { margin-top: .25rem; }
.field.checkbox span, .checkbox-grid span { display: flex; flex-direction: column; font-weight: 500; }
.field.checkbox span small, .checkbox-grid span small { font-weight: 400; color: var(--muted); }

fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin: 0; }
legend { font-weight: 600; padding: 0 .35rem; }

.radio-cards { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.radio-cards label {
    display: flex; gap: .6rem; align-items: flex-start;
    border: 1px solid var(--border); border-radius: 10px; padding: .7rem .85rem; cursor: pointer;
}
.radio-cards label:has(input:checked) { border-color: var(--brand); background: rgba(208, 54, 47, .04); }
.radio-cards span { display: flex; flex-direction: column; }
.radio-cards small { color: var(--muted); }

.checkbox-grid { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.text-grid { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.text-grid label { display: flex; flex-direction: column; gap: .3rem; font-size: .9rem; }

.field-note { color: var(--muted); font-size: .875rem; margin: 0; }
.hint { color: var(--muted); }
.reason { display: block; color: var(--muted); font-size: .78rem; }

.submit-row { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.quota { color: var(--muted); font-size: .9rem; margin: 0; }

.stack { display: flex; flex-direction: column; gap: 1rem; }

/* ------------------------------------------------------------ progress -- */

.progress-track { background: var(--bg); border-radius: 999px; height: 10px; overflow: hidden; margin: .75rem 0; }
.progress-bar { background: var(--brand); height: 100%; width: 0; transition: width .35s ease; }
.progress-note { color: var(--muted); font-size: .9rem; }

/* -------------------------------------------------------------- result -- */

.result-header { text-align: center; margin-bottom: 1.5rem; }
.result-tick, .result-cross {
    width: 56px; height: 56px; border-radius: 50%; display: inline-flex;
    align-items: center; justify-content: center; font-size: 1.75rem; margin-bottom: .75rem;
}
.result-tick { background: #eaf7f0; color: var(--success); }
.result-cross { background: #fdeceb; color: var(--danger); }

.download-row { display: flex; gap: .75rem; justify-content: center; flex-wrap: wrap; margin-bottom: 1.5rem; }

.output-list { list-style: none; margin: 0 0 1.5rem; padding: 0; display: grid; gap: .5rem; }
.output-list li {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: .7rem .9rem;
}
.output-name { display: block; font-weight: 600; word-break: break-all; }
.output-meta { color: var(--muted); font-size: .85rem; }
.retention-note { color: var(--muted); font-size: .9rem; text-align: center; }
.privacy-note { color: var(--muted); font-size: .85rem; text-align: center; margin: 1.5rem 0; }

/* --------------------------------------------------------------- stats -- */

.stat-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin: 0 0 1.25rem; }
.stat-grid div { margin: 0; }
.stat-grid.cards div { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; }
.stat-grid dt { color: var(--muted); font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; }
.stat-grid dd { margin: .15rem 0 0; font-size: 1.35rem; font-weight: 650; }
.stat-grid dd small { display: block; font-size: .8rem; font-weight: 400; color: var(--muted); }

.detail-list { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); margin: 0; }
.detail-list dt { color: var(--muted); font-size: .85rem; }
.detail-list dd { margin: 0; font-weight: 600; }

/* -------------------------------------------------------------- tables -- */

.table-scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { text-align: left; padding: .6rem .7rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table thead th { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
.table tbody tr:hover { background: var(--bg); }
.row-actions { display: flex; gap: .4rem; white-space: nowrap; }
.empty { color: var(--muted); }

.pill { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--bg); color: var(--muted); }
.pill-completed { background: #eaf7f0; color: var(--success); }
.pill-failed, .pill-cancelled { background: #fdeceb; color: var(--danger); }
.pill-processing, .pill-queued, .pill-pending { background: #eef3fd; color: #1a4fa0; }
.pill-expired { background: #f2f4f8; color: var(--muted); }

.filter-row { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: 1rem; }
.chip { padding: .3rem .75rem; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); text-decoration: none; color: var(--text); font-size: .875rem; }
.chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }

.pagination { display: flex; gap: 1rem; align-items: center; justify-content: center; color: var(--muted); }

/* billing + payments */
.wallet-card { display: grid; gap: .1rem; padding: .8rem 1.1rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); text-align: right; }
.wallet-card span { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
.wallet-card strong { font-size: 1.5rem; }
.plan-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); margin-bottom: 1rem; }
.plan-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem; display: flex; flex-direction: column; gap: .5rem; background: var(--bg); }
.plan-card.is-current { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(26,79,160,.12); }
.plan-card h3 { margin: 0; }
.plan-price { font-size: 1.35rem; font-weight: 700; margin: 0; }
.plan-desc { color: var(--muted); margin: 0; font-size: .9rem; }
.plan-features { margin: 0 0 .5rem; padding-left: 1.1rem; color: var(--muted); font-size: .9rem; }
.plan-card form { margin-top: auto; }
.amount-credit { color: var(--success); font-weight: 600; }
.amount-debit { color: var(--danger); font-weight: 600; }
.payment-layout { display: grid; gap: 1.25rem; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); }
.payment-qr { text-align: center; }
.payment-status-box { padding: 1rem; border-radius: var(--radius); background: var(--bg); margin-bottom: 1rem; }
.payment-status-box[data-state="success"] { background: #eaf7f0; }
.payment-status-box[data-state="failed"], .payment-status-box[data-state="amount_mismatch"] { background: #fdeceb; }
.payment-status-box[data-state="expired"] { background: #f2f4f8; }
.payment-status-box p { margin: .5rem 0 0; }
.payment-status-box[data-state="pending"] #status-pill, .payment-status-box[data-state="initiated"] #status-pill { background: #eef3fd; color: #1a4fa0; }
.payment-status-box[data-state="success"] #status-pill { background: #d5efdf; color: var(--success); }
.payment-status-box[data-state="failed"] #status-pill, .payment-status-box[data-state="amount_mismatch"] #status-pill { background: #f8d7d4; color: var(--danger); }
.payment-timer { color: var(--muted); font-size: .9rem; }
.qr-wrap { margin: 0 auto 1rem; }
.qr-image { width: min(280px, 80vw); height: auto; border: 1px solid var(--border); border-radius: 12px; background: #fff; padding: .5rem; }
.payment-qr .submit-row { justify-content: center; }
@media (max-width: 800px) { .payment-layout { grid-template-columns: 1fr; } }

/* admin: users + plans */
.pill-plan { background: #eef3fd; color: #1a4fa0; text-transform: capitalize; }
.button.small { padding: .3rem .7rem; font-size: .82rem; }
.button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.button.ghost.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.filter-form { margin-bottom: 1rem; }
.filter-fields { display: grid; gap: 1rem; grid-template-columns: 2fr 1fr 1fr auto; align-items: end; }
.crumbs { margin: 0 0 .25rem; color: var(--muted); font-size: .875rem; }
.crumbs a { color: inherit; }
.danger-zone { border-color: #f5c2be; }
.danger-zone h2 { color: var(--danger); }
.delete-account { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.detail-list div { display: flex; flex-direction: column; }
.detail-list dt { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
.detail-list dd { margin: 0; }
.field select { font: inherit; padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); }
@media (max-width: 800px) { .filter-fields { grid-template-columns: 1fr; } }
.two-column { display: grid; gap: 1.25rem; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.page-header { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-actions { display: flex; gap: .5rem; }

/* ----------------------------------------------------------- auth/prose -- */

.auth-card { max-width: 440px; margin: 0 auto; }
.auth-alt { color: var(--muted); font-size: .9rem; margin: 1rem 0 0; }
.prose { max-width: 720px; padding: 2rem 0 3rem; }
.prose.narrow { max-width: 520px; }
.prose.centred { text-align: center; }
.prose h2 { margin-top: 2rem; }
.prose li { margin-bottom: .4rem; }

/* ------------------------------------------------------ signature/crop -- */

.signature { grid-column: 1 / -1; }
.signature-tabs { display: flex; gap: .5rem; margin: .5rem 0; }
#signature-pad {
    width: 100%; max-width: 640px; height: 200px; touch-action: none;
    background: var(--surface); border: 1px dashed #c4cddd; border-radius: 10px; display: block; margin-bottom: .5rem;
}

.cropper { grid-column: 1 / -1; }
.cropper-stage { position: relative; display: inline-block; max-width: 100%; }
.cropper-stage img { max-width: 100%; display: block; border-radius: 8px; }
.crop-box { position: absolute; border: 2px solid var(--brand); background: rgba(208, 54, 47, .12); display: none; }

/* -------------------------------------------------------------- footer -- */

.site-footer { border-top: 1px solid var(--border); background: var(--surface); margin-top: 3rem; }
.footer-inner { padding: 2rem 1.25rem; display: grid; gap: .75rem; justify-items: center; text-align: center; }
.footer-privacy { color: var(--muted); font-size: .875rem; max-width: 620px; margin: 0; }
.footer-links { display: flex; gap: 1rem; flex-wrap: wrap; justify-content: center; }
.footer-links a { color: var(--muted); text-decoration: none; font-size: .9rem; }
.footer-links a:hover { color: var(--text); }
.footer-legal { color: var(--muted); font-size: .8rem; margin: 0; }

/* -------------------------------------------------------------- mobile -- */

@media (max-width: 900px) {
    .nav-toggle { display: block; margin-left: auto; }
    .site-nav, .header-actions { display: none; width: 100%; }
    .header-inner { flex-wrap: wrap; padding-bottom: .5rem; }
    .site-nav.open, .header-actions.open { display: flex; flex-direction: column; align-items: stretch; gap: .25rem; margin: 0 0 .75rem; }
    .nav-menu { position: static; display: block; border: 0; box-shadow: none; padding: 0 0 0 .75rem; }
    .nav-trigger { text-align: left; width: 100%; font-weight: 600; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}
