:root {
    --bg-color: #f1f5f9;
    --surface-color: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --primary-color: #4f46e5;
    --border-color: #cbd5e1;
    --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
    /* Mathematically calculated sizes for 10 slips on A4 */
    --slip-width: 320px;
    --slip-height: 195px;
}

[data-theme="dark"] {
    --bg-color: #0f172a;
    --surface-color: #1e293b;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --border-color: #334155;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Poppins', sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    scroll-behavior: smooth;
}

/* Dashboard Header */
header {
    background: var(--primary-color);
    padding: 15px 5%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: white;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.logo a {
    color: white;
    text-decoration: none;
    font-size: 1.4rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-btns {
    display: flex;
    gap: 10px;
}

.btn-theme {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.4);
    color: white;
    padding: 8px 15px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    transition: 0.3s;
}

.btn-theme:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Main Container */
.app-container {
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: 10px;
    padding: 30px 5%;
    max-width: 1600px;
    margin: 0 auto;
}

/* Modern Sidebar */
.controls-panel {
    background: var(--surface-color);
    padding: 25px;
    border-radius: 16px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
    height: fit-content;
}

.panel-title {
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 20px;
    color: var(--primary-color);
    border-bottom: 2px solid var(--bg-color);
    padding-bottom: 10px;
}

.control-group {
    margin-bottom: 18px;
}

.control-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

input[type="text"],
input[type="number"],
select,
input[type="range"] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-color);
    color: var(--text-primary);
    transition: 0.3s;
    outline: none;
}

input[type="text"]:focus,
input[type="number"]:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

/* Theme Selector */
.template-selector {
    display: flex;
    gap: 10px;
}

.template-card {
    flex: 1;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    padding: 12px;
    text-align: center;
    cursor: pointer;
    font-weight: 600;
    transition: 0.3s;
    background: var(--bg-color);
}

.template-card.active {
    border-color: var(--primary-color);
    background: rgba(79, 70, 229, 0.1);
    color: var(--primary-color);
}

.template-card input {
    display: none;
}

/* File Uploaders */
.upload-box {
    border: 2px dashed var(--primary-color);
    padding: 12px;
    border-radius: 10px;
    text-align: center;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--primary-color);
    background: rgba(79, 70, 229, 0.05);
    transition: 0.3s;
}

.upload-box:hover {
    background: rgba(79, 70, 229, 0.1);
}

.cartoon-controls {
    background: var(--bg-color);
    padding: 15px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    display: none;
    margin-top: 10px;
}

/* Action Buttons */
.action-btns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 25px;
}

