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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: #f5f7fa;
    color: #1a1a2e;
    line-height: 1.5;
    padding-bottom: 80px;
}

a {
    text-decoration: none;
    color: inherit;
}

/* === Header === */
header {
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    position: sticky;
    top: 0;
    z-index: 100;
    height: 49px;
}

.header-inner {
    max-width: 960px;
    margin: 0 auto;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    font-size: 18px;
    font-weight: 700;
    color: #2563eb;
}

.header-info {
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 14px;
}

.header-info .child-name {
    font-weight: 600;
}

.header-info .balance {
    color: #64748b;
}

/* === Main === */
main {
    max-width: 960px;
    margin: 0 auto;
    padding: 24px 20px;
}

.page-title {
    margin-bottom: 24px;
}

.page-title h1 {
    font-size: 24px;
    font-weight: 700;
}

.page-title p {
    color: #64748b;
    margin-top: 4px;
}

/* === Buttons === */
.btn {
    display: inline-block;
    padding: 10px 24px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}

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

.btn-primary {
    background: #2563eb;
    color: #fff;
}

.btn-primary:hover {
    background: #1d4ed8;
}

.btn-secondary {
    background: #e2e8f0;
    color: #334155;
}

.btn-secondary:hover {
    background: #cbd5e1;
}

.btn-green {
    background: #16a34a;
    color: #fff;
}

.btn-green:hover {
    background: #15803d;
}

/* === Index: Child Grid === */
.child-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

.child-card {
    background: #fff;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    padding: 32px 24px;
    text-align: center;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.child-card:hover {
    border-color: #2563eb;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.1);
}

.child-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #2563eb;
    color: #fff;
    font-size: 24px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 12px;
}

.child-card .child-name {
    font-size: 18px;
    font-weight: 600;
}

.child-card .child-id {
    font-size: 13px;
    color: #94a3b8;
    margin-top: 4px;
}

/* === Menu Page === */
.menu-actions {
    margin-bottom: 20px;
}

.day-block {
    background: #fff;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    margin-bottom: 16px;
}

.day-header {
    padding: 12px 16px;
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    border-radius: 12px 12px 0 0;
    display: flex;
    align-items: center;
    gap: 12px;
    position: sticky;
    top: 49px;
    z-index: 10;
}

.day-date {
    font-weight: 700;
    font-size: 15px;
}

.day-weekday {
    color: #64748b;
    font-size: 13px;
}

.meal-type-section {
    padding: 12px 16px;
}

.meal-type-section + .meal-type-section {
    border-top: 1px solid #f1f5f9;
}

.meal-type-label {
    font-size: 12px;
    font-weight: 600;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.collapse-toggle {
    display: inline-block;
    margin-left: 8px;
    font-size: 11px;
    font-weight: 600;
    color: #3b82f6;
    cursor: pointer;
    padding: 2px 8px;
    border-radius: 4px;
    text-transform: none;
    letter-spacing: 0;
}

.collapse-toggle:hover {
    background: #eff6ff;
}

.meal-type-section.collapsed .item-grid {
    display: none !important;
}

.multi-hint {
    text-transform: none;
    font-weight: 400;
    color: #3b82f6;
    font-size: 11px;
    margin-bottom: 8px;
}

.item-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 8px;
}

.menu-item {
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    padding: 10px 12px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    position: relative;
}

.menu-item:hover {
    border-color: #93c5fd;
}

.menu-item.recommended {
    border-color: #22c55e;
    background: #f0fdf4;
    box-shadow: 0 0 0 1px #22c55e;
}

.menu-item.selected {
    background: #dbeafe;
    border-color: #2563eb;
    box-shadow: 0 0 0 2px #2563eb;
    position: relative;
}

.menu-item.selected::after {
    content: "\2713";
    position: absolute;
    bottom: 6px;
    right: 6px;
    width: 28px;
    height: 28px;
    background: #2563eb;
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 700;
    box-shadow: 0 2px 4px rgba(37, 99, 235, 0.3);
    border-color: #2563eb;
}

.menu-item.recommended.selected {
    background: #dbeafe;
    border-color: #2563eb;
    box-shadow: 0 0 0 2px #2563eb;
}

.rec-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    color: #16a34a;
    background: #f0fdf4;
    padding: 1px 6px;
    border-radius: 4px;
    margin-bottom: 4px;
}

.item-name {
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: flex-start;
    gap: 4px;
}

.item-name-en {
    font-size: 11px;
    color: #94a3b8;
    margin-top: 1px;
    line-height: 1.3;
}

.info-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #e2e8f0;
    color: #64748b;
    font-size: 10px;
    font-weight: 700;
    cursor: pointer;
    flex-shrink: 0;
    margin-top: 2px;
    position: relative;
}

.info-icon:hover {
    background: #3b82f6;
    color: #fff;
}

