/* App pages — overrides and additions to /assets/site.css.
   Targets: /admin.html, /account.html, /invoice.html, /pay-invoice.html.
   Mobile-first: 360px wide must work end-to-end. */

/* Reset marketing-site element-level styles that would otherwise leak onto
   <section> and <footer> on app pages. site.css styles these elements
   globally (position:relative + padding:7rem 2rem, etc.) for the homepage. */
body.app-page section,
body.app-page footer {
    position: static;
    top: auto; right: auto; bottom: auto; left: auto;
    padding: 0;
    margin: 0;
    background: transparent;
    border: 0;
    transition: none;
    backdrop-filter: none;
    z-index: auto;
}

/* Don't let any leaked rule override the [hidden] attribute. */
[hidden] { display: none !important; }

body.app-page {
    /* No fixed-position nav on app pages; content can flow naturally. */
    padding-bottom: calc(96px + env(safe-area-inset-bottom));
    /* iOS sticky action bar room */
}

/* ---------- Header (logo + user bar) ---------- */
.app-header {
    position: sticky;
    top: 0;
    z-index: 50;
    background: rgba(7, 14, 26, 0.92);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--trace);
    padding: 0.85rem 1rem;
    padding-top: calc(0.85rem + env(safe-area-inset-top));
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.app-brand {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--white);
    text-decoration: none;
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
}

.app-brand img {
    border-radius: 50%;
    clip-path: circle(40% at center);
}

.app-user-email {
    font-size: 0.75rem;
    color: var(--white-dim);
    margin-right: 0.6rem;
    word-break: break-all;
    max-width: 60vw;
}

/* ---------- Layout ---------- */
.app-main {
    max-width: 960px;
    margin: 0 auto;
    padding: 1.25rem 1rem 0;
}

.app-view {
    margin-top: 0.5rem;
}

.app-card {
    background: rgba(13, 27, 42, 0.65);
    border: 1px solid var(--trace);
    border-radius: 10px;
    padding: 1.5rem;
}

.app-card-narrow {
    max-width: 420px;
    margin: 2.5rem auto 0;
}

.app-title {
    font-family: 'Outfit', sans-serif;
    font-size: 1.6rem;
    margin: 0.4rem 0 0.6rem;
    letter-spacing: -0.02em;
}

.app-section-title {
    font-family: 'Outfit', sans-serif;
    font-size: 1.4rem;
    letter-spacing: -0.02em;
    margin: 0;
}

.app-muted   { color: var(--white-dim); font-size: 0.9rem; }
.app-hint    { color: var(--white-muted); font-size: 0.78rem; margin-top: 0.35rem; }
.app-status  { font-size: 0.85rem; margin-top: 0.6rem; padding: 0.6rem 0.8rem; border-radius: 6px; }
.app-status.is-error  { background: rgba(255, 95, 87, 0.12); color: #ff857a; border: 1px solid rgba(255, 95, 87, 0.3); }
.app-status.is-ok     { background: rgba(40, 200, 64, 0.12); color: #4cd969; border: 1px solid rgba(40, 200, 64, 0.3); }

/* ---------- Tabs (Invoices / Customers) ---------- */
.app-tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--trace);
    margin: 0.5rem 0 1.25rem;
}

.app-tab {
    flex: 1;
    background: transparent;
    background-color: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--white);
    padding: 0.85rem 1rem;
    font-family: 'Outfit', 'IBM Plex Mono', sans-serif;
    font-size: 0.95rem;
    font-weight: 500;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    cursor: pointer;
    min-height: 48px;
    -webkit-appearance: none;
    appearance: none;
    -webkit-tap-highlight-color: transparent;
    line-height: 1;
}

.app-tab.is-active {
    color: var(--blue);
    border-bottom-color: var(--blue);
}

/* ---------- Filter pills ---------- */
.filter-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin: 0 0 1rem;
}
.filter-pill {
    background: rgba(13, 27, 42, 0.6);
    border: 1px solid var(--trace);
    color: var(--white-dim);
    border-radius: 999px;
    padding: 0.45rem 0.95rem;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.78rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    min-height: 36px;
    transition: border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
}
.filter-pill:hover { color: var(--white); border-color: rgba(33, 150, 243, 0.25); }
.filter-pill.is-active {
    background: var(--blue);
    color: var(--deep);
    border-color: var(--blue);
    font-weight: 600;
}

