/* ============================================================
   Nam Việt Portal - Invoice styling
   Palette: navy + cream + amber
   ============================================================ */

:root {
    --c-navy: #1e3a5f;
    --c-navy-deep: #132847;
    --c-amber: #c9944a;
    --c-bg: #f5f3ef;
    --c-card: #ffffff;
    --c-border: #e5e2dc;
    --c-text: #2a2a2a;
    --c-muted: #6a6a6a;
    --c-success: #2d7a4f;
    --c-warning: #c47500;
    --c-danger: #b8322d;
    --shadow-sm: 0 1px 3px rgba(30, 58, 95, 0.08);
    --shadow-md: 0 4px 12px rgba(30, 58, 95, 0.12);
    --radius: 6px;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    background: var(--c-bg);
    color: var(--c-text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
}

.container {
    max-width: 1040px;
    margin: 0 auto;
    padding: 0 24px;
}

/* TOPBAR */
.topbar {
    background: var(--c-navy);
    color: #fff;
    padding: 14px 0;
    box-shadow: var(--shadow-sm);
}

    .topbar .container {
        display: flex;
        align-items: center;
        justify-content: space-between;
    }

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-mark {
    width: 34px;
    height: 34px;
    background: var(--c-amber);
    color: var(--c-navy-deep);
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 15px;
    border-radius: 6px;
    letter-spacing: -0.5px;
}

.brand-name {
    font-size: 15px;
    font-weight: 500;
    letter-spacing: 0.3px;
}

.topbar-meta {
    font-size: 12px;
    opacity: 0.75;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.page-main {
    padding: 32px 0 48px;
    min-height: calc(100vh - 110px);
}

/* INVOICE CARD */
.invoice-card {
    background: var(--c-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

.invoice-header {
    padding: 32px 40px 24px;
    border-bottom: 3px solid var(--c-navy);
    background: linear-gradient(to right, #fafafa, #ffffff);
}

.invoice-header-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.invoice-title {
    font-size: 28px;
    font-weight: 700;
    color: var(--c-navy);
    margin: 0 0 4px;
    letter-spacing: -0.5px;
}

.invoice-subtitle {
    font-size: 13px;
    color: var(--c-muted);
    letter-spacing: 0.3px;
}

.invoice-number {
    font-family: "SF Mono", Menlo, Consolas, monospace;
    font-size: 16px;
    color: var(--c-navy-deep);
    font-weight: 600;
}

.invoice-body {
    padding: 24px 40px 32px;
}

.invoice-footer {
    padding: 20px 40px 28px;
    background: #fafafa;
    border-top: 1px solid var(--c-border);
}

/* META GRID */
.meta-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px 40px;
    margin: 20px 0;
}

.meta-block {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.meta-block-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--c-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 2px;
}

.meta-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    border-bottom: 1px dotted var(--c-border);
    font-size: 13px;
}

    .meta-row:last-child {
        border-bottom: none;
    }

    .meta-row .label {
        color: var(--c-muted);
    }

    .meta-row .value {
        font-weight: 500;
        text-align: right;
    }

.party {
    background: #fafafa;
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    padding: 14px 16px;
}

.party-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--c-navy);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin: 0 0 8px;
}

.party-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--c-text);
    margin-bottom: 4px;
}

.party-addr {
    font-size: 12px;
    color: var(--c-muted);
    white-space: pre-line;
    line-height: 1.45;
}

/* ITEMS TABLE */
.section-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--c-navy);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin: 28px 0 12px;
    padding-bottom: 6px;
    border-bottom: 2px solid var(--c-navy);
}

