/* Envelope & Postcard Addressing. Wide screens: the form on the left, the bar (count + Download) and the live
   preview on the right, sticky. Below 900 px: Edit / Preview tabs and a fixed bottom bar. */
.env-wrap { max-width: 1240px; margin: 0 auto; padding: 96px 16px 48px; color: var(--text-primary); box-sizing: border-box;
  --env-accent: var(--color-primary, #6366f1); --env-warn: var(--color-warning, #f59e0b); --env-ok: #4ade80; --env-bad: #f43f5e; --env-info: #60a5fa; }
:root[data-theme="light"] .env-wrap { --env-accent: #4f46e5; --env-warn: #b45309; --env-ok: #15803d; --env-bad: #e11d48; --env-info: #1d4ed8; }
.env-wrap *, .env-wrap *::before, .env-wrap *::after { box-sizing: border-box; }
.env-wrap [hidden] { display: none !important; }
.env-intro h1 { font-size: clamp(1.6rem, 4vw, 2.4rem); margin: 0 0 8px; }
.env-intro p { color: var(--text-secondary); margin: 0 0 16px; max-width: 70ch; }
.env-file { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.env-grid { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); min-width: 0; }
.env-form { display: grid; gap: 16px; min-width: 0; margin: 0; }
.env-side { display: grid; gap: 12px; min-width: 0; align-content: start; }

.env-card { background: var(--bg-secondary); border: 1px solid var(--border-color); border-radius: 12px; padding: 16px; display: grid; gap: 12px; min-width: 0; }
.env-card h2 { font-size: 1.1rem; margin: 0; }
.env-field { display: grid; gap: 4px; min-width: 0; }
.env-label { font-weight: 600; font-size: 0.9rem; color: var(--text-secondary); }
.env-req { font-weight: 500; font-size: 0.78rem; color: var(--env-accent); }
.env-input { width: 100%; max-width: 100%; min-width: 0; padding: 9px 10px; border-radius: 8px; border: 1px solid var(--border-color);
  background: var(--bg-primary); color: var(--text-primary); font: inherit; font-size: 16px; min-height: 44px; }
textarea.env-input { resize: vertical; line-height: 1.4; }
.env-input:focus-visible { outline: 2px solid var(--env-accent); outline-offset: 1px; }
.env-input.is-bad { border-color: var(--env-bad); box-shadow: 0 0 0 1px var(--env-bad); }
.env-row2 { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 560px) { .env-row2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }
.env-row-name { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr) 120px; align-items: end; }
.env-row-name:has(> .env-hon[hidden]) { grid-template-columns: minmax(0, 1fr); }
.env-hint { color: var(--text-secondary); font-size: 0.88rem; margin: 0; overflow-wrap: anywhere; }
.env-hint--info { color: var(--env-info); }
.env-msg { margin: 0; font-weight: 600; color: var(--env-warn); overflow-wrap: anywhere; font-size: 0.92rem; }
.env-msg--ok { color: var(--env-ok); }
.env-msg:empty { display: none; }
.env-check { display: flex; align-items: center; gap: 8px; font-weight: 600; cursor: pointer; min-height: 44px; }
.env-check input { width: 20px; height: 20px; accent-color: var(--env-accent); margin: 0; flex: 0 0 auto; }
.env-check input:disabled + span { opacity: 0.5; }
.env-remember { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; border-top: 1px solid var(--border-color); padding-top: 8px; }
.env-link { background: none; border: 0; padding: 8px 4px; color: var(--env-accent); font: inherit; font-weight: 600; text-decoration: underline; cursor: pointer; min-height: 44px; }

.env-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border-color); background: var(--bg-primary);
  color: var(--text-primary); border-radius: 10px; padding: 9px 16px; cursor: pointer; font: inherit; font-weight: 600; line-height: 1.2; min-height: 44px; }
