* { box-sizing: border-box; }
body {
    font-family: "Microsoft JhengHei", "Segoe UI", Arial, sans-serif;
    margin: 0;
    padding: 30px;
    background: #f0f2f5;
    color: #1a1a2e;
}

/* Page Header */
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.page-header h2 { margin: 0; font-size: 18px; color: #1a1a2e; }

/* Page Title Bar (unified theme header) */
.page-title-bar {
    display: flex;
    align-items: center;
    margin: -30px -30px 20px;
    padding: 11px 30px 11px 27px;
    background: #f0f2f5;
    color: #1a1a2e;
    border-left: 5px solid #f0f2f5;
    border-bottom: 1px solid #e9ecef;
}
.page-title-main {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0.5px;
    line-height: 1.2;
}

/* Alerts */
.alert {
    padding: 14px 20px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 14px;
    font-weight: 500;
}
.alert-success { background: #d4edda; color: #155724; border-left: 4px solid #28a745; }
.alert-danger { background: #f8d7da; color: #721c24; border-left: 4px solid #dc3545; }

.error-msg, .success-msg {
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 16px;
    text-align: center;
    font-size: 14px;
    background: #f0fff4;
    color: #2e7d32;
    border: 1px solid #c8e6c9;
}
.error-msg {
    background: #fff5f5;
    color: #dc3545;
    border: 1px solid #ffe0e0;
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 16px;
    text-align: center;
    font-size: 14px;
}

/* Info box */
.info-box { background: #e7f3ff; border-left: 4px solid #4361ee; padding: 12px; margin-bottom: 16px; border-radius: 4px; font-size: 13px; }

/* Tab bar (sub-navigation) */
.tab-bar {
    display: inline-flex;
    gap: 4px;
    background: #eef0f4;
    border: 1px solid #e0e3e8;
    border-radius: 10px;
    padding: 4px;
    margin-bottom: 16px;
}
.tab-bar .tab {
    display: inline-block;
    padding: 8px 20px;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    color: #6c757d;
    border-radius: 7px;
    white-space: nowrap;
    transition: all 0.2s;
}
.tab-bar .tab:hover {
    color: #4361ee;
    background: #fff;
}
.tab-bar .tab.active {
    color: #fff;
    background: #4361ee;
    box-shadow: 0 2px 8px rgba(67,97,238,0.3);
}
.tab-bar .tab.active:hover {
    color: #fff;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    font-family: inherit;
}
.btn-primary { background: #4361ee; color: #fff; }
.btn-primary:hover { background: #3a56d4; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(67,97,238,0.3); }
.btn-success { background: #28a745; color: #fff; }
.btn-success:hover { background: #218838; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(40,167,69,0.3); }
.btn-warning { background: #f0ad4e; color: #fff; }
.btn-warning:hover { background: #ec971f; }
.btn-danger { background: #dc3545; color: #fff; }
.btn-danger:hover { background: #c82333; }
.btn-sm { padding: 5px 12px; font-size: 12px; }

/* Tables */
.table-container {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    overflow: hidden;
}
table { width: 100%; border-collapse: collapse; }
thead th {
    background: #f8f9fc;
    color: #495057;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    padding: 14px 12px;
    border-bottom: 2px solid #e9ecef;
    white-space: nowrap;
}
tbody tr { transition: background 0.15s; cursor: pointer; }
tbody tr:hover { background: #dce8f7; }
tbody tr + tr { border-top: 1px solid #f0f0f0; }
tbody td { padding: 14px 12px; font-size: 13px; vertical-align: middle; line-height: 1.5; }

.empty-state { text-align: center; padding: 60px 20px; color: #6c757d; }
.empty-state p { font-size: 16px; margin: 0; }

.status-in { color: #28a745; font-weight: 700; }
.status-out { color: #dc3545; font-weight: 700; }

/* Filter Bar */
.filter-bar {
    background: #fff;
    padding: 14px 20px;
    border-radius: 10px;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    display: flex;
    gap: 12px;
    align-items: flex-end;
    flex-wrap: wrap;
}
.filter-bar label { font-size: 12px; font-weight: 600; color: #6c757d; display: block; margin-bottom: 4px; }
.filter-bar input, .filter-bar select {
    padding: 7px 12px;
    border: 1.5px solid #dee2e6;
    border-radius: 6px;
    font-size: 13px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s;
}
.filter-bar input:focus, .filter-bar select:focus { border-color: #4361ee; }
.filter-bar .field { display: flex; flex-direction: column; }
.filter-bar .field-check { display: flex; align-items: flex-end; padding-bottom: 2px; }
.filter-bar .check-label { display: flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 500; color: #495057; cursor: pointer; white-space: nowrap; }
.filter-bar .check-label input[type=checkbox] { width: 15px; height: 15px; cursor: pointer; margin: 0; }
.filter-bar .btn-search {
    background: #4361ee; color: #fff; border: none;
    padding: 8px 20px; border-radius: 6px;
    font-size: 13px; font-weight: 600; cursor: pointer; font-family: inherit;
    transition: background 0.15s;
}
.filter-bar .btn-search:hover { background: #3a56d4; }
.filter-bar .btn-clear {
    background: transparent; color: #6c757d;
    border: 1.5px solid #dee2e6; padding: 7px 16px; border-radius: 6px;
    font-size: 13px; cursor: pointer; text-decoration: none; font-family: inherit;
    transition: all 0.15s;
}
.filter-bar .btn-clear:hover { background: #f8f9fa; border-color: #adb5bd; }

/* Badges */
.badge { display: inline-block; padding: 3px 10px; border-radius: 12px; font-size: 11px; font-weight: 600; text-decoration: none; }
a.badge { cursor: pointer; }
.badge-green { background: #e8f5e9; color: #2e7d32; }
.badge-red { background: #ffe0e0; color: #d32f2f; }
.badge-blue { background: #e3f2fd; color: #1565c0; }
.badge-orange { background: #fff3e0; color: #e65100; }
.badge-gray { background: #f0f0f0; color: #888; }
.badge-yellow { background: #fff8e1; color: #f57f17; }

/* Forms */
.form-container {
    max-width: 550px;
    background: #fff;
    padding: 35px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    margin: 0 auto;
}
.form-container h2 {
    font-size: 20px;
    font-weight: 600;
    color: #1a1a2e;
    margin: 0 0 24px 0;
    padding-bottom: 12px;
    border-bottom: 2px solid #e9ecef;
}
.form-group { margin-bottom: 18px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 600; font-size: 13px; color: #495057; }
.form-group input, .form-group select, .form-group textarea {
    width: 100%;
    padding: 9px 12px;
    box-sizing: border-box;
    border: 1.5px solid #dee2e6;
    border-radius: 6px;
    font-family: inherit;
    font-size: 14px;
    transition: border-color 0.15s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none;
    border-color: #4361ee;
    box-shadow: 0 0 0 3px rgba(67,97,238,0.1);
}
.form-group input[readonly] { background-color: #f8f9fa; color: #6c757d; }
.form-group textarea { resize: vertical; }

.form-section {
    border: 1.5px solid #d0d5dd;
    border-radius: 10px;
    padding: 22px 24px;
    margin-bottom: 20px;
    background: #fff;
}
.form-section-title {
    font-size: 15px;
    font-weight: 700;
    color: #1a1a2e;
    margin: 0 0 18px 0;
    padding-bottom: 10px;
    border-bottom: 2px solid #e9ecef;
}
.form-section-highlight {
    background: #f8f9fa;
    border-color: #bfc6d2;
}

.btn-submit {
    background: #4361ee;
    color: #fff;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    width: 100%;
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    transition: background 0.15s;
}
.btn-submit:hover { background: #3a56d4; }

.btn-toggle {
    background: none;
    border: 1px solid #adb5bd;
    color: #6c757d;
    border-radius: 4px;
    padding: 1px 6px;
    margin-left: 6px;
    cursor: pointer;
    font-size: 12px;
    line-height: 1;
    vertical-align: middle;
    transition: all 0.15s;
}
.btn-toggle:hover { border-color: #4361ee; color: #4361ee; }

.back-link {
    display: block;
    text-align: center;
    margin-top: 16px;
    color: #6c757d;
    text-decoration: none;
    font-size: 13px;
}
.back-link:hover { color: #4361ee; }

.row-2 { display: flex; gap: 15px; }
.row-2 .form-group { flex: 1; }

/* Summary Cards */
.summary-cards { display: flex; gap: 16px; margin-bottom: 20px; }
.summary-card { background: #fff; border-radius: 10px; padding: 16px 20px; box-shadow: 0 1px 3px rgba(0,0,0,0.06); flex: 1; }
.summary-card .num { font-size: 24px; font-weight: 700; color: #1a1a2e; }
.summary-card .lbl { font-size: 12px; color: #6c757d; margin-top: 4px; }

/* Overdue order rows */
.row-overdue { background: #fff5f5 !important; }
.row-overdue td { color: #c62828 !important; }
.row-overdue:hover td { background: #ffebee !important; }
.overdue-days { color: #d32f2f; font-weight: 600; font-size: 12px; }

/* Low stock warning */
.low-stock { background: #fff5f5 !important; }
.low-stock td { color: #d32f2f !important; }

/* Loading overlay */
.loading-overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(255,255,255,0.7); z-index: 9999; justify-content: center; align-items: center; }
.loading-overlay.active { display: flex; }

/* Order info box */
.order-info { background: #e7f3ff; border-left: 4px solid #4361ee; padding: 12px; margin-bottom: 15px; border-radius: 4px; font-size: 13px; }

/* Inventory actions row */
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.btn-info { background: #17a2b8; color: #fff; }
.btn-info:hover { background: #138496; }
.btn-outline { background: transparent; color: #4361ee; border: 1.5px solid #4361ee; }
.btn-outline:hover { background: #eef1ff; }

/* Order-specific cells */
.order-cell { display: flex; flex-direction: column; gap: 2px; }
.order-number { font-weight: 700; font-size: 14px; }
.customer-name { font-size: 12px; color: #6c757d; }
.product-cell { display: flex; flex-direction: column; gap: 2px; }
.product-name { font-weight: 600; }
.product-spec { display: flex; gap: 10px; font-size: 11px; color: #6c757d; flex-wrap: wrap; }
.amount-cell { display: flex; flex-direction: column; gap: 2px; }
.amount-expected { font-weight: 700; font-size: 14px; }
.amount-actual { font-weight: 700; font-size: 14px; }
.amount-actual.diff { color: #dc3545; }
.diff-reason { font-size: 11px; color: #6c757d; font-style: italic; }
.delivery-date { font-size: 13px; }
.delivery-date.past { color: #dc3545; font-weight: 600; }

/* Production collapse */
.customer-header { background: #e8eaf6; cursor: pointer; font-weight: 700; font-size: 14px; }
.customer-header td { padding: 12px 14px; border-bottom: 1px solid #c5cae9; }
.order-header { background: #f5f5f5; cursor: pointer; font-size: 13px; }
.order-header td { padding: 10px 14px; border-bottom: 1px solid #e0e0e0; }
.data-row.hidden { display: none; }
tr.hidden { display: none; }
.customer-header .icon, .order-header .icon { display: inline-block; margin-right: 8px; font-size: 10px; transition: transform 0.15s; }
.customer-header .icon.collapsed, .order-header .icon.collapsed { transform: rotate(-90deg); }
.customer-header .count { font-size: 12px; color: #6c757d; margin-left: 12px; }
.order-header .stat { margin-left: 16px; font-size: 12px; color: #555; }
.progress-bar { display: inline-block; background: #e9ecef; border-radius: 8px; overflow: hidden; vertical-align: middle; }
.progress-fill { height: 100%; text-align: center; color: #fff; font-weight: 600; border-radius: 8px; }
.empty-msg { text-align: center; padding: 30px; color: #999; font-size: 14px; }

/* Modal - reusable pattern for all pages */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(200, 200, 200, 0.5);
    z-index: 9999;
}
.modal-overlay.show {
    display: block;
}
.modal-overlay .modal-wrap {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
    padding: 30px 35px 35px;
    width: 500px;
    max-width: 90vw;
    max-height: 85vh;
    overflow-y: auto;
}
.modal-overlay .modal-wrap h3 {
    margin: 0 0 24px 0;
    font-size: 20px;
    font-weight: 600;
    color: #1a1a2e;
    padding-bottom: 12px;
    border-bottom: 2px solid #e9ecef;
}
.modal-overlay .modal-close {
    position: absolute;
    top: 20px;
    right: 24px;
    background: none;
    border: none;
    font-size: 28px;
    color: #6c757d;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}
.modal-overlay .modal-close:hover { color: #1a1a2e; }
.modal-overlay .form-group { margin-bottom: 18px; }
.modal-overlay .form-group label { display: block; margin-bottom: 6px; font-weight: 600; font-size: 13px; color: #495057; }
.modal-overlay .form-group input,
.modal-overlay .form-group select,
.modal-overlay .form-group textarea {
    width: 100%;
    padding: 9px 12px;
    box-sizing: border-box;
    border: 1.5px solid #dee2e6;
    border-radius: 6px;
    font-family: inherit;
    font-size: 14px;
    transition: border-color 0.15s;
}
.modal-overlay .form-group input:focus,
.modal-overlay .form-group select:focus,
.modal-overlay .form-group textarea:focus {
    outline: none;
    border-color: #4361ee;
    box-shadow: 0 0 0 3px rgba(67,97,238,0.1);
}
.modal-overlay .btn-submit { margin-top: 8px; }
.modal-overlay .error-msg { margin-bottom: 0; }

/* Order Detail Modal */
.detail-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4);
    z-index: 9998;
    align-items: center;
    justify-content: center;
}
.detail-overlay.show { display: flex; }
.detail-card {
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 12px 48px rgba(0,0,0,0.2);
    width: 640px;
    max-width: 94vw;
    max-height: 88vh;
    overflow-y: auto;
    position: relative;
}
.detail-card .detail-close {
    position: absolute;
    top: 16px; right: 20px;
    background: none; border: none;
    font-size: 26px; color: #adb5bd;
    cursor: pointer; padding: 0; line-height: 1;
    transition: color 0.15s;
}
.detail-card .detail-close:hover { color: #1a1a2e; }
.detail-card .detail-head {
    padding: 28px 30px 20px;
    border-bottom: 2px solid #e9ecef;
}
.detail-card .detail-head h3 {
    margin: 0 0 4px;
    font-size: 20px; font-weight: 700;
    color: #1a1a2e;
}
.detail-card .detail-head .detail-sub {
    font-size: 13px; color: #6c757d;
}
.detail-card .detail-body { padding: 20px 30px 28px; }
.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
.detail-section {
    background: #f8f9fc;
    border-radius: 10px;
    padding: 16px;
}
.detail-section.full { grid-column: 1 / -1; }
.detail-section h4 {
    margin: 0 0 10px;
    font-size: 13px; font-weight: 700;
    color: #4361ee;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.detail-section .row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    font-size: 13px;
}
.detail-section .row + .row { border-top: 1px solid #e9ecef; }
.detail-section .row .label { color: #6c757d; }
.detail-section .row .value { font-weight: 600; color: #1a1a2e; text-align: right; }
.detail-section .row .value.diff { color: #dc3545; }

@media (max-width: 600px) {
    .detail-grid { grid-template-columns: 1fr; }
}

/* Cancel Button (modal footer) */
.btn-cancel {
    display: block;
    width: 100%;
    margin-top: 10px;
    padding: 10px 20px;
    background: #fff;
    color: #6c757d;
    border: 1.5px solid #dee2e6;
    border-radius: 6px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    transition: all 0.15s;
}
.btn-cancel:hover { background: #f8f9fa; border-color: #adb5bd; }

/* Confirm Dialog */
.confirm-overlay {
    display: flex;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 10000;
    align-items: center;
    justify-content: center;
}
.confirm-card {
    background: #fff;
    border-radius: 12px;
    padding: 28px 32px;
    min-width: 400px;
    max-width: 90vw;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.confirm-card h3 {
    margin: 0 0 20px;
    font-size: 18px;
    color: #1a1a2e;
    border-bottom: 2px solid #e9ecef;
    padding-bottom: 12px;
}
.confirm-card table {
    width: 100%;
    font-size: 14px;
    border-collapse: collapse;
}
.confirm-card table td {
    padding: 6px 0;
}
.confirm-card table td:first-child {
    padding-right: 12px;
    color: #6c757d;
    white-space: nowrap;
}
.confirm-card table td:last-child {
    font-weight: 600;
}
.confirm-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 24px;
}
.btn-confirm-cancel {
    padding: 8px 24px;
    border: 1px solid #6c757d;
    background: #fff;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-family: inherit;
    transition: background 0.15s;
}
.btn-confirm-cancel:hover { background: #f8f9fa; }
.btn-confirm-ok {
    padding: 8px 24px;
    border: none;
    background: #4361ee;
    color: #fff;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-family: inherit;
    transition: background 0.15s;
}
.btn-confirm-ok:hover { background: #3a56d4; }

/* Toast Notification */
.toast {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 20000;
    padding: 14px 28px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    box-shadow: 0 6px 20px rgba(0,0,0,0.2);
    opacity: 0;
    transform: translateY(-12px);
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: none;
}
.toast-show {
    opacity: 1;
    transform: translateY(0);
}
.toast-success { background: #28a745; }

/* 編輯/新增後高亮該筆資料列 */
.row-highlight {
    animation: rowHighlightFade 3s ease-out;
}
@keyframes rowHighlightFade {
    0% { background-color: #fff3cd; box-shadow: inset 0 0 0 2px #f0ad4e; }
    70% { background-color: #fff3cd; box-shadow: inset 0 0 0 2px #f0ad4e; }
    100% { background-color: transparent; box-shadow: inset 0 0 0 0 transparent; }
}
.toast-error { background: #dc3545; }
