/* Visual language matches control/css/editor.css (Inter, blue accent) —
   kept as its own copy rather than a cross-folder @import, same reasoning
   as control/: each tool under the repo root is a standalone static
   subsystem with its own deploy-independent assets. */

:root {
    --primary: #2f66f3;
    --primary-dark: #1f4fce;
    --text: #1b2430;
    --muted: #667085;
    --bg: #f5f7fb;
    --surface: #ffffff;
    --border: #e3e7ef;
    --border-strong: #cdd4e0;
    --shadow: 0 1px 3px rgba(20, 30, 60, 0.08);
    --r: 12px;
    --r-lg: 16px;
    --warn-bg: #fff6dd;
    --warn-border: #f0ddaa;
    --warn-text: #6b5410;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
    font-family: "Inter", system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

a { color: var(--primary); }

.ctrl-topbar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}
.ctrl-topbar h1 { font-size: 16px; margin: 0; }
.ctrl-topbar .ctrl-kicker { font-size: 12px; color: var(--muted); margin: 0 0 2px 0; }
.ctrl-topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.ctrl-databanner {
    flex: 0 0 auto;
    padding: 8px 24px;
    background: var(--warn-bg);
    border-bottom: 1px solid var(--warn-border);
    color: var(--warn-text);
    font-size: 12.5px;
    line-height: 1.4;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: var(--r);
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 13px;
    cursor: pointer;
    text-decoration: none;
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:disabled:hover { border-color: var(--border-strong); color: var(--text); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

.app-layout {
    flex: 1 1 auto;
    display: flex;
    min-height: 0;
}

#editor-column {
    flex: 0 0 460px;
    min-width: 320px;
    max-width: 60%;
    overflow-y: auto;
    padding: 20px 12px 40px 24px;
}

#preview-column {
    flex: 1 1 auto;
    min-width: 320px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 20px 24px 20px 12px;
}

@media (max-width: 980px) {
    .app-layout { flex-direction: column; }
    #editor-column, #preview-column { flex: 1 1 auto; max-width: 100%; padding: 16px; }
    /* Without a floor, the preview column collapses to whatever its content
       naturally needs — which, before a template loads, is just one line
       of placeholder text — since neither body nor .app-layout has a fixed
       height here to force the two stacked columns to split it. That left
       canvas-stage just tall enough for that placeholder line, so the
       fit-to-container math (computeFitDisplayScale in app.js) had almost
       no vertical room to work with and rendered the certificate at a
       tiny, barely-usable size on phones. */
    #canvas-stage { min-height: 60vh; }
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow);
    padding: 16px 18px;
    margin-bottom: 16px;
}
.panel h2 {
    font-size: 14px;
    margin: 0 0 12px 0;
}
.panel .muted { color: var(--muted); font-size: 12.5px; margin: 0 0 10px 0; }
.panel[data-disabled="true"] {
    opacity: 0.5;
    pointer-events: none;
}

/* Drag & drop of a template file onto the template panel or the preview
   canvas — same highlight class on both drop zones (see app.js), so the
   feedback and the actual load behavior can't drift apart. outline (not
   border) so it doesn't shift surrounding layout by a couple of pixels
   while dragging. */
.drop-target-active {
    outline: 2px dashed var(--primary);
    outline-offset: -2px;
    background: rgba(47, 102, 243, 0.06);
}

.field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 12px;
    font-size: 12.5px;
    color: var(--text);
    /* Grid/flex items default to min-width:auto, which for a field wrapping
       a form control resolves to that control's own intrinsic width (a
       number input's browser-default width, ~150-200px, regardless of its
       container) — without this, narrow layouts (phones, a squeezed
       .field-grid column) can't shrink it and content overflows to the
       right instead of wrapping. */
    min-width: 0;
}
.field label:first-child { font-weight: 500; }
.field input[type="text"],
.field input[type="number"],
.field select,
.field textarea {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    padding: 7px 10px;
    font: inherit;
    font-size: 13px;
    background: #fff;
}
.field textarea { resize: vertical; min-height: 120px; font-family: ui-monospace, monospace; }
.field input[type="file"] { font-size: 12.5px; max-width: 100%; }

.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.field-grid .field { margin-bottom: 0; }

