*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    -webkit-font-smoothing: antialiased;
    color: #111827;
    background: #f8f9fc;
}

/* ── Login / Dashboard shared ─────────────────────────────── */

.login-bg,
.dashboard-bg {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f0f2f8;
    padding: 1rem;
}

.login-card,
.dashboard-card {
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,.06), 0 8px 32px rgba(0,0,0,.08);
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 420px;
}

/* ── Brand ────────────────────────────────────────────────── */

.login-brand {
    display: flex;
    align-items: center;
    gap: .625rem;
    margin-bottom: 2rem;
}

.brand-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: #4f46e5;
    color: #fff;
    font-weight: 700;
    font-size: 1.05rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.brand-name {
    font-size: 1.2rem;
    font-weight: 700;
    color: #111827;
    letter-spacing: -.02em;
}

/* ── Login headings ───────────────────────────────────────── */

.login-title {
    font-size: 1.625rem;
    font-weight: 700;
    color: #111827;
    margin: 0 0 .375rem;
    letter-spacing: -.025em;
}

.login-subtitle {
    color: #6b7280;
    font-size: .9375rem;
    margin: 0 0 1.75rem;
}

/* ── Error alert ──────────────────────────────────────────── */

.login-error {
    background: #fef2f2;
    border: 1.5px solid #fecaca;
    color: #dc2626;
    border-radius: 8px;
    padding: .75rem 1rem;
    font-size: .875rem;
    margin-bottom: 1.25rem;
    animation: fadeIn .18s ease;
}

/* ── Form controls ────────────────────────────────────────── */

.form-group {
    margin-bottom: 1.125rem;
}

.form-group label {
    display: block;
    font-size: .875rem;
    font-weight: 500;
    color: #374151;
    margin-bottom: .375rem;
}

.form-input {
    width: 100%;
    padding: .625rem .875rem;
    border: 1.5px solid #e5e7eb;
    border-radius: 8px;
    font-size: .9375rem;
    font-family: inherit;
    color: #111827;
    background: #fff;
    transition: border-color .15s, box-shadow .15s;
    outline: none;
}

.form-input:focus {
    border-color: #4f46e5;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, .12);
}

.form-input::placeholder {
    color: #9ca3af;
}

.form-input:disabled {
    background: #f9fafb;
    color: #9ca3af;
    cursor: not-allowed;
}

/* ── Password toggle ──────────────────────────────────────── */

.input-wrapper {
    position: relative;
}

.input-wrapper .form-input {
    padding-right: 4.5rem;
}

.toggle-pw {
    position: absolute;
    right: .75rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: #6b7280;
    font-size: .8125rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    padding: .25rem .125rem;
    line-height: 1;
}

.toggle-pw:hover {
    color: #4f46e5;
}

/* ── Buttons ──────────────────────────────────────────────── */

.btn-primary {
    width: 100%;
    padding: .75rem 1rem;
    background: #4f46e5;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: .9375rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    margin-top: .5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    transition: background .15s, transform .1s;
    letter-spacing: -.01em;
}

.btn-primary:hover:not(:disabled) {
    background: #4338ca;
}

.btn-primary:active:not(:disabled) {
    transform: scale(.99);
}

.btn-primary:disabled {
    opacity: .65;
    cursor: not-allowed;
}

.btn-outline {
    padding: .5rem .875rem;
    background: none;
    color: #6b7280;
    border: 1.5px solid #e5e7eb;
    border-radius: 8px;
    font-size: .875rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: border-color .15s, color .15s;
}

.btn-outline:hover {
    border-color: #d1d5db;
    color: #374151;
}

/* ── Loading spinner ──────────────────────────────────────── */

.spinner {
    width: 15px;
    height: 15px;
    border: 2px solid rgba(255, 255, 255, .35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .65s linear infinite;
    flex-shrink: 0;
}

/* ── Dashboard ────────────────────────────────────────────── */

.dashboard-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2rem;
}

.dashboard-header .login-brand {
    margin-bottom: 0;
}

.dashboard-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: #111827;
    margin: 0 0 .375rem;
    letter-spacing: -.025em;
}

.dashboard-subtitle {
    color: #6b7280;
    font-size: .9375rem;
    margin: 0;
}