.items-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

    .items-table thead th {
        background: var(--c-navy);
        color: #fff;
        padding: 10px 12px;
        text-align: left;
        font-weight: 600;
        font-size: 12px;
        letter-spacing: 0.3px;
    }

        .items-table thead th.num {
            text-align: right;
        }

    .items-table tbody td {
        padding: 10px 12px;
        border-bottom: 1px solid var(--c-border);
        vertical-align: top;
    }

    .items-table tbody tr:nth-child(even) {
        background: #fafafa;
    }

    .items-table td.num {
        text-align: right;
        font-variant-numeric: tabular-nums;
    }

    .items-table td.total {
        font-weight: 600;
        color: var(--c-navy-deep);
    }

    .items-table td.stt {
        width: 36px;
        text-align: center;
        color: var(--c-muted);
    }

    .items-table td.empty-row {
        text-align: center;
        color: var(--c-muted);
        padding: 20px;
    }

    .items-table td.hs-code {
        font-family: monospace;
        font-size: 12px;
    }

    .items-table .item-name {
        font-weight: 500;
    }

    .items-table .item-meta {
        font-size: 11px;
        color: var(--c-muted);
        margin-top: 2px;
    }

/* Pre block cho Payment / Notes */
.pre-block {
    white-space: pre-line;
    font-size: 13px;
    padding: 12px 16px;
    background: #fafafa;
    border-radius: var(--radius);
    border: 1px solid var(--c-border);
}

/* TOTALS */
.totals {
    margin-top: 20px;
    margin-left: auto;
    width: 340px;
    background: #fafafa;
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    padding: 16px 20px;
}

    .totals .row {
        display: flex;
        justify-content: space-between;
        padding: 6px 0;
        font-size: 13px;
    }

        .totals .row.grand {
            border-top: 2px solid var(--c-navy);
            margin-top: 8px;
            padding-top: 12px;
            font-size: 16px;
            font-weight: 700;
            color: var(--c-navy-deep);
        }

        .totals .row.final {
            color: var(--c-amber);
            font-size: 14px;
            font-weight: 600;
        }

/* BUTTON */
.btn {
    display: inline-block;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
    line-height: 1.2;
}

.btn-primary {
    background: var(--c-navy);
    color: #fff;
}

    .btn-primary:hover:not(:disabled) {
        background: var(--c-navy-deep);
        transform: translateY(-1px);
        box-shadow: var(--shadow-md);
    }

.btn-amber {
    background: var(--c-amber);
    color: var(--c-navy-deep);
}

    .btn-amber:hover:not(:disabled) {
        background: #b5833f;
    }

.btn-ghost {
    background: transparent;
    color: var(--c-navy);
    border: 1px solid var(--c-border);
}

    .btn-ghost:hover {
        background: #f0ede6;
    }

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-lg {
    padding: 14px 32px;
    font-size: 15px;
}

/* Action rows */
.action-row {
    text-align: center;
    margin-top: 28px;
}

.action-hint {
    margin-top: 8px;
    color: var(--c-muted);
    font-size: 12px;
}

.action-row-secondary {
    text-align: center;
    margin-top: 16px;
}

/* SIGNATURE SECTION */
.signature-section {
    background: #fafafa;
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    padding: 24px;
    margin-top: 24px;
}

    .signature-section h2 {
        margin: 0 0 16px;
        font-size: 18px;
        color: var(--c-navy);
    }

.signature-intro {
    color: var(--c-muted);
    font-size: 13px;
    margin: -8px 0 16px;
}

.form-field {
    display: flex;
    flex-direction: column;
}

    .form-field label {
        font-size: 12px;
        font-weight: 600;
        color: var(--c-muted);
        margin-bottom: 4px;
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }

    .form-field input {
        padding: 10px 12px;
        border: 1px solid var(--c-border);
        border-radius: var(--radius);
        font-size: 14px;
        background: #fff;
        font-family: inherit;
    }

        .form-field input:focus {
            outline: none;
            border-color: var(--c-navy);
            box-shadow: 0 0 0 3px rgba(30, 58, 95, 0.1);
        }

.signer-name-field {
    max-width: 420px;
    margin-bottom: 16px;
}

