@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap');

:root {
    --bg: #f7fbff;
    --card: #ffffff;
    --primary: #38b6ff;
    --primary-dark: #004aad;
    --primary-light: #e8f6ff;
    --accent-orange: #f59f2f;
    --accent-yellow: #f5da42;
    --success: #16a34a;
    --danger: #f59f2f;
    --text: #4d4d4d;
    --text-mid: #5a5a5a;
    --text-light: #7a7a7a;
    --border: #dbe6f3;
    --thai-qr-blue: #003d6b;
    --radius: 20px;
    --shadow: 0 6px 26px rgba(0, 74, 173, 0.08);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; margin: 0; padding: 0; }

body {
    font-family: 'Plus Jakarta Sans', -apple-system, 'Segoe UI', Tahoma, sans-serif;
    background: radial-gradient(circle at 10% 0%, rgba(56, 182, 255, 0.12), transparent 45%),
                radial-gradient(circle at 90% 100%, rgba(245, 218, 66, 0.16), transparent 40%),
                var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 24px 16px 48px;
}

/* ── Status Screens ──────────────────────────── */
#error-screen, #success-screen {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9999;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 28px;
    backdrop-filter: blur(4px);
}

#success-screen,
#error-screen {
    background: radial-gradient(circle at 10% 0%, rgba(56, 182, 255, 0.12), transparent 45%),
                radial-gradient(circle at 90% 100%, rgba(245, 218, 66, 0.16), transparent 40%),
                var(--bg);
}

.status-card {
    width: 100%;
    max-width: 340px;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.45);
    backdrop-filter: blur(10px);
    border-radius: 26px;
    padding: 42px 28px 30px;
    text-align: center;
    box-shadow: 0 20px 42px -16px rgba(2, 6, 23, 0.55);
    animation: cardIn 0.42s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.success-card { border-top: 3px solid var(--success); }
.error-card   { border-top: 3px solid var(--accent-orange); }

