* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft JhengHei', Arial, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.6;
}

/* 通用隱藏工具類 */
.hidden {
    display: none !important;
}

.container {
    display: flex;
    min-height: 100vh;
    gap: 20px;
    padding: 20px;
}

/* 主內容區域 */
.main-content {
    flex: 1;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    overflow: hidden;
}

/* 標籤導航 */
.tabs {
    display: flex;
    border-bottom: 1px solid #e0e0e0;
    background-color: #fafafa;
}

.tab-btn {
    padding: 15px 30px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    color: #666;
    border-bottom: 3px solid transparent;
    transition: all 0.3s;
}

.tab-btn.active {
    color: #1976d2;
    border-bottom-color: #1976d2;
    font-weight: 600;
}

.tab-btn:hover {
    background-color: #f0f0f0;
}

/* 標籤內容 */
.tab-content {
    display: none;
    padding: 30px;
}

.tab-content.active {
    display: block;
}

/* 表單區塊 */
.form-section {
    margin-bottom: 30px;
    position: relative;
}

.form-section h2,
.form-section h3 {
    margin-bottom: 20px;
    color: #333;
    display: flex;
    align-items: center;
    gap: 8px;
}

.icon {
    font-size: 20px;
}

.view-stats-btn {
    position: absolute;
    right: 0;
    top: 0;
    padding: 8px 16px;
    background-color: #2196F3;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.3s;
}

.view-stats-btn:hover {
    background-color: #1976D2;
}

/* 表單行和組 */
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 15px;
}

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

.form-group label {
    margin-bottom: 8px;
    font-weight: 500;
    color: #555;
}

.required {
    color: #f44336;
}

.form-group input,
.form-group select {
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    transition: border-color 0.3s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #2196F3;
}

.phone-group {
    display: flex;
    gap: 10px;
}

.phone-input {
    flex: 2;
}

.ext-input {
    flex: 1;
}

/* 切換按鈕 */
.toggle-btn {
    padding: 8px 16px;
    background: none;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    color: #666;
    margin-bottom: 15px;
    transition: all 0.3s;
}

.toggle-btn:hover {
    background-color: #f5f5f5;
}

/* 服務項目表格 */
.add-item-btn {
    padding: 10px 20px;
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    margin-bottom: 20px;
    font-size: 14px;
    transition: background-color 0.3s;
}

.add-item-btn:hover {
    background-color: #45a049;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.section-header h3 {
    margin: 0;
}

.items-container {
    display: none;
}

.item-card {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.item-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid #e0e0e0;
}

.item-card-title {
    font-weight: 600;
    color: #1976d2;
    font-size: 16px;
}

.item-card .form-group {
    margin-bottom: 12px;
}

.item-card label {
    display: block;
    margin-bottom: 6px;
    color: #666;
    font-size: 14px;
    font-weight: 500;
}

.item-card input,
.item-card select {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    background-color: white;
}

.item-card input:focus {
    outline: none;
    border-color: #1976d2;
}

.item-card .form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.item-card-total {
    background-color: #f5f5f5;
    padding: 12px;
    border-radius: 4px;
    text-align: right;
    font-size: 16px;
    font-weight: 600;
    color: #333;
    margin-bottom: 12px;
}

.item-card-total .amount-mobile {
    color: #1976d2;
    font-size: 18px;
}

.items-table {
    overflow-x: auto;
    margin-bottom: 20px;
}

#itemsTable {
    width: 100%;
    border-collapse: collapse;
    background: white;
}

#itemsTable th,
#itemsTable td {
    padding: 12px;
    text-align: left;
    border: 1px solid #e0e0e0;
}

#itemsTable th {
    background-color: #f5f5f5;
    font-weight: 600;
    color: #333;
}

#itemsTable input,
#itemsTable select {
    width: 100%;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.remove-item-btn {
    background-color: #f44336;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.3s;
    width: 100%;
}

.remove-item-btn:hover {
    background-color: #da190b;
}

/* 折扣設定 */
.discount-section,
.tax-section {
    margin-top: 20px;
    padding: 16px;
    background-color: #fafafa;
    border-radius: 6px;
}

.discount-section h4,
.tax-section h4 {
    margin: 0 0 12px 0;
    font-size: 14px;
    color: #333;
    font-weight: 600;
}

.discount-section .form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.discount-section .form-group,
.tax-section {
    margin: 0;
}

.discount-section select,
.discount-section input,
.tax-section select {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    background-color: white;
}