.signature-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--c-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.signature-pad-wrapper {
    background: #fff;
    border: 2px dashed var(--c-border);
    border-radius: var(--radius);
    position: relative;
    overflow: hidden;
    margin-bottom: 8px;
}

    .signature-pad-wrapper.has-signature {
        border-style: solid;
        border-color: var(--c-success);
    }

    .signature-pad-wrapper canvas {
        display: block;
        width: 100%;
        height: 200px;
        touch-action: none;
        cursor: crosshair;
    }

.signature-placeholder {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #c0b8a7;
    font-style: italic;
    pointer-events: none;
    user-select: none;
    font-size: 14px;
}

.signature-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 12px;
}

.signature-buttons {
    display: flex;
    gap: 8px;
}

.signature-hint {
    color: var(--c-muted);
    font-size: 12px;
}

/* Signed display trong invoice-footer */
.signed-block {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 32px;
}

.signer-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--c-navy-deep);
}

.signer-date {
    font-size: 11px;
    color: var(--c-muted);
    margin-top: 4px;
}

.signature-display {
    max-width: 240px;
}

    .signature-display img {
        max-width: 100%;
        height: auto;
        background: #fff;
        border: 1px solid var(--c-border);
        border-radius: 4px;
    }

/* STATUS BADGE */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.badge-sent {
    background: #e8f0fa;
    color: #1e3a5f;
}

.badge-viewed {
    background: #fff6e5;
    color: #c47500;
}

.badge-signed {
    background: #e5f4ec;
    color: #2d7a4f;
}

/* ALERTS */
.alert {
    padding: 14px 18px;
    border-radius: var(--radius);
    margin: 16px 0;
    font-size: 13px;
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

    .alert strong {
        font-weight: 600;
    }

.alert-info {
    background: #e8f0fa;
    color: #1e3a5f;
    border-left: 3px solid var(--c-navy);
}

.alert-warning {
    background: #fff6e5;
    color: #7a4a00;
    border-left: 3px solid var(--c-warning);
}

.alert-error {
    background: #fbe7e6;
    color: #7a2220;
    border-left: 3px solid var(--c-danger);
}

.alert-success {
    background: #e5f4ec;
    color: #1a4d32;
    border-left: 3px solid var(--c-success);
}

.alert-icon {
    font-size: 18px;
    line-height: 1;
}

.link-inline {
    color: var(--c-navy);
    text-decoration: underline;
}

/* CENTERED CARD (error / landing / token invalid) */
.centered-card {
    max-width: 520px;
    margin: 60px auto;
    background: #fff;
    padding: 40px 36px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    text-align: center;
}

    .centered-card h1 {
        margin: 0 0 12px;
        color: var(--c-navy);
        font-size: 24px;
    }

    .centered-card p {
        color: var(--c-muted);
        margin: 8px 0;
    }

/* THANK YOU */
.ty-hero {
    text-align: center;
    padding: 40px 20px;
}

.ty-check {
    width: 80px;
    height: 80px;
    background: var(--c-success);
    color: #fff;
    border-radius: 50%;
    display: grid;
    place-items: center;
    margin: 0 auto 24px;
    font-size: 42px;
}

.ty-hero h1 {
    margin: 0 0 8px;
    color: var(--c-navy-deep);
    font-size: 28px;
}

.ty-hero p {
    color: var(--c-muted);
    font-size: 15px;
    max-width: 460px;
    margin: 6px auto;
}

.ty-action {
    margin-top: 28px;
}

/* FOOTER */
.footer {
    background: transparent;
    color: var(--c-muted);
    font-size: 12px;
    padding: 20px 0;
}

    .footer .container {
        display: flex;
        justify-content: center;
        gap: 8px;
    }

    .footer .sep {
        opacity: 0.4;
    }

/* RESPONSIVE */
@media (max-width: 720px) {
    .invoice-header, .invoice-body, .invoice-footer {
        padding-left: 20px;
        padding-right: 20px;
    }

    .meta-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .totals {
        width: 100%;
        margin-left: 0;
    }

    .items-table {
        font-size: 12px;
    }

        .items-table thead th,
        .items-table tbody td {
            padding: 8px 6px;
        }

    .invoice-title {
        font-size: 22px;
    }

    .signer-name-field {
        max-width: 100%;
    }

    .signature-actions {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }
}

/* SAY row dưới Total — hiển thị "SAY: ONE THOUSAND..." */
.totals .row.say {
    display: block;
    margin-top: 6px;
    padding-top: 8px;
    border-top: 1px dashed var(--c-border);
    font-size: 11px;
    color: var(--c-muted);
    font-style: italic;
    line-height: 1.4;
}

    .totals .row.say span:first-child {
        font-weight: 600;
        margin-right: 6px;
        color: var(--c-navy);
    }

/* PRINT */
@media print {
    .topbar, .footer, .signature-actions, .btn,
    .action-row, .action-row-secondary, .signature-section {
        display: none !important;
    }

    body {
        background: #fff;
    }

    .invoice-card {
        box-shadow: none;
        border: 1px solid var(--c-border);
    }
}

/* ============================================================
   BRANDING — logo công ty bán + tên trong header invoice
   ============================================================ */
.invoice-brand {
    display: flex;
    gap: 14px;
    align-items: flex-start;
    max-width: 420px;
}

.invoice-logo {
    max-width: 120px;
    max-height: 80px;
    object-fit: contain;
    flex-shrink: 0;
}

.invoice-brand-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.invoice-company-name {
    font-size: 14px;
    font-weight: 700;
    color: var(--c-navy-deep);
    line-height: 1.3;
}

.invoice-company-addr {
    font-size: 11px;
    color: var(--c-muted);
    line-height: 1.4;
    white-space: pre-line;
}

.invoice-company-tax {
    font-size: 11px;
    color: var(--c-muted);
    margin-top: 2px;
}

.invoice-title-block {
    text-align: right;
    flex-shrink: 0;
}

.invoice-badge-wrap {
    margin-top: 8px;
}

/* ============================================================
   SIGN CARD — page ký riêng (clean, focused)
   ============================================================ */
.sign-card {
    max-width: 560px;
    margin: 0 auto;
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 36px 36px 32px;
}

.sign-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--c-border);
    margin-bottom: 24px;
}

