/* CIG v2 print + screen styles. Mirror the readable cadence of the v1 PDF. */

:root {
    --body-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
                 Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
    --mono-font: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    --ink:        #111;
    --ink-soft:   #333;
    --rule:       #ddd;
    --accent:     #0077b6;
    --max-width:  8.0in;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: var(--body-font);
    color: var(--ink);
    font-size: 11.5pt;
    line-height: 1.45;
}

body {
    background: #eee;
    padding: 0;
}

.guide {
    background: #fff;
    margin: 0 auto;
    max-width: var(--max-width);
    padding: 0.75in 0.85in;
    box-shadow: 0 2px 10px rgba(0,0,0,0.12);
}

.guide-section {
    page-break-inside: auto;
}

.guide-section h1 {
    font-size: 22pt;
    margin: 0.3em 0 0.4em;
    color: var(--ink);
}
.guide-section h2 {
    font-size: 16pt;
    margin: 1em 0 0.3em;
}
.guide-section h3 { font-size: 13pt; }

.guide-section p { margin: 0.35em 0; }
.guide-section ul, .guide-section ol { margin: 0.35em 0 0.5em 0; padding-left: 1.5em; }
.guide-section img { max-width: 100%; height: auto; }
.guide-section a { color: #1561a8; }

/* v1 used a pagebreak marker embedded in body HTML. We support both:
   (a) our own .pagebreak divs emitted between sections by guide.php
   (b) the legacy <div class="pagebreak"/> markup, preserved for parity */
.pagebreak {
    page-break-after: always;
    break-after: page;
    border: 0;
    margin: 0;
    height: 0;
}

/* Debug helpers - never printed */
.no-print { }
@media print {
    body { background: #fff; padding: 0; }
    .guide { box-shadow: none; margin: 0; padding: 0; max-width: none; }
    .no-print { display: none !important; }
}

/* ── Engineer input form ─────────────────────────────────────────── */
.cig-form-wrap {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 1em 1.5em;
}

/* Sticky header */
.form-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1em;
    background: #fff;
    border-radius: 0 0 8px 8px;
    padding: .45em 1em;
    margin-bottom: .5em;
    box-shadow: 0 2px 8px rgba(0,0,0,.08);
    position: sticky;
    top: 0;
    z-index: 100;
}
.form-header-title h1 {
    font-size: 14pt;
    margin: 0;
    color: var(--accent);
}
.form-header-title p {
    font-size: 8pt;
    color: #777;
    margin: .05em 0 0;
}
.req-mark { color: #c0392b; font-weight: 700; }

.btn-generate {
    background: var(--accent);
    color: #fff;
    border: 0;
    padding: .6em 1.4em;
    border-radius: 6px;
    font-size: 11pt;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: opacity .15s;
}
.btn-generate:hover { opacity: .88; }

/* Two-column group grid */
.groups-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .75em;
    align-items: start;
}
@media (max-width: 700px) {
    .groups-grid { grid-template-columns: 1fr; }
}

/* Group cards */
.group-card {
    background: #fff;
    border-radius: 8px;
    padding: .8em 1em 1em;
    box-shadow: 0 1px 5px rgba(0,0,0,.07);
}
.group-card.span-full {
    grid-column: 1 / -1;
}
.group-title {
    font-size: 10pt;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--accent);
    margin: 0 0 .6em;
    padding-bottom: .3em;
    border-bottom: 2px solid var(--accent);
}

/* Field grid inside each card */
.fields-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: .5em .75em;
    align-items: start;
}
.fields-grid--assets {
    grid-template-columns: 1fr 1fr;
}

/* Individual field */
.field { display: flex; flex-direction: column; }
.field--wide { grid-column: 1 / -1; }
.field[style*="display:none"],
.field.field--hidden { display: none !important; }

.field label {
    font-size: 8.5pt;
    font-weight: 600;
    color: #444;
    margin-bottom: .2em;
    line-height: 1.2;
}
.field input[type="text"],
.field input[type="number"],
.field select,
.field textarea {
    width: 100%;
    padding: .35em .5em;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-family: inherit;
    font-size: 9.5pt;
    background: #fafafa;
    transition: border-color .15s;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
    outline: none;
    border-color: var(--accent);
    background: #fff;
}
.field textarea { resize: vertical; min-height: 3em; }
.field .hint {
    font-size: 8pt;
    color: #999;
    margin: .15em 0 0;
    line-height: 1.2;
}

/* Asset upload widget */
.asset-upload-widget { display: flex; flex-wrap: wrap; gap: .4em; align-items: center; }
.asset-upload-widget .asset-url-input { flex: 1; min-width: 120px; font-size: 8.5pt; }
.upload-btn {
    display: inline-flex;
    align-items: center;
    gap: .25em;
    background: var(--accent);
    color: #fff;
    padding: .3em .7em;
    border-radius: 4px;
    cursor: pointer;
    font-size: 8.5pt;
    font-weight: 600;
    white-space: nowrap;
}
.upload-btn:hover { opacity: .85; }
.upload-status { font-size: 8pt; color: #666; width: 100%; }
.asset-preview {
    display: block;
    max-width: 100%;
    max-height: 80px;
    margin-top: .35em;
    border: 1px solid #ddd;
    border-radius: 4px;
}

/* Subsection headings inside group cards */
.subsection-title {
    font-size: 9pt;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--accent);
    margin: 0;
}

/* Required fields subsection (always visible) */
.general-required-subsection {
    margin-top: .75em;
    border-top: 2px solid var(--accent);
    padding-top: .5em;
}
.general-required-subsection .fields-grid { margin-top: .4em; }