.tooltip-bubble {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: #1e293b;
    color: #fff;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 400;
    line-height: 1.5;
    white-space: normal;
    max-width: 260px;
    min-width: 120px;
    z-index: 200;
    pointer-events: none;
}

.tooltip-bubble::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: #1e293b;
}

.item-desc {
    font-size: 12px;
    color: #94a3b8;
    margin-top: 2px;
}

.item-price {
    font-size: 14px;
    font-weight: 700;
    color: #2563eb;
    margin-top: 6px;
}

/* === Bottom Bar === */
.bottom-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #fff;
    border-top: 1px solid #e2e8f0;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 100;
}

.bottom-info {
    font-size: 15px;
    font-weight: 600;
}

#selected-count {
    color: #2563eb;
    font-size: 20px;
}

/* === Confirm Page === */
.confirm-days {
    display: flex;
    flex-direction: column;
    gap: 2px;
    background: #fff;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    overflow: hidden;
    margin-bottom: 24px;
}

.confirm-day-card {
    display: flex;
    align-items: stretch;
    border-bottom: 1px solid #f1f5f9;
}

.confirm-day-card:last-child {
    border-bottom: none;
}

.confirm-day-left {
    flex: 0 0 100px;
    padding: 16px;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    justify-content: center;
    border-right: 1px solid #e2e8f0;
}

.confirm-date {
    font-size: 18px;
    font-weight: 700;
    color: #1e293b;
}

.confirm-weekday {
    font-size: 12px;
    color: #94a3b8;
    margin-top: 2px;
}

.confirm-edit-link {
    display: inline-block;
    margin-top: 6px;
    font-size: 12px;
    color: #3b82f6;
    cursor: pointer;
}

.confirm-edit-link:hover {
    text-decoration: underline;
}

.confirm-day-center {
    flex: 1;
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
}

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

.confirm-item-name {
    color: #334155;
}

.confirm-item-price {
    color: #94a3b8;
    font-size: 13px;
    flex-shrink: 0;
    margin-left: 12px;
}

.confirm-day-right {
    flex: 0 0 auto;
    min-width: 90px;
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    border-left: 1px solid #f1f5f9;
}

.confirm-day-total {
    font-size: 16px;
    font-weight: 700;
    color: #2563eb;
}

/* Summary */
.confirm-summary {
    background: #fff;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    padding: 16px 20px;
    margin-bottom: 24px;
}

.summary-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    font-size: 15px;
    color: #475569;
}

.summary-total {
    font-size: 18px;
    font-weight: 700;
    color: #1e293b;
    border-bottom: 1px solid #e2e8f0;
    padding-bottom: 12px;
}

.summary-balance {
    padding-top: 12px;
}

.summary-remaining {
    font-weight: 600;
    color: #16a34a;
}

.summary-remaining.insufficient {
    color: #dc2626;
}

.balance-warning {
    margin-top: 12px;
    padding: 10px 14px;
    background: #fef2f2;
    color: #dc2626;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
}

.confirm-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.btn-disabled {
    display: inline-block;
    padding: 10px 28px;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    background: #e2e8f0;
    color: #94a3b8;
    cursor: not-allowed;
    border: none;
}

.text-right {
    text-align: right;
}

/* === Success Page === */
.success-page {
    text-align: center;
    padding: 60px 20px;
}

.success-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: #16a34a;
    color: #fff;
    font-size: 20px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
}

.success-page h1 {
    font-size: 22px;
    margin-bottom: 8px;
}

.success-page p {
    color: #64748b;
    margin-bottom: 24px;
}

.success-actions {
    margin-top: 20px;
}

/* === Data Status === */
.data-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 14px 20px;
    margin: 16px auto;
    max-width: 400px;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 10px;
    color: #1d4ed8;
    font-size: 14px;
    font-weight: 500;
}

.data-status .btn-spinner {
    border-color: rgba(37, 99, 235, 0.2);
    border-top-color: #2563eb;
}

/* === Balance Link === */
.balance-link {
    font-size: 13px;
    color: #16a34a;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 6px;
    transition: background 0.15s;
}

.balance-link:hover {
    background: #f0fdf4;
    text-decoration: underline;
}

/* === Logout Link === */
.logout-link {
    font-size: 13px;
    color: #94a3b8;
    padding: 4px 10px;
    border-radius: 6px;
    transition: color 0.15s, background 0.15s;
}

.logout-link:hover {
    color: #dc2626;
    background: #fef2f2;
}

/* === Login Page === */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: calc(100vh - 200px);
}

.login-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 40px 36px;
    width: 100%;
    max-width: 400px;
}

.login-title {
    font-size: 24px;
    font-weight: 700;
    text-align: center;
    margin-bottom: 4px;
}