/* ---------- Customer dashboard list-item actions ---------- */
.customer-actions {
    display: flex;
    gap: 1rem;
    margin-top: 0.4rem;
}
.customer-actions .btn-link { padding: 0.35rem 0; min-height: 32px; }

/* ---------- Toolbars ---------- */
.app-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin: 0 0 1rem;
}

/* ---------- Lists (invoices, customers) ---------- */
.app-list {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.app-list-item {
    background: rgba(13, 27, 42, 0.55);
    border: 1px solid var(--trace);
    border-radius: 8px;
    padding: 0.9rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    cursor: pointer;
    transition: border-color 0.2s ease, transform 0.2s ease;
    color: inherit;
    text-decoration: none;
    min-height: 48px;
}

.app-list-item:hover { border-color: rgba(33, 150, 243, 0.25); }

.app-list-item-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.8rem;
}

.app-list-primary  { font-weight: 600; color: var(--white); }
.app-list-secondary{ font-size: 0.8rem; color: var(--white-dim); }
.app-list-amount   { font-weight: 700; color: var(--white); white-space: nowrap; }

.status-pill {
    display: inline-block;
    font-size: 0.65rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-weight: 600;
}
.status-draft           { background: rgba(136,153,179,0.15); color: var(--white-dim); }
.status-sent            { background: rgba(33,150,243,0.18); color: var(--blue-light); }
.status-viewed          { background: rgba(33,150,243,0.28); color: var(--blue-light); }
.status-payment_claimed { background: rgba(254,188,46,0.18); color: #febc2e; }
.status-paid            { background: rgba(40,200,64,0.18); color: #4cd969; }
.status-overdue         { background: rgba(255,95,87,0.18); color: #ff857a; }
.status-void            { background: rgba(136,153,179,0.10); color: var(--white-muted); }

/* ---------- Forms / editors ---------- */
.app-form { display: flex; flex-direction: column; gap: 1rem; }

.app-form .form-group label {
    font-size: 0.7rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--white-muted);
    margin-bottom: 0.35rem;
}

.app-form input,
.app-form select,
.app-form textarea {
    background: rgba(7, 14, 26, 0.75);
    border: 1px solid rgba(74, 111, 165, 0.25);
    border-radius: 6px;
    padding: 0.75rem 0.9rem;
    color: var(--white);
    font-family: 'IBM Plex Mono', monospace;
    font-size: 16px;            /* prevent iOS auto-zoom */
    min-height: 44px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    outline: none;
    width: 100%;
}

.app-form input:focus,
.app-form select:focus,
.app-form textarea:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.15);
}

.app-form select option {
    background: var(--navy);
    color: var(--white);
}

.app-form textarea {
    min-height: 96px;
    resize: vertical;
    line-height: 1.5;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.8rem;
}

@media (min-width: 640px) {
    .form-row { grid-template-columns: 1fr 1fr; gap: 1rem; }
    .form-row-3 { grid-template-columns: 1fr 1fr 1fr; }
}

.app-fieldset {
    border: 1px solid var(--trace);
    border-radius: 8px;
    padding: 0.9rem 0.9rem 1rem;
    margin: 0;
}

.app-fieldset legend {
    padding: 0 0.4rem;
    font-size: 0.75rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--white-muted);
}

/* Line-item rows render as stacked cards on mobile, table-ish at >=640px */
.inv-lines { display: flex; flex-direction: column; gap: 0.7rem; margin: 0.6rem 0 0.85rem; }

.inv-line {
    background: rgba(7, 14, 26, 0.5);
    border: 1px solid var(--trace);
    border-radius: 6px;
    padding: 0.7rem 0.7rem 0.5rem;
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.5rem;
}

.inv-line .form-group label { margin-bottom: 0.2rem; }

.inv-line-meta {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, auto) auto;
    gap: 0.6rem;
    align-items: end;
}

/* Hide native number-input spinner arrows — they eat the input width and
   make typed digits invisible on narrow columns. */
.inv-line input[type="number"]::-webkit-outer-spin-button,
.inv-line input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.inv-line input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}

/* Tighter padding inside line-item inputs so qty/unit values fit. */
.inv-line .ln-qty,
.inv-line .ln-unit {
    padding: 0.55rem 0.6rem;
    text-align: right;
    min-width: 0;
}

.inv-line-total {
    font-weight: 600;
    color: var(--white);
    align-self: end;
    padding: 0.55rem 0.4rem;
    text-align: right;
    font-size: 0.95rem;
    white-space: nowrap;
    min-width: 0;
}

