/* ============== 基础重置 ============== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #faf6f0;
    --bg-card: #ffffff;
    --bg-soft: #f5ebd9;
    --color-warm: #b8743a;
    --color-warm-dark: #8a5128;
    --color-warm-light: #e8b678;
    --color-text: #3d2817;
    --color-text-light: #7a6347;
    --color-border: #e8dcc4;
    --color-accent: #c2410c;
    --color-success: #16a34a;
    --color-warning: #f59e0b;
    --color-danger: #dc2626;
    --shadow-sm: 0 1px 3px rgba(139, 90, 43, 0.08);
    --shadow-md: 0 4px 12px rgba(139, 90, 43, 0.1);
    --shadow-lg: 0 8px 24px rgba(139, 90, 43, 0.12);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    background: var(--bg-primary);
    background-image:
        radial-gradient(circle at 20% 10%, rgba(232, 182, 120, 0.15), transparent 40%),
        radial-gradient(circle at 80% 90%, rgba(184, 116, 58, 0.12), transparent 40%);
    color: var(--color-text);
    line-height: 1.6;
    min-height: 100vh;
    padding: 24px 16px 60px;
}

.container {
    max-width: 920px;
    margin: 0 auto;
}

/* ============== 头部 ============== */
.hero {
    text-align: center;
    margin-bottom: 32px;
    padding: 20px 0;
}

.hero h1 {
    font-size: 2.4rem;
    color: var(--color-warm-dark);
    font-weight: 700;
    margin-bottom: 8px;
    letter-spacing: -0.5px;
}

.subtitle {
    color: var(--color-text-light);
    font-size: 1rem;
}

/* ============== 卡片 ============== */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--color-border);
    transition: box-shadow 0.2s ease;
}

.card:hover {
    box-shadow: var(--shadow-lg);
}

.card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 6px;
}

.card-header h2 {
    font-size: 1.35rem;
    color: var(--color-warm-dark);
    font-weight: 600;
}

.step-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--color-warm), var(--color-warm-dark));
    color: white;
    font-weight: 700;
    font-size: 0.95rem;
    flex-shrink: 0;
}

.summary-badge {
    background: linear-gradient(135deg, var(--color-warm-light), var(--color-warm));
    font-size: 1rem;
}

.card-hint {
    color: var(--color-text-light);
    font-size: 0.88rem;
    margin-bottom: 18px;
    padding-left: 44px;
}

/* ============== 表单字段 ============== */
.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
    min-width: 0;
}

.field label {
    font-size: 0.85rem;
    color: var(--color-text-light);
    font-weight: 500;
}

input[type="number"],
input[type="text"],
select {
    width: 100%;
    padding: 9px 12px;
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: white;
    color: var(--color-text);
    font-size: 0.95rem;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    font-family: inherit;
}

input[type="number"]:focus,
input[type="text"]:focus,
select:focus {
    outline: none;
    border-color: var(--color-warm);
    box-shadow: 0 0 0 3px rgba(184, 116, 58, 0.15);
}

input[type="number"]:hover,
input[type="text"]:hover,
select:hover {
    border-color: var(--color-warm-light);
}

/* ============== 面粉配比区 ============== */
.flour-base,
.hydration-base,
.sugar-base {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    padding: 16px;
    background: var(--bg-soft);
    border-radius: var(--radius-md);
    margin-bottom: 16px;
}

.hydration-base,
.sugar-base {
    grid-template-columns: 1fr auto;
    align-items: end;
}

.hydration-info,
.sugar-info {
    background: white;
    padding: 9px 14px;
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--color-border);
    color: var(--color-text-light);
    font-size: 0.95rem;
    white-space: nowrap;
}

.hydration-info strong,
.sugar-info strong {
    color: var(--color-warm-dark);
    font-size: 1.05rem;
    margin-left: 4px;
}

/* ============== 列表行 ============== */
.flour-list,
.liquid-list,
.extras-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 12px;
}