/* Additional fields collapsible subsection */
.general-subsection {
    margin-top: .6em;
    border-top: 1px solid #ddd;
    padding-top: .45em;
}
.general-subsection > summary {
    cursor: pointer;
    user-select: none;
    list-style: none;
    display: flex;
    align-items: center;
    gap: .4em;
}
.general-subsection > summary::before {
    content: '▶';
    font-size: 7pt;
    color: #888;
    transition: transform .15s;
    flex-shrink: 0;
}
.general-subsection[open] > summary::before { transform: rotate(90deg); }
.general-subsection > summary::-webkit-details-marker { display: none; }
.subsection-title--toggle { color: #555; }
.general-subsection .fields-grid { margin-top: .5em; }

/* Form footer */
.form-footer {
    display: flex;
    justify-content: flex-end;
    margin-top: .75em;
}

/* Debug warnings */
.debug-warnings {
    max-width: var(--max-width);
    margin: 1em auto;
    padding: .75em 1em;
    background: #fff7d6;
    border: 1px solid #e3c95c;
    border-radius: 4px;
    font-family: var(--mono-font);
    font-size: 10pt;
}

/* ── Guide section edit button ───────────────────────────────────── */
.guide-section { position: relative; }
.section-edit-btn {
    position: absolute;
    top: .4em;
    right: .3em;
    display: inline-flex;
    align-items: center;
    gap: .2em;
    font-size: 8pt;
    font-weight: 600;
    color: var(--accent);
    background: rgba(0,119,182,.08);
    border: 1px solid rgba(0,119,182,.25);
    border-radius: 4px;
    padding: .15em .55em;
    text-decoration: none;
    opacity: 0;
    transition: opacity .15s, background .15s;
    white-space: nowrap;
}
.guide-section:hover .section-edit-btn { opacity: 1; }
.section-edit-btn:hover {
    background: rgba(0,119,182,.18);
    color: var(--accent);
}

/* ── Editor page ─────────────────────────────────────────────────── */
.editor-wrap {
    max-width: 1000px;
    margin: 0 auto;
    padding: 1em 1.2em 3em;
    background: #fff;
}
.editor-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1em;
    margin-bottom: 1.2em;
    padding-bottom: .6em;
    border-bottom: 2px solid var(--accent);
}
.editor-header h1 {
    font-size: 15pt;
    margin: 0;
    color: var(--accent);
}
.editor-meta {
    font-size: 8.5pt;
    color: #777;
    margin: .2em 0 1em;
}
.editor-meta code {
    background: #f0f0f0;
    padding: .1em .3em;
    border-radius: 3px;
    font-size: 8pt;
}
.editor-field { margin-bottom: .9em; }
.editor-field label {
    display: block;
    font-size: 8.5pt;
    font-weight: 700;
    color: #444;
    margin-bottom: .25em;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.editor-field input[type=text] {
    width: 100%;
    padding: .4em .55em;
    border: 1px solid #ccc;
    border-radius: 5px;
    font-size: 10pt;
    font-family: inherit;
    background: #fafafa;
    transition: border-color .15s;
}
.editor-field input[type=text]:focus {
    outline: none;
    border-color: var(--accent);
    background: #fff;
}
.editor-field textarea {
    width: 100%;
    padding: .4em .55em;
    border: 1px solid #ccc;
    border-radius: 5px;
    font-size: 9.5pt;
    font-family: inherit;
    background: #fafafa;
    resize: vertical;
    min-height: 4em;
    transition: border-color .15s;
}
.editor-field textarea:focus {
    outline: none;
    border-color: var(--accent);
    background: #fff;
}
.btn-save {
    background: var(--accent);
    color: #fff;
    border: 0;
    padding: .55em 1.5em;
    border-radius: 6px;
    font-size: 10.5pt;
    font-weight: 600;
    cursor: pointer;
    transition: opacity .15s;
}
.btn-save:hover { opacity: .88; }
.editor-actions {
    display: flex;
    align-items: center;
    gap: .75em;
    margin-top: .6em;
}
.btn-back {
    font-size: 9pt;
    color: #666;
    text-decoration: none;
    padding: .45em .9em;
    border: 1px solid #ddd;
    border-radius: 5px;
    background: #fff;
    transition: border-color .15s;
}
.btn-back:hover { border-color: #aaa; color: #333; }
.saved-notice {
    font-size: 9pt;
    color: #1a7a3c;
    background: #e6f7ee;
    border: 1px solid #a3d9b8;
    border-radius: 4px;
    padding: .3em .8em;
}
.editor-history {
    margin-top: 2em;
    border-top: 1px solid #e0e0e0;
    padding-top: 1em;
}
.editor-history h2 {
    font-size: 11pt;
    color: #555;
    margin: 0 0 .6em;
    text-transform: uppercase;
    letter-spacing: .05em;
}
.editor-history table {
    width: 100%;
    border-collapse: collapse;
    font-size: 9pt;
}
.editor-history th {
    text-align: left;
    padding: .3em .5em;
    border-bottom: 2px solid #e0e0e0;
    color: #555;
    font-weight: 700;
    font-size: 8pt;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.editor-history td {
    padding: .3em .5em;
    border-bottom: 1px solid #f0f0f0;
    vertical-align: middle;
}
.editor-history tr:hover td { background: #fafafa; }
.btn-restore {
    font-size: 8pt;
    color: var(--accent);
    background: rgba(0,119,182,.07);
    border: 1px solid rgba(0,119,182,.3);
    border-radius: 4px;
    padding: .2em .6em;
    cursor: pointer;
    transition: background .15s;
}
.btn-restore:hover { background: rgba(0,119,182,.16); }
