/* ============================================================
   Teachmatic Generator – Frontend + A4 Print CSS
   ============================================================ */

/* ── Variables ── */
:root {
    --tm-primary:   #1976D2;
    --tm-primary-d: #1565C0;
    --tm-accent:    #0D47A1;
    --tm-bg:        #f5f7fa;
    --tm-card-bg:   #ffffff;
    --tm-border:    #dde3ec;
    --tm-text:      #1a1a2e;
    --tm-muted:     #6b7280;
    --tm-radius:    8px;
    --tm-shadow:    0 2px 8px rgba(0,0,0,.08);
    --tm-a4-width:  210mm;
    --tm-a4-min:    794px;
}

/* ── Outer Wrapper ── */
.tm-generator {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--tm-text);
    max-width: 900px;
    margin: 0 auto;
}

/* ── Panel base ── */
.tm-panel {
    background: var(--tm-card-bg);
    border: 1px solid var(--tm-border);
    border-radius: var(--tm-radius);
    box-shadow: var(--tm-shadow);
    padding: 28px 32px;
}

/* ── Logo Row ── */
.tm-logo-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 2px solid var(--tm-primary);
}
.tm-logo-text {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--tm-primary);
    letter-spacing: -0.5px;
}
.tm-subject-badge {
    background: var(--tm-primary);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 20px;
}

/* ── Form Layout ── */
.tm-row { margin-bottom: 16px; }
.tm-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.tm-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.tm-row-options { display: flex; align-items: center; gap: 20px; }

.tm-field { display: flex; flex-direction: column; gap: 5px; }
.tm-field-full { width: 100%; }

.tm-field label {
    font-size: 12px;
    font-weight: 600;
    color: var(--tm-muted);
    text-transform: uppercase;
    letter-spacing: .5px;
}
.tm-optional { font-weight: normal; color: #aaa; font-size: 11px; text-transform: none; letter-spacing: 0; }

.tm-field input[type="text"],
.tm-field select,
.tm-field textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--tm-border);
    border-radius: 6px;
    font-size: 14px;
    color: var(--tm-text);
    background: #fff;
    transition: border-color .15s, box-shadow .15s;
    box-sizing: border-box;
}
.tm-field input[type="text"]:focus,
.tm-field select:focus,
.tm-field textarea:focus {
    outline: none;
    border-color: var(--tm-primary);
    box-shadow: 0 0 0 3px rgba(25,118,210,.12);
}
.tm-field textarea { resize: vertical; min-height: 72px; }

/* ── PDF Labor Section ── */
.tm-pdf-section {
    background: #f8faff;
    border: 1px solid #c5d5f0;
    border-radius: 6px;
    padding: 14px 16px;
}
.tm-pdf-section > label {
    font-size: 12px;
    font-weight: 600;
    color: var(--tm-primary-d);
    text-transform: uppercase;
    letter-spacing: .5px;
    display: block;
    margin-bottom: 10px;
}
.tm-pdf-search-row {
    display: flex;
    gap: 8px;
}
.tm-pdf-search-row input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--tm-border);
    border-radius: 6px;
    font-size: 13px;
}
.tm-arc-results {
    margin-top: 8px;
    border: 1px solid var(--tm-border);
    border-radius: 6px;
    background: #fff;
    max-height: 200px;
    overflow-y: auto;
}
.tm-arc-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 9px 13px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 13px;
    border-bottom: 1px solid #f0f0f0;
    transition: background .1s;
}
.tm-arc-item:hover { background: #e8f0fe; }
.tm-arc-type { font-size: 11px; color: #888; background: #f0f0f0; border-radius: 4px; padding: 1px 5px; margin-left: 6px; }
.tm-arc-loading, .tm-arc-empty { padding: 10px 14px; font-size: 13px; color: #888; }
.tm-arc-selected {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
    padding: 8px 12px;
    background: #e8f5e9;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    color: #2E7D32;
}
.tm-btn-remove {
    background: none;
    border: none;
    color: #c62828;
    cursor: pointer;
    font-size: 12px;
    margin-left: auto;
}

/* ── Checkbox ── */
.tm-checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 14px;
}
.tm-checkbox-label input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; }

/* ── Buttons ── */
.tm-btn-primary {
    background: var(--tm-primary);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 11px 24px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, transform .1s;
}
.tm-btn-primary:hover { background: var(--tm-primary-d); }
.tm-btn-primary:active { transform: scale(.98); }
.tm-btn-primary:disabled { opacity: .6; cursor: not-allowed; }

.tm-btn-secondary {
    background: #fff;
    color: var(--tm-primary);
    border: 1px solid var(--tm-border);
    border-radius: 6px;
    padding: 9px 18px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s;
}
.tm-btn-secondary:hover { background: var(--tm-bg); }

.tm-actions { margin-top: 22px; }

/* ── Output Panel ── */
.tm-output-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--tm-border);
}

/* ── A4 Wrapper ── */
.tm-a4-wrapper {
    background: #e8ecf0;
    border-radius: 6px;
    padding: 24px;
    min-height: 400px;
}

/* ── A4 Page ── */
.tm-a4-page {
    width: var(--tm-a4-min);
    max-width: 100%;
    min-height: 1123px; /* 297mm at 96dpi */
    background: #fff;
    margin: 0 auto;
    padding: 20mm 20mm 25mm 20mm;
    box-sizing: border-box;
    box-shadow: 0 4px 20px rgba(0,0,0,.15);
    border-radius: 2px;
    position: relative;
    font-family: 'Georgia', serif;
    font-size: 11pt;
    line-height: 1.55;
    color: #1a1a1a;
}

/* ── Generated Content Styles ── */