.row {
    display: grid;
    grid-template-columns: 1.4fr 1fr 1.4fr auto;
    gap: 10px;
    align-items: end;
    padding: 12px;
    background: var(--bg-soft);
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.row:hover {
    border-color: var(--color-warm-light);
    background: #fdf6e8;
}

.row.highlight {
    background: linear-gradient(135deg, #fff8eb, #fef3d9);
    border-color: var(--color-warm-light);
}

.row .row-result {
    background: white;
    border: 1.5px solid var(--color-warm-light);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    color: var(--color-warm-dark);
    text-align: center;
    font-variant-numeric: tabular-nums;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
}

.row-result .result-mass {
    font-size: 1rem;
    line-height: 1.2;
}

.row-result .result-ratio {
    font-size: 0.72rem;
    font-weight: 400;
    color: var(--color-text-light);
    letter-spacing: 0.2px;
}

.auto-tag {
    display: inline-block;
    background: var(--color-warm);
    color: white;
    font-size: 0.62rem;
    padding: 1px 6px;
    border-radius: 8px;
    margin-left: 6px;
    vertical-align: middle;
    font-weight: 500;
    letter-spacing: 0.3px;
}

.row-result.invalid {
    background: #fef2f2;
    border-color: #fca5a5;
    color: var(--color-danger);
}

.flour-hint {
    margin-top: 4px;
    padding: 8px 12px;
    background: #fff8eb;
    border: 1px solid var(--color-warm-light);
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    color: var(--color-warm-dark);
    line-height: 1.5;
}

.btn-remove {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--color-border);
    background: white;
    color: var(--color-text-light);
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
    transition: all 0.15s ease;
    flex-shrink: 0;
    align-self: end;
}

.btn-remove:hover {
    background: #fef2f2;
    border-color: #fca5a5;
    color: var(--color-danger);
}

/* 液体行更紧凑 */
.liquid-list .row {
    grid-template-columns: 1.3fr 0.9fr 0.9fr 1.2fr auto;
}

/* 糖行：与液体行同结构 */
.sugar-list .row {
    grid-template-columns: 1.3fr 0.9fr 0.9fr 1.2fr auto;
}

/* 附加材料行 */
.extras-list .row {
    grid-template-columns: 1.4fr 1fr 1.2fr auto;
}

/* ============== 按钮 ============== */
.btn-add {
    width: 100%;
    padding: 10px;
    background: white;
    border: 2px dashed var(--color-warm-light);
    border-radius: var(--radius-md);
    color: var(--color-warm);
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.15s ease;
}

.btn-add:hover {
    background: var(--bg-soft);
    border-color: var(--color-warm);
    color: var(--color-warm-dark);
}

/* ============== 快捷模板 ============== */
.quick-templates {
    margin-top: 14px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.quick-label {
    font-size: 0.85rem;
    color: var(--color-text-light);
    margin-right: 4px;
}

.btn-template {
    padding: 6px 12px;
    background: var(--bg-soft);
    border: 1px solid var(--color-border);
    border-radius: 999px;
    color: var(--color-warm-dark);
    font-size: 0.82rem;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: inherit;
}

.btn-template:hover {
    background: var(--color-warm);
    color: white;
    border-color: var(--color-warm);
    transform: translateY(-1px);
}

/* ============== 糖行 ============== */
.sugar-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 16px;
    padding: 16px;
    background: var(--bg-soft);
    border-radius: var(--radius-md);
}

.result-value {
    padding: 9px 12px;
    background: white;
    border: 1.5px solid var(--color-warm-light);
    border-radius: var(--radius-sm);
    font-weight: 600;
    color: var(--color-warm-dark);
    text-align: center;
    font-variant-numeric: tabular-nums;
}

/* ============== 总览表 ============== */
.summary-card {
    background: linear-gradient(135deg, #fff8eb, #fef3d9);
    border-color: var(--color-warm-light);
}

.summary-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 16px;
}

.summary-table thead th {
    text-align: left;
    padding: 10px 12px;
    background: var(--color-warm-dark);
    color: white;
    font-size: 0.88rem;
    font-weight: 600;
    letter-spacing: 0.3px;
}

.summary-table thead th:first-child {
    border-top-left-radius: var(--radius-sm);
}

.summary-table thead th:last-child {
    border-top-right-radius: var(--radius-sm);
    text-align: right;
}

.summary-table tbody td {
    padding: 10px 12px;
    border-bottom: 1px solid rgba(184, 116, 58, 0.15);
    font-size: 0.95rem;
    font-variant-numeric: tabular-nums;
}

.summary-table tbody tr:hover {
    background: rgba(232, 182, 120, 0.1);
}

.summary-table tbody td.text-right {
    text-align: right;
    font-weight: 600;
    color: var(--color-warm-dark);
}

.summary-table tfoot td {
    padding: 12px;
    background: var(--color-warm-dark);
    color: white;
    font-size: 1.05rem;
}

.summary-table tfoot td.text-right {
    text-align: right;
}

/* ============== 操作按钮 ============== */
.actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 12px;
}