.btn {
    padding: 12px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.9rem;
    transition: 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-print {
    background: var(--primary-color);
    color: white;
    grid-column: span 2;
    font-size: 1rem;
}

.btn-print:hover {
    background: #4338ca;
}

.btn-pdf {
    background: #ef4444;
    color: white;
}

.btn-pdf:hover {
    background: #dc2626;
}

.btn-png {
    background: #10b981;
    color: white;
}

.btn-png:hover {
    background: #059669;
}

.btn-lang {
    background: #f59e0b;
    color: white;
    grid-column: span 2;
}

/* Preview Section */
.preview-section {
    background: var(--surface-color);
    padding: 25px;
    border-radius: 16px;
    box-shadow: var(--shadow);
    margin-bottom: 30px;
    border: 1px solid var(--border-color);
}

.preview-section h3 {
    font-size: 1.2rem;
    margin-bottom: 20px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 10px;
}

.slip-container {
    display: flex;
    justify-content: center;
    padding: 30px;
    background: repeating-conic-gradient(#cbd5e1 0% 25%, transparent 0% 50%) 50% / 20px 20px;
    border-radius: 12px;
}

/* The Actual Slip Design */
.slip-card {
    width: var(--slip-width);
    height: var(--slip-height);
    background: white;
    border-radius: 8px;
    position: relative;
    overflow: hidden;
    display: flex;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    border: 1px solid #e2e8f0;
    page-break-inside: avoid;
}

.slip-boy {
    background: #fffdf5;
    border: 2px dashed #fcd34d;
}

.slip-boy::before {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    width: 55%;
    height: 100%;
    background: linear-gradient(135deg, #fef08a, #facc15);
    clip-path: polygon(25% 0, 100% 0, 100% 100%, 0 100%);
}

.slip-girl {
    background: #f8fafc;
    border: 2px solid #a5b4fc;
}

.slip-girl::before {
    content: '';
    position: absolute;
    right: -10%;
    top: -10%;
    width: 70%;
    height: 120%;
    background: radial-gradient(circle, #e0e7ff, #c7d2fe);
    border-radius: 50%;
}

.slip-content {
    position: relative;
    z-index: 2;
    display: flex;
    width: 100%;
    padding: 12px 15px;
    gap: 12px;
    align-items: center;
}

.photo-frame {
    width: 80px;
    height: 100px;
    background: #e2e8f0;
    border: 3px solid white;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.slip-girl .photo-frame {
    border-radius: 50%;
    width: 90px;
    height: 90px;
}

/* Object-position top center ensures face is always visible and recognizable */
.photo-frame img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: top center;
}

.text-info {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.name-txt {
    font-size: 22px;
    margin-bottom: 6px;
    color: #000;
    font-weight: 700;
    line-height: 1.1;
    word-break: break-word;
}

.detail-row {
    display: flex;
    align-items: flex-end;
    gap: 5px;
    margin-bottom: 5px;
}

.detail-row span {
    font-size: 11px;
    font-weight: 700;
    color: #334155;
    white-space: nowrap;
}

.detail-row div {
    flex-grow: 1;
    border-bottom: 1px dotted #64748b;
    height: 10px;
}

.school-tag {
    position: absolute;
    bottom: 6px;
    right: 10px;
    font-size: 9px;
    font-weight: 800;
    color: white;
    background: rgba(0, 0, 0, 0.6);
    padding: 3px 8px;
    border-radius: 12px;
    z-index: 3;
    text-transform: uppercase;
}

.cartoon-element {
    position: absolute;
    z-index: 4;
    pointer-events: none;
}

.cartoon-element img {
    width: 100%;
    height: auto;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

/* A4 Layout View - Perfectly Math Calculated */
.a4-wrapper {
    background: #94a3b8;
    padding: 20px;
    display: flex;
    justify-content: center;
    border-radius: 12px;
    overflow-y: auto;
    max-height: 600px;
}

.a4-preview {
    width: 210mm;
    min-height: 297mm;
    background: white;
    padding: 8mm 5mm;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 5mm;
    align-content: start;
    justify-items: center;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);
    transform: scale(0.6);
    transform-origin: top center;
    margin-bottom: -110mm;
}

/* Content & SEO Section */
.seo-content {
    background: var(--surface-color);
    padding: 40px;
    border-radius: 16px;
    box-shadow: var(--shadow);
    margin: 0 5% 40px 5%;
    border: 1px solid var(--border-color);
    max-width: 1600px;
}

.seo-content h2 {
    color: var(--primary-color);
    margin-bottom: 20px;
    font-size: 1.8rem;
}

.seo-content h3 {
    color: var(--text-primary);
    margin: 25px 0 10px 0;
}

.seo-content p,
.seo-content li {
    color: var(--text-secondary);
    line-height: 1.7;
    margin-bottom: 10px;
}

.seo-content ul {
    padding-left: 20px;
    margin-bottom: 20px;
}

.faq-box {
    background: var(--bg-color);
    padding: 15px 20px;
    border-radius: 8px;
    margin-bottom: 15px;
    border-left: 4px solid var(--primary-color);
}

.faq-box h4 {
    margin-bottom: 5px;
    color: var(--text-primary);
}

footer {
    text-align: center;
    padding: 25px;
    background: var(--surface-color);
    color: var(--text-secondary);
    border-top: 1px solid var(--border-color);
}

/* --- PRINT CSS: THE SECRET TO PERFECT A4 PRINT --- */
@media print {
    body * {
        visibility: hidden;
    }

    #a4-print,
    #a4-print * {
        visibility: visible;
    }

    #a4-print {
        position: absolute;
        left: 0;
        top: 0;
        margin: 0;
        padding: 5mm;
        transform: none !important;
        width: 210mm;
        height: 297mm;
        box-shadow: none;
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 5mm;
        align-content: start;
        justify-items: center;
        background: white;
    }

    .slip-card {
        border: 1px solid #94a3b8;
    }

    @page {
        size: A4 portrait;
        margin: 0;
    }
}

@media (max-width: 900px) {
    .app-container {
        grid-template-columns: 1fr;
    }

    .a4-preview {
        transform: scale(0.4);
        margin-bottom: -160mm;
    }
}