@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;700&family=Merriweather:wght@400;700;900&family=Playfair+Display:wght@600;700;800&family=Space+Grotesk:wght@400;500;700&display=swap');

:root {
    --ink: #1f2a3d;
    --bg-soft: #f1f4f9;
    --bg-card: #ffffff;
    --line: #d6deea;
    --primary: #12447a;
    --primary-strong: #0e3764;
    --accent: #f5b21b;
    --success-bg: #e9f9ef;
    --error-bg: #ffecef;
    --error-ink: #a93b4a;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "DM Sans", "Segoe UI", Tahoma, sans-serif;
    color: var(--ink);
    background: linear-gradient(140deg, #eef3fb 0%, #f8fafc 45%, #eef2f6 100%);
}

.app-shell {
    max-width: 1180px;
    margin: 20px auto;
    padding: 0 16px 20px;
}

.hero {
    background: var(--bg-card);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 18px;
    margin-bottom: 16px;
}

.hero-top {
    margin-bottom: 14px;
}

.hero-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.rpt-nav-btn {
    display: inline-block;
    padding: 7px 14px;
    border-radius: 8px;
    background: #1e5aa8;
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    text-decoration: none;
    white-space: nowrap;
}

.rpt-nav-btn:hover {
    background: #154380;
}

.badge {
    display: inline-block;
    background: #e4edf8;
    color: var(--primary);
    border-radius: 999px;
    padding: 4px 11px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.2px;
}

.hero h1 {
    margin: 8px 0 4px;
    color: var(--primary-strong);
    font-size: 28px;
}

.hero p {
    margin: 0;
    color: #55627b;
}

.template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 10px;
}

.template-card {
    display: block;
    background: #f9fbff;
    border: 1px solid #d5deed;
    border-radius: 10px;
    padding: 12px;
    text-decoration: none;
    color: inherit;
    transition: transform 0.14s ease, border-color 0.14s ease, background 0.14s ease;
}

.template-card:hover {
    border-color: #92add5;
    transform: translateY(-1px);
}

.template-card.active {
    border-color: var(--primary);
    background: #edf4ff;
}

.template-title {
    display: block;
    font-weight: 700;
    color: #183f71;
}

.template-meta {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    color: #5e6e88;
}

.content-grid {
    display: grid;
    grid-template-columns: 1.25fr 0.75fr;
    gap: 16px;
    margin-bottom: 16px;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 16px;
}

.card h2,
.card h3,
.card h4 {
    margin-top: 0;
    color: #163d6d;
}

.alert {
    padding: 10px 12px;
    border: 1px solid transparent;
    border-radius: 8px;
    margin-bottom: 12px;
}

.alert.success {
    background: var(--success-bg);
    border-color: #9fd8b0;
}

.alert.error {
    background: var(--error-bg);
    border-color: #e0a0aa;
    color: var(--error-ink);
}

.guest-info {
    margin: 0 0 12px;
    padding: 9px 10px;
    border-radius: 8px;
    border: 1px solid #bdd1ec;
    background: #eef5ff;
    color: #24466e;
}

.guest-info.danger {
    background: #fff0f3;
    border-color: #e4a1ac;
    color: #a24150;
}

.form-grid,
.auth-block {
    display: grid;
    gap: 7px;
}

.invoice-layout {
    display: grid;
    gap: 10px;
}

.template-picker {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 8px;
}

.template-style-card {
    background: #f8fbff;
    border: 1px solid #cbd8ea;
    color: #1f3555;
    text-align: left;
}

.template-style-card span,
.template-style-card small {
    display: block;
}

.template-style-card small {
    margin-top: 4px;
    color: #61718b;
}

.template-style-card.active {
    border-color: var(--primary);
    background: #eaf2ff;
}

.invoice-tabs {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 6px;
    align-items: center;
}

.invoice-actions {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
}

.mini-tab {
    width: auto;
    background: #f0e8b6;
    border: 1px solid #d2c078;
    color: #313131;
}

.mini-tab.active {
    background: #e6edf6;
    border-color: #b3c6e3;
}

.mini-save {
    width: auto;
    padding-inline: 16px;
}