.login-subtitle {
    text-align: center;
    color: #64748b;
    font-size: 14px;
    margin-bottom: 24px;
}

.login-error {
    background: #fef2f2;
    color: #dc2626;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 16px;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 14px;
    font-weight: 600;
    color: #334155;
}

.form-group input {
    padding: 10px 14px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 15px;
    outline: none;
    transition: border-color 0.15s;
}

.form-group input:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.login-btn {
    width: 100%;
    padding: 12px;
    font-size: 15px;
    margin-top: 4px;
}

/* Loading spinner */
#loading-overlay {
    text-align: center;
    padding: 20px 0;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #e2e8f0;
    border-top-color: #2563eb;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 16px;
}

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

.loading-text {
    font-size: 15px;
    font-weight: 600;
    color: #334155;
    margin-bottom: 4px;
}

.loading-hint {
    font-size: 13px;
    color: #94a3b8;
}

/* === Child Action Buttons === */
.child-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
}

.child-action-btn {
    flex: 1;
    display: inline-block;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    text-align: center;
    transition: background 0.15s, transform 0.1s;
}

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

.child-action-btn.btn-loading {
    opacity: 0.8;
}

.btn-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-right: 6px;
    vertical-align: middle;
}

.child-action-btn.secondary .btn-spinner {
    border-color: rgba(0,0,0,0.15);
    border-top-color: #334155;
}

.child-action-btn.primary {
    background: #2563eb;
    color: #fff;
}

.child-action-btn.primary:hover {
    background: #1d4ed8;
}

.child-action-btn.secondary {
    background: #e2e8f0;
    color: #334155;
}

.child-action-btn.secondary:hover {
    background: #cbd5e1;
}

/* === Tabs === */
.tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 20px;
    background: #e2e8f0;
    border-radius: 10px;
    padding: 4px;
}

.tab {
    flex: 1;
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 600;
    border: none;
    background: transparent;
    color: #64748b;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.tab.active {
    background: #fff;
    color: #1e293b;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.tab:hover:not(.active) {
    color: #334155;
}

.pagination {
    text-align: center;
    padding: 20px 0;
}

/* === Orders Page === */
.order-day-right {
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
}

.btn-cancel {
    display: inline-block;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    background: #fef2f2;
    color: #dc2626;
    border: 1px solid #fecaca;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
}

.btn-cancel:hover {
    background: #fee2e2;
}

.btn-danger {
    display: inline-block;
    padding: 10px 24px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    background: #dc2626;
    color: #fff;
    border: none;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-danger:hover {
    background: #b91c1c;
}

.cancelled-badge {
    display: inline-block;
    font-size: 12px;
    font-weight: 600;
    color: #94a3b8;
    background: #f1f5f9;
    padding: 4px 10px;
    border-radius: 6px;
}

.order-cancelled {
    opacity: 0.5;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #94a3b8;
    font-size: 16px;
}

/* === Cancel Dialog === */
.dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.dialog-box {
    background: #fff;
    border-radius: 12px;
    padding: 28px 32px;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

.dialog-box h3 {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 8px;
}

.dialog-box p {
    color: #64748b;
    font-size: 14px;
    margin-bottom: 20px;
}

.dialog-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

/* === Mobile === */
/* === Responsive === */
@media (max-width: 768px) {
    .container {
        padding: 16px 12px;
    }

    .item-grid {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .menu-item {
        padding: 10px;
    }

    .item-name {
        font-size: 13px;
    }

    .item-name-en {
        font-size: 10px;
    }

    /* 底部工具栏 */
    .bottom-bar {
        padding: 10px 12px;
        gap: 8px;
    }

    .bottom-info {
        font-size: 13px;
    }

    #selected-count {
        font-size: 17px;
    }

    .btn {
        padding: 8px 16px;
        font-size: 13px;
    }

    /* 确认页 */
    .confirm-day-card {
        flex-direction: column;
    }

    .confirm-day-left {
        flex: none;
        flex-direction: row;
        align-items: center;
        gap: 12px;
        padding: 10px 16px;
        border-right: none;
        border-bottom: 1px solid #e2e8f0;
    }

    .confirm-day-right {
        flex: none;
        border-left: none;
        border-top: 1px solid #f1f5f9;
        justify-content: flex-end;
        padding: 8px 16px;
    }

    .header-inner {
        padding: 0 12px;
    }

    .header-info {
        font-size: 12px;
    }
}

@media (max-width: 420px) {
    .item-grid {
        grid-template-columns: 1fr;
    }

    .child-grid {
        grid-template-columns: 1fr;
    }

    .confirm-actions {
        flex-direction: column;
    }

    .confirm-actions .btn {
        text-align: center;
        width: 100%;
    }

    .menu-actions {
        position: sticky;
        top: 48px;
        z-index: 50;
        background: #f5f7fa;
        padding: 8px 0;
    }
}