.env-btn:hover:not(:disabled) { border-color: var(--env-accent); }
.env-btn--primary { background: var(--env-accent); border-color: var(--env-accent); color: #fff; }
.env-btn--primary:hover:not(:disabled) { background: var(--color-primary-active, #4f46e5); }
.env-btn--quiet { background: transparent; color: var(--text-secondary); }
.env-btn--small { min-height: 40px; padding: 6px 12px; font-size: 0.92rem; }
.env-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.env-btn:focus-visible, .env-icon:focus-visible, .env-link:focus-visible { outline: 2px solid var(--env-accent); outline-offset: 2px; }
#envAddRow { justify-self: start; }
.env-reset { display: flex; justify-content: flex-start; }

/* bar: total + Download */
.env-bar { display: grid; gap: 6px; padding: 12px 16px; border-radius: 12px; background: var(--bg-secondary); border: 1px solid var(--border-color);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18); min-width: 0; }
.env-bar-row { display: flex; align-items: center; gap: 12px; min-width: 0; }
.env-sum { display: grid; min-width: 0; flex: 1 1 auto; }
.env-sum-label { font-size: 0.8rem; color: var(--text-secondary); font-weight: 600; }
.env-sum-amt { font-size: 1.25rem; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.env-bar .env-btn--primary { flex: 0 0 auto; }

/* preview */
.env-preview { display: grid; gap: 8px; min-width: 0; }
.env-preview-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.env-preview-head h2 { font-size: 1rem; margin: 0; color: var(--text-secondary); }
.env-pagesel { width: auto; min-height: 40px; }
.env-sheet { position: relative; min-width: 0; display: grid; justify-items: center; }
#envCanvas { display: block; max-width: 100%; background: #fff; box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3); border-radius: 2px; }
#envCanvas[width="300"][height="150"] { width: 100%; aspect-ratio: 1 / 1.414; height: auto; }
.env-badge { position: absolute; top: 8px; right: 8px; padding: 4px 10px; border-radius: 999px; font-size: 0.8rem; font-weight: 600;
  background: rgba(15, 23, 42, 0.75); color: #fff; pointer-events: none; }

/* tabs (phone only) */
.env-tabs { display: none; }

@media (min-width: 900px) {
  .env-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
  .env-side { position: sticky; top: 80px; }
}
@media (max-width: 899px) {
  .env-wrap { padding-bottom: 160px; }
  .env-tabs { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--border-color); border-radius: 10px; overflow: hidden;
    background: var(--bg-secondary); margin-bottom: 12px; position: sticky; top: 68px; z-index: 4; }
  .env-tabs button { border: 0; background: transparent; color: var(--text-primary); font: inherit; font-weight: 600; padding: 8px 6px; cursor: pointer; min-height: 44px; }
  .env-tabs button + button { border-left: 1px solid var(--border-color); }
  .env-tabs button[aria-selected="true"] { background: var(--env-accent); color: #fff; }
  .env-wrap[data-view="edit"] .env-preview { display: none; }
  .env-wrap[data-view="preview"] .env-form { display: none; }
  .env-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; border-radius: 12px 12px 0 0; border-bottom: 0;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); max-height: 50vh; overflow-y: auto; }
}

.img-foot { text-align: center; padding: 24px 16px; font-size: 0.875rem; }
.img-foot a { color: var(--text-secondary); }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
@media (max-width: 899px) { .img-foot { padding-bottom: 150px; } .env-wrap { padding-bottom: 24px; } }
@media print { .nav, .img-foot, .env-bar, .env-tabs { display: none; } }

/* addressing */
.env-fields { display: grid; gap: 12px; min-width: 0; }
.env-btns { display: flex; flex-wrap: wrap; gap: 8px; }
.env-card h3 { font-size: 1rem; margin: 0; }
.env-card--note .env-note { margin: 0; color: var(--text-secondary); }
.env-many { display: grid; gap: 10px; padding: 12px; border-radius: 10px; border: 1px dashed var(--border-color); min-width: 0; }
.env-matcher { display: grid; gap: 10px; min-width: 0; }
.env-map { display: grid; gap: 10px; grid-template-columns: minmax(0, 1fr); min-width: 0; }
@media (min-width: 560px) { .env-map { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }
.env-map-item { display: grid; gap: 4px; min-width: 0; padding: 8px; border-radius: 8px; background: var(--bg-primary); border: 1px solid var(--border-color); }
.env-map-sample { font-size: 0.85rem; color: var(--text-secondary); overflow-wrap: anywhere; min-height: 1.3em; }
.env-list { display: grid; gap: 8px; min-width: 0; border-top: 1px solid var(--border-color); padding-top: 8px; }
.env-list-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.env-rows { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: 360px; overflow-y: auto; min-width: 0; }
.env-row { display: grid; grid-template-columns: minmax(0, 1fr) 40px; gap: 6px; align-items: stretch; min-width: 0; }
.env-row-main { display: grid; gap: 2px; text-align: left; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border-color); background: var(--bg-primary);
  color: var(--text-primary); font: inherit; cursor: pointer; min-height: 44px; min-width: 0; }
.env-row.is-selected .env-row-main { border-color: var(--env-accent); box-shadow: 0 0 0 1px var(--env-accent); }
.env-row-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.env-row-status { font-size: 0.85rem; color: var(--env-ok); overflow-wrap: anywhere; }
.env-row.is-warn .env-row-status { color: var(--env-warn); }
.env-row.is-error .env-row-status { color: var(--env-bad); font-weight: 600; }
.env-row.is-pending .env-row-status { color: var(--text-secondary); }
.env-row .env-icon { height: auto; min-height: 44px; }
.env-blocked { display: grid; gap: 4px; min-width: 0; }
.env-blocked-list { margin: 0; padding-left: 1.2em; color: var(--env-bad); font-size: 0.9rem; max-height: 160px; overflow-y: auto; overflow-wrap: anywhere; }
.env-icon { width: 40px; height: 40px; border-radius: 8px; border: 1px solid var(--border-color); background: var(--bg-secondary); color: var(--text-primary);
  font: 700 18px/1 system-ui, sans-serif; cursor: pointer; display: inline-grid; place-items: center; padding: 0; }
.env-icon:hover { border-color: var(--env-bad); color: var(--env-bad); }
.env-empty { margin: 0; padding: 48px 16px; text-align: center; color: var(--text-secondary); border: 1px dashed var(--border-color); border-radius: 8px; width: 100%; }
.env-sum-amt { font-size: 1.1rem; }
