/* 重置和基本樣式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    line-height: 1.6;
    color: #5d4e37;
    background: linear-gradient(135deg, #faf7f0 0%, #f5f1e8 50%, #f0ead2 100%);
    background-attachment: fixed;
    min-height: 100vh;
    position: relative;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(circle at 25% 25%, rgba(222, 184, 135, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 75% 75%, rgba(245, 222, 179, 0.1) 0%, transparent 50%);
    pointer-events: none;
    z-index: -1;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 15px;
    min-height: 100vh;
}

/* 頁頭樣式 */
header {
    text-align: center;
    margin-bottom: 30px;
    color: #8b7355;
    padding: 20px 15px;
}

header h1 {
    font-size: 2.2rem;
    margin-bottom: 12px;
    font-weight: 700;
    color: #6b5b47;
    text-shadow: 0 2px 4px rgba(139, 115, 85, 0.1);
}

header p {
    margin: 0.5rem 0 1rem 0;
    color: var(--text-secondary);
    font-size: 1rem;
}

.version-info {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    justify-content: center;
}

.version-info span {
    background: var(--accent-light);
    color: var(--text-secondary);
    padding: 0.2rem 0.5rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
    border: 1px solid var(--border-color);
}

@media (max-width: 480px) {
    .version-info {
        justify-content: center;
    }
    
    .version-info span {
        font-size: 0.7rem;
        padding: 0.15rem 0.4rem;
    }
}

/* 主要內容 */
main {
    background: #fdfcf7;
    border-radius: 16px;
    padding: 25px;
    box-shadow: 
        0 8px 32px rgba(139, 115, 85, 0.1),
        0 2px 8px rgba(139, 115, 85, 0.05);
    margin-bottom: 20px;
    border: 1px solid #f0ead2;
    position: relative;
}

/* 表單樣式 */
.invoice-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

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

.form-group label {
    font-weight: 600;
    color: #6b5b47;
    font-size: 1.1rem;
}

/* 發票類型選擇器 */
.invoice-type-selector {
    display: flex;
    gap: 10px;
    margin-top: 8px;
}

.type-btn {
    flex: 1;
    padding: 16px 20px;
    border: 2px solid #e8dcc0;
    border-radius: 12px;
    background: #fefdfb;
    color: #6b5b47;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    touch-action: manipulation;
}

.type-btn:hover {
    border-color: #d4c2a0;
    background: #f9f6f0;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(139, 115, 85, 0.15);
}

.type-btn.active {
    background: #c4a484;
    color: white;
    border-color: #c4a484;
    box-shadow: 0 4px 15px rgba(196, 164, 132, 0.3);
}

.type-btn.active:hover {
    background: #a8906f;
    border-color: #a8906f;
}

/* 發票欄位容器 */
.invoice-fields {
    transition: all 0.3s ease;
}

/* 統編輸入組 */
.tax-id-input-group {
    display: flex;
    gap: 8px;
    align-items: stretch;
}

.tax-id-input-group input {
    flex: 1;
}

/* 查詢功能相關樣式已移除 */

/* 記憶資訊提示 */
.memory-info {
    margin-top: 6px;
    font-size: 0.75rem;
    color: #8b7355;
    opacity: 0.7;
    text-align: right;
}

/* 儲存成功通知 */
.save-notification {
    margin-top: 8px;
    padding: 8px 12px;
    background: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    animation: slideInUp 0.3s ease, fadeOut 0.5s ease 2.5s forwards;
    text-align: center;
}

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

@keyframes fadeOut {
    to {
        opacity: 0;
        transform: translateY(-5px);
    }
}

.form-group input,
.form-group textarea {
    padding: 14px 16px;
    border: 2px solid #e8dcc0;
    border-radius: 10px;
    font-size: 16px; /* 防止 iOS 縮放 */
    transition: all 0.3s ease;
    background: #fefdfb;
    box-shadow: 0 2px 4px rgba(139, 115, 85, 0.08);
    font-weight: 500;
    width: 100%;
    -webkit-appearance: none; /* 移除 iOS 預設樣式 */
    appearance: none;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #c4a484;
    background: #ffffff;
    box-shadow: 
        0 0 0 3px rgba(196, 164, 132, 0.2),
        0 4px 12px rgba(139, 115, 85, 0.15);
    transform: translateY(-1px);
}

.form-group input:hover,
.form-group textarea:hover {
    border-color: #d4c2a0;
    box-shadow: 0 4px 8px rgba(139, 115, 85, 0.12);
}

/* 品名項目樣式 */
#itemsContainer {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.item-row {
    display: grid;
    grid-template-columns: 2fr 1fr auto;
    gap: 10px;
    align-items: center;
    padding: 15px;
    background: #f9f6f0;
    border-radius: 12px;
    border: 2px solid #ede4d3;
    transition: all 0.3s ease;
    margin-bottom: 10px;
}