/* Header block */
.tm-a4-page .tm-header {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 0;
    border-bottom: 1px solid #555;
    padding-bottom: 8px;
    margin-bottom: 18px;
    font-size: 10pt;
}
.tm-a4-page .tm-header span {
    display: block;
}

/* Exercise block */
.tm-a4-page .tm-exercise {
    position: relative;
}
.tm-a4-page .tm-title {
    font-size: 14pt;
    font-weight: bold;
    margin: 0 0 6px 0;
    color: #000;
}
.tm-a4-page .tm-instructions {
    font-size: 10pt;
    font-style: italic;
    color: #333;
    margin-bottom: 14px;
    border-left: 3px solid #1976D2;
    padding-left: 10px;
}
.tm-a4-page .tm-points {
    position: absolute;
    top: 0;
    right: 0;
    font-size: 10pt;
    font-weight: bold;
    border: 1px solid #555;
    padding: 3px 10px;
    border-radius: 4px;
}

/* Word box */
.tm-a4-page .tm-word-box {
    background: #f5f5f5;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 10px 14px;
    margin-bottom: 14px;
    font-size: 10pt;
    line-height: 1.8;
}

/* Tables */
.tm-a4-page table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 10pt;
}
.tm-a4-page th {
    background: #e8f0fe;
    padding: 7px 10px;
    text-align: left;
    font-weight: bold;
    border: 1px solid #bbb;
}
.tm-a4-page td {
    padding: 7px 10px;
    border: 1px solid #ddd;
    vertical-align: top;
}
.tm-a4-page tr:nth-child(even) td { background: #fafafa; }

/* Lists */
.tm-a4-page ol, .tm-a4-page ul {
    margin: 8px 0 8px 22px;
    padding: 0;
    font-size: 10pt;
}
.tm-a4-page li { margin-bottom: 6px; line-height: 1.6; }

/* Writing lines */
.tm-a4-page .tm-lines {
    margin: 8px 0;
}
.tm-a4-page .tm-line {
    border-bottom: 1px solid #bbb;
    height: 22px;
    margin-bottom: 4px;
}

/* Blank / gap */
.tm-a4-page .tm-gap {
    display: inline-block;
    border-bottom: 1.5px solid #333;
    min-width: 60px;
    height: 1em;
    vertical-align: bottom;
    margin: 0 3px;
}

/* Role card (Information gap / Roleplay) */
.tm-a4-page .tm-role-card {
    border: 2px solid #1976D2;
    border-radius: 6px;
    padding: 12px 16px;
    margin: 14px 0;
}
.tm-a4-page .tm-role-card h3 {
    margin: 0 0 8px 0;
    font-size: 11pt;
    color: #1976D2;
}

/* Answer Key */
.tm-a4-page .tm-page-break { break-before: page; }
.tm-a4-page .tm-answer-key {
    break-before: page;
    padding-top: 8px;
}
.tm-a4-page .tm-ak-title {
    font-size: 14pt;
    font-weight: bold;
    text-align: center;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 2px solid #555;
}
.tm-a4-page .tm-ak-item {
    display: flex;
    gap: 12px;
    padding: 4px 0;
    border-bottom: 1px dotted #ddd;
    font-size: 10pt;
}
.tm-a4-page .tm-ak-num { font-weight: bold; min-width: 24px; }
.tm-a4-page .tm-ak-answer { color: #1565C0; }

/* Schoolbook-style divider */
.tm-a4-page .tm-divider {
    border: none;
    border-top: 1px dashed #bbb;
    margin: 16px 0;
}

/* Footer */
.tm-a4-page .tm-footer,
.tm-a4-footer {
    position: absolute;
    bottom: 12mm;
    left: 20mm;
    right: 20mm;
    text-align: center;
    font-size: 8pt;
    color: #888;
    border-top: 1px solid #ddd;
    padding-top: 5px;
    font-family: Arial, sans-serif;
}
.tm-a4-footer::before {
    content: attr(data-footer);
}

/* ============================================================
   @MEDIA PRINT
   ============================================================ */
@media print {

    /* Hide everything except the A4 page */
    body > * { display: none !important; }

    /* Show only the A4 content */
    #tm-a4-wrapper,
    #tm-a4-wrapper *,
    .tm-a4-wrapper,
    .tm-a4-wrapper * {
        display: revert !important;
        visibility: visible !important;
    }

    #tm-a4-wrapper {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: auto !important;
        background: #fff !important;
        padding: 0 !important;
        margin: 0 !important;
        box-shadow: none !important;
    }

    .tm-a4-page {
        width: 100% !important;
        min-height: auto !important;
        padding: 15mm 18mm 22mm 18mm !important;
        box-shadow: none !important;
        border-radius: 0 !important;
        margin: 0 !important;
    }

    .tm-output-toolbar,
    .tm-back-btn,
    .tm-print-btn,
    #tm-form-panel { display: none !important; }

    /* A4 page setup */
    @page {
        size: A4 portrait;
        margin: 0;
    }

    /* Page breaks */
    .tm-a4-page .tm-page-break,
    .tm-a4-page .tm-answer-key {
        break-before: page;
        page-break-before: always;
    }

    /* Footer on each page */
    .tm-a4-footer,
    .tm-a4-page .tm-footer {
        position: fixed;
        bottom: 8mm;
        left: 18mm;
        right: 18mm;
    }
}

/* ── Responsive ── */
@media (max-width: 640px) {
    .tm-row-3, .tm-row-2 { grid-template-columns: 1fr; }
    .tm-panel { padding: 18px 16px; }
    .tm-a4-wrapper { padding: 12px; }
    .tm-a4-page { padding: 12px; font-size: 10pt; }
}
