* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    display: flex; flex-direction: column;
    min-height: 100vh; min-height: 100dvh;   /* dvh: no jump when Android URL bar hides */
    background: #fff; color: #111;
    touch-action: manipulation;              /* kills 300ms tap delay + double-tap zoom on buttons */
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}
.viewport { padding: 12px 14px 4px; display: flex; flex-direction: column; gap: 10px; }
.template-toggles { display: flex; gap: 8px; overflow-x: auto; }
.chip {
    padding: 10px 18px; border-radius: 999px; border: 2px solid #111;
    background: #fff; color: #111; font-size: 16px; font-weight: 700; white-space: nowrap;
}
/* #047857 on white text = 5.5:1 contrast. The original #25D366 was ~2:1, unreadable in sunlight. */
.chip.active { background: #047857; border-color: #047857; color: #fff; }
.field {
    width: 100%; padding: 12px 14px; font-size: 26px; font-weight: 700; letter-spacing: .5px;
    border: 3px solid #a1a1aa; border-radius: 10px; background: #fff; color: #111; outline: none;
    caret-color: transparent;
}
.field::placeholder { color: #71717a; font-weight: 500; font-size: 20px; }
.field.is-active { border-color: #047857; box-shadow: 0 0 0 3px rgba(4,120,87,.25); }
.field[hidden] { display: none; }
.msg { min-height: 1.3em; font-size: 15px; font-weight: 600; color: #b91c1c; }
.keypad {
    margin-top: auto; padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    border-top: 2px solid #e4e4e7;
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
}
.key {
    min-height: clamp(48px, 8.5dvh, 72px);
    font-size: 28px; font-weight: 700; color: #111;
    border: 2px solid #d4d4d8; background: #f4f4f5; border-radius: 10px;
}
.key:active { background: #d4d4d8; }
.key:disabled { opacity: .35; }
.key.action { background: #fee2e2; border-color: #fca5a5; color: #991b1b; font-size: 20px; }
.btn-primary {
    grid-column: span 3; min-height: clamp(52px, 9dvh, 72px);
    background: #047857; color: #fff; font-size: 24px; font-weight: 800;
    border: none; border-radius: 10px; margin-top: 4px;
}
.btn-primary:active { background: #065f46; }
.donate-link { grid-column: span 3; text-align: center; padding: 6px; color: #52525b; text-decoration: none; font-size: 14px; }

/* ---- Clarity pass: purpose line, labelled chips, live preview, guiding button ---- */
.viewport { gap: 8px; padding-top: 10px; }
.hero-title { font-size: 17px; font-weight: 800; }
.hero-trust { display: flex; align-items: center; gap: 5px; font-size: 12.5px; color: #047857; font-weight: 600; margin-top: 2px; }
.template-toggles { gap: 6px; }
.chip { display: flex; align-items: center; gap: 4px; padding: 6px 8px 6px 6px; border-radius: 14px; flex: 1 1 auto; text-align: left; }
.chip svg { width: 18px; height: 18px; flex: none; }
.chip-text { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.chip-text b { font-size: 15px; }
.chip-text small { font-size: 10.5px; font-weight: 600; opacity: .85; white-space: nowrap; }
.field { padding: 9px 12px; font-size: 24px; }
.field::placeholder { font-size: 18px; }
.msg:empty { display: none; }
.preview-label { font-size: 12px; font-weight: 700; color: #52525b; text-transform: uppercase; letter-spacing: .4px; margin-bottom: 4px; }
.bubble {
    background: #dcfce7; border: 1px solid #bbf7d0; border-radius: 12px 12px 12px 3px;
    padding: 8px 11px; font-size: 14px; line-height: 1.35; color: #14532d;
}
.keypad { gap: 6px; padding-top: 8px; padding-bottom: calc(6px + env(safe-area-inset-bottom)); }
.key { min-height: clamp(44px, 7.4dvh, 68px); font-size: 26px; }
.btn-primary {
    display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.15;
    background: #e4e4e7; color: #3f3f46; font-size: 19px; margin-top: 2px;
    min-height: clamp(52px, 8.6dvh, 72px);
}
.btn-primary small { font-size: 14px; font-weight: 700; opacity: .95; }
.btn-primary small:empty { display: none; }
.btn-primary.ready { background: #047857; color: #fff; font-size: 23px; }
.btn-primary:active { background: #d4d4d8; }
.btn-primary.ready:active { background: #065f46; }
.donate-link { padding: 3px; font-size: 13px; }

/* ---- Template editor ---- */
.preview-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.preview-head .preview-label { margin-bottom: 0; }
.custom-tag { text-transform: none; letter-spacing: 0; font-weight: 700; color: #047857; background: #d1fae5; border-radius: 6px; padding: 1px 6px; margin-left: 4px; }
.custom-tag[hidden], .edit-btn[hidden], .bubble[hidden], .editor[hidden] { display: none; }
.edit-btn {
    display: flex; align-items: center; gap: 4px; flex: none;
    font-size: 14px; font-weight: 700; color: #047857; background: #fff;
    border: 2px solid #047857; border-radius: 8px; padding: 3px 9px;
}
.editor-text {
    width: 100%; font: inherit; font-size: 16px; line-height: 1.4; color: #111;
    border: 3px solid #047857; border-radius: 10px; padding: 9px 11px; resize: none;
    user-select: text; -webkit-user-select: text;
}
.editor-hint { font-size: 13px; color: #3f3f46; margin: 6px 0 8px; }
.editor-actions { display: flex; gap: 8px; }
.editor-actions button { min-height: 48px; border-radius: 10px; font-size: 15px; font-weight: 700; }
.btn-ghost { flex: 1; background: #fff; color: #3f3f46; border: 2px solid #a1a1aa; }
.btn-save { flex: 1.3; background: #047857; color: #fff; border: none; font-size: 18px !important; }
body.editing .keypad { display: none; }
/* keep the main screen within 640px even with a long custom message */
.viewport { gap: 6px; }
.edit-btn { padding: 1px 8px; font-size: 13px; border-width: 1.5px; }
.bubble { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; }
.preview-label { line-height: 1.2; }
.custom-tag { font-size: 11px; padding: 0 5px; }
.key { min-height: clamp(44px, 7.1dvh, 68px); }

/* ---- Proof-of-delivery photo ---- */
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
body.has-recent .hero-title { display: none; }          /* courier already knows the app by now; frees room */
.proof-bar {
    display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
    background: #fffbeb; color: #78350f; border: 2px solid #f59e0b; border-radius: 10px; padding: 6px 12px;
    font-size: 16px; font-weight: 800;
}
.proof-bar[hidden] { display: none; }
.proof-bar-text { flex: 1; display: flex; flex-direction: column; line-height: 1.15; }
.proof-bar-text small { font-size: 13px; font-weight: 700; color: #92400e; }
body.proofing .viewport, body.proofing .keypad { display: none; }
.proof { padding: 12px 14px 20px; display: flex; flex-direction: column; gap: 8px; }
.proof[hidden] { display: none; }
.proof-head { display: flex; align-items: center; justify-content: space-between; font-size: 19px; }
.proof-close { background: #fff; border: 2px solid #a1a1aa; border-radius: 8px; padding: 6px 10px; font-size: 15px; font-weight: 700; color: #3f3f46; }
.proof-label { font-size: 13px; font-weight: 800; color: #3f3f46; margin-top: 2px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg-btn {
    padding: 9px 12px; border-radius: 999px; border: 2px solid #a1a1aa; background: #fff;
    color: #111; font-size: 15px; font-weight: 700;
}
.seg-btn.active { background: #047857; border-color: #047857; color: #fff; }
.cam-btn {
    display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 64px;
    border: 3px dashed #047857; border-radius: 12px; color: #047857; background: #ecfdf5;
    font-size: 20px; font-weight: 800;
}
.proof-img { width: 100%; max-height: 34dvh; object-fit: contain; border-radius: 10px; background: #18181b; }
.proof-img[hidden] { display: none; }
.proof-caption { -webkit-line-clamp: 4; }
.proof .btn-primary { margin-top: 4px; }
.proof-hint { font-size: 14px; font-weight: 700; color: #047857; text-align: center; }
.proof-hint:empty { display: none; }
/* fit: after the first send the hero has done its job; bar is one compact line */
body.has-recent .hero { display: none; }
.proof-bar { padding: 4px 10px; min-height: 42px; font-size: 15px; }
.proof-bar-text { flex-direction: row; align-items: baseline; gap: 6px; flex-wrap: wrap; }
/* photo screen: the send button is always visible at the bottom; the rest scrolls */
.proof { min-height: 100dvh; padding-bottom: 0; }
.proof-footer { position: sticky; bottom: 0; margin: auto -14px 0; padding: 8px 14px calc(10px + env(safe-area-inset-bottom)); background: #fff; border-top: 2px solid #e4e4e7; }
.proof-img { max-height: 30dvh; }
.proof-bar { min-height: 40px; padding: 3px 10px; }
.proof .btn-primary { width: 100%; }

/* ---- Six message types: 3×2 grid ---- */
.template-toggles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; overflow: visible; }
.chip { padding: 5px 6px; border-radius: 12px; gap: 4px; min-width: 0; }
.chip svg { width: 16px; height: 16px; }
.chip-text { overflow: hidden; }
.chip-text b { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip-text small { font-size: 10px; overflow: hidden; text-overflow: ellipsis; }
.bubble { white-space: pre-line; }
/* small phones (≤ 380 px wide or ≤ 700 px tall): text-only chips, tighter rhythm */
@media (max-width: 380px) {
    .chip svg { display: none; }
    .chip { padding: 5px 7px; }
    .chip-text b { font-size: 13.5px; }
}
@media (max-height: 700px) {
    .viewport { padding-top: 6px; gap: 5px; }
    .hero-title { font-size: 15px; }
    .hero-trust { font-size: 11.5px; margin-top: 0; }
    .field { padding: 7px 12px; font-size: 23px; }
    .bubble { -webkit-line-clamp: 2; padding: 6px 10px; font-size: 13.5px; }
    .keypad { padding-top: 6px; gap: 5px; }
    .key { min-height: 42px; font-size: 25px; }
    .btn-primary { min-height: 50px; }
}
/* clamp by height too, so no sliver of the next line peeks out under the padding */
.bubble { max-height: calc(1.35em * 3 + 18px); }
body.no-amount .bubble { -webkit-line-clamp: 7; max-height: calc(1.35em * 7 + 18px); }
@media (max-height: 700px) {
    .bubble { max-height: calc(1.35em * 2 + 14px); }
    body.no-amount .bubble { -webkit-line-clamp: 5; max-height: calc(1.35em * 5 + 14px); }
}
/* clamp fix: overflow still paints into padding, so the bottom spacing is a same-colour border instead */
.bubble { padding-bottom: 0; border-bottom: 8px solid #dcfce7; box-shadow: 0 1px 0 #bbf7d0; }
@media (max-height: 700px) { .bubble { border-bottom-width: 6px; } }
@media (max-height: 700px) { .bubble { -webkit-line-clamp: 3; max-height: calc(1.35em * 3 + 8px); } }
@media (max-height: 700px) {
    .bubble { max-height: calc(1.35em * 3 + 14px); }
    body.no-amount .bubble { -webkit-line-clamp: 7; max-height: calc(1.35em * 7 + 14px); }
}
