* {
    box-sizing: border-box;
}

:root {
    --primary: #0b2d59;
    --primary-dark: #08203f;
    --accent: #f26b21;
    --accent-dark: #c95417;
    --text: #1b1f2a;
    --muted: #4c5566;
    --bg: #f6f7fb;
    --card: #ffffff;
}

body {
    margin: 0;
    font-family: "Segoe UI", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

a {
    color: var(--primary);
    text-decoration: none;
}

.container {
    width: min(1100px, 92%);
    margin: 0 auto;
}

.site-header {
    background: var(--primary);
    color: #fff;
    padding: 1.5rem 0;
    margin-bottom: 2rem;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 2rem;
    flex-wrap: wrap;
}

.site-header .brand {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.brand-logo {
    width: 64px;
    height: auto;
}

.site-header .brand h1 {
    margin: 0;
    font-size: 1.5rem;
}

.site-header .brand p {
    margin: 0.25rem 0 0;
    font-size: 0.9rem;
    opacity: 0.8;
}

nav ul,
.main-nav .nav-links {
    list-style: none;
    padding: 0;
    display: flex;
    gap: 1rem;
    margin: 1rem 0 0;
    flex-wrap: wrap;
    align-items: center;
}

nav a {
    color: #fff;
    font-weight: 600;
}

main.container {
    padding-bottom: 3rem;
}

footer {
    text-align: center;
    padding: 2rem 0;
    color: var(--muted);
}

.admin-body {
    background: var(--bg);
}

.admin-layout {
    display: flex;
    min-height: 100vh;
    background: var(--bg);
}

.admin-sidebar {
    width: 260px;
    background: var(--primary);
    color: #fff;
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    position: sticky;
    top: 0;
    height: 100vh;
}

.admin-brand {
    display: flex;
    align-items: center;
    gap: 0.9rem;
}

.admin-brand h1 {
    font-size: 1.1rem;
    margin: 0;
}

.admin-brand p {
    margin: 0.25rem 0 0;
    font-size: 0.85rem;
    opacity: 0.85;
}

.admin-nav {
    display: grid;
    gap: 0.6rem;
}

.admin-nav a {
    color: #fff;
    padding: 0.6rem 0.85rem;
    border-radius: 10px;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.08);
}

.admin-nav a:hover,
.admin-nav a:focus {
    background: rgba(255, 255, 255, 0.18);
}

.admin-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.admin-topbar {
    background: #fff;
    border-bottom: 1px solid #e4e8f1;
    padding: 1.2rem 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.admin-topbar h2 {
    margin: 0;
}

.admin-topbar p {
    margin: 0.2rem 0 0;
    color: var(--muted);
}

.admin-user {
    font-weight: 600;
    color: var(--primary);
}

.admin-main {
    padding: 2rem;
    width: min(1200px, 100%);
    margin: 0 auto;
}

.admin-footer {
    text-align: center;
    padding: 1.5rem 0 2rem;
    color: var(--muted);
}

.hero {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 2rem;
    align-items: center;
    margin-bottom: 2rem;
}

.hero-card {
    background: var(--card);
    padding: 1.5rem;
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(16, 24, 40, 0.08);
}

.card {
    background: var(--card);
    padding: 1.5rem;
    border-radius: 16px;
    box-shadow: 0 8px 24px rgba(16, 24, 40, 0.08);
    margin-bottom: 2rem;
}

.card.narrow {
    max-width: 480px;
    margin: 0 auto 2rem;
}

.grid {
    display: grid;
    gap: 1.5rem;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.grid.two {
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.form-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.form-grid .full {
    grid-column: 1 / -1;
}

label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.35rem;
}

input,
select,
textarea {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border-radius: 8px;
    border: 1px solid #cdd3df;
    font-size: 0.95rem;
}

button,
.button {
    display: inline-block;
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 0.65rem 1.2rem;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}

.button.outline {
    background: transparent;
    color: var(--accent);
    border: 1px solid var(--accent);
}

.actions {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.helper {
    font-size: 0.9rem;
    color: var(--muted);
}

.alert {
    padding: 0.75rem 1rem;
    background: #ffe9e9;
    border-radius: 8px;
    color: #8b1c1c;
    margin-bottom: 1rem;
}

.status {
    padding: 0.5rem 0.8rem;
    border-radius: 6px;
    display: inline-block;
}

.status.success {
    background: #e6f8ed;
    color: #1b6b3a;
}

.status.danger {
    background: #ffe9e9;
    color: #8b1c1c;
}

.stat {
    font-size: 2rem;
    font-weight: 700;
    margin: 0.5rem 0 0;
}

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

th,
td {
    text-align: left;
    padding: 0.75rem 0.5rem;
    border-bottom: 1px solid #e4e8f1;
}

.danger {
    color: #b42318;
    font-weight: 600;
    margin-left: 0.5rem;
}

.qr-panel {
    text-align: center;
}

.admin-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.certificate-preview {
    border: 1px solid #e4e8f1;
    border-radius: 12px;
    overflow: hidden;
    background: #fff;
}

.certificate-preview iframe {
    width: 100%;
    height: 70vh;
    border: 0;
}

.certificate {
    background: var(--card);
    padding: 2rem;
    border-radius: 18px;
    box-shadow: 0 10px 30px rgba(16, 24, 40, 0.08);
}

.certificate-header {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: center;
    border-bottom: 2px solid #eef1f7;
    padding-bottom: 1rem;
    margin-bottom: 1.5rem;
}

.certificate-brand {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.certificate-brand img {
    width: 70px;
    height: auto;
}

.certificate-qr img {
    width: 140px;
    height: 140px;
}

.certificate-body {
    text-align: center;
}

.certificate-body h3 {
    margin: 0.5rem 0;
    font-size: 2rem;
}

.certificate-body h4 {
    margin: 0.5rem 0;
    font-size: 1.3rem;
}

.certificate-meta {
    display: flex;
    justify-content: space-between;
    gap: 2rem;
    margin-top: 1.5rem;
    text-align: left;
    flex-wrap: wrap;
}

.certificate-actions {
    margin-top: 1.5rem;
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.certificate-wrapper {
    margin-bottom: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.certificate-template {
    position: relative;
    background: #fff url('../images/certificate-template.png') center/100% 100% no-repeat;
    border-radius: 18px;
    padding: 0;
    width: min(1123px, 100%);
    aspect-ratio: 1123 / 794;
    height: auto;
    box-shadow: 0 12px 32px rgba(16, 24, 40, 0.1);
}

.certificate-bg {
    display: none;
}

.exact-template .certificate-dynamic {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    color: #244037;
    background: transparent;
    padding: 0;
    font-family: "Georgia", "Times New Roman", serif;
    z-index: 2;
}

.exact-template .recipient-name {
    top: 49%;
    font-size: 2.7rem;
    font-weight: 700;
    letter-spacing: 0.01em;
}

.exact-template .certificate-body-text {
    top: 58%;
    max-width: 640px;
    font-size: 1rem;
    line-height: 1.7;
    font-family: "Segoe UI", Arial, sans-serif;
}

.exact-template .signature-block {
    top: 79.5%;
}

.exact-template .signature-name {
    font-weight: 700;
    font-size: 1.05rem;
    font-family: "Georgia", "Times New Roman", serif;
}

.exact-template .signature-title {
    margin-top: 0.2rem;
    font-size: 0.95rem;
    font-family: "Segoe UI", Arial, sans-serif;
}

.exact-template .certificate-qr {
    position: absolute;
    right: 11%;
    bottom: calc(16% + 1cm);
    width: 110px;
    height: 110px;
    background: #fff;
    padding: 6px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(16, 24, 40, 0.12);
    z-index: 2;
}

.exact-template .certificate-qr img {
    width: 100%;
    height: 100%;
    display: block;
}

.muted {
    color: #667085;
}

.small {
    font-size: 0.85rem;
    color: var(--muted);
}

@media print {
    .certificate-template {
        background: none;
    }

    .certificate-bg {
        display: block;
        position: absolute;
        inset: 0;
        width: 100%;
        height: 100%;
        object-fit: fill;
        z-index: 1;
    }
    @page {
        size: A4 landscape;
        margin: 0;
    }

    html,
    body {
        height: 210mm;
        margin: 0;
        padding: 0;
        overflow: hidden;
    }

    body {
        background: #fff;
    }

    .site-header,
    footer,
    .certificate-actions {
        display: none;
    }

    main.container {
        padding: 0;
    }

    .certificate,
    .certificate-template {
        box-shadow: none;
        border: none;
        padding: 0;
    }

    .certificate-template {
        width: 297mm;
        height: 210mm;
        min-height: 0;
        border-radius: 0;
        padding: 0;
        page-break-after: avoid;
        page-break-inside: avoid;
    }

    .certificate-wrapper {
        margin: 0;
        page-break-after: avoid;
        page-break-inside: avoid;
    }
}

@media (max-width: 980px) {
    .admin-layout {
        flex-direction: column;
    }

    .admin-sidebar {
        width: 100%;
        height: auto;
        position: static;
        flex-direction: row;
        align-items: center;
        flex-wrap: wrap;
    }

    .admin-nav {
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
        width: 100%;
    }

    .admin-main {
        padding: 1.5rem;
    }
}

@media (max-width: 720px) {
    .header-content {
        flex-direction: column;
        align-items: flex-start;
    }

    .main-nav .nav-links {
        margin-top: 0.5rem;
        gap: 0.75rem;
    }

    .admin-topbar {
        flex-direction: column;
        align-items: flex-start;
    }
}