:root {
    --navy: #10253f;
    --navy-2: #173b5f;
    --teal: #135678;
    --teal-light: #e7f3f7;
    --orange: #e78a2f;
    --ink: #1c2a38;
    --muted: #667482;
    --line: #dce3ea;
    --paper: #ffffff;
    --background: #f2f5f8;
    --success: #17744a;
    --warning: #9a5a00;
    --danger: #a52f2f;
    --radius: 14px;
    --shadow: 0 10px 30px rgba(16, 37, 63, .08);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--ink);
    background: var(--background);
    line-height: 1.5;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--background); }
a { color: var(--teal); }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.site-header {
    min-height: 70px;
    padding: 0 max(20px, calc((100vw - 1240px) / 2));
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    background: var(--navy);
    color: white;
    box-shadow: 0 3px 15px rgba(6, 25, 44, .18);
}

.brand { display: inline-flex; align-items: center; gap: 11px; color: white; text-decoration: none; font-weight: 800; letter-spacing: -.02em; font-size: 1.1rem; }
.brand-mark { width: 62px; height: 62px; border-radius: 17px; display: grid; place-items: center; color: white; background: linear-gradient(145deg, var(--teal), #1a759c); font-weight: 900; letter-spacing: -.05em; box-shadow: 0 8px 20px rgba(19, 86, 120, .24); margin: 0 auto 14px; }
.brand-mark.small { width: 38px; height: 38px; border-radius: 10px; margin: 0; box-shadow: none; }
.site-header nav { display: flex; align-items: center; gap: 5px; }
.site-header nav a { color: #dce8f3; text-decoration: none; padding: 10px 13px; border-radius: 8px; font-weight: 650; font-size: .93rem; }
.site-header nav a:hover, .site-header nav a:focus-visible { color: white; background: rgba(255,255,255,.1); }
.nav-user { color: #9fb4c6; padding: 10px 7px; font-size: .8rem; white-space: nowrap; }
.admin-link { color: #dce8f3; text-decoration: none; padding: 9px 13px; border: 1px solid rgba(255,255,255,.3); border-radius: 8px; font-size: .86rem; font-weight: 700; }
.admin-link:hover, .admin-link:focus-visible { color: white; background: rgba(255,255,255,.1); }
.nav-toggle { display: none; color: white; border: 1px solid rgba(255,255,255,.35); border-radius: 8px; padding: 7px 12px; background: transparent; }

.container { width: min(1240px, calc(100% - 40px)); margin: 0 auto; padding: 42px 0 65px; }
.page-heading { display: flex; justify-content: space-between; align-items: center; gap: 28px; margin-bottom: 28px; }
.page-heading h1 { margin: 2px 0 4px; font-size: clamp(2rem, 4vw, 3.2rem); letter-spacing: -.05em; line-height: 1.04; color: var(--navy); }
.lead { color: var(--muted); font-size: 1.04rem; margin: 7px 0 0; }
.eyebrow { color: var(--teal); font-size: .74rem; font-weight: 850; letter-spacing: .13em; text-transform: uppercase; margin: 0; }
.document-badge { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; color: var(--muted); display: flex; gap: 10px; align-items: center; box-shadow: var(--shadow); }
.document-badge > span:first-child { color: white; background: var(--orange); border-radius: 6px; padding: 4px 7px; font-size: .75rem; font-weight: 850; }

.panel { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 26px; }
fieldset.panel { min-width: 0; }
fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 20px; margin: 0; }
legend { padding: 0 10px; font-size: 1.12rem; color: var(--navy); font-weight: 800; }
.step { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; color: white; background: var(--teal); font-size: .8rem; margin-right: 5px; }
.section-intro { color: var(--muted); margin: -3px 0 22px; }

.party-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; margin-bottom: 22px; }
.party-card.full-width { grid-column: 1 / -1; }
.document-type-panel { margin-bottom: 22px; border-top: 4px solid var(--navy); }
.mode-banner { display: flex; align-items: center; gap: 11px; margin-bottom: 22px; padding: 13px 17px; border: 1px solid; border-radius: 11px; }
.mode-banner strong { white-space: nowrap; color: var(--navy); }
.mode-banner span { color: #435361; }
.mode-banner.logged-in { background: #e9f7ef; border-color: #bde3cd; }
.mode-banner.public { background: #fff8e7; border-color: #ecd69e; }
.series-choice { max-width: 620px; margin-top: 18px; }
.series-choice .alert { margin: 0; }
.radio-card-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.radio-card {
    flex-direction: row;
    align-items: center;
    gap: 13px;
    min-height: 78px;
    padding: 15px;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: #fbfcfd;
    cursor: pointer;
}
.radio-card:has(input:checked) { border-color: var(--teal); background: var(--teal-light); box-shadow: 0 0 0 2px rgba(19, 86, 120, .08); }
.radio-card input { width: 20px; height: 20px; min-height: 0; flex: 0 0 auto; accent-color: var(--teal); }
.radio-card span { display: flex; flex-direction: column; gap: 3px; }
.radio-card strong { color: var(--navy); font-size: 1rem; }
.radio-card small { color: var(--muted); font-weight: 520; }
.party-card { border-top: 4px solid var(--teal); }
.buyer-card { border-top-color: var(--orange); }
.buyer-card .step { background: var(--orange); }
.form-grid { display: grid; gap: 17px; }
.form-grid.two { grid-template-columns: 1fr 1fr; }
.form-grid.four { grid-template-columns: repeat(4, 1fr); }
.span-2 { grid-column: span 2; }
label { display: flex; flex-direction: column; gap: 6px; color: #3c4b59; font-size: .84rem; font-weight: 720; }
.optional { color: #8a96a2; font-size: .75rem; font-weight: 520; }
input, select, textarea {
    width: 100%;
    min-height: 45px;
    padding: 10px 12px;
    border: 1px solid #c9d2dc;
    border-radius: 8px;
    background: white;
    color: var(--ink);
    outline: none;
    transition: border-color .16s, box-shadow .16s;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(19, 86, 120, .13); }
input[type="file"] { padding: 8px; min-height: 45px; background: #f9fbfc; }
input[type="checkbox"] { width: 18px; height: 18px; min-height: 0; accent-color: var(--teal); }
.password-input { position: relative; width: 100%; }
.password-input input { padding-right: 70px; }
.password-toggle {
    position: absolute;
    top: 50%;
    right: 7px;
    transform: translateY(-50%);
    min-width: 55px;
    padding: 6px 8px;
    border: 0;
    border-radius: 6px;
    color: var(--teal);
    background: var(--teal-light);
    cursor: pointer;
    font-size: .76rem;
    font-weight: 800;
}
.password-toggle:hover, .password-toggle:focus-visible { background: #d3e9f0; outline: 2px solid rgba(19, 86, 120, .25); }
.check-row { flex-direction: row; align-items: center; gap: 9px; margin-top: 18px; font-weight: 650; }
.file-hint { color: var(--muted); font-size: .7rem; font-weight: 500; }
.signature-hint { margin: 5px 0 0 27px; }
.connection-test-row { display: flex; align-items: center; gap: 14px; margin-top: 17px; }
.connection-result { flex: 1; border-radius: 8px; padding: 10px 12px; font-size: .83rem; font-weight: 650; }
.connection-result.testing { color: #164f6a; background: #edf7fb; border: 1px solid #c2e0ec; }
.connection-result.success { color: #0d643d; background: #e9f7ef; border: 1px solid #bde3cd; }
.connection-result.error { color: #8a2727; background: #fff0f0; border: 1px solid #efc1c1; }

.specification-panel { margin-bottom: 22px; }
.item-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.item-row {
    display: grid;
    grid-template-columns: minmax(190px, 2.3fr) 85px 130px 90px minmax(160px, 1.4fr) 120px 36px;
    gap: 12px;
    align-items: end;
    position: relative;
    border: 1px solid var(--line);
    border-radius: 11px;
    padding: 38px 13px 13px;
    background: #fbfcfd;
}
.item-number { position: absolute; top: 9px; left: 13px; color: var(--teal); font-size: .73rem; letter-spacing: .09em; text-transform: uppercase; font-weight: 850; }
.row-total { min-height: 45px; display: flex; flex-direction: column; justify-content: center; align-items: flex-end; color: var(--muted); font-size: .72rem; }
.row-total strong { color: var(--navy); font-size: .96rem; white-space: nowrap; }
.icon-button { width: 36px; height: 36px; border: 0; border-radius: 8px; display: grid; place-items: center; cursor: pointer; font-size: 1.4rem; line-height: 1; }
.remove-row { color: var(--danger); background: #fbeeee; margin-bottom: 5px; }
.remove-row:hover { background: #f6dada; }
.remove-row:disabled { opacity: .3; cursor: not-allowed; }

.final-grid { display: grid; grid-template-columns: 1.4fr .6fr; align-items: stretch; gap: 22px; }
.totals-card { display: flex; flex-direction: column; gap: 10px; background: var(--navy); color: white; border-color: var(--navy); }
.totals-card > div, .summary-totals > div { display: flex; justify-content: space-between; gap: 20px; align-items: center; padding: 4px 0; }
.totals-card > div span { color: #bed0df; }
.totals-card .grand-total { border-top: 1px solid rgba(255,255,255,.23); margin-top: 4px; padding: 15px 0 8px; }
.totals-card .grand-total span { color: white; font-weight: 800; }
.totals-card .grand-total strong { font-size: 1.7rem; }
.privacy-note { color: #aebfce; font-size: .76rem; margin: 0; text-align: center; }

.button { display: inline-flex; justify-content: center; align-items: center; gap: 8px; min-height: 42px; padding: 9px 16px; border: 1px solid transparent; border-radius: 9px; cursor: pointer; text-decoration: none; font-weight: 780; transition: transform .12s, box-shadow .12s, background .12s; }
.button:hover { transform: translateY(-1px); }
.button:disabled { opacity: .65; cursor: wait; transform: none; }
.button.primary { color: white; background: var(--teal); box-shadow: 0 7px 16px rgba(19, 86, 120, .2); }
.button.primary:hover { background: #0d4664; }
.button.secondary { color: var(--teal); background: var(--teal-light); border-color: #c7e0e8; }
.button.ghost { color: var(--navy); background: white; border-color: var(--line); }
.button.large { min-height: 50px; padding: 12px 20px; }
.button.small { min-height: 34px; padding: 6px 11px; font-size: .8rem; }

.alert { border-radius: 10px; padding: 13px 16px; margin-bottom: 18px; border: 1px solid; font-weight: 650; }
.alert.success { color: #0d643d; background: #e9f7ef; border-color: #bde3cd; }
.alert.warning { color: #845000; background: #fff6df; border-color: #edd39a; }
.alert.error { color: #8a2727; background: #fff0f0; border-color: #efc1c1; }
.alert.info { color: #164f6a; background: #edf7fb; border-color: #c2e0ec; }

.auth-card { width: min(430px, 100%); margin: 8vh auto; padding: 34px; border: 1px solid var(--line); border-radius: 18px; background: white; box-shadow: 0 22px 55px rgba(16, 37, 63, .14); text-align: center; }
.auth-card h1 { margin: 3px 0 22px; color: var(--navy); font-size: 2rem; }
.auth-card .lead { margin-bottom: 28px; }
.wide-card { width: min(980px, calc(100% - 32px)); margin: 35px auto; text-align: left; }
.wide-card > .brand-mark, .wide-card > h1, .wide-card > .eyebrow, .wide-card > .lead { text-align: center; }
.wide-card > .lead { max-width: 650px; margin-left: auto; margin-right: auto; }
.stack-form { display: flex; flex-direction: column; gap: 20px; text-align: left; }
.install-page { padding: 1px 0; background: radial-gradient(circle at top, #dcebf2, var(--background) 45%); }

.heading-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.receipt-parties { margin-bottom: 22px; }
.party-summary { box-shadow: none; }
.party-summary h2 { color: var(--navy); margin: 3px 0 12px; }
.party-summary p { color: var(--muted); }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { color: #4b5b69; background: #f1f5f7; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; text-align: left; }
th, td { padding: 13px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:hover { background: #fafcfd; }
.numeric { text-align: right; white-space: nowrap; }
.item-thumbnail { display: block; width: 62px; height: 48px; border-radius: 7px; object-fit: cover; border: 1px solid var(--line); }
.receipt-bottom { display: grid; grid-template-columns: 1fr 360px; gap: 35px; padding-top: 25px; }
.receipt-notes h3 { margin-top: 0; color: var(--navy); }
.receipt-notes p { color: var(--muted); white-space: normal; }
.receipt-signature { width: min(100%, 420px); margin-top: 42px; border-top: 2px dashed var(--teal); }
.receipt-signature span { display: block; padding-top: 7px; color: var(--muted); font-size: .8rem; }
.summary-totals { display: flex; flex-direction: column; gap: 6px; }
.summary-totals .grand-total { background: var(--navy); color: white; padding: 13px 15px; border-radius: 9px; margin-top: 7px; }
.summary-totals .grand-total strong { font-size: 1.25rem; }
.email-panel { margin-top: 22px; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.email-panel p { margin: 5px 0; }
.email-panel small { color: var(--muted); }

.search-bar { display: flex; gap: 9px; margin-bottom: 20px; }
.search-bar input { flex: 1; }
.history-table a { text-decoration: none; }
.status { font-size: .8rem; white-space: nowrap; }
.status::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.success-dot::before { background: #27a669; }
.neutral-dot::before { background: #a8b1ba; }
.document-type-badge { display: inline-block; padding: 4px 8px; border-radius: 999px; font-size: .72rem; font-weight: 800; white-space: nowrap; }
.document-type-badge.receipt { color: #145779; background: #e4f2f7; }
.document-type-badge.invoice { color: #8a4e00; background: #fff0d9; }
.row-actions { text-align: right; }
.empty-state { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 55px 20px; color: var(--muted); }
.empty-state strong { color: var(--navy); font-size: 1.2rem; }
.pagination { display: flex; justify-content: center; align-items: center; gap: 15px; margin-top: 22px; }
.nowrap { white-space: nowrap; }
.journal-filter { align-items: flex-end; }
.journal-filter label { min-width: min(420px, 100%); }
.journal-table small { color: var(--muted); }

.management-create { margin-bottom: 22px; }
.management-create h2, .management-card h2 { margin: 0; color: var(--navy); }
.management-grid { grid-template-columns: repeat(5, minmax(130px, 1fr)); align-items: end; margin-top: 18px; }
.management-submit { align-self: end; }
.management-list { display: grid; gap: 18px; }
.management-card { box-shadow: none; }
.management-card-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.management-card-heading p, .management-meta { color: var(--muted); margin: 4px 0 0; font-size: .82rem; }
.management-meta { margin-top: 16px; }
.status-pill { display: inline-flex; align-items: center; border-radius: 999px; padding: 4px 9px; font-size: .72rem; font-weight: 800; white-space: nowrap; }
.status-pill.active { color: #0d643d; background: #e9f7ef; }
.status-pill.inactive { color: #68747f; background: #edf0f2; }
.status-pill.public { color: #875100; background: #fff0d9; }
.account-panel { max-width: 800px; }

.settings-sections { display: grid; gap: 22px; }
.settings-section h2, .export-card h2, .export-accounts h2 { margin: 2px 0 0; color: var(--navy); }
.settings-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.settings-heading + .section-intro { margin-top: -10px; }
.settings-save { display: flex; justify-content: flex-end; }
.profile-grid { display: grid; grid-template-columns: 1fr 260px; gap: 26px; align-items: center; margin-bottom: 24px; }
.logo-preview { min-height: 125px; display: grid; place-items: center; padding: 15px; border: 1px dashed #bdc8d2; border-radius: 12px; background: #f8fafb; color: var(--muted); font-size: .82rem; text-align: center; }
.logo-preview img { display: block; max-width: 220px; max-height: 95px; object-fit: contain; }
.theme-fieldset { padding-top: 12px; }
.theme-fieldset legend { font-size: .9rem; }
.theme-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 11px; }
.theme-option { position: relative; align-items: center; gap: 8px; padding: 11px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; text-align: center; }
.theme-option:has(input:checked) { border-color: var(--teal); box-shadow: 0 0 0 2px rgba(19, 86, 120, .1); }
.theme-option input { position: absolute; opacity: 0; pointer-events: none; }
.theme-swatch { width: 100%; height: 40px; border-radius: 7px; background: linear-gradient(135deg, var(--theme-primary) 0 48%, var(--theme-accent) 48% 72%, var(--theme-soft) 72%); }
.theme-option strong { color: var(--navy); font-size: .78rem; }
.account-grid { align-items: end; }

.seller-profile-summary { display: grid; grid-template-columns: 84px 1fr; gap: 17px; align-items: start; margin-bottom: 18px; }
.seller-profile-summary h3 { margin: 0 0 8px; color: var(--navy); }
.seller-profile-summary p { margin: 4px 0; color: var(--muted); }
.profile-badge { width: 84px; height: 84px; display: grid; place-items: center; overflow: hidden; padding: 8px; border-radius: 15px; color: white; background: linear-gradient(145deg, var(--profile-primary), var(--profile-accent)); font-size: 1.25rem; font-weight: 900; }
.profile-badge img { display: block; width: 100%; height: 100%; object-fit: contain; padding: 5px; border-radius: 8px; background: white; }

.export-panel { margin-bottom: 22px; }
.export-dates { max-width: 650px; }
.export-count { display: flex; align-items: baseline; gap: 9px; color: var(--muted); }
.export-count strong { color: var(--navy); font-size: 1.8rem; }
.export-options { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.export-card { display: flex; flex-direction: column; align-items: flex-start; padding: 22px; border: 1px solid var(--line); border-radius: 12px; background: #fafcfd; }
.export-card p:not(.eyebrow) { flex: 1; color: var(--muted); }
.account-summary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.account-summary-grid > div { display: flex; justify-content: space-between; gap: 18px; padding: 12px 14px; border-radius: 9px; background: #f3f6f8; }
.account-summary-grid span { color: var(--muted); }
.account-summary-grid strong { color: var(--navy); text-align: right; }
.export-warning { margin: 20px 0 0; }

.site-footer { padding: 25px 20px; border-top: 1px solid var(--line); color: var(--muted); text-align: center; font-size: .82rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 1100px) {
    .site-header { position: relative; }
    .nav-toggle { display: block; }
    .site-header nav { display: none; position: absolute; z-index: 20; top: 70px; left: 0; right: 0; padding: 10px 20px 15px; background: var(--navy); flex-direction: column; align-items: stretch; }
    .site-header nav.open { display: flex; }
    .nav-user { border-top: 1px solid rgba(255,255,255,.15); margin-top: 4px; padding-top: 13px; }
    .item-row { grid-template-columns: minmax(190px, 2fr) 80px 120px 85px 1.3fr 105px 36px; gap: 8px; }
}

@media (max-width: 900px) {
    .item-row { grid-template-columns: 2fr 1fr 1.2fr 1fr; padding-top: 38px; }
    .description-field, .upload-field { grid-column: span 2; }
    .row-total { align-items: flex-start; }
    .remove-row { position: absolute; top: 8px; right: 9px; }
    .final-grid { grid-template-columns: 1fr; }
    .totals-card { order: 2; }
    .theme-grid { grid-template-columns: repeat(3, 1fr); }
    .profile-grid { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
    .site-header { min-height: 62px; padding: 0 16px; position: relative; }
    .site-header nav { top: 62px; padding-left: 16px; padding-right: 16px; }
    .container { width: min(100% - 24px, 1240px); padding-top: 28px; }
    .page-heading { align-items: flex-start; flex-direction: column; }
    .document-badge { display: none; }
    .party-grid, .receipt-bottom { grid-template-columns: 1fr; }
    .form-grid.four { grid-template-columns: 1fr 1fr; }
    .email-panel { align-items: stretch; flex-direction: column; }
    .email-panel .button { width: 100%; }
    .search-bar { flex-wrap: wrap; }
    .search-bar input { flex-basis: 100%; }
    .connection-test-row { align-items: stretch; flex-direction: column; }
    .management-grid { grid-template-columns: 1fr 1fr; }
    .export-options, .account-summary-grid { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
    .panel { padding: 18px; }
    .form-grid.two, .form-grid.four { grid-template-columns: 1fr; }
    .radio-card-grid { grid-template-columns: 1fr; }
    .span-2 { grid-column: span 1; }
    .item-row { grid-template-columns: 1fr 1fr; }
    .description-field, .upload-field { grid-column: span 2; }
    .row-total { grid-column: span 2; align-items: flex-end; border-top: 1px solid var(--line); padding-top: 9px; }
    .heading-actions { width: 100%; }
    .heading-actions .button { flex: 1; }
    .auth-card { padding: 25px 20px; }
    .mode-banner { align-items: flex-start; flex-direction: column; }
    .management-grid { grid-template-columns: 1fr; }
    .theme-grid { grid-template-columns: 1fr 1fr; }
    .settings-heading { align-items: flex-start; flex-direction: column; }
    .settings-heading .button { width: 100%; }
    .settings-save .button { width: 100%; }
    .seller-profile-summary { grid-template-columns: 64px 1fr; }
    .profile-badge { width: 64px; height: 64px; }
}

@media print {
    .site-header, .site-footer, .heading-actions, .email-panel { display: none !important; }
    body, :root { background: white; }
    .container { width: 100%; padding: 0; }
    .panel { box-shadow: none; break-inside: avoid; }
}
