/* ===== AprilTag generator – beautified UI ===== */

.apriltag-page { max-width: 900px; }

/* ---- Header with mini-tag badge ---- */
.apriltag-header {
    display: flex;
    align-items: center;
    gap: 24px;
    margin-bottom: 32px;
    padding: 28px;
    background: linear-gradient(135deg, #f6f9ff 0%, #eef3fb 100%);
    border: 1px solid #e3e9f4;
    border-radius: 12px;
}

.apriltag-header h1 {
    font-size: 28px;
    font-weight: 700;
    margin: 0 0 8px 0;
    text-align: left;
    letter-spacing: -0.02em;
    color: #1a2540;
}

.apriltag-header p {
    color: #44516b;
    margin: 0;
    font-size: 15px;
    line-height: 1.55;
}

.apriltag-badge {
    flex-shrink: 0;
    width: 88px;
    height: 88px;
    border-radius: 12px;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #d8e0ee;
    box-shadow: 0 1px 3px rgba(20, 50, 120, 0.05);
    padding: 8px;
    box-sizing: border-box;
}

.apriltag-badge img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    image-rendering: pixelated;       /* keep the tag crisp, no blur */
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

/* ---- Tool: 2-column form + preview ---- */
.apriltag-tool {
    margin-top: 0;
    padding: 0;
    background: none;
    border: none;
}

.apriltag-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    align-items: stretch;
}

/* Form panel */
.setup {
    margin: 0;
    width: 100%;
    max-width: none;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: #fafbfc;
    border: 1px solid #ebedf0;
    border-radius: 10px;
    padding: 22px;
}

.setup .field {
    display: flex;
    flex-direction: column;
    margin: 0;
}

