:root {
    --bg: #f4efe3;
    --panel: #fbf8f1;
    --card: #fffdf8;
    --line: #d7ccb8;
    --text: #2c2418;
    --muted: #6b604e;
    --accent: #0f6a61;
    --accent-dark: #0a4d47;
    --danger: #b6463a;
    --shadow: 0 20px 50px rgba(72, 56, 33, 0.12);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Georgia, "Times New Roman", serif;
    color: var(--text);
    background:
        radial-gradient(circle at top left, rgba(15, 106, 97, 0.16), transparent 24%),
        linear-gradient(135deg, #f3ead7 0%, #f9f7f0 50%, #efe6d5 100%);
}

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

.page-shell {
    display: grid;
    grid-template-columns: 340px 1fr;
    min-height: 100vh;
}

.search-panel {
    padding: 32px 24px;
    border-right: 1px solid rgba(117, 96, 68, 0.16);
    background: rgba(255, 251, 243, 0.7);
    backdrop-filter: blur(10px);
}

.invoice-area {
    padding: 28px;
}

.eyebrow {
    margin: 0 0 8px;
    font-size: 0.85rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--accent);
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

.muted {
    color: var(--muted);
}

.search-card,
.invoice-card,
.result-card,
.verify-card {
    background: var(--card);
    border: 1px solid rgba(112, 94, 70, 0.14);
    border-radius: 20px;
    box-shadow: var(--shadow);
}

.search-card {
    padding: 18px;
    margin: 28px 0;
}

.search-card label,
.comment-box label,
.totals-box label,
.client-grid label,
.doc-grid label {
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-weight: 700;
    font-size: 0.95rem;
}

input,
textarea,
button,
.action-link {
    font: inherit;
}

input,
textarea {
    width: 100%;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: #fffdfa;
    color: var(--text);
}

textarea {
    resize: vertical;
}

button,
.action-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 18px;
    border: 0;
    border-radius: 12px;
    cursor: pointer;
    transition: transform 0.2s ease, background 0.2s ease;
}

button:hover,
.action-link:hover {
    transform: translateY(-1px);
}

.primary {
    background: var(--accent);
    color: #fff;
}

.secondary {
    background: #efe4cf;
    color: var(--text);
}

.danger {
    background: #f4d7d3;
    color: #6e2218;
}

.ghost-link {
    display: inline-block;
    margin-top: 12px;
    color: var(--accent-dark);
}

.search-results {
    display: grid;
    gap: 12px;
}

.result-card {
    display: grid;
    gap: 4px;
    padding: 14px 16px;
}

.flash {
    margin-bottom: 18px;
    padding: 14px 16px;
    border-radius: 14px;
}

.success {
    background: #d8efe4;
    color: #17573d;
}

.error {
    background: #f5d7d7;
    color: #7a1d1d;
}

.invoice-card {
    padding: 22px;
    margin-bottom: 20px;
}

.hero-card {
    display: grid;
    grid-template-columns: 1.1fr 1fr;
    gap: 20px;
}

.invoice-title {
    font-size: 1.2rem;
    font-weight: 700;
}

.doc-grid,
.client-grid {
    display: grid;
    gap: 16px;
}

.doc-grid {
    grid-template-columns: repeat(2, 1fr);
}

.client-grid {
    grid-template-columns: repeat(2, 1fr);
}

.section-title,
.line-actions,
.action-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.table-wrap {
    overflow-x: auto;
}

.items-table {
    width: 100%;
    border-collapse: collapse;
}

.items-table th,
.items-table td {
    padding: 10px 8px;
    border-bottom: 1px solid #eadfcd;
    text-align: left;
}

.totals-card {
    display: grid;
    grid-template-columns: 1.4fr 0.8fr;
    gap: 18px;
}

.totals-box {
    display: grid;
    gap: 12px;
}

.action-bar {
    justify-content: flex-start;
}

.modal {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    background: rgba(26, 22, 18, 0.45);
}

.hidden {
    display: none;
}