.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* One canonical checkbox+label look, used for every checkbox in the app
   (autofit, bold, italic, field2-enable, ...). Previously these were built
   two different ways (a .field wrapping a separate <label for>, vs. a
   <label> wrapping the checkbox directly) which quietly rendered with
   different spacing/sizing — hard to notice individually, obvious once two
   are next to each other. Structure is always
   <label class="checkbox-row"><input type="checkbox">...text...</label>
   now, so there's only one thing to style. */
.checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 400;
    color: var(--text);
    cursor: pointer;
    user-select: none;
    line-height: 1.35;
}
.checkbox-row input[type="checkbox"] {
    flex: none;
    width: 16px;
    height: 16px;
    margin: 0;
    accent-color: var(--primary);
    cursor: pointer;
}

.segmented { display: flex; border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; min-width: 0; }
.segmented button {
    flex: 1;
    min-width: 0;
    padding: 6px 4px;
    border: none;
    background: #fff;
    font: inherit;
    font-size: 12px;
    cursor: pointer;
    border-right: 1px solid var(--border-strong);
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.segmented button:last-child { border-right: none; }
.segmented button.active { background: var(--primary); color: #fff; }

.names-summary {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin: 4px 0 10px 0;
    font-size: 13px;
}
.names-summary .count { font-weight: 700; color: var(--primary); font-size: 18px; }

.names-preview-list {
    max-height: 130px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 12px;
    background: #fafbfd;
}
.names-preview-list div {
    padding: 4px 10px;
    border-bottom: 1px solid var(--border);
}
.names-preview-list div:last-child { border-bottom: none; }
.names-preview-list div:nth-child(even) { background: #f2f4f9; }

.canvas-stage {
    /* Deliberately NOT flex+align-items/justify-content:center (the
       obvious way to center a smaller-than-container child): centering via
       flex alignment is well known to make browsers refuse to scroll to
       the "before" edge of a child once it overflows the container —  the
       start of the content becomes permanently unreachable. That's fatal
       for a zoomable canvas, where zooming in routinely makes the content
       bigger than the visible area in both directions. margin:auto on a
       plain block child (below) centers the same way when it fits, but
       degrades to ordinary scrollable overflow — reachable from every
       edge — once it doesn't. */
    position: relative;
    flex: 1 1 auto;
    background: #dfe3ea;
    border-radius: var(--r-lg);
    overflow: auto;
    min-height: 0;
    padding: 16px;
}
/* Only while the "choose a template" placeholder is showing (no canvas
   yet) do we want true centering — nothing can overflow a text prompt, so
   the flex-centering scroll trap this file otherwise avoids doesn't apply
   here. */
.canvas-stage:has(.canvas-empty) {
    display: flex;
    align-items: center;
    justify-content: center;
}
.canvas-wrap {
    display: block;
    width: max-content;
    margin: 0 auto;
    box-shadow: 0 2px 14px rgba(0, 0, 0, 0.18);
    background: #fff;
    line-height: 0;
}
/* No max-width/height:auto here — the canvas's CSS size is set precisely in
   JS (state.displayScale × state.zoom) to be exactly what should appear on
   screen; letting CSS additionally shrink it to fit would silently rescale
   the already-DPR-corrected bitmap a second time and reintroduce the exact
   blurriness that fix was for. Overflow at high zoom is handled by
   .canvas-stage's scrollbars instead of by shrinking the canvas. */
.canvas-wrap canvas { display: block; cursor: crosshair; }
.canvas-empty {
    color: var(--muted);
    font-size: 14px;
    text-align: center;
    padding: 40px;
}

.preview-toolbar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 10px 14px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
    flex-wrap: wrap;
}
.preview-toolbar .spacer { flex: 1 1 auto; }
.preview-toolbar .nav-pos { font-size: 13px; color: var(--muted); min-width: 90px; text-align: center; }

.zoom-controls { display: flex; align-items: center; gap: 2px; }
.zoom-controls .btn { padding: 5px 10px; }
.zoom-controls #zoom-reset-btn { min-width: 52px; }
#zoom-level { font-size: 12px; }

.progress-note { font-size: 12.5px; color: var(--muted); margin-top: 8px; }

@media print {
    body { display: none !important; }
}