/* 總計區域 */
.total-section {
    background-color: #f9f9f9;
    border-radius: 8px;
    padding: 20px;
    margin-top: 20px;
}

.total-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 16px;
    color: #333;
    margin-bottom: 10px;
}

.total-row:last-child {
    margin-bottom: 0;
}

.discount-row .discount-amount {
    color: #4caf50;
    font-weight: 600;
}

.after-discount-amount {
    font-weight: 600;
}

.tax-row .tax-amount {
    color: #d32f2f;
    font-weight: 600;
}

.total-final {
    font-size: 20px;
    font-weight: 700;
    padding-top: 12px;
    border-top: 2px solid #e0e0e0;
}

.subtotal-amount,
.total-amount {
    font-weight: 600;
}

.total-amount {
    color: #d32f2f;
}

/* 右側預覽面板 */
.preview-panel {
    width: 450px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    position: sticky;
    top: 20px;
    height: fit-content;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
}

.preview-header {
    padding: 20px;
    border-bottom: 1px solid #e0e0e0;
}

.preview-header h2 {
    margin-bottom: 15px;
    color: #333;
}

.alert {
    background-color: #fff3cd;
    border: 1px solid #ffc107;
    color: #856404;
    padding: 10px;
    border-radius: 4px;
    margin-bottom: 15px;
    font-size: 14px;
}

.export-buttons {
    display: flex;
    gap: 10px;
}

.export-btn {
    flex: 1;
    padding: 10px;
    border: 1px solid #ddd;
    background: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s;
}

.export-btn:hover:not(:disabled) {
    background-color: #f5f5f5;
    border-color: #2196F3;
}

.export-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* 預覽標籤 */
.preview-tabs {
    display: flex;
    border-bottom: 1px solid #e0e0e0;
    background-color: #fafafa;
}

.preview-tab {
    flex: 1;
    padding: 12px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    color: #666;
    border-bottom: 2px solid transparent;
    transition: all 0.3s;
}

.preview-tab.active {
    color: #2196F3;
    border-bottom-color: #2196F3;
    font-weight: 600;
}

/* 預覽內容 */
.preview-content {
    padding: 20px;
}

.preview-content h3 {
    margin-bottom: 15px;
    font-size: 18px;
    color: #333;
}

.preview-info {
    margin-bottom: 20px;
    font-size: 14px;
    color: #666;
}

.preview-info div {
    margin-bottom: 5px;
}

.preview-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 15px;
    font-size: 13px;
}

.preview-table th,
.preview-table td {
    padding: 10px;
    text-align: left;
    border: 1px solid #e0e0e0;
}

.preview-table th {
    background-color: #f5f5f5;
    font-weight: 600;
}

.empty-message {
    text-align: center;
    color: #999;
    padding: 30px !important;
}

.preview-total {
    padding: 15px;
    background-color: #f9f9f9;
    border-radius: 6px;
    margin-top: 15px;
}

.preview-total-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    font-size: 14px;
}

.preview-total-row.preview-final {
    border-top: 2px solid #e0e0e0;
    margin-top: 10px;
    padding-top: 12px;
    font-size: 18px;
    font-weight: 700;
}

.preview-total-row .discount-text {
    color: #4caf50;
}

.preview-total-row .tax-text {
    color: #d32f2f;
}

.preview-total-row .total-text {
    color: #d32f2f;
    font-weight: 700;
}

.standard-totals {
    margin-top: 20px;
    padding: 15px;
    background-color: #f9f9f9;
    border-radius: 6px;
}

.standard-total-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
}

.standard-total-row.standard-final {
    border-top: 2px solid #e0e0e0;
    margin-top: 10px;
    padding-top: 12px;
    font-size: 18px;
    font-weight: 700;
}

.standard-total-row .discount-text {
    color: #4caf50;
}

.standard-total-row .tax-text {
    color: #d32f2f;
}

.preview-signature {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid #e0e0e0;
    color: #666;
    font-size: 14px;
}

/* 詳細版預覽樣式 */
.detailed-preview {
    font-size: 13px;
}

.detailed-header {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid #333;
}

.customer-initial {
    width: 50px;
    height: 50px;
    background-color: #2196F3;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    font-weight: bold;
    border-radius: 4px;
}

.detailed-title {
    font-size: 24px;
    font-weight: bold;
    color: #333;
    margin: 0;
}

.detailed-info-row {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
    margin-bottom: 20px;
    padding: 10px;
    background-color: #f9f9f9;
    border-radius: 4px;
    text-align: right;
}