.modal-card {
    width: min(420px, calc(100vw - 32px));
    padding: 30px;
    text-align: center;
    border-radius: 24px;
    background: #fffefc;
    box-shadow: var(--shadow);
}

.loader {
    width: 64px;
    height: 64px;
    margin: 0 auto 18px;
    border: 6px solid #e7dcc8;
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.verify-body {
    background: #fcfbf8;
}

.verify-shell {
    max-width: 1250px;
    margin: 30px auto;
    padding: 0 16px;
}

.verify-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}

.verify-card {
    overflow: hidden;
}

.verify-row {
    display: grid;
    grid-template-columns: 250px 1fr;
    border-bottom: 1px solid #e6e1d6;
}

.verify-row strong,
.verify-row span {
    padding: 12px 16px;
}

.accepted {
    color: #24714f;
    font-weight: 700;
}

.print-body {
    background: #fff;
    font-size: 12px;
}

.print-sheet {
    width: 210mm;
    min-height: 297mm;
    margin: 0 auto;
    padding: 10mm 8mm 14mm;
    background: #fff;
    color: #000;
    font-size: 12px;
    line-height: 1.25;
}

.print-top,
.print-client-box,
.print-bottom,
.signatures {
    display: flex;
    justify-content: space-between;
    gap: 18px;
}

.print-bottom {
    align-items: flex-start;
}

.print-top,
.print-client-box,
.print-table,
.print-bottom {
    margin-bottom: 16px;
}

.print-doc-data {
    text-align: right;
}

.print-company-head {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.print-logo {
    width: 90px;
    height: auto;
    object-fit: contain;
    flex: 0 0 90px;
}

.print-sheet h1 {
    font-size: 1.7rem;
    margin-bottom: 6px;
}

.print-sheet h2 {
    font-size: 1.2rem;
    margin-bottom: 6px;
}

.print-sheet h3 {
    font-size: 0.95rem;
    margin-bottom: 6px;
}

.print-sheet p,
.print-sheet td,
.print-sheet th,
.print-sheet div {
    font-size: 0.9rem;
}

.center-title {
    text-align: center;
    margin: 20px 0 14px;
    font-size: 1.8rem;
}

.print-client-box {
    border: 1px solid #000;
}

.print-client-box > div {
    flex: 1;
    padding: 12px;
}

.print-client-box > div:first-child {
    border-right: 1px solid #000;
}

.print-table {
    width: 100%;
    border-collapse: collapse;
}

.print-table th,
.print-table td {
    border-bottom: 1px solid #000;
    padding: 6px 5px;
    vertical-align: top;
}

.print-table thead th {
    border: 1px solid #000;
    text-align: left;
}

.print-comment {
    width: 60%;
}

.print-totals {
    width: 34%;
    border: 1px solid #000;
    align-self: flex-start;
    flex: 0 0 34%;
}

.print-totals div {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px;
    border-bottom: 1px solid #000;
    gap: 12px;
}

.print-totals div:last-child {
    border-bottom: 0;
}

.qr-image {
    width: 150px;
    height: 150px;
    margin: 18px 0 10px;
}

.qr-box {
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #000;
    background: #fff;
    overflow: hidden;
}

.qr-box img,
.qr-box canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.qr-fallback-link {
    max-width: 260px;
    font-size: 0.62rem;
    word-break: break-all;
}

.signatures {
    margin-top: 110px;
}

.signatures div {
    width: 38%;
    padding-top: 8px;
    text-align: center;
    border-top: 1px solid #000;
    font-size: 0.9rem;
}

@media (max-width: 980px) {
    .page-shell,
    .hero-card,
    .totals-card,
    .client-grid,
    .doc-grid {
        grid-template-columns: 1fr;
    }

    .search-panel {
        border-right: 0;
        border-bottom: 1px solid rgba(117, 96, 68, 0.16);
    }
}

@media print {
    .print-sheet {
        width: auto;
        min-height: auto;
        margin: 0;
        padding: 0;
    }
}
