/* Same tokens as /logistic, /redirector and /split-bill so the tools read as
   one family. */
:root {
    --bg: #f4f5f7;
    --card-bg: #ffffff;
    --text: #1f2430;
    --muted: #6b7280;
    --border: #e2e4e9;
    --soft: #eef0f5;
    --primary: #3b5bdb;
    --primary-dark: #2f47ad;
    --danger: #d64545;
    --success: #2f9e44;
    --radius: 8px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

code {
    background: var(--soft);
    border-radius: 4px;
    padding: 1px 5px;
    font-size: 0.9em;
}

.topbar { background: var(--card-bg); border-bottom: 1px solid var(--border); }

.topbar-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
}

.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); }
.brand:hover { text-decoration: none; }

.topnav { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; }

.container { max-width: 1100px; margin: 0 auto; padding: 20px; }
.container-wide { max-width: 1320px; }

.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 24px;
    margin-bottom: 20px;
}

.card-form { max-width: 640px; margin-left: auto; margin-right: auto; }

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 16px;
}

.card-head h1, .card-head h2 { margin: 0; }

h1 { font-size: 1.4rem; margin-top: 0; }
h2 { font-size: 1.1rem; margin-top: 0; }

/* -------------------------------------------------------------- controls */

label {
    display: block;
    margin-bottom: 14px;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--muted);
}

label.checkbox { display: flex; align-items: center; gap: 8px; font-weight: 400; color: var(--text); }
label.checkbox input { width: auto; margin-top: 0; }

.opt { font-weight: 400; font-size: 0.85em; }

.field { margin-bottom: 14px; }
.field-label { margin-bottom: 6px; font-size: 0.9rem; font-weight: 600; color: var(--muted); }

input[type=text], input[type=number], input[type=file], select, textarea {
    display: block;
    width: 100%;
    margin-top: 4px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    /* 16px, so tapping a field on iOS never zooms the page. */
    font-size: 16px;
    font-family: inherit;
    color: var(--text);
    background: #fff;
}

input[type=color] {
    display: block;
    width: 100%;
    height: 36px;
    margin-top: 4px;
    padding: 2px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
}

textarea { resize: vertical; }

input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--primary);
    outline-offset: -1px;
    border-color: var(--primary);
}

.btn, button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    background: #fff;
    color: var(--text);
    border: 1px solid var(--border);
    padding: 7px 12px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    font-family: inherit;
    line-height: 1.3;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
}

.btn:hover, button:hover { background: var(--soft); text-decoration: none; }

button, .btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
button:hover, .btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }

