/* ============ GLOBAL RESET ============ */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Poppins', 'Roboto', sans-serif;
    background: #e8edf2;
    display: flex;
    min-height: 100vh;
}

/* ============ EDITOR PANEL ============ */
.editor-panel {
    width: 380px;
    min-width: 380px;
    background: #1a2a3a;
    color: #fff;
    padding: 25px 20px;
    overflow-y: auto;
    height: 100vh;
    position: sticky;
    top: 0;
}

.editor-panel h2 {
    font-size: 1.3rem;
    margin-bottom: 20px;
    border-bottom: 2px solid #3a5a7a;
    padding-bottom: 10px;
    text-align: center;
}

.editor-section {
    background: #243447;
    border-radius: 10px;
    padding: 15px;
    margin-bottom: 15px;
}

.editor-section h3 {
    font-size: 0.95rem;
    color: #7ab8e8;
    margin-bottom: 12px;
}

.leader-section h3 {
    color: #ffd700;
}

.editor-section label {
    display: block;
    font-size: 0.8rem;
    color: #9bb8d0;
    margin-bottom: 10px;
}

.req {
    color: #ff4d4d;
    font-weight: 700;
}

.editor-section input:invalid:not(:placeholder-shown) {
    border-color: #ff4d4d;
}

.editor-section input:valid:not([type="range"]):not([type="file"]) {
    border-color: #4caf50;
}

.editor-section input[type="text"],
.editor-section input[type="email"],
.editor-section input[type="url"],
.editor-section textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #3a5a7a;
    border-radius: 6px;
    background: #1a2a3a;
    color: #fff;
    font-size: 0.85rem;
    margin-top: 4px;
    outline: none;
    transition: border-color .2s;
}

.editor-section input:focus,
.editor-section textarea:focus {
    border-color: #5a9fd4;
}

.editor-section input[type="file"] {
    width: 100%;
    margin-top: 4px;
    font-size: 0.8rem;
}

.editor-section input[type="range"] {
    width: calc(100% - 50px);
    margin-top: 4px;
    vertical-align: middle;
}

.size-display {
    font-size: 0.75rem;
    color: #7ab8e8;
    vertical-align: middle;
}