.inv-line-remove {
    background: none;
    border: 1px solid rgba(255, 95, 87, 0.3);
    color: #ff857a;
    border-radius: 6px;
    padding: 0.55rem 0.7rem;
    font-size: 0.8rem;
    cursor: pointer;
    min-height: 44px;
    min-width: 44px;
}

/* Credit / discount lines — visually distinct so you can spot them at a glance. */
.inv-line.is-credit {
    background: rgba(255, 200, 100, 0.05);
    border-color: rgba(254, 188, 46, 0.35);
}
.inv-line.is-credit .ln-desc { color: #ffd478; }
.inv-line.is-credit [data-role="line-total"] { color: #febc2e; }

/* Row of "+ Add line" / "+ Add credit" buttons under the line items. */
.inv-add-row { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.inv-add-row .btn { flex: 0 0 auto; }

.inv-line-remove:hover { background: rgba(255, 95, 87, 0.1); }

@media (min-width: 640px) {
    .inv-line { grid-template-columns: 2fr 1fr 1fr auto auto; align-items: end; gap: 0.7rem; }
    /* Flatten the meta wrapper so its children participate directly in the
       parent grid — otherwise everything (qty, unit, total, remove) is
       squashed into a single track and inputs end up too narrow to read. */
    .inv-line-meta { display: contents; }
}

/* ---------- Totals + sticky action bar ---------- */
.app-totals {
    margin-top: 0.5rem;
    border-top: 1px solid var(--trace);
    padding-top: 0.8rem;
    display: flex;
    justify-content: flex-end;
}

.app-total-row {
    display: flex;
    align-items: baseline;
    gap: 1rem;
}

.app-total-label { font-size: 0.78rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--white-muted); }
.app-total-value { font-family: 'Outfit', sans-serif; font-weight: 700; font-size: 1.6rem; color: var(--white); }

.app-actionbar {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 40;
    background: rgba(7, 14, 26, 0.95);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--trace);
    padding: 0.75rem 1rem;
    padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: stretch;
}

.app-actionbar .btn { flex: 1 1 calc(50% - 0.25rem); min-height: 48px; justify-content: center; padding: 0.7rem 0.6rem; }

@media (min-width: 640px) {
    .app-actionbar { padding: 0.85rem 1.25rem; padding-bottom: calc(0.85rem + env(safe-area-inset-bottom)); }
    .app-actionbar .btn { flex: 0 0 auto; min-width: 160px; }
    .app-actionbar { justify-content: flex-end; }
}

/* ---------- Buttons (additions to site.css) ---------- */
.btn-block { width: 100%; justify-content: center; }
.btn-link {
    background: none;
    border: none;
    color: var(--blue);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.85rem;
    padding: 0.5rem;
    min-height: 44px;
}
.btn-link:hover { color: var(--blue-light); text-decoration: underline; }
.app-back { padding-left: 0; margin-bottom: 0.5rem; }

/* ---------- Public invoice page ---------- */
.invoice-page {
    max-width: 720px;
    margin: 0 auto;
    padding: 1.25rem 1rem 4rem;
}

.invoice-hero {
    background: linear-gradient(180deg, rgba(33,150,243,0.10), rgba(13,27,42,0.4));
    border: 1px solid var(--trace);
    border-radius: 12px;
    padding: 1.4rem 1.4rem 1.6rem;
    margin-bottom: 1.4rem;
}

.invoice-hero h1 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.6rem;
    letter-spacing: -0.02em;
    margin: 0.4rem 0 0.4rem;
    color: var(--white);
}

.invoice-amount {
    font-family: 'Outfit', sans-serif;
    font-size: 2.4rem;
    font-weight: 800;
    color: var(--white);
    line-height: 1.1;
    margin-bottom: 0.25rem;
}

.invoice-meta-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.8rem 1.4rem;
    color: var(--white-dim);
    font-size: 0.85rem;
    margin-top: 0.5rem;
}

.invoice-meta-row strong { color: var(--white); font-weight: 600; }

.invoice-pay-row {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    margin-top: 1.2rem;
}
.invoice-pay-row .btn { width: 100%; justify-content: center; min-height: 52px; font-size: 0.95rem; }

@media (min-width: 640px) {
    .invoice-pay-row { flex-direction: row; }
    .invoice-pay-row .btn { width: auto; flex: 1; }
}

.invoice-lines-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 0.4rem;
}