.info-item {
    font-size: 12px;
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.info-label {
    color: #666;
}

.info-value {
    color: #333;
    font-weight: 500;
}

.customer-section {
    margin-bottom: 15px;
}

.customer-section h4 {
    margin: 0;
    padding: 8px;
    background-color: #f5f5f5;
    border-left: 4px solid #2196F3;
    font-size: 14px;
    color: #333;
}

.customer-details {
    padding: 15px 10px;
    background-color: #fafafa;
    margin-bottom: 20px;
    border-radius: 4px;
}

.customer-name {
    font-size: 18px;
    font-weight: bold;
    color: #333;
    margin-bottom: 8px;
}

.customer-tax-id {
    font-size: 12px;
    color: #666;
}

.detailed-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 15px;
    font-size: 12px;
}

.detailed-table th,
.detailed-table td {
    padding: 10px;
    text-align: left;
    border: 1px solid #e0e0e0;
}

.detailed-table th {
    background-color: #f5f5f5;
    font-weight: 600;
    color: #333;
}

.detailed-table td:nth-child(2),
.detailed-table td:nth-child(3),
.detailed-table td:nth-child(4),
.detailed-table th:nth-child(2),
.detailed-table th:nth-child(3),
.detailed-table th:nth-child(4) {
    text-align: right;
}

.detailed-totals {
    text-align: right;
    padding: 15px 10px;
    background-color: #f9f9f9;
    border-radius: 4px;
    margin-bottom: 20px;
}

.subtotal-row {
    font-size: 14px;
    color: #666;
    margin-bottom: 8px;
}

.total-row {
    font-size: 16px;
    font-weight: bold;
    color: #333;
}

.total-amount {
    color: #f44336;
    font-size: 18px;
}

.signature-section {
    display: flex;
    gap: 20px;
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid #e0e0e0;
}

.signature-box {
    flex: 1;
    padding: 15px;
    background-color: #fafafa;
    border-radius: 4px;
}

.signature-box h5 {
    margin: 0 0 15px 0;
    font-size: 13px;
    color: #333;
    font-weight: 600;
}

.signature-field {
    margin-bottom: 10px;
    font-size: 12px;
    color: #666;
}

.version-info {
    text-align: center;
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid #e0e0e0;
    font-size: 11px;
    color: #999;
}

/* 精簡版預覽樣式 */
.standard-preview {
    font-size: 13px;
}

.standard-title {
    font-size: 20px;
    font-weight: 600;
    margin: 0 0 10px 0;
    color: #333;
}

.standard-tax-id {
    font-size: 12px;
    color: #555;
    margin-bottom: 15px;
}

.standard-info {
    font-size: 12px;
    margin-bottom: 15px;
    line-height: 1.6;
}

.standard-info .label {
    color: #333;
    font-weight: 600;
}

.standard-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 10px;
    font-size: 12px;
}

.standard-table th,
.standard-table td {
    padding: 10px;
    border: 1px solid #e0e0e0;
    text-align: left;
}

.standard-table th {
    background-color: #f5f5f5;
    font-weight: 600;
    color: #333;
}

.standard-table td:nth-child(3),
.standard-table td:nth-child(4),
.standard-table td:nth-child(5),
.standard-table th:nth-child(3),
.standard-table th:nth-child(4),
.standard-table th:nth-child(5) {
    text-align: center;
}

.standard-total {
    font-size: 14px;
    font-weight: 600;
    text-align: right;
    margin-top: 10px;
}

.standard-total .amount-red {
    color: #d32f2f;
    font-weight: 700;
}

/* 響應式設計 */
@media (max-width: 1200px) {
    .container {
        flex-direction: column;
    }
    
    .preview-panel {
        width: 100%;
        position: static;
        max-height: none;
    }
}

@media (max-width: 768px) {
    .form-row {
        grid-template-columns: 1fr;
    }
    
    .container {
        padding: 10px;
    }
    
    .tab-content {
        padding: 15px;
    }
    
    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
    
    .section-header h3 {
        width: 100%;
    }
    
    .add-item-btn {
        width: 100%;
    }
    
    /* 隱藏桌面版表格 */
    .desktop-only {
        display: none !important;
    }
    
    /* 顯示卡片式布局 */
    .items-container {
        display: block !important;
    }
    
    .total-section {
        padding: 16px;
    }
    
    .total-row {
        font-size: 14px;
    }
    
    .total-final {
        font-size: 18px;
    }
}