.btn-download {
    width: 100%;
    padding: 14px;
    background: linear-gradient(135deg, #2a6aaa, #1a4a7a);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    margin-top: 10px;
    transition: background .2s, transform .1s;
}

.btn-download:hover {
    background: linear-gradient(135deg, #3a7aba, #2a5a8a);
    transform: translateY(-1px);
}

.btn-download:active {
    transform: translateY(0);
}

.btn-pdf {
    background: linear-gradient(135deg, #aa2a5a, #7a1a3a);
    margin-top: 8px;
}

.btn-pdf:hover {
    background: linear-gradient(135deg, #ba3a6a, #8a2a4a);
}

/* ============ TEMPLATE ============ */
.template-wrapper {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 30px;
    overflow: auto;
}

.template {
    box-sizing: border-box;
    width: 559px; /* A5 width at 96dpi (148mm) */
    height: 794px; /* A5 height at 96dpi (210mm) */
    background: #fff;
    position: relative;
    padding: 20px 25px 25px;
    box-shadow: 0 4px 30px rgba(0,0,0,0.15);
    overflow: hidden;
}

/* Decorative corner lines */
.deco-lines {
    position: absolute;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.deco-lines span {
    display: block;
    height: 2px;
    background: linear-gradient(90deg, #1a3a6c, #4a8ac0, #1a3a6c);
    border-radius: 1px;
}

.deco-lines.top-left {
    top: 10px;
    left: 10px;
    width: 80px;
}
.deco-lines.top-right {
    top: 10px;
    right: 10px;
    width: 80px;
}
.deco-lines.bottom-left {
    bottom: 10px;
    left: 10px;
    width: 80px;
}
.deco-lines.bottom-right {
    bottom: 10px;
    right: 10px;
    width: 80px;
}

.deco-lines span:nth-child(1) { width: 100%; }
.deco-lines span:nth-child(2) { width: 85%; }
.deco-lines span:nth-child(3) { width: 70%; }
.deco-lines span:nth-child(4) { width: 55%; }
.deco-lines span:nth-child(5) { width: 40%; }

.deco-lines.top-right span,
.deco-lines.bottom-right span {
    margin-left: auto;
}

/* Header */
.template-header {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 10px;
    padding-top: 10px;
}

.header-logo-img {
    max-width: 100%;
    width: auto;
    height: 60px;
    display: block;
    margin: 0 auto;
    object-fit: contain;
}

/* Main Title */
.main-title {
    text-align: center;
    font-size: 1.3rem;
    font-weight: 900;
    color: #1a2a5c;
    letter-spacing: 3px;
    margin: 15px 0 20px;
    text-transform: uppercase;
}

/* Info Fields */
.info-row {
    display: flex;
    gap: 30px;
    margin-bottom: 12px;
}

.info-field {
    flex: 1;
    position: relative;
}

.field-label {
    font-size: 0.82rem;
    font-weight: 800;
    color: #1a3a6c;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    font-family: 'Poppins', sans-serif;
}

.field-value {
    font-size: 0.85rem;
    color: #2c3e50;
    margin-left: 10px;
    font-weight: 500;
    font-family: 'Poppins', sans-serif;
    letter-spacing: 0.3px;
}

.field-line {
    width: 100%;
    height: 1px;
    margin-top: 6px;
    border-bottom: none;
}

/* Members Row */
.members-row {
    display: flex;
    gap: 15px;
    margin: 25px 0 20px;
    justify-content: center;
}

/* Member Card */
.member-card {
    width: 160px;
    border: 2.5px solid #2a4a7c;
    border-radius: 14px;
    padding: 14px 8px 10px;
    text-align: center;
    position: relative;
    background: #fff;
}

.leader-card {
    border-color: #1a3a6c;
    box-shadow: 0 0 0 1px #4a7ab8;
}

/* Crown */
.crown {
    position: absolute;
    top: -18px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 1.6rem;
    color: #1a3a6c;
    z-index: 2;
}

/* Photo */
.photo-container {
    display: flex;
    justify-content: center;
    margin-bottom: 8px;
}

.photo-circle {
    width: 90px;
    height: 90px;
    border-radius: 50%;
    overflow: hidden;
    border: 3px solid #c0d4e8;
    background: #dce8f0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.leader-photo {
    border-color: #8ab0d8;
}

.photo-circle img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: width 0.2s, height 0.2s;
}

.default-avatar {
    width: 80%;
    height: 80%;
}

/* Member Name */
.member-name {
    font-size: 0.85rem;
    font-weight: 800;
    color: #1a2a5c;
    margin: 6px 0 10px;
    line-height: 1.25;
    min-height: 2.4em;
    font-family: 'Poppins', sans-serif;
    letter-spacing: 0.5px;
    text-transform: capitalize;
}

/* Member Info */
.member-info {
    text-align: left;
    padding: 0 4px;
    margin-bottom: 10px;
    overflow: hidden;
}

.info-item {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 4px;
    font-size: 0.72rem;
    color: #34495e;
    font-family: 'Poppins', sans-serif;
    font-weight: 400;
    max-width: 100%;
    overflow: hidden;
}

.info-item span:last-child {
    overflow: hidden;
    word-break: break-all;
    min-width: 0;
    font-size: 0.58rem;
}

.info-icon {
    font-size: 0.75rem;
    color: #1a3a6c;
    font-weight: 700;
    min-width: 20px;
    text-align: center;
}

.email-icon {
    font-size: 0.85rem;
}

/* QR Row */
.qr-row {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 4px;
}

.qr-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.qr-box {
    width: 58px;
    height: 58px;
    border: 2.5px solid #2a4a7c;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #ffffff;
    position: relative;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(42, 74, 124, 0.1);
}

.qr-box canvas,
.qr-box img {
    width: 48px !important;
    height: 48px !important;
    border-radius: 4px;
}

.qr-label {
    display: flex;
    align-items: center;
    justify-content: center;
}

.qr-icon {
    display: block;
}

/* Description Box */
.description-box {
    border: 2.5px solid #2a4a7c;
    border-radius: 16px;
    padding: 20px 25px;
    margin-top: 15px;
    min-height: 140px;
    position: relative;
}

.desc-line {
    display: none;
}

.description-text {
    position: absolute;
    top: 15px;
    left: 25px;
    right: 25px;
    font-size: 0.82rem;
    color: #2c3e50;
    line-height: 1.85;
    white-space: pre-wrap;
    font-family: 'Poppins', sans-serif;
    font-weight: 400;
    letter-spacing: 0.2px;
}

/* ============ RESPONSIVE ============ */
@media (max-width: 1200px) {
    body {
        flex-direction: column;
    }
    .editor-panel {
        width: 100%;
        min-width: auto;
        height: auto;
        position: relative;
    }
    .template-wrapper {
        padding: 15px;
    }
    .template {
        transform-origin: top center;
        transform: scale(0.85);
    }
}

@media (max-width: 850px) {
    .template {
        transform: scale(0.6);
    }
}

/* ============ DOWNLOAD OVERLAY ============ */
.download-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.download-overlay .spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #fff;
    border-top-color: #4a8ac0;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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