.invoice-status-submenu {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 8px 0 12px;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 999px;
    border: 1px solid #c8d4e6;
    background: #f4f8ff;
    color: #1e416f;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
}

.status-pill:hover {
    border-color: #9fb3d4;
    background: #ebf2ff;
}

.status-pill.active {
    border-color: #1b4e89;
    background: #dfeeff;
    color: #0f3d73;
}

.row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.row-actions > button,
.row-actions .inline-action-form button {
    width: auto;
    padding: 5px 9px;
    border-radius: 7px;
    font-size: 12px;
    line-height: 1.15;
    white-space: nowrap;
}

.inline-action-form {
    margin: 0;
}

.inline-action-form button {
    width: auto;
    white-space: nowrap;
}

.paid-badge {
    display: inline-block;
    padding: 5px 10px;
    border-radius: 999px;
    background: #e8f7ed;
    border: 1px solid #9ad0aa;
    color: #21613a;
    font-size: 12px;
    font-weight: 700;
}

.invoice-sheet {
    background: #dce9f5;
    border: 1px solid #bfd2e8;
    border-radius: 8px;
    box-sizing: border-box;
    padding: 12px;
    display: grid;
    gap: 10px;
    width: min(210mm, 100%);
    min-height: 297mm;
    margin-inline: auto;
}

.invoice-sheet h1,
.invoice-sheet h2,
.invoice-sheet h3,
.invoice-sheet .invoice-total,
.invoice-sheet label {
    letter-spacing: 0.1px;
}

.doc-title {
    margin: 0 0 10px;
    text-align: center;
    font-size: 30px;
    font-weight: 800;
    color: #14365e;
    text-transform: uppercase;
}

.doc-top-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.doc-meta-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: #2bc2ea;
    color: #07374a;
    font-size: 14px;
    font-family: "DM Sans", Arial, sans-serif;
}

.invoice-style-classic {
    background: #f8fafc;
    border-color: #d7dfe9;
    font-family: "Merriweather", Georgia, serif;
    position: relative;
    overflow: hidden;
}

.invoice-style-classic::before {
    content: "";
    position: absolute;
    inset: -40% -30% auto auto;
    width: 1200px;
    height: 1200px;
    background: radial-gradient(circle, rgba(22, 47, 74, 0.06) 0%, rgba(22, 47, 74, 0) 65%);
    pointer-events: none;
}

.invoice-style-classic .invoice-total,
.invoice-style-classic label {
    font-family: "DM Sans", Arial, sans-serif;
}

.invoice-style-classic .doc-title {
    text-align: left;
    font-size: clamp(42px, 8vw, 64px);
    color: #1a1d23;
    line-height: 0.95;
    letter-spacing: 1px;
}

.invoice-style-classic .doc-logo-preview {
    min-width: 180px;
    justify-content: flex-end;
    margin: 0;
}

.invoice-style-classic .doc-meta-bar {
    margin: 2px 0 10px;
}

.invoice-style-classic .invoice-items-table thead th {
    background: #2bc2ea;
    color: #07374a;
    border-color: #2bc2ea;
}

.invoice-style-classic .invoice-items-table,
.invoice-style-classic .invoice-items-table td {
    border-color: #d7dee8;
}

.invoice-style-classic .invoice-items-table th,
.invoice-style-classic .invoice-items-table td {
    font-size: 13px;
    padding: 7px 8px;
}

.invoice-style-classic .totals-box {
    margin-top: 4px;
}

.invoice-style-classic .footer-thank-you {
    margin-top: 20px;
    font-weight: 700;
}

.invoice-style-classic .signature-preview {
    border: none;
    background: transparent;
    justify-content: flex-end;
    min-height: 90px;
}

.invoice-style-classic .signature-title {
    margin-top: 8px;
    border-top: 2px solid #3a3f45;
    padding-top: 6px;
    text-align: center;
    font-weight: 700;
}

.invoice-style-minimal {
    background: #f5f7fa;
    border-color: #d6dde7;
    font-family: "Space Grotesk", "DM Sans", sans-serif;
}

