/*
 * 檔案用途：為收據產生器 (shopping-list.html) 提供特定的佈局和樣式。
 * This file provides specific layout and styles for the Receipt Generator (shopping-list.html).
 */

/* 繼承自 style.css 的變數 */

.shopping-container {
    display: flex;
    flex-direction: row;
    gap: 30px;
    max-width: 1400px !important;
    /* 覆蓋 style.css 的限制 */
    margin: 0 auto 60px auto;
    align-items: flex-start;
}

/* ----- 左側控制項 ----- */
.controls {
    flex: 1;
    min-width: 400px;
    background-color: rgba(0, 0, 0, 0.2);
    /* 較暗的透明背景 */
    padding: 20px;
    border-radius: 12px;
    height: fit-content;
    border: 1px solid var(--border-color);
}

.controls h1,
.controls h2 {
    color: var(--accent-color);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
    margin-top: 0;
}

#title-options {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}
#title-options label {
    margin-bottom: 0;
}
#receipt-title-other {
    flex: 1;
    min-width: 100px;
}

.item-input-header {
    display: flex;
    gap: 10px;
    font-weight: bold;
    color: var(--text-color);
    margin-bottom: 5px;
}
.input-name-label { flex: 4; }
.input-qty-label, .input-price-label { flex: 1; text-align: right; }
.controls-placeholder { width: 70px; } /* 對應按鈕寬度 */


.item-input-row {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 10px;
    padding: 10px;
    background-color: rgba(255, 255, 255, 0.05);
    border-radius: 5px;
    border: 1px solid var(--border-color);
}

.item-input-row input {
    margin-bottom: 0;
}
.item-input-row .item-name { flex: 4; }
.item-input-row .item-qty, .item-input-row .item-price { flex: 1; text-align: right; }

.item-controls {
    display: flex;
    gap: 5px;
}

/* 按鈕 */
.btn-add {
    width: 100%;
    margin-top: 10px;
}
.btn-move, .btn-remove {
    padding: 5px;
    font-size: 0.8em;
    line-height: 1;
    width: 30px;
    height: 30px;
}
.btn-remove {
    background-color: var(--error-color);
    color: white;
}

.download-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
    margin-top: 20px;
}

/* ----- 右側預覽畫面 ----- */
.preview-container {
    flex: 1;
    min-width: 400px;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: sticky;
    top: 20px;
}

.receipt {
    width: 384px; /* 80mm 熱感應紙寬度模擬 */
    background-color: #fff;
    /* 收據預覽必須是白色背景以供列印 */
    color: #000;
    /* 收據文字必須是黑色 */
    padding: 15px;
    box-sizing: border-box;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    font-family: 'Noto Sans TC', sans-serif;
}

.receipt .text-center { text-align: center; }
.receipt header, .receipt main, .receipt footer { padding: 0 5px; }

#preview-logo {
    max-width: 150px;
    max-height: 80px;
    margin: 0 auto 10px;
    display: block;
}

.receipt h2 { font-size: 1.2em; margin: 0; color: #000; }
.receipt p { margin: 4px 0; font-size: 0.9em; }
.receipt hr.dashed { border: none; border-top: 1px dashed #000; margin: 10px 0; }

.item-list-header {
    display: flex;
    justify-content: space-between;
    font-weight: bold;
    font-size: 0.9em;
    border-bottom: 1px solid #000;
    padding-bottom: 5px;
}
.item-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.9em;
    padding: 2px 0;
}
.col-name { flex: 4; text-align: left; }
.col-qty, .col-price, .col-total { flex: 1; text-align: right; }

.totals { margin-top: 10px; }
.total-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.9em;
    padding: 2px 0;
}
.grand-total { font-weight: bold; font-size: 1.1em; }

.notes { margin-top: 10px; font-size: 0.8em; }
.print-separator { text-align: center; margin: 10px 0; font-size: 0.8em; }


/* 列印樣式覆蓋 */
@media print {
    body {
        background: none;
    }
    .shopping-container {
        display: block;
        background: none;
        backdrop-filter: none;
        border: none;
        box-shadow: none;
    }

    /* 隱藏所有非列印內容 */
    .controls, .footer, .menu-btn, .download-buttons, .preview-container h2 {
        display: none !important;
    }

    /* 只顯示預覽畫面 */
    .preview-container {
        display: block;
        position: static;
        width: 100%;
        min-width: unset;
    }

    .receipt {
        box-shadow: none;
        margin: 0;
        width: 100%;
        border: none;
        padding: 0;
    }
}

/* RWD 響應式設計 */
@media (max-width: 992px) {
    .shopping-container {
        flex-direction: column;
        align-items: stretch;
    }

    .controls, .preview-container {
        width: 100%;
        box-sizing: border-box;
        min-width: unset;
    }
    .preview-container {
        position: static;
        margin-top: 30px;
    }
    .receipt {
        width: 100%;
        max-width: 384px; /* 在手機上保持最大寬度 */
        margin: 0 auto;
    }
}