.status-icon {
    width: 68px; height: 68px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 20px;
}
.success-icon { background: #ecfdf3; color: var(--success); }
.error-icon   { background: #fff3df; color: var(--accent-orange); }
.status-icon svg { width: 36px; height: 36px; }
.success-icon { animation: pulseSuccess 2s infinite; }
.error-icon { animation: pulseOrange 2s infinite; }

.status-title { font-size: 1.2rem; font-weight: 700; margin-bottom: 8px; }
.status-desc  { font-size: 0.875rem; color: var(--text-mid); line-height: 1.65; margin-bottom: 20px; }

.status-actions {
    display: flex;
    justify-content: center;
    margin-bottom: 10px;
}

.error-retry-btn {
    border: none;
    border-radius: 11px;
    padding: 10px 16px;
    font-size: 0.85rem;
    font-weight: 700;
    font-family: inherit;
    color: #fff;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    box-shadow: 0 5px 16px rgba(0, 74, 173, 0.25);
    cursor: pointer;
    transition: transform 0.1s ease, opacity 0.2s ease;
}

.error-retry-btn:active { transform: scale(0.98); }

.error-retry-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.error-meta {
    margin-bottom: 4px;
    font-size: 0.72rem;
    color: #94a3b8;
}

.txn-row { border-top: 1px solid #f3f4f6; padding-top: 16px; text-align: left; }
.compact-row { padding-top: 10px; }
.txn-label {
    font-size: 0.68rem; font-weight: 600; letter-spacing: 0.07em;
    text-transform: uppercase; color: #9ca3af; display: block; margin-bottom: 4px;
}
.txn-value { font-size: 0.85rem; font-weight: 700; color: var(--success); font-family: monospace; word-break: break-all; }
.error-value { color: var(--accent-orange); }
.status-ref-list { margin-bottom: 6px; }

.status-footer {
    margin-top: 20px; padding-top: 14px; border-top: 1px solid #f3f4f6;
    font-size: 0.82rem; color: #9ca3af; line-height: 1.7;
}
.status-footer a { color: var(--primary); text-decoration: none; font-weight: 600; }

@keyframes cardIn {
    from { opacity: 0; transform: translateY(18px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Main Page ───────────────────────────────── */
.page {
    display: none;
    width: 100%;
    max-width: 400px;
}

/* Header */
.app-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 6px 18px;
}
.brand-icon {
    width: 46px; height: 46px;
    background: #fff;
    border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
    box-shadow: 0 4px 14px rgba(0, 74, 173, 0.18);
}
.brand-icon img { width: 100%; height: 100%; object-fit: cover; }
.brand-name { font-size: 1.08rem; font-weight: 800; color: var(--text); line-height: 1.2; }
.brand-sub  { font-size: 0.73rem; color: var(--text-light); }

/* Card */
.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
}

/* Machine Info */
.machine-info { text-align: center; padding-bottom: 20px; }
.machine-badge {
    display: inline-block;
    background: rgba(245, 218, 66, 0.28);
    color: var(--primary-dark);
    font-size: 0.7rem; font-weight: 700;
    letter-spacing: 0.08em; text-transform: uppercase;
    padding: 4px 12px; border-radius: 99px;
    margin-bottom: 10px;
}
.machine-num {
    font-size: 1.75rem; font-weight: 800;
    letter-spacing: -0.5px; line-height: 1.1;
    margin-bottom: 8px;
}
.machine-meta {
    font-size: 0.8rem; color: var(--text-light);
    display: flex; align-items: center; justify-content: center; gap: 5px;
}
.machine-meta svg { width: 13px; height: 13px; flex-shrink: 0; }
.meta-sep { color: var(--border); }

.divider { height: 1px; background: var(--border); margin-bottom: 20px; }

/* Labels */
.field-label {
    font-size: 0.75rem; font-weight: 600; color: var(--text-mid);
    text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 10px;
}
.field-hint { font-size: 0.75rem; color: var(--text-light); text-align: center; margin-bottom: 18px; }

/* Presets */
.presets-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 14px;
}
.preset-btn {
    padding: 11px 4px;
    background: #fbfdff;
    border: 1.5px solid var(--border);
    border-radius: 12px;
    font-size: 0.95rem; font-weight: 700;
    color: var(--text);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
    font-family: inherit;
}
.preset-btn:active { transform: scale(0.93); background: var(--primary-light); border-color: var(--primary); color: var(--primary-dark); }
.preset-other { color: var(--text-mid); font-size: 0.82rem; font-weight: 600; }

/* Amount Input */
.amount-input-wrap {
    display: flex; align-items: center;
    border: 2px solid var(--border);
    border-radius: 14px;
    background: #fbfdff;
    margin-bottom: 6px;
    transition: border-color 0.2s;
}
.amount-input-wrap:focus-within { border-color: var(--primary); background: var(--primary-light); }
.baht-sign { font-size: 1.2rem; font-weight: 700; color: var(--text-light); padding-left: 16px; }
.amount-input-wrap input {
    flex: 1; border: none; background: transparent;
    font-size: 1.5rem; font-weight: 700; color: var(--text);
    padding: 13px 16px; text-align: right;
    outline: none; width: 100%; font-family: inherit;
}

/* Pay Button */
.pay-btn {
    width: 100%; padding: 15px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: #fff;
    border: none; border-radius: 14px;
    font-size: 1.05rem; font-weight: 700;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center; gap: 8px;
    box-shadow: 0 5px 16px rgba(0, 74, 173, 0.28);
    transition: background 0.2s, transform 0.1s;
    font-family: inherit; margin-top: 4px;
}
.pay-btn svg { width: 18px; height: 18px; }
.pay-btn:hover  { background: linear-gradient(135deg, #2da9f1 0%, #003d8f 100%); }
.pay-btn:active { transform: scale(0.98); }
.pay-btn:disabled { background: #cbd5e1; box-shadow: none; cursor: not-allowed; }

/* QR Container */
#qr-container {
    display: none; margin-top: 20px;
    border: 1.5px solid var(--border);
    border-radius: 16px; background: #fff;
    overflow: hidden; animation: fadeUp 0.3s ease;
}
.qr-header-bar {
    background: var(--thai-qr-blue); padding: 10px;
    display: flex; justify-content: center;
}
.qr-logo-img { height: 42px; }
.promptpay-row { padding: 12px 0 4px; text-align: center; }
.promptpay-logo-img { height: 28px; }

.qr-image-wrap {
    width: 220px; height: 220px;
    margin: 10px auto;
    display: flex; align-items: center; justify-content: center;
    position: relative;
}
.qr-image-wrap img#actual-qr { width: 100%; height: 100%; object-fit: contain; }
.qr-loading-txt { font-size: 0.8rem; color: var(--text-light); }

.qr-detail {
    border-top: 1px dashed var(--border);
    margin: 0 14px; padding: 14px 0 16px;
    text-align: center; display: flex; flex-direction: column; gap: 4px;
}
.qr-shopname  { font-size: 0.85rem; font-weight: 700; color: var(--text); }
.qr-amt-label { font-size: 1.05rem; font-weight: 800; color: var(--accent-orange); }

.qr-warning-box {
    margin-top: 6px;
    padding: 10px;
    border: 1px solid #ffd8a8;
    border-radius: 12px;
    background: linear-gradient(180deg, #fffaf2 0%, #fff6e8 100%);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.qr-warning-title {
    font-size: 0.78rem;
    font-weight: 800;
    color: #9a4b00;
}

.qr-warning-text {
    font-size: 0.76rem;
    font-weight: 600;
    color: #7a4a1f;
}

.qr-methods {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
}

.qr-method-pill {
    font-size: 0.72rem;
    font-weight: 700;
    color: #5f4a2a;
    background: #fff;
    border: 1px solid #f0d9b4;
    border-radius: 999px;
    padding: 5px 8px;
    line-height: 1.2;
}

.download-btn {
    width: 100%;
    margin-top: 12px;
    padding: 12px;
    border: 1.5px solid var(--primary);
    border-radius: 12px;
    background: #fff;
    color: var(--primary-dark);
    font-size: 0.95rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.2s, color 0.2s, transform 0.1s;
}

.download-btn:hover {
    background: var(--primary-light);
}

.download-btn:active {
    transform: scale(0.98);
}

.download-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Contact Footer */
.contact-footer {
    margin-top: 20px; padding-top: 16px;
    border-top: 1px solid var(--border);
    font-size: 0.78rem; color: var(--text-light);
    text-align: center; line-height: 1.8;
}
.contact-footer a { color: var(--primary); text-decoration: none; font-weight: 600; }

.powered-by { text-align: center; font-size: 0.68rem; color: var(--text-light); margin-top: 16px; }

/* ── Animations ──────────────────────────────── */
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes pulseSuccess {
    0% { transform: scale(0.96); box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.32); }
    70% { transform: scale(1); box-shadow: 0 0 0 12px rgba(22, 163, 74, 0); }
    100% { transform: scale(0.96); box-shadow: 0 0 0 0 rgba(22, 163, 74, 0); }
}

@keyframes pulseOrange {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(245, 159, 47, 0.35); }
    70% { transform: scale(1); box-shadow: 0 0 0 10px rgba(245, 159, 47, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(245, 159, 47, 0); }
}


