/* ====== CSS Reset & Base ====== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary: #4a7c59;
    --primary-dark: #3a6147;
    --primary-light: #e8f5ed;
    --accent: #c8a96e;
    --text-dark: #2c3e50;
    --text-mid: #556070;
    --text-light: #8a9bb0;
    --bg: #f5f7f2;
    --white: #ffffff;
    --border: #dde5d8;
    --error: #e05252;
    --error-bg: #fdf0f0;
    --success: #4a7c59;
    --radius: 16px;
    --shadow: 0 2px 12px rgba(74, 124, 89, 0.1);
    --shadow-md: 0 4px 24px rgba(74, 124, 89, 0.15);
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'PingFang TC', 'Microsoft JhengHei',
                 'Noto Sans TC', 'Segoe UI', sans-serif;
    background-color: var(--bg);
    color: var(--text-dark);
    line-height: 1.6;
    min-height: 100vh;
}

/* ====== Layout ====== */
.page-wrapper {
    max-width: 480px;
    margin: 0 auto;
    padding: 0 16px 40px;
}

/* ====== Header ====== */
.site-header {
    text-align: center;
    padding: 28px 0 16px;
}

.cross-icon {
    font-size: 28px;
    color: var(--primary);
    margin-bottom: 4px;
}

.church-name {
    font-size: 13px;
    color: var(--text-light);
    letter-spacing: 0.05em;
}

/* ====== Event Card ====== */
.event-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 24px 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
    border-top: 4px solid var(--primary);
}

.event-badge {
    display: inline-block;
    background: var(--primary-light);
    color: var(--primary-dark);
    font-size: 12px;
    font-weight: 600;
    padding: 4px 12px;
    border-radius: 20px;
    margin-bottom: 12px;
    letter-spacing: 0.03em;
}

.event-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-dark);
    line-height: 1.3;
}

.event-subtitle {
    font-size: 18px;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 20px;
}

.event-details {
    border-top: 1px solid var(--border);
    padding-top: 16px;
    margin-bottom: 16px;
}

.detail-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 12px;
}

.detail-row:last-child {
    margin-bottom: 0;
}

.detail-icon {
    font-size: 16px;
    flex-shrink: 0;
    margin-top: 1px;
}

.detail-row > div {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.detail-row strong {
    font-size: 12px;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.detail-row span {
    font-size: 14px;
    color: var(--text-dark);
}

/* ====== Price Section ====== */
.price-section {
    background: var(--primary-light);
    border-radius: 12px;
    padding: 14px 16px;
    margin-top: 4px;
}

.price-section h3 {
    font-size: 13px;
    color: var(--primary-dark);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.price-grid {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.price-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
}

.price-label {
    color: var(--text-mid);
}

.price-amount {
    font-weight: 700;
    color: var(--primary-dark);
}

.price-item.free .price-label {
    color: var(--text-light);
    font-size: 13px;
}

.free-tag {
    color: var(--accent) !important;
}

/* ====== Form Card ====== */
.form-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 24px 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.form-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-dark);
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--primary-light);
}

/* ====== Form Elements ====== */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 8px;
}

.required {
    color: var(--error);
}

.optional {
    font-weight: 400;
    color: var(--text-light);
    font-size: 12px;
}

input[type="text"],
input[type="tel"],
input[type="email"],
textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    font-size: 16px;
    font-family: inherit;
    color: var(--text-dark);
    background: var(--white);
    transition: border-color 0.2s, box-shadow 0.2s;
    -webkit-appearance: none;
}

input[type="text"]:focus,
input[type="tel"]:focus,
input[type="email"]:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(74, 124, 89, 0.12);
}

input.error,
textarea.error {
    border-color: var(--error);
}

textarea {
    resize: vertical;
    min-height: 80px;
}

/* ====== Field Error ====== */
.field-error {
    display: block;
    font-size: 12px;
    color: var(--error);
    margin-top: 4px;
    min-height: 16px;
}

/* ====== Count Controls ====== */
.count-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 8px;
}

.count-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sub-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-mid);
    margin-bottom: 0 !important;
}

.count-control {
    display: flex;
    align-items: center;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    background: var(--white);
}

.count-btn {
    width: 40px;
    height: 44px;
    background: var(--primary-light);
    border: none;
    font-size: 20px;
    color: var(--primary-dark);
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s;
    font-weight: 300;
    line-height: 1;
}

.count-btn:active {
    background: var(--border);
}

.count-control input[type="number"] {
    flex: 1;
    border: none;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    border-radius: 0;
    text-align: center;
    font-size: 18px;
    font-weight: 600;
    padding: 0;
    height: 44px;
    box-shadow: none;
    -moz-appearance: textfield;
}

.count-control input[type="number"]::-webkit-outer-spin-button,
.count-control input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.hint-text {
    font-size: 12px;
    color: var(--text-light);
    margin-top: 6px;
}

/* ====== Amount Preview ====== */
.amount-preview {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    border-radius: 12px;
    padding: 14px 18px;
    margin-bottom: 20px;
}

.amount-label {
    color: rgba(255, 255, 255, 0.85);
    font-size: 14px;
    font-weight: 500;
}