.sign-logo {
    max-width: 60px;
    max-height: 40px;
    object-fit: contain;
}

.sign-brand-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--c-navy-deep);
}

.sign-title {
    margin: 0 0 16px;
    color: var(--c-navy);
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.sign-summary {
    background: #fafafa;
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    padding: 14px 18px;
    margin-bottom: 24px;
}

.sign-summary-row {
    display: flex;
    justify-content: space-between;
    padding: 5px 0;
    font-size: 13px;
}

    .sign-summary-row .label {
        color: var(--c-muted);
    }

    .sign-summary-row .value {
        font-weight: 500;
    }

    .sign-summary-row.total {
        border-top: 2px solid var(--c-navy);
        margin-top: 6px;
        padding-top: 10px;
        font-size: 15px;
        font-weight: 700;
        color: var(--c-navy-deep);
    }

        .sign-summary-row.total .label {
            color: var(--c-navy-deep);
        }

.sign-intro {
    font-size: 13px;
    color: var(--c-muted);
    line-height: 1.55;
    margin: 0 0 20px;
}

.sign-card .form-field {
    margin-bottom: 16px;
}

.sign-card .signature-actions {
    margin-top: 16px;
}

.sign-back {
    text-align: center;
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--c-border);
}

    .sign-back a {
        font-size: 13px;
        color: var(--c-muted);
        text-decoration: none;
    }

        .sign-back a:hover {
            color: var(--c-navy);
            text-decoration: underline;
        }

/* Mobile sign card */
@media (max-width: 600px) {
    .sign-card {
        padding: 24px 20px;
        margin: 0 -8px;
    }

    .sign-title {
        font-size: 19px;
    }

    .invoice-header-row {
        flex-direction: column;
        gap: 16px;
    }

    .invoice-title-block {
        text-align: left;
    }

    .invoice-logo {
        max-width: 100px;
    }
}