.btn-action {
    padding: 9px 18px;
    background: white;
    border: 1.5px solid var(--color-warm-light);
    border-radius: var(--radius-md);
    color: var(--color-warm-dark);
    cursor: pointer;
    font-size: 0.92rem;
    font-weight: 500;
    font-family: inherit;
    transition: all 0.15s ease;
}

.btn-action:hover {
    background: var(--bg-soft);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.btn-action.primary {
    background: var(--color-warm);
    color: white;
    border-color: var(--color-warm);
}

.btn-action.primary:hover {
    background: var(--color-warm-dark);
    border-color: var(--color-warm-dark);
}

/* ============== 缩放面板 ============== */
.scale-panel {
    margin-top: 14px;
    display: flex;
    gap: 12px;
    align-items: end;
    padding: 14px;
    background: white;
    border-radius: var(--radius-md);
    border: 1.5px solid var(--color-warm-light);
}

.scale-panel .field {
    flex: 0 0 160px;
}

/* ============== 警告信息 ============== */
.hydration-warning,
.protein-warning {
    margin-top: 14px;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.hydration-warning.show,
.protein-warning.show {
    display: flex !important;
}

.hydration-warning {
    background: #fef3c7;
    border: 1px solid #fcd34d;
    color: #92400e;
}

.protein-warning {
    background: #dbeafe;
    border: 1px solid #93c5fd;
    color: #1e40af;
}

/* ============== 页脚 ============== */
footer {
    text-align: center;
    margin-top: 36px;
    color: var(--color-text-light);
    font-size: 0.85rem;
}

footer p {
    margin: 4px 0;
}

.footer-tip {
    font-size: 0.78rem;
    opacity: 0.85;
}

/* ============== Toast ============== */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--color-text);
    color: white;
    padding: 12px 22px;
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transition: all 0.25s ease;
    pointer-events: none;
    z-index: 1000;
}

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

/* ============== 图片预览弹窗 ============== */
#image-preview-modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.preview-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(2px);
    cursor: pointer;
}

.preview-dialog {
    position: relative;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.25s ease;
}

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

.preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--color-border);
    background: var(--bg-soft);
    font-weight: 600;
    color: var(--color-warm-dark);
    font-size: 1.05rem;
}

.preview-close {
    background: transparent;
    border: none;
    font-size: 1.6rem;
    line-height: 1;
    color: var(--color-text-light);
    cursor: pointer;
    padding: 0 4px;
    transition: color 0.15s ease;
    font-family: inherit;
}

.preview-close:hover {
    color: var(--color-danger);
}

.preview-body {
    flex: 1;
    overflow: auto;
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #2d2419;
    min-height: 200px;
}

.preview-body img {
    max-width: 100%;
    max-height: 70vh;
    display: block;
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.preview-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--color-border);
    background: var(--bg-soft);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.preview-hint {
    font-size: 0.82rem;
    color: var(--color-text-light);
    flex: 1;
    min-width: 200px;
}

.preview-actions {
    display: flex;
    gap: 8px;
}

/* ============== 响应式 ============== */
@media (max-width: 720px) {
    body {
        padding: 16px 12px 40px;
    }

    .hero h1 {
        font-size: 1.8rem;
    }

    .card {
        padding: 18px;
    }

    .flour-base,
    .hydration-base,
    .sugar-base {
        grid-template-columns: 1fr;
    }

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

    .row .field:nth-child(1),
    .row .row-result {
        grid-column: span 2;
    }

    .row .btn-remove {
        grid-column: span 2;
        width: 100%;
        margin-top: 4px;
    }

    .liquid-list .row,
    .sugar-list .row,
    .extras-list .row {
        grid-template-columns: 1fr 1fr;
    }

    .summary-table {
        font-size: 0.85rem;
    }
}
