/* ─── Reset & Base ──────────────────────────────────────────────────── */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg: var(--tg-theme-bg-color, #ffffff);
    --text: var(--tg-theme-text-color, #000000);
    --hint: var(--tg-theme-hint-color, #999999);
    --link: var(--tg-theme-link-color, #2481cc);
    --btn: var(--tg-theme-button-color, #2481cc);
    --btn-text: var(--tg-theme-button-text-color, #ffffff);
    --secondary-bg: var(--tg-theme-secondary-bg-color, #f0f0f0);
    --section-bg: var(--tg-theme-section-bg-color, var(--bg));
    --section-header: var(--tg-theme-section-header-text-color, var(--hint));
    --subtitle: var(--tg-theme-subtitle-text-color, var(--hint));
    --destructive: var(--tg-theme-destructive-text-color, #e53935);

    --radius: 12px;
    --gap: 12px;
}

body {
    font-family: -apple-system, 'SF Pro Text', 'Helvetica Neue', sans-serif;
    background: var(--secondary-bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.4;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

#app { padding-bottom: 20px; }

/* ─── Header ───────────────────────────────────────────────────────── */
header {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    background: var(--bg);
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 0.5px solid rgba(0,0,0,0.08);
}

header h1 {
    flex: 1;
    font-size: 17px;
    font-weight: 600;
    text-align: center;
}

.header-btn {
    background: none;
    border: none;
    color: var(--link);
    cursor: pointer;
    padding: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    min-height: 40px;
    -webkit-tap-highlight-color: rgba(0,0,0,0.1);
    position: relative;
    z-index: 101;
}

/* ─── Loading ──────────────────────────────────────────────────────── */
.loading {
    display: flex;
    justify-content: center;
    padding: 60px 0;
}

.spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--secondary-bg);
    border-top-color: var(--btn);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

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

/* ─── Empty state ──────────────────────────────────────────────────── */
.empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--hint);
    font-size: 15px;
}

/* ─── List items ───────────────────────────────────────────────────── */
.list {
    padding: var(--gap);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.list-item {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    background: var(--bg);
    border-radius: var(--radius);
    cursor: pointer;
    transition: transform 0.1s, opacity 0.1s;
    -webkit-tap-highlight-color: transparent;
}

.list-item:active {
    transform: scale(0.98);
    opacity: 0.7;
}

.list-item .icon {
    font-size: 20px;
    margin-right: 12px;
    flex-shrink: 0;
}

.list-item .item-body {
    flex: 1;
    min-width: 0;
}

.list-item .item-title {
    font-weight: 500;
    font-size: 15px;
}

.list-item .item-sub {
    font-size: 13px;
    color: var(--subtitle);
    margin-top: 2px;
}

.list-item .chevron {
    color: var(--hint);
    flex-shrink: 0;
    margin-left: 8px;
    opacity: 0.4;
}

/* ─── Status badge ─────────────────────────────────────────────────── */
.status-badge {
    display: inline-block;
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 500;
}

.status-collecting { background: #e8f5e9; color: #2e7d32; }
.status-purchasing { background: #fff3e0; color: #ef6c00; }
.status-ready      { background: #e3f2fd; color: #1565c0; }
.status-cancelled  { background: #fbe9e7; color: #c62828; }

/* dark theme overrides */
@media (prefers-color-scheme: dark) {
    .status-collecting { background: rgba(46,125,50,0.2); }
    .status-purchasing { background: rgba(239,108,0,0.2); }
    .status-ready      { background: rgba(21,101,192,0.2); }
    .status-cancelled  { background: rgba(198,40,40,0.2); }
}

/* ─── Product card ─────────────────────────────────────────────────── */
.product-photo-wrap {
    width: 100%;
    max-height: 300px;
    overflow: hidden;
    background: var(--secondary-bg);
}

.product-photo {
    width: 100%;
    height: auto;
    display: block;
    object-fit: cover;
}

.product-info {
    padding: 16px;
    background: var(--bg);
}

.product-info h2 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 8px;
}

.product-meta {
    font-size: 13px;
    color: var(--subtitle);
    margin-bottom: 4px;
}

.product-price {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
    margin: 8px 0;
}

.product-desc {
    font-size: 14px;
    color: var(--text);
    margin-top: 12px;
    line-height: 1.5;
    white-space: pre-wrap;
}

/* ─── Cart section ─────────────────────────────────────────────────── */
.cart-section {
    padding: 16px;
    margin-top: 8px;
    background: var(--bg);
}

.qty-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    margin-bottom: 12px;
}

.qty-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--secondary-bg);
    color: var(--text);
    font-size: 22px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.15s;
}

.qty-btn:active { background: var(--btn); color: var(--btn-text); }

.qty-value {
    font-size: 20px;
    font-weight: 600;
    min-width: 40px;
    text-align: center;
}

.cart-total {
    text-align: center;
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text);
}

/* ─── Buttons ──────────────────────────────────────────────────────── */
.btn {
    display: block;
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    -webkit-tap-highlight-color: transparent;
    transition: opacity 0.15s;
}

.btn:active { opacity: 0.7; }

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

.btn-danger {
    background: none;
    color: var(--destructive);
    font-weight: 500;
    font-size: 14px;
    padding: 10px;
}

/* ─── Order card ───────────────────────────────────────────────────── */
.order-qty {
    font-size: 14px;
    font-weight: 600;
    color: var(--btn);
    flex-shrink: 0;
    margin-left: 8px;
}

/* ─── Toast ────────────────────────────────────────────────────────── */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    background: var(--text);
    color: var(--bg);
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    transition: transform 0.3s ease;
    z-index: 1000;
    pointer-events: none;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
}

/* ─── Admin section ────────────────────────────────────────────────── */
.admin-section {
    padding: 12px 16px;
    margin-top: 8px;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.admin-actions {
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.section-header {
    padding: 12px 16px 4px;
    font-size: 13px;
    color: var(--section-header);
    font-weight: 500;
    text-transform: uppercase;
}

.btn-secondary {
    background: var(--secondary-bg);
    color: var(--text);
}

.btn-outline {
    background: none;
    color: var(--link);
    border: 1.5px solid var(--link);
}

.btn-sm {
    padding: 10px 14px;
    font-size: 14px;
    border-radius: 10px;
}

/* ─── Forms ────────────────────────────────────────────────────────── */
.form-section {
    padding: 16px;
    background: var(--bg);
    margin: var(--gap);
    border-radius: var(--radius);
}

.form-label {
    display: block;
    font-size: 13px;
    color: var(--subtitle);
    margin-bottom: 6px;
    margin-top: 14px;
    font-weight: 500;
}

.form-label:first-child { margin-top: 0; }

.form-input {
    display: block;
    width: 100%;
    padding: 12px;
    border: 1.5px solid rgba(0,0,0,0.1);
    border-radius: 10px;
    font-size: 15px;
    background: var(--secondary-bg);
    color: var(--text);
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
}

.form-input:focus {
    border-color: var(--btn);
}

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

.form-row {
    display: flex;
    gap: 8px;
}

/* ─── Confirm dialog ───────────────────────────────────────────────── */
.confirm-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    animation: fadeIn 0.15s ease;
}

.confirm-box {
    background: var(--bg);
    border-radius: 16px;
    padding: 24px;
    margin: 20px;
    max-width: 320px;
    width: 100%;
    text-align: center;
}

.confirm-box p {
    font-size: 15px;
    margin-bottom: 20px;
    line-height: 1.4;
}

.confirm-buttons {
    display: flex;
    gap: 8px;
}

.confirm-buttons .btn {
    flex: 1;
}

/* ─── Admin orders ─────────────────────────────────────────────────── */
.admin-order-group {
    margin: var(--gap);
    background: var(--bg);
    border-radius: var(--radius);
    overflow: hidden;
}

.admin-order-group-title {
    padding: 12px 16px;
    font-weight: 600;
    font-size: 15px;
    background: var(--secondary-bg);
}

.admin-order-item {
    padding: 10px 16px;
    border-top: 0.5px solid rgba(0,0,0,0.06);
    font-size: 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.admin-order-item .buyer { color: var(--text); }
.admin-order-item .qty { color: var(--subtitle); font-weight: 500; }

/* Issue button */
.btn-issue {
    background: #e8f5e9;
    color: #2e7d32;
    border: none;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.btn-issue:active { opacity: 0.7; }

/* Link display */
.link-box {
    background: var(--secondary-bg);
    padding: 12px;
    border-radius: 10px;
    word-break: break-all;
    font-size: 14px;
    color: var(--link);
    cursor: pointer;
    text-align: center;
    margin: 8px 0;
}

/* ─── Order summary ───────────────────────────────────────────────── */
.order-summary {
    padding: 14px 16px;
    background: var(--bg);
    border-radius: var(--radius);
    font-size: 14px;
    color: var(--text);
    line-height: 1.6;
}

.order-summary b {
    font-weight: 600;
}

/* ─── Page transitions ─────────────────────────────────────────────── */
.page {
    animation: fadeIn 0.15s ease;
}

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