.setup label {
    font-size: 13px;
    color: #5a6473;
    margin-bottom: 6px;
    text-align: left;
    width: auto;
    display: block;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.setup label .info {
    color: #999;
    margin-left: 2px;
    cursor: help;
    text-transform: none;
}

/* Small "(0 – 586)" hint next to Tag ID label */
.setup label .id-range {
    color: #1772d0;
    font-weight: 500;
    font-size: 11px;
    text-transform: none;
    margin-left: 4px;
    letter-spacing: 0;
    font-variant-numeric: tabular-nums;
}

/* Friendly error overlay inside the live preview marker */
.tag-error {
    color: #b53a3a;
    font-size: 13px;
    text-align: center;
    padding: 30px 20px;
    background: #fff3f3;
    border: 1px dashed #d04a4a;
    border-radius: 6px;
    max-width: 280px;
}

.setup input,
.setup select {
    font: inherit;
    font-size: 15px;
    padding: 10px 12px;
    border: 1px solid #d8dde4;
    border-radius: 7px;
    background: #fff;
    width: 100%;
    margin: 0;
    color: #1a2540;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.setup input:hover,
.setup select:hover { border-color: #b0bbcc; }

.setup input:focus,
.setup select:focus {
    outline: none;
    border-color: #1772d0;
    box-shadow: 0 0 0 3px rgba(23, 114, 208, 0.15);
}

/* Preview pane */
.preview-pane {
    background: #fff;
    border: 1px solid #ebedf0;
    border-radius: 10px;
    padding: 22px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background-image:
        linear-gradient(#f4f6f9 1px, transparent 1px),
        linear-gradient(90deg, #f4f6f9 1px, transparent 1px);
    background-size: 20px 20px;
    background-position: -1px -1px;
    min-height: 320px;
}

.preview-caption {
    margin: 12px 0 0 0;
    font-size: 12px;
    color: #8a93a3;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

/* Marker preview (must keep .marker / .marker-id selectors – used by main.js) */
.marker {
    text-align: center;
    background: #fff;
    margin: 0;
    padding: 16px;
    border: 1px solid #d8dde4;
    border-radius: 6px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    display: inline-block;
}

.marker table {
    border: none;
    border-collapse: collapse;
    margin: 0 auto;
    padding: 0;
    width: 70mm;
    height: 70mm;
}

.marker table td {
    margin: 0;
    padding: 0;
    border: none;
    background: white;
}

.marker-id {
    display: none;
    text-align: center;
    color: #555;
    font-size: 13px;
    margin-top: 8px;
}

/* Tools / actions */
.tools {
    margin-top: 8px;
    text-align: center;
    font-size: 14px;
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
}

.tools a, .tools button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 16px;
    background: #1772d0;
    color: #fff !important;
    border-radius: 7px;
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
    border: none;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s, transform 0.05s;
    flex: 1;
    min-width: 110px;
}
.tools a:hover, .tools button:hover {
    background: #135ea8;
    text-decoration: none;
}
.tools a:active, .tools button:active { transform: translateY(1px); }

.tools .add-button {
    background: #fff;
    color: #1772d0 !important;
    border: 1px solid #1772d0;
}
.tools .add-button:hover { background: #eaf2fb; }

.tools .print-button {
    background: #2ea043;
}
.tools .print-button:hover { background: #258a37; }

/* ---- Print sheet: A4 paginated preview ---- */
.sheet-section {
    margin-top: 36px;
    padding: 24px;
    background: #f1f3f7;
    border: 1px solid #e3e7ee;
    border-radius: 10px;
}

.sheet-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    flex-wrap: wrap;
}

.sheet-header h2 {
    font-size: 18px;
    margin: 0;
    font-weight: 600;
    color: #1a2540;
}

.sheet-actions {
    display: flex;
    align-items: center;
    gap: 14px;
}

.page-info {
    font-size: 13px;
    color: #6a7280;
    font-variant-numeric: tabular-nums;
}

.sheet-count {
    display: inline-block;
    margin-left: 6px;
    background: #1772d0;
    color: #fff;
    border-radius: 999px;
    padding: 2px 10px;
    font-size: 12px;
    font-weight: 700;
    vertical-align: middle;
}

.clear-sheet {
    background: #fff;
    border: 1px solid #d8dde4;
    color: #555;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    font-family: inherit;
}
.clear-sheet:hover { background: #fff5f5; border-color: #d04a4a; color: #d04a4a; }

.sheet-help {
    font-size: 13px;
    color: #6a7280;
    margin: 8px 0 18px 0;
}

/* The container that holds A4 pages */
.print-pages {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
}

/* A real-size A4 page (210x297mm) for accurate WYSIWYG print preview */
.print-page {
    width: 210mm;
    height: 297mm;
    background: #fff;
    box-shadow: 0 4px 18px rgba(20, 30, 70, 0.12);
    border: 1px solid #d8dde4;
    box-sizing: border-box;
    overflow: hidden;
    position: relative;
    max-width: 100%;
}

.page-content {
    padding: 10mm;            /* matches A4 margin used by paginator */
    box-sizing: border-box;
    width: 100%;
    height: 100%;
}

.page-row {
    display: flex;
    gap: 3mm;                 /* matches GAP in paginator */
    margin-bottom: 3mm;
    align-items: flex-start;
}
.page-row:last-child { margin-bottom: 0; }

/* Each tag card */
.print-marker {
    position: relative;
    box-sizing: border-box;
    padding: 3mm;             /* matches CARD_PAD in paginator */
    border: 1px dashed #888;  /* dashed CUT LINE */
    background: #fff;
    border-radius: 0;
    flex-shrink: 0;
}

.print-marker .tag-box {
    display: block;
    background: #fff;
}

.print-marker svg {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

.print-marker-label {
    margin-top: 1mm;
    text-align: center;
    font-size: 8pt;
    color: #555;
    line-height: 1.2;
    font-family: -apple-system, sans-serif;
    height: 4mm;
    overflow: hidden;
}

.print-marker .remove-btn {
    position: absolute;
    top: -10px;
    right: -10px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: none;
    background: #d04a4a;
    color: #fff;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0,0,0,0.25);
    font-family: inherit;
    z-index: 5;
}
.print-marker .remove-btn:hover { background: #b53a3a; }

/* Page number in bottom-right corner of each A4 sheet */
.page-number {
    position: absolute;
    bottom: 4mm;
    right: 6mm;
    font-size: 9pt;
    color: #aab1bd;
    font-family: -apple-system, sans-serif;
}

/* ---- Family table ---- */
.apriltag-table { margin-top: 40px; }
.apriltag-table h2 {
    font-size: 18px;
    margin: 0 0 14px 0;
    font-weight: 600;
    color: #1a2540;
}
.apriltag-table table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    border: 1px solid #ebedf0;
    border-radius: 8px;
    overflow: hidden;
}
.apriltag-table th,
.apriltag-table td {
    border: none;
    border-bottom: 1px solid #ebedf0;
    text-align: left;
    padding: 10px 14px;
}
.apriltag-table tbody tr:last-child td { border-bottom: none; }
.apriltag-table th {
    background: #f6f8fa;
    font-weight: 600;
    color: #1a2540;
    text-transform: uppercase;
    font-size: 12px;
    letter-spacing: 0.05em;
}
.apriltag-table tr:nth-child(even) td { background: #fafbfc; }
.apriltag-table td:nth-child(2) {
    font-variant-numeric: tabular-nums;
    color: #1772d0;
    font-weight: 600;
}

.table-intro {
    font-size: 14px;
    color: #555;
    margin: 0 0 12px 0;
}

/* ---- Long-form article sections (SEO content) ---- */
.article {
    margin-top: 40px;
    max-width: 760px;
}
.article h2 {
    font-size: 20px;
    font-weight: 600;
    margin: 0 0 12px 0;
    color: #1a2540;
    letter-spacing: -0.01em;
}
.article h3 {
    font-size: 16px;
    font-weight: 600;
    margin: 22px 0 6px 0;
    color: #1a2540;
}
.article p {
    margin: 0 0 12px 0;
    color: #333;
    line-height: 1.6;
}
.article ul,
.article ol {
    margin: 0 0 14px 22px;
    padding: 0;
    color: #333;
    line-height: 1.7;
}
.article li { margin: 4px 0; }
.article code {
    background: #f1f3f7;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 13px;
    color: #c0392b;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.article a { color: #1772d0; }

.article .chart {
    margin: 18px 0 24px 0;
    padding: 14px;
    background: #fafbfc;
    border: 1px solid #ebedf0;
    border-radius: 10px;
    text-align: center;
}
.article .chart img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto 10px auto;
    border-radius: 4px;
}
.article .chart figcaption {
    font-size: 13px;
    color: #5a6473;
    line-height: 1.5;
    text-align: center;
    max-width: 620px;
    margin: 0 auto;
}

/* ---- Responsive ---- */
@media (max-width: 720px) {
    .apriltag-header {
        flex-direction: column;
        text-align: center;
        padding: 22px;
    }
    .apriltag-grid { grid-template-columns: 1fr; }
}

/* ---- Print ---- */
@media print {
    @page { size: A4; margin: 0; }

    html, body {
        background: #fff !important;
        margin: 0 !important;
        padding: 0 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    /* Hide everything by default */
    body * { visibility: hidden; }

    /* ---------- Mode A: queue empty -> print just the live preview ---------- */
    body:not(.has-queue) .preview-pane .marker,
    body:not(.has-queue) .preview-pane .marker *,
    body:not(.has-queue) .marker-id,
    body:not(.has-queue) .marker-id * {
        visibility: visible;
    }

    body:not(.has-queue) .preview-pane .marker {
        position: absolute !important;
        top: 10mm;
        left: 10mm;
        margin: 0 !important;
        padding: 0 !important;
        border: none !important;
        box-shadow: none !important;
        background: #fff !important;
        display: block !important;
    }

    body:not(.has-queue) .marker-id {
        display: block !important;
        position: absolute !important;
        bottom: 10mm;
        left: 0;
        right: 0;
        text-align: center;
        color: #000 !important;
        font-size: 12px;
    }

    /* ---------- Mode B: queue has tags -> print packed A4 pages ---------- */
    body.has-queue .print-pages,
    body.has-queue .print-pages * {
        visibility: visible;
    }

    body.has-queue .print-pages {
        position: absolute !important;
        top: 0;
        left: 0;
        right: 0;
        margin: 0 !important;
        padding: 0 !important;
        background: none !important;
        gap: 0 !important;
        display: block !important;
    }

    /* Each A4 page becomes one printed sheet */
    body.has-queue .print-page {
        width: 210mm !important;
        height: 297mm !important;
        margin: 0 !important;
        padding: 0 !important;
        border: none !important;
        box-shadow: none !important;
        page-break-after: always;
        break-after: page;
        overflow: hidden;
        background: #fff !important;
    }
    body.has-queue .print-page:last-child {
        page-break-after: auto;
        break-after: auto;
    }

    /* Don't allow a card to be split across pages (defensive) */
    body.has-queue .print-marker {
        page-break-inside: avoid;
        break-inside: avoid;
        background: #fff !important;
        border: 1px dashed #555 !important;
    }

    body.has-queue .remove-btn { display: none !important; }

    /* Make sure tag SVG is rendered fully */
    .marker table, .marker table tr, .marker table td {
        background-image: none;
    }
}