.invoice-style-sunrise {
    background: #fff4d6;
    border-color: #efce80;
    font-family: "Playfair Display", Georgia, serif;
}

.invoice-style-sunrise .invoice-items-table,
.invoice-style-sunrise .totals-box,
.invoice-style-sunrise label {
    font-family: "DM Sans", Arial, sans-serif;
}

.invoice-style-forest {
    background: #e4f1e8;
    border-color: #a4c2ae;
    font-family: "DM Sans", "Segoe UI", sans-serif;
}

.invoice-style-forest .invoice-total,
.invoice-style-forest .brand {
    font-family: "Merriweather", Georgia, serif;
}

.invoice-head-grid {
    display: grid;
    grid-template-columns: 1.45fr 0.55fr;
    gap: 12px;
}

.invoice-style-classic .invoice-head-grid {
    grid-template-columns: 1.45fr 0.55fr;
}

.invoice-style-minimal .invoice-head-grid {
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}

.invoice-style-sunrise .invoice-head-grid {
    grid-template-columns: 0.9fr 1.1fr;
    gap: 16px;
}

.invoice-style-sunrise .invoice-head-grid > div:first-child {
    order: 2;
}

.invoice-style-sunrise .invoice-head-grid > div:last-child {
    order: 1;
}

.invoice-style-forest .invoice-head-grid {
    grid-template-columns: 1fr;
    border-bottom: 1px dashed #8cab95;
    padding-bottom: 10px;
}

.brand {
    text-align: right;
    font-size: 36px;
    font-weight: 900;
    color: #e18100;
    text-shadow: 1px 1px 0 #163d6d;
    margin-bottom: 6px;
}

.brand-empty {
    min-width: 180px;
    min-height: 48px;
    text-shadow: none;
}

.brand-preview {
    display: flex;
    justify-content: flex-end;
    min-height: 58px;
    margin-bottom: 6px;
}

#brand-logo-preview {
    max-width: 200px;
    max-height: 72px;
    object-fit: contain;
}

.signature-preview {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 120px;
    border: 1px dashed #c1d0e3;
    border-radius: 8px;
    background: #fff6d8;
    padding: 8px;
}

#signature-preview-image {
    max-width: 180px;
    max-height: 100px;
    object-fit: contain;
}

.signature-placeholder {
    color: #7f6b23;
    font-weight: 700;
}

.signature-empty {
    color: transparent;
    min-width: 140px;
    min-height: 80px;
}

.invoice-items-table {
    width: 100%;
    border-collapse: collapse;
    border: 1px solid #afc4df;
    background: rgba(255, 255, 255, 0.75);
}

.invoice-items-table th,
.invoice-items-table td {
    border: 1px solid #b9cae1;
    padding: 8px;
    vertical-align: top;
}

.invoice-items-table thead th {
    background: rgba(255, 255, 255, 0.95);
    font-weight: 700;
    color: #17395f;
}

.invoice-items-table textarea,
.invoice-items-table input {
    background: #fff;
    margin: 0;
}

.invoice-items-table th:nth-child(2),
.invoice-items-table th:nth-child(3),
.invoice-items-table th:nth-child(4),
.invoice-items-table th:nth-child(5),
.invoice-items-table td:nth-child(2),
.invoice-items-table td:nth-child(3),
.invoice-items-table td:nth-child(4),
.invoice-items-table td:nth-child(5) {
    text-align: right;
}

.edit-table th:last-child,
.edit-table td:last-child {
    width: 84px;
    text-align: center;
}

.text-right {
    text-align: right;
}

.export-value {
    white-space: pre-wrap;
}

.remove-item {
    width: 36px;
    background: #df455c;
    border-color: #df455c;
    color: #fff;
    padding: 8px 0;
}

.totals-box {
    justify-self: end;
    text-align: right;
    display: grid;
    gap: 2px;
    min-width: 220px;
}

.totals-box p {
    margin: 0;
}

.invoice-total {
    font-size: 26px;
    font-weight: 800;
    color: #133f72;
}

.invoice-total strong {
    color: #1f5ba5;
}

.invoice-foot-grid {
    display: grid;
    grid-template-columns: 1.4fr 0.6fr;
    gap: 10px;
}