.invoice-lines-table th, .invoice-lines-table td {
    padding: 0.7rem 0.5rem;
    border-bottom: 1px solid var(--trace);
    font-size: 0.85rem;
    color: var(--white);
    text-align: left;
}
.invoice-lines-table th { color: var(--white-muted); font-weight: 600; font-size: 0.7rem; letter-spacing: 0.1em; text-transform: uppercase; }
.invoice-lines-table .num { text-align: right; white-space: nowrap; }

/* Billed to / Issued by columns on the public invoice page.
   Selector includes `body.app-page` so it beats the body.app-page section reset. */
body.app-page section.parties {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.2rem;
    margin: 1.4rem 0;
    padding: 1rem 0;
    border-top: 1px solid var(--trace);
    border-bottom: 1px solid var(--trace);
}
@media (min-width: 640px) {
    body.app-page section.parties { grid-template-columns: 1fr 1fr; gap: 2rem; }
}
.party-label {
    font-size: 0.7rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--white-muted);
    margin-bottom: 0.35rem;
}
.party-body { color: var(--white); font-size: 0.9rem; line-height: 1.5; }
.party-body div + div { margin-top: 0.1rem; }

/* Bank transfer block on the public invoice page.
   Selector includes `body.app-page` so it beats the body.app-page section reset. */
body.app-page section.bank-block { margin: 3rem 0 3rem; }
body.app-page section.bank-block .app-section-title { margin-bottom: 0.4rem; }
.bank-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    margin-top: 0.8rem;
    align-items: stretch;
}
@media (min-width: 640px) {
    .bank-grid { grid-template-columns: 1fr 1fr; gap: 1.2rem; }
}

/* Make each sub-block fill the row height so the local + international cards
   line up nicely even when one has more rows than the other. */
.bank-sub { display: flex; flex-direction: column; }
.bank-sub .bank-card { flex: 1; }

.bank-sub-title {
    font-family: 'Outfit', sans-serif;
    font-size: 1rem;
    color: var(--white);
    margin: 0 0 0.2rem;
}
.bank-sub-subtitle {
    font-size: 0.78rem;
    color: var(--white-muted);
    margin: 0 0 0.5rem;
}

/* Spacing for the "Line items" heading when it sits below the bank block. */
.invoice-page .invoice-lines-heading { margin-bottom: 0.6rem; }

.bank-card {
    background: rgba(13, 27, 42, 0.55);
    border: 1px solid var(--trace);
    border-radius: 10px;
    overflow: hidden;
}

.bank-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.7rem 1rem;
    border-bottom: 1px solid var(--trace);
}
.bank-row:last-child { border-bottom: none; }

.bank-label {
    font-size: 0.7rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--white-muted);
}

.bank-value {
    font-family: 'IBM Plex Mono', monospace;
    color: var(--white);
    font-size: 0.88rem;
    letter-spacing: 0.04em;
    text-align: right;
    white-space: pre-line;
    word-break: break-word;
}

.bank-reference {
    color: var(--blue);
    font-weight: 600;
}

.bank-note {
    margin-top: 0.6rem;
    font-size: 0.78rem;
    color: var(--white-muted);
}

.invoice-summary {
    margin-top: 1rem;
    display: flex;
    justify-content: flex-end;
    font-size: 1.05rem;
    color: var(--white);
    gap: 1.5rem;
}

@media (max-width: 540px) {
    /* Stack invoice line table for very narrow screens. */
    .invoice-lines-table thead { display: none; }
    .invoice-lines-table tr {
        display: block;
        background: rgba(7,14,26,0.5);
        border: 1px solid var(--trace);
        border-radius: 6px;
        padding: 0.6rem 0.7rem;
        margin-bottom: 0.5rem;
    }
    .invoice-lines-table td {
        display: flex;
        justify-content: space-between;
        gap: 1rem;
        padding: 0.25rem 0;
        border: none;
    }
    .invoice-lines-table td.num { text-align: right; }
    .invoice-lines-table td::before {
        content: attr(data-label);
        color: var(--white-muted);
        font-size: 0.7rem;
        letter-spacing: 0.1em;
        text-transform: uppercase;
    }
}

/* Spinner */
.spinner {
    display: inline-block;
    width: 14px; height: 14px;
    border: 2px solid rgba(33,150,243,0.3);
    border-top-color: var(--blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    vertical-align: -2px;
    margin-right: 0.4rem;
}
@keyframes spin { to { transform: rotate(360deg); } }