/* ── Blazor error UI ──────────────────────────────────────── */

#blazor-error-ui {
    color-scheme: light only;
    background: #fef2f2;
    border-top: 1px solid #fecaca;
    color: #dc2626;
    bottom: 0;
    box-sizing: border-box;
    display: none;
    left: 0;
    padding: .75rem 1.25rem;
    position: fixed;
    width: 100%;
    font-size: .875rem;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: .75rem;
    top: .5rem;
}

.blazor-error-boundary {
    background: #b32121;
    padding: 1rem 1rem 1rem 3.7rem;
    color: white;
    border-radius: 8px;
}

.blazor-error-boundary::after {
    content: "An error has occurred.";
}

/* ── Loading progress ─────────────────────────────────────── */

.loading-progress {
    position: absolute;
    display: block;
    width: 8rem;
    height: 8rem;
    inset: 20vh 0 auto 0;
    margin: 0 auto;
}

.loading-progress circle {
    fill: none;
    stroke: #e0e0e0;
    stroke-width: 0.6rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}

.loading-progress circle:last-child {
    stroke: #4f46e5;
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}

.loading-progress-text {
    position: absolute;
    text-align: center;
    font-weight: 600;
    color: #6b7280;
    inset: calc(20vh + 3.25rem) 0 auto 0.2rem;
    font-size: .875rem;
}

.loading-progress-text::after {
    content: var(--blazor-load-percentage-text, "Loading");
}

/* ── Validation ───────────────────────────────────────────── */

.valid.modified:not([type=checkbox]) {
    border-color: #16a34a;
}

.invalid {
    border-color: #dc2626;
}

.validation-message {
    color: #dc2626;
    font-size: .8125rem;
    margin-top: .25rem;
}

/* ── Page layout (list + form pages) ─────────────────────── */

.page-bg {
    min-height: 100vh;
    background: #f0f2f8;
    padding: 1rem 1rem env(safe-area-inset-bottom, 1rem);
}

.page-container {
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
    padding-top: .5rem;
}

/* ── Page header ─────────────────────────────────────────── */

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
}

.page-header .login-brand {
    margin-bottom: 0;
}

/* ── Section header ──────────────────────────────────────── */

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.section-title {
    font-size: 1.375rem;
    font-weight: 700;
    color: #111827;
    margin: 0;
    letter-spacing: -.025em;
}

.new-record-title {
    margin-bottom: 1.25rem;
}

/* ── Add button ──────────────────────────────────────────── */

.btn-add {
    background: #4f46e5;
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: .5rem .875rem;
    font-size: .875rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background .15s;
    white-space: nowrap;
}

.btn-add:hover {
    background: #4338ca;
}

/* ── Back button ─────────────────────────────────────────── */

.btn-back {
    background: none;
    border: none;
    color: #4f46e5;
    font-size: .9375rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    padding: 0;
}

.btn-back:hover {
    color: #4338ca;
}

/* ── Record list ─────────────────────────────────────────── */

.record-list {
    display: flex;
    flex-direction: column;
    gap: .625rem;
}

.record-card {
    background: #fff;
    border-radius: 12px;
    padding: .875rem 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
    animation: fadeIn .18s ease;
}

.record-card-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: .75rem;
    margin-bottom: .5rem;
}

.record-desc {
    font-weight: 600;
    color: #111827;
    font-size: .9375rem;
    flex: 1;
    word-break: break-word;
}

.record-card-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.record-amount {
    font-size: .875rem;
    font-weight: 600;
    color: #374151;
}

.record-date {
    font-size: .8125rem;
    color: #9ca3af;
}

/* ── Status badges ───────────────────────────────────────── */

.record-status {
    font-size: .6875rem;
    font-weight: 600;
    border-radius: 6px;
    padding: .2rem .5rem;
    flex-shrink: 0;
    text-transform: uppercase;
    letter-spacing: .02em;
}