.amount-value {
    color: var(--white);
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

/* ====== Alert ====== */
.alert {
    border-radius: 10px;
    padding: 12px 16px;
    margin-bottom: 16px;
    font-size: 14px;
    line-height: 1.5;
}

.alert-error {
    background: var(--error-bg);
    color: var(--error);
    border: 1px solid #f5c6c6;
}

/* ====== Submit Button ====== */
.submit-btn {
    width: 100%;
    padding: 16px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: var(--white);
    border: none;
    border-radius: 12px;
    font-size: 17px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    letter-spacing: 0.02em;
}

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

.submit-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* ====== Spinner ====== */
.spinner {
    width: 20px;
    height: 20px;
    border: 2.5px solid rgba(255, 255, 255, 0.4);
    border-top-color: var(--white);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    flex-shrink: 0;
}

.spinner.large {
    width: 40px;
    height: 40px;
    border-color: var(--border);
    border-top-color: var(--primary);
    margin: 0 auto 16px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ====== Success Page ====== */
.loading-card {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-light);
}

.success-card {
    text-align: center;
    padding: 32px 20px 24px;
}

.success-icon {
    width: 72px;
    height: 72px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: var(--white);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    margin: 0 auto 16px;
    box-shadow: 0 4px 20px rgba(74, 124, 89, 0.35);
}

.success-title {
    font-size: 26px;
    font-weight: 700;
    color: var(--text-dark);
    margin-bottom: 8px;
}

.success-subtitle {
    font-size: 14px;
    color: var(--text-light);
    line-height: 1.6;
}

/* ====== Info Card ====== */
.info-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.info-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-dark);
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--primary-light);
}

.info-grid {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 11px 0;
    border-bottom: 1px solid var(--primary-light);
}

.info-row:last-child {
    border-bottom: none;
}

.info-row.highlight {
    background: var(--primary-light);
    margin: 0 -20px;
    padding: 11px 20px;
}

.info-label {
    font-size: 14px;
    color: var(--text-light);
}

.info-value {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-dark);
    text-align: right;
}

.info-row.highlight .info-value {
    color: var(--primary-dark);
    font-size: 18px;
}

.ref-text {
    font-size: 12px !important;
    font-family: 'Courier New', monospace;
    color: var(--text-light) !important;
    font-weight: 400 !important;
}

/* ====== Status Badge ====== */
.status-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
}

.status-paid {
    background: #e8f5ed;
    color: #2e7d32;
}

.status-pending {
    background: #fff8e1;
    color: #f57f17;
}

.status-failed {
    background: #fdf0f0;
    color: #c62828;
}

/* ====== Event Reminder ====== */
.event-reminder {
    background: var(--white);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
    border-left: 4px solid var(--accent);
}

.event-reminder h3 {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-mid);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.reminder-item {
    display: flex;
    gap: 10px;
    font-size: 14px;
    color: var(--text-dark);
    margin-bottom: 8px;
    align-items: flex-start;
    line-height: 1.5;
}

.reminder-item:last-child {
    margin-bottom: 0;
}

/* ====== Error State ====== */
.error-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 40px 20px;
    text-align: center;
    box-shadow: var(--shadow);
    margin-bottom: 16px;
}

.error-icon {
    font-size: 48px;
    margin-bottom: 16px;
    color: var(--error);
}

.error-card h2 {
    font-size: 20px;
    margin-bottom: 8px;
    color: var(--text-dark);
}

.error-card p {
    color: var(--text-light);
    margin-bottom: 24px;
    font-size: 14px;
}

.back-btn {
    display: inline-block;
    padding: 12px 28px;
    background: var(--primary);
    color: var(--white);
    border-radius: 10px;
    text-decoration: none;
    font-weight: 600;
    font-size: 15px;
    transition: background 0.2s;
}

.back-btn:hover {
    background: var(--primary-dark);
}

/* ====== Footer ====== */
.site-footer {
    text-align: center;
    padding: 20px 0 8px;
    font-size: 12px;
    color: var(--text-light);
}

/* ====== Desktop Adjustments ====== */
@media (min-width: 520px) {
    .page-wrapper {
        padding: 0 24px 48px;
    }

    .event-card,
    .form-card,
    .info-card,
    .event-reminder,
    .error-card {
        padding: 28px 24px;
    }
}

/* ====== Admin (paid registrations) ====== */
.page-wrapper.admin-page {
    max-width: 960px;
}

.admin-card .admin-title {
    margin-bottom: 8px;
}

.admin-hint {
    font-size: 13px;
    color: var(--text-mid);
    margin-bottom: 16px;
    line-height: 1.5;
}

.admin-hint code {
    font-size: 12px;
    background: var(--primary-light);
    padding: 2px 6px;
    border-radius: 4px;
}

.admin-form {
    margin-top: 8px;
}

.admin-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    text-align: left;
}

.admin-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

.admin-logout-form {
    display: inline;
    margin: 0;
}

.btn-secondary,
.btn-outline {
    display: inline-block;
    padding: 10px 18px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    border: none;
    font-family: inherit;
    transition: background 0.2s, color 0.2s;
}

.btn-secondary {
    background: var(--primary);
    color: var(--white);
}

.btn-secondary:hover {
    background: var(--primary-dark);
    color: var(--white);
}

.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 2px solid var(--primary);
}

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

.admin-list-title {
    font-size: 18px;
    font-weight: 700;
    margin: 8px 0 12px;
    color: var(--text-dark);
}

.admin-table-wrap {
    background: var(--white);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    border-top: 4px solid var(--primary);
}

.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

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

.admin-table th {
    background: var(--primary-light);
    color: var(--primary-dark);
    font-weight: 600;
}

.admin-table tbody tr:hover td {
    background: #fafcf9;
}

.admin-empty {
    text-align: center;
    color: var(--text-light);
    white-space: normal;
    padding: 24px !important;
}
