:root {
    --app-ink: #1f2937;
    --app-muted: #64748b;
    --app-line: #d8dee8;
    --app-bg: #f4f7fb;
    --app-primary: #2458a6;
    --app-accent: #0f766e;
    --print-top: 37mm;
    --print-section-top: 74.25mm;
}

body {
    min-height: 100vh;
    color: var(--app-ink);
    background: var(--app-bg);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app-navbar {
    background: #183b73;
}

.navbar-brand {
    color: #fff;
    font-weight: 700;
}

.navbar-brand:hover {
    color: #fff;
}

.app-main {
    min-height: calc(100vh - 58px);
}

.login-screen {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: linear-gradient(135deg, #eef4fb, #f8fbf7);
}

.login-panel {
    width: min(100%, 430px);
    background: #fff;
    border: 1px solid var(--app-line);
    border-radius: 8px;
    padding: 32px;
    box-shadow: 0 18px 50px rgba(31, 41, 55, .12);
}

.login-heading h1,
.content-header h1 {
    font-size: clamp(1.65rem, 2.4vw, 2.3rem);
    font-weight: 800;
    margin: 0 0 6px;
}

.login-heading p,
.content-header p,
.result-head p {
    color: var(--app-muted);
    margin: 0;
}

.toolbar-panel,
.result-panel {
    background: #fff;
    border: 1px solid var(--app-line);
    border-radius: 8px;
    padding: 20px;
    margin-top: 18px;
}

.result-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
}

.result-head h2 {
    font-size: 1.25rem;
    font-weight: 800;
    margin: 0 0 4px;
}

.action-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.student-table th {
    background: #edf3f8;
    white-space: nowrap;
}

.student-table .address-cell {
    min-width: 260px;
    white-space: pre-line;
}

.empty-state,
.empty-print {
    text-align: center;
    color: var(--app-muted);
    padding: 34px 16px;
}

.btn-primary {
    background: var(--app-primary);
    border-color: var(--app-primary);
}

.print-toolbar {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    background: #fff;
    border-bottom: 1px solid var(--app-line);
    padding: 12px 20px;
}

.print-settings {
    display: flex;
    align-items: end;
    gap: 10px;
    flex-wrap: wrap;
}

.print-settings label {
    display: grid;
    gap: 3px;
    color: var(--app-muted);
    font-size: 12px;
}

.print-setting-input {
    width: 82px;
}

.print-unit {
    color: var(--app-muted);
    font-size: 13px;
    padding-bottom: 7px;
}

.envelope-stack {
    display: grid;
    gap: 24px;
    padding: 24px;
}

.envelope-page {
    width: 210mm;
    height: 297mm;
    margin: 0 auto;
    background: #fff;
    border: 1px dashed #94a3b8;
    position: relative;
    page-break-after: always;
}

.envelope-page::after {
    content: "";
    position: absolute;
    top: 74.25mm;
    left: 0;
    right: 0;
    border-top: 1px dashed #d5dce7;
}

.envelope-page::before {
    content: "";
    position: absolute;
    top: 148.5mm;
    left: 0;
    right: 0;
    border-top: 1px dashed #d5dce7;
}

.envelope-section {
    position: absolute;
    top: var(--print-section-top);
    left: 0;
    right: 0;
    height: 74.25mm;
}

.stamp-box {
    position: absolute;
    top: 2mm;
    right: 8mm;
    width: 47mm;
    height: 18mm;
    border: 1px solid #334155;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-size: 9.5px;
    line-height: 1.2;
    color: #0f172a;
    padding: 1.5mm 2mm;
    box-sizing: border-box;
    background: #fff;
    z-index: 2;
}

.sender-box {
    position: absolute;
    top: 10mm;
    left: 14mm;
    font-size: 13px;
    color: #475569;
}

.receiver-box {
    position: absolute;
    left: 82mm;
    top: var(--print-top);
    width: 110mm;
    max-height: none;
    overflow: visible;
    font-size: 16px;
    line-height: 1.35;
}

.receiver-prefix {
    font-size: 15px;
    color: #475569;
    margin-bottom: 4px;
}

.receiver-box h1 {
    font-size: 21px;
    font-weight: 800;
    margin: 0 0 3px;
    line-height: 1.2;
}

.receiver-box p {
    margin: 0 0 3px;
}

.address {
    line-height: 1.35;
    white-space: normal;
}

.verify-code {
    position: absolute;
    left: 14mm;
    bottom: 4mm;
    color: #64748b;
    font-size: 9px;
    line-height: 1.2;
}

@media (max-width: 767.98px) {
    .result-head {
        align-items: flex-start;
        flex-direction: column;
    }

    .action-group {
        width: 100%;
    }

    .action-group .btn {
        flex: 1 1 auto;
    }
}

@media print {
    @page {
        size: A4;
        margin: 0;
    }

    body {
        background: #fff;
    }

    .no-print,
    .app-navbar {
        display: none !important;
    }

    .app-main,
    .envelope-stack {
        padding: 0;
        display: block;
    }

    .envelope-page {
        width: 210mm;
        height: 297mm;
        border: 0;
        margin: 0;
        page-break-after: always;
    }

    .envelope-page::after {
        display: none;
    }

    .envelope-page::before {
        display: none;
    }

    .stamp-box {
        display: flex;
    }
}