.full-save {
    margin-top: 2px;
}

label {
    font-size: 13px;
    font-weight: 700;
}

input,
select,
textarea,
button {
    width: 100%;
    border: 1px solid #c8d3e5;
    border-radius: 8px;
    padding: 10px;
    font-family: inherit;
    font-size: 14px;
}

button {
    cursor: pointer;
    font-weight: 700;
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.primary:hover {
    background: var(--primary-strong);
}

.secondary {
    background: #fdf4d8;
    border-color: #f1d69a;
    color: #5c4200;
}

.muted {
    color: #5a6780;
}

hr {
    border: none;
    border-top: 1px solid #e0e6f0;
    margin: 14px 0;
}

.mini-stats {
    margin-top: 14px;
    padding: 10px;
    border: 1px solid #e2e8f3;
    border-radius: 10px;
    background: #f9fbff;
}

.mini-stats p {
    margin: 7px 0;
}

.table-card {
    overflow: hidden;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    text-align: left;
    padding: 11px;
    border-bottom: 1px solid #e5ebf4;
    font-size: 14px;
}

td .download-doc-btn {
    width: auto;
    padding: 7px 10px;
    font-size: 12px;
}

th {
    background: #f7f9fd;
    color: #20446f;
}

.danger-text {
    color: #b03e51;
}

.empty {
    text-align: center;
    color: #60708a;
}

.site-footer {
    margin: 8px auto 24px;
    max-width: 1180px;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    color: #d7e6ff;
    font-size: 13px;
    background: linear-gradient(135deg, #123a67 0%, #0f2e53 60%, #0c2544 100%);
    border: 1px solid #0a2140;
    border-radius: 14px;
}

.site-footer p {
    margin: 0;
}

.whatsapp-btn {
    display: inline-block;
    text-decoration: none;
    background: #1fae5b;
    color: #fff;
    font-weight: 700;
    border-radius: 999px;
    padding: 8px 14px;
}

.whatsapp-btn:hover {
    background: #19944d;
}

@media (max-width: 900px) {
    .content-grid {
        grid-template-columns: 1fr;
    }

    .invoice-tabs {
        grid-template-columns: 1fr;
    }

    .invoice-actions {
        justify-content: stretch;
    }

    .invoice-head-grid,
    .invoice-foot-grid {
        grid-template-columns: 1fr;
    }

    .invoice-items-table th,
    .invoice-items-table td {
        font-size: 12px;
        padding: 6px;
    }

    .invoice-sheet {
        width: 100%;
        min-height: auto;
    }

    .doc-top-row,
    .doc-meta-bar {
        flex-direction: column;
        align-items: flex-start;
    }

    .site-footer {
        flex-direction: column;
        align-items: flex-start;
    }

    .brand {
        text-align: left;
    }

    .brand-preview {
        justify-content: flex-start;
    }

    .totals-box {
        justify-self: start;
        text-align: left;
    }
}

@media print {
    body {
        background: #fff;
    }

    .hero,
    .card.table-card,
    aside.card,
    .guest-info,
    .alert,
    .invoice-tabs,
    .template-picker,
    .full-save,
    .remove-item,
    #add-item {
        display: none !important;
    }

    .app-shell,
    .content-grid,
    .card {
        margin: 0;
        padding: 0;
        border: none;
        box-shadow: none;
        max-width: none;
        display: block;
    }

    .invoice-sheet {
        background: #fff;
        border: 1px solid #cfcfcf;
        width: 210mm;
        min-height: 297mm;
        margin: 0;
        border-radius: 0;
        box-sizing: border-box;
    }

    .doc-top-row,
    .doc-meta-bar {
        flex-direction: row;
        align-items: center;
    }

    textarea,
    input,
    select {
        border: none;
        padding: 0;
        background: transparent;
        appearance: none;
    }

    input[type=file] {
        display: none !important;
    }

    .signature-preview {
        border: none;
        background: transparent;
        justify-content: flex-start;
        min-height: auto;
        padding: 0;
    }

    .site-footer {
        display: none;
    }
}