.status-issued       { background: #eff6ff; color: #1d4ed8; }
.status-presented    { background: #fef9c3; color: #854d0e; }
.status-acknowledged { background: #f0fdf4; color: #166534; }
.status-cancelled    { background: #f9fafb; color: #6b7280; border: 1px solid #e5e7eb; }
.status-expired      { background: #fef2f2; color: #dc2626; }

/* ── Loading spinner (dark, for page bg) ─────────────────── */

.list-loading {
    display: flex;
    justify-content: center;
    padding: 3rem 0;
}

.spinner-dark {
    width: 22px;
    height: 22px;
    border: 2.5px solid #e5e7eb;
    border-top-color: #4f46e5;
    border-radius: 50%;
    animation: spin .65s linear infinite;
}

/* ── Empty state ─────────────────────────────────────────── */

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: #6b7280;
    font-size: .9375rem;
}

.empty-state p {
    margin: 0 0 1rem;
}

.empty-btn {
    width: auto !important;
    display: inline-flex !important;
    padding: .625rem 1.25rem !important;
}

/* ── Membership info block ───────────────────────────────── */

.membership-info {
    background: #f9fafb;
    border: 1.5px solid #e5e7eb;
    border-radius: 8px;
    padding: .75rem 1rem;
    margin-bottom: 1.125rem;
    display: flex;
    flex-direction: column;
    gap: .375rem;
}

.membership-row {
    display: flex;
    align-items: baseline;
    gap: .5rem;
}

.membership-label {
    font-size: .8125rem;
    font-weight: 500;
    color: #6b7280;
    min-width: 80px;
    flex-shrink: 0;
}

.membership-value {
    font-size: .9375rem;
    font-weight: 600;
    color: #111827;
}

/* ── Form extras ─────────────────────────────────────────── */

.form-row {
    display: flex;
    gap: .75rem;
}

.form-row-main { flex: 1; }
.form-row-unit { flex: 0 0 110px; }

.form-textarea {
    resize: vertical;
    min-height: 80px;
}

.label-optional {
    color: #9ca3af;
    font-weight: 400;
    font-size: .8125rem;
}

/* ── Record card actions ────────────────────────────────────── */

.record-card-actions {
    margin-top: .5rem;
    display: flex;
    justify-content: flex-end;
    gap: .5rem;
}

.btn-edit-record {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    background: none;
    border: 1.5px solid #e5e7eb;
    color: #374151;
    border-radius: 7px;
    padding: .3rem .625rem;
    font-size: .8125rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: border-color .15s, color .15s;
}

.btn-edit-record:hover {
    border-color: #d1d5db;
    color: #111827;
}

.btn-show-qr {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    background: none;
    border: 1.5px solid #4f46e5;
    color: #4f46e5;
    border-radius: 7px;
    padding: .3rem .625rem;
    font-size: .8125rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background .15s, color .15s;
}

.btn-show-qr:hover {
    background: #4f46e5;
    color: #fff;
}

/* ── QR overlay ─────────────────────────────────────────────── */

.qr-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 1rem;
    animation: fadeIn .18s ease;
}

.qr-modal {
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, .18);
    padding: 1.25rem 1.25rem 1.5rem;
    width: 100%;
    max-width: 280px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .75rem;
}

.qr-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.qr-modal-title {
    font-size: 1rem;
    font-weight: 700;
    color: #111827;
    letter-spacing: -.015em;
}

.qr-close {
    background: none;
    border: none;
    color: #9ca3af;
    font-size: 1rem;
    cursor: pointer;
    padding: .25rem;
    line-height: 1;
    border-radius: 4px;
    transition: color .15s;
}

.qr-close:hover {
    color: #374151;
}

.qr-image {
    display: block;
    width: 220px;
    height: 220px;
    border-radius: 8px;
}

.qr-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 220px;
    width: 220px;
}

.qr-error {
    background: #fef2f2;
    border: 1.5px solid #fecaca;
    color: #dc2626;
    border-radius: 8px;
    padding: .625rem .875rem;
    font-size: .875rem;
    width: 100%;
    text-align: center;
}

.qr-timer-track {
    height: 4px;
    background: #e5e7eb;
    border-radius: 2px;
    width: 220px;
    overflow: hidden;
}

.qr-timer-fill {
    height: 100%;
    background: #4f46e5;
    border-radius: 2px;
    transition: width 1s linear, background .3s;
}

.qr-timer-fill--urgent {
    background: #dc2626;
}

.qr-timer-label {
    font-size: .8125rem;
    color: #9ca3af;
    font-weight: 500;
}

/* ── Public transaction record view ───────────────────────── */

.trview-card {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-top: 24px;
    background: #fff;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 1px 4px rgba(0,0,0,.08);
}

.trview-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.trview-label {
    font-size: .6875rem;
    font-weight: 600;
    color: #9ca3af;
    text-transform: uppercase;
    letter-spacing: .06em;
}

.trview-value {
    font-size: 1rem;
    font-weight: 500;
    color: #111827;
}

.trview-amount {
    font-size: 1.375rem;
    font-weight: 700;
    color: #111827;
}

.trview-timer {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.trview-success {
    font-size: .875rem;
    font-weight: 500;
    color: #059669;
    padding: .625rem .875rem;
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    border-radius: 8px;
    text-align: center;
}

/* ── Line items ───────────────────────────────────────────── */

.items-toggle {
    background: none;
    border: none;
    color: #4f46e5;
    font-size: .875rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    padding: 0;
    margin-bottom: 1.125rem;
    display: inline-flex;
    align-items: center;
    gap: .25rem;
}

.items-toggle:hover {
    color: #4338ca;
}

.items-toggle:disabled {
    color: #9ca3af;
    cursor: not-allowed;
}

.items-section {
    margin-bottom: 1.125rem;
    animation: fadeIn .15s ease;
}

.items-list {
    display: flex;
    flex-direction: column;
    gap: .375rem;
    margin-bottom: .75rem;
}

.item-row {
    display: flex;
    align-items: center;
    gap: .625rem;
    background: #f9fafb;
    border: 1.5px solid #e5e7eb;
    border-radius: 8px;
    padding: .5rem .75rem;
}

.item-row-name {
    flex: 1;
    font-size: .9rem;
    font-weight: 500;
    color: #111827;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.item-row-qty {
    font-size: .875rem;
    color: #6b7280;
    white-space: nowrap;
    flex-shrink: 0;
}

.btn-remove-item {
    background: none;
    border: none;
    color: #9ca3af;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 .125rem;
    flex-shrink: 0;
    transition: color .12s;
}

.btn-remove-item:hover {
    color: #dc2626;
}

.item-row--pending {
    border-style: dashed;
    border-color: #c7d2fe;
    background: #eef2ff;
}

.item-row--pending .item-row-name,
.item-row--pending .item-row-qty {
    color: #4338ca;
}

.item-add-row {
    display: flex;
    gap: .5rem;
    align-items: flex-end;
}

.item-add-row .form-input {
    margin: 0;
}

.item-add-name {
    flex: 1;
}

.item-add-qty {
    flex: 0 0 80px;
}

.btn-add-item {
    flex-shrink: 0;
    padding: .625rem .875rem;
    background: #4f46e5;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: .875rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s;
    height: 40px;
    align-self: flex-end;
}

.btn-add-item:hover:not(:disabled) {
    background: #4338ca;
}

.btn-add-item:disabled {
    opacity: .5;
    cursor: not-allowed;
}

/* ── Public view — line items ─────────────────────────────── */

.trview-items-label {
    font-size: .6875rem;
    font-weight: 600;
    color: #9ca3af;
    text-transform: uppercase;
    letter-spacing: .06em;
    margin-bottom: .5rem;
}

.trview-items-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .875rem;
}

.trview-items-table th {
    text-align: left;
    font-size: .75rem;
    font-weight: 600;
    color: #9ca3af;
    padding: 0 0 .375rem;
    border-bottom: 1px solid #f3f4f6;
}

.trview-items-table th:last-child,
.trview-items-table td:last-child {
    text-align: right;
}

.trview-items-table td {
    padding: .5rem 0;
    color: #111827;
    border-bottom: 1px solid #f9fafb;
    vertical-align: top;
}

.trview-items-table tr:last-child td {
    border-bottom: none;
}

.trview-items-name {
    font-weight: 500;
}

.trview-items-sku {
    font-size: .75rem;
    color: #9ca3af;
    margin-top: .125rem;
}

.trview-items-total {
    font-weight: 600;
    white-space: nowrap;
}

/* ── Animations ───────────────────────────────────────────── */

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}