.item-row:hover {
    border-color: #d4c2a0;
    box-shadow: 0 4px 12px rgba(139, 115, 85, 0.15);
    transform: translateY(-1px);
}

.item-name, .item-amount {
    margin: 0 !important;
}

.remove-item {
    background: #d4a574;
    color: white;
    border: none;
    border-radius: 8px;
    width: 32px;
    height: 32px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.3s ease;
    box-shadow: 0 2px 6px rgba(212, 165, 116, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.remove-item:hover {
    background: #b8935f;
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(212, 165, 116, 0.4);
}

.add-item-btn {
    background: #c4a484;
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: all 0.3s ease;
    align-self: flex-start;
    box-shadow: 0 3px 10px rgba(196, 164, 132, 0.3);
    margin-top: 10px;
}

.add-item-btn:hover {
    background: #a8906f;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(196, 164, 132, 0.4);
}

/* 計算區域 */
.calculation-section {
    background: #f7f3ed;
    padding: 20px;
    border-radius: 12px;
    border: 2px solid #ede4d3;
    margin: 25px 0;
    box-shadow: 0 4px 12px rgba(139, 115, 85, 0.1);
}

.calc-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    font-size: 1.1rem;
    font-weight: 500;
    color: #6b5b47;
}

.calc-row.total {
    border-top: 2px solid #d4c2a0;
    padding-top: 15px;
    margin-top: 12px;
    font-weight: 700;
    font-size: 1.3rem;
    color: #8b7355;
}

/* 按鈕組 */
.button-group {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    justify-content: center;
    margin-top: 25px;
}

.generate-btn, .copy-btn, .clear-btn {
    padding: 14px 20px;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 120px;
    touch-action: manipulation; /* 改善觸控體驗 */
}

.generate-btn {
    background: #c4a484;
    color: white;
}

.generate-btn:hover {
    background: #a8906f;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(196, 164, 132, 0.4);
}

.copy-btn {
    background-color: #8b7355;
    color: white;
}

.copy-btn:hover:not(:disabled) {
    background-color: #75634a;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(139, 115, 85, 0.4);
}

.copy-btn:disabled {
    background-color: #a8a29e;
    cursor: not-allowed;
    opacity: 0.6;
}

.clear-btn {
    background-color: #9f8a73;
    color: white;
}

.clear-btn:hover {
    background-color: #8a7563;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(159, 138, 115, 0.4);
}

/* 輸出區域 */
.output-section {
    margin-top: 25px;
    padding: 20px;
    background-color: #f7f3ed;
    border-radius: 12px;
    border: 2px solid #ede4d3;
}

.output-section h3 {
    color: #6b5b47;
    margin-bottom: 15px;
    font-size: 1.2rem;
}

.invoice-output {
    background-color: #fefdfb;
    padding: 18px;
    border-radius: 10px;
    border: 1px solid #e8dcc0;
    font-family: 'SF Mono', 'Monaco', 'Menlo', 'Courier New', monospace;
    white-space: pre-wrap;
    line-height: 1.6;
    font-size: 0.9rem;
    color: #5d4e37;
    min-height: 150px;
    word-break: break-all; /* 防止長文字超出容器 */
}

/* 頁腳 */
footer {
    text-align: center;
    color: #8b7355;
    font-size: 0.85rem;
    opacity: 0.8;
    padding: 20px 15px;
}

/* 超級手機友好的響應式設計 */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
    
    header {
        margin-bottom: 20px;
        padding: 15px 10px;
    }
    
    header h1 {
        font-size: 1.8rem;
        margin-bottom: 8px;
    }
    
    header p {
        font-size: 0.9rem;
    }
    
    main {
        padding: 20px 15px;
        border-radius: 12px;
    }
    
    .form-group {
        gap: 6px;
        margin-bottom: 20px;
    }
    
    .form-group label {
        font-size: 1rem;
        font-weight: 600;
    }
    
    .form-group input,
    .form-group textarea {
        padding: 16px 14px; /* 增加觸控面積 */
        font-size: 16px; /* 防止 iOS 縮放 */
        border-radius: 8px;
    }
    
    .item-row {
        grid-template-columns: 1fr;
        gap: 12px;
        padding: 15px;
        margin-bottom: 15px;
    }
    
    .item-name, .item-amount {
        grid-column: 1;
    }
    
    .remove-item {
        grid-column: 1;
        justify-self: end;
        width: 40px;
        height: 40px;
        font-size: 16px;
        margin-top: -8px;
    }
    
    .invoice-type-selector {
        flex-direction: column;
        gap: 8px;
    }
    
    .type-btn {
        padding: 18px 16px;
        font-size: 1rem;
        min-height: 50px;
    }
    
    .tax-id-input-group {
        flex-direction: column;
        gap: 8px;
    }
    
    .query-btn {
        width: 100%;
        padding: 16px;
        font-size: 1rem;
    }
    
    .add-item-btn {
        width: 100%;
        padding: 16px;
        font-size: 1.1rem;
        margin-top: 15px;
    }
    
    .calculation-section {
        padding: 18px 15px;
        margin: 20px 0;
    }
    
    .calc-row {
        padding: 12px 0;
        font-size: 1rem;
    }
    
    .calc-row.total {
        font-size: 1.25rem;
        padding-top: 18px;
    }
    
    .button-group {
        flex-direction: column;
        gap: 12px;
        margin-top: 25px;
    }
    
    .generate-btn, .copy-btn, .clear-btn {
        width: 100%;
        padding: 18px;
        font-size: 1.1rem;
        min-height: 50px; /* 確保觸控面積足夠 */
    }
    
    .output-section {
        margin-top: 20px;
        padding: 15px;
    }
    
    .invoice-output {
        padding: 15px;
        font-size: 0.85rem;
        min-height: 120px;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 8px;
    }
    
    header h1 {
        font-size: 1.6rem;
    }
    
    header p {
        font-size: 0.85rem;
    }
    
    main {
        padding: 18px 12px;
    }
    
    .form-group input,
    .form-group textarea {
        padding: 18px 16px; /* 更大的觸控面積 */
    }
    
    .type-btn {
        padding: 20px 16px;
        font-size: 0.95rem;
        min-height: 54px;
    }
    
    .query-btn {
        padding: 18px;
        font-size: 0.95rem;
    }
    
    .item-row {
        padding: 12px;
    }
    
    .calculation-section {
        padding: 15px 12px;
    }
    
    .calc-row {
        font-size: 0.95rem;
        flex-wrap: wrap;
        gap: 5px;
    }
    
    .calc-row.total {
        font-size: 1.1rem;
    }
    
    .generate-btn, .copy-btn, .clear-btn {
        padding: 20px;
        font-size: 1rem;
        min-height: 54px;
    }
    
    .invoice-output {
        font-size: 0.8rem;
        padding: 12px;
    }
}