button.btn { background: #fff; color: var(--text); border-color: var(--border); }
button.btn:hover { background: var(--soft); }

button.danger { background: #fff; color: var(--danger); border-color: #f3c3c3; }
button.danger:hover { background: #fdecec; }

button[disabled], .btn[disabled] { opacity: 0.55; cursor: not-allowed; }

.btn-big { padding: 10px 18px; font-size: 0.95rem; }

.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.mt { margin-top: 20px; }

.inline-form { display: inline-flex; gap: 6px; margin: 0; align-items: center; }

.flash {
    padding: 10px 14px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 0.9rem;
}
.flash-error { background: #fdecec; color: #a12a2a; border: 1px solid #f3c3c3; }
.flash-success { background: #eaf7ec; color: #1f7a34; border: 1px solid #c3e6cb; }
.flash-warn { background: #fdf6e3; color: #7a5c00; border: 1px solid #eadaa8; }

.error-list { margin: 0; padding-left: 18px; }

.hint { color: var(--muted); font-size: 0.85rem; margin: 10px 0 0; }
.empty { color: var(--muted); }
.muted-note { color: var(--muted); font-size: 0.85rem; font-weight: 400; }

.pill {
    display: inline-block;
    border-radius: 999px;
    padding: 1px 9px;
    font-size: 0.74rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    vertical-align: middle;
    background: var(--soft);
    color: var(--muted);
}

.table-wrap { overflow-x: auto; }

.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }

.data-table th, .data-table td {
    text-align: left;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    white-space: nowrap;
}

.data-table th { color: var(--muted); font-weight: 600; }
.data-table th.num, .data-table td.num { text-align: right; }
.data-table td.cell-actions .actions { flex-wrap: nowrap; }
.row-off td { opacity: 0.6; }

/* The artwork in the templates table, small enough to scan a list by. */
.thumb-cell { width: 132px; }

.thumb {
    display: block;
    width: 116px;
    height: 62px;
    object-fit: contain;
    object-position: left center;
    background: var(--soft);
    border: 1px solid var(--border);
    border-radius: 4px;
}

/* ------------------------------------------------------------- gallery */

.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
}

.tpl-card {
    display: flex;
    flex-direction: column;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    color: inherit;
}

.tpl-card:hover { border-color: var(--primary); text-decoration: none; }

.tpl-shot {
    display: block;
    width: 100%;
    aspect-ratio: 5 / 3;
    object-fit: contain;
    background: var(--soft);
    border-bottom: 1px solid var(--border);
}

.tpl-body { padding: 12px 14px; }
.tpl-body strong { display: block; }
.tpl-body .muted-note { margin-top: 2px; }

.tpl-keys { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 4px; }

/* --------------------------------------------------------- the designer */

/* Artwork on the left, the field being set up on the right; one under the
   other once the screen is too narrow to keep the canvas usable. */
.designer {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 380px;
    gap: 20px;
    align-items: start;
}

@media (max-width: 1000px) {
    .designer { grid-template-columns: minmax(0, 1fr); }
}

.stage {
    position: sticky;
    top: 16px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
}

@media (max-width: 1000px) {
    .stage { position: static; }
}

.stage canvas {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 4px;
    /* Checkerboard, so transparent artwork does not look like white artwork. */
    background-color: #fff;
    background-image:
        linear-gradient(45deg, #eceef3 25%, transparent 25%, transparent 75%, #eceef3 75%),
        linear-gradient(45deg, #eceef3 25%, transparent 25%, transparent 75%, #eceef3 75%);
    background-size: 18px 18px;
    background-position: 0 0, 9px 9px;
    cursor: grab;
    /* The browser must not take the drag as a scroll or a pinch. */
    touch-action: none;
}

.stage canvas.is-dragging { cursor: grabbing; }

.stage-note {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    margin: 10px 2px 0;
    color: var(--muted);
    font-size: 0.82rem;
}

.stage-note b { color: var(--text); font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------ the fields */

.field-rows { display: flex; flex-direction: column; gap: 10px; }

.field-row {
    border: 1px solid var(--border);
    border-left: 4px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
    padding: 10px 12px;
}

.field-row.is-selected { border-color: var(--primary); background: #f7f9ff; }

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

.row-head .row-no {
    width: 22px;
    height: 22px;
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--soft);
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 700;
}

.field-row.is-selected .row-no { background: var(--primary); color: #fff; }

.row-head input[type=text] { flex: 1; margin-top: 0; }

.row-head .btn { padding: 5px 8px; }

/* Every knob for one field: a caption over a control, wrapped into whatever
   width the panel has. */
.knobs {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
    gap: 8px;
    margin-top: 10px;
}

.knob { min-width: 0; margin-bottom: 0; }

.knob > span {
    display: block;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--muted);
}

.knob input, .knob select {
    margin-top: 2px;
    padding: 5px 6px;
    font-size: 0.85rem;
}

.knob-wide { grid-column: 1 / -1; }

.knob-check {
    display: flex;
    margin-bottom: 0;
    align-items: flex-end;
    gap: 6px;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--muted);
    padding-bottom: 6px;
}

.knob-check input { width: auto; margin: 0; }

.row-key {
    margin-top: 8px;
    font-size: 0.78rem;
    color: var(--muted);
}

/* --------------------------------------------------------- the generator */

.maker {
    display: grid;
    grid-template-columns: 340px minmax(0, 1fr);
    gap: 20px;
    align-items: start;
}

@media (max-width: 900px) {
    .maker { grid-template-columns: minmax(0, 1fr); }
}

.maker-form { margin-bottom: 0; }

.maker-preview {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
}

.maker-preview canvas {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 4px;
    background: #fff;
}

.preview-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
    margin-top: 12px;
}

.busy { color: var(--muted); font-size: 0.85rem; }

@media (max-width: 640px) {
    .container { padding: 14px; }
    .card { padding: 16px; }
    .designer, .maker { gap: 14px; }
}