/* 超小螢幕優化 */
@media (max-width: 360px) {
    header h1 {
        font-size: 1.4rem;
    }
    
    main {
        padding: 15px 10px;
    }
    
    .form-group input,
    .form-group textarea {
        padding: 16px 12px;
    }
    
    .calc-row {
        font-size: 0.9rem;
    }
    
    .calc-row.total {
        font-size: 1rem;
    }
}

/* 橫向模式優化 */
@media (max-width: 768px) and (orientation: landscape) {
    .container {
        padding: 10px 15px;
    }
    
    main {
        padding: 20px;
    }
    
    .invoice-type-selector {
        flex-direction: row;
        gap: 10px;
    }
    
    .item-row {
        grid-template-columns: 2fr 1fr auto;
        gap: 10px;
    }
    
    .remove-item {
        margin-top: 0;
    }
    
    .button-group {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .generate-btn, .copy-btn, .clear-btn {
        flex: 1;
        min-width: 140px;
        max-width: 200px;
    }
}

/* 動畫效果 */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.output-section {
    animation: fadeInUp 0.5s ease;
}

/* 複製成功提示 */
.copy-success {
    background-color: #c4a484 !important;
    transform: scale(1.02);
}

.copy-success:after {
    content: " ✓";
}

/* 手機觸控優化 */
@media (hover: none) and (pointer: coarse) {
    /* 移除懸停效果，改善觸控體驗 */
    .form-group input:hover,
    .form-group textarea:hover,
    .item-row:hover,
    .add-item-btn:hover,
    .generate-btn:hover,
    .copy-btn:hover:not(:disabled),
    .clear-btn:hover,
    .remove-item:hover {
        transform: none;
        box-shadow: inherit;
    }
    
    /* 增加按鈕的觸控回饋 */
    .add-item-btn:active,
    .generate-btn:active,
    .copy-btn:active:not(:disabled),
    .clear-btn:active,
    .remove-item:active {
        transform: scale(0.98);
        opacity: 0.8;
    }
}

/* 確保在所有裝置上都有良好的可讀性 */
@media (max-width: 768px) {
    * {
        -webkit-tap-highlight-color: rgba(196, 164, 132, 0.2);
    }
    
    /* 防止用戶縮放但保持可訪問性 */
    input, textarea, select {
        font-size: 16px !important; /* 防止 iOS Safari 縮放 */
    }
}

/* 深色模式支援（如果需要的話） */
@media (prefers-color-scheme: dark) {
    /* 可以在這裡添加深色模式樣式 */
}