* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #0f0f13;
    color: #e0e0e0;
    min-height: 100vh;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 40px 20px;
}

header {
    text-align: center;
    margin-bottom: 48px;
}

header h1 {
    font-size: 32px;
    font-weight: 700;
    color: #fff;
    margin-bottom: 8px;
}

.subtitle {
    color: #888;
    font-size: 16px;
}

.header-links {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    margin-top: 14px;
}

.header-link-btn {
    display: inline-block;
    padding: 10px 18px;
    border-radius: 10px;
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    background: linear-gradient(135deg, #3498db, #2980b9);
    transition: transform 0.2s, box-shadow 0.2s;
}

.header-link-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(52, 152, 219, 0.35);
}

/* Upload cards */
.upload-section {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-bottom: 40px;
}

.upload-card {
    background: #1a1a24;
    border: 2px solid #2a2a3a;
    border-radius: 16px;
    padding: 32px 24px;
    text-align: center;
    transition: border-color 0.3s, box-shadow 0.3s;
}

.upload-card:hover {
    border-color: #4a4a6a;
}

.upload-card.loaded {
    border-color: #3dd68c;
    box-shadow: 0 0 20px rgba(61, 214, 140, 0.1);
}

.upload-card.error {
    border-color: #e74c3c;
}

.upload-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6c5ce7, #a855f7);
    color: #fff;
    font-size: 20px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
}

.upload-card h3 {
    font-size: 18px;
    color: #fff;
    margin-bottom: 8px;
}

.upload-card p {
    font-size: 13px;
    color: #777;
    margin-bottom: 20px;
}

.upload-btn {
    display: inline-block;
    position: relative;
    overflow: hidden;
    padding: 10px 28px;
    background: linear-gradient(135deg, #6c5ce7, #a855f7);
    color: #fff;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.upload-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(108, 92, 231, 0.4);
}

.upload-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}

.pick-order-toggle {
    display: inline-flex;
    gap: 0;
    margin-top: 12px;
    border: 1px solid #34344a;
    border-radius: 10px;
    overflow: hidden;
    background: #15151f;
}

.pick-order-toggle label {
    cursor: pointer;
}

.pick-order-toggle input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.pick-order-toggle span {
    display: block;
    padding: 8px 10px;
    font-size: 12px;
    color: #aaa;
    transition: background 0.2s, color 0.2s;
}

.pick-order-toggle input:checked + span {
    background: #34344a;
    color: #fff;
}

.upload-btn-test {
    border: 1px solid #4a4a6a;
    background: #242433;
}

.upload-btn-test:hover {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}

.file-status {
    margin-top: 14px;
    font-size: 13px;
    min-height: 20px;
}

.file-status.success {
    color: #3dd68c;
}

.file-status.error {
    color: #e74c3c;
}

/* Preview */
.preview-section {
    margin-bottom: 32px;
}

.preview-section h2 {
    font-size: 22px;
    color: #fff;
    margin-bottom: 16px;
}

.stats {
    display: flex;
    gap: 24px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.stat-item {
    background: #1a1a24;
    border-radius: 10px;
    padding: 12px 20px;
    font-size: 14px;
}

.stat-item span {
    font-weight: 700;
    color: #a855f7;
}

.table-wrap {
    overflow-x: auto;
    border-radius: 12px;
    border: 1px solid #2a2a3a;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

thead {
    background: #1a1a24;
}

th {
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    color: #aaa;
    white-space: nowrap;
}

td {
    padding: 10px 16px;
    border-top: 1px solid #1e1e2e;
}

tr:hover {
    background: rgba(108, 92, 231, 0.05);
}

tr.no-match {
    background: rgba(231, 76, 60, 0.15);
}

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
}

.badge-ok {
    background: rgba(61, 214, 140, 0.15);
    color: #3dd68c;
}

.badge-fail {
    background: rgba(231, 76, 60, 0.15);
    color: #e74c3c;
}

/* Action */
.action-section {
    text-align: center;
    margin-bottom: 32px;
}

.uat-safety-banner {
    margin: 0 auto 22px;
    max-width: 980px;
    padding: 12px 16px;
    border: 1px solid #f0b429;
    border-radius: 12px;
    background: #fff7df;
    color: #6f4b00;
    font-weight: 700;
    text-align: center;
}

.file-input-cover {
    position: absolute;
    inset: 0;
    z-index: 1;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.fbs-combined-option {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    width: min(560px, calc(100% - 32px));
    margin: 0 auto 18px;
    padding: 14px 18px;
    border: 1px solid #34344a;
    border-radius: 12px;
    background: #1a1a24;
    color: #fff;
    text-align: left;
    cursor: pointer;
}

.fbs-combined-option input {
    width: 18px;
    height: 18px;
    margin-top: 2px;
    accent-color: #6c5ce7;
}

.fbs-combined-option span {
    display: grid;
    gap: 4px;
}

.fbs-combined-option small {
    color: #999;
    line-height: 1.35;
}

.generate-btn {
    padding: 14px 48px;
    background: linear-gradient(135deg, #6c5ce7, #a855f7);
    color: #fff;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.generate-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 24px rgba(108, 92, 231, 0.4);
}

.generate-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.progress-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-top: 20px;
}

.progress-bar {
    width: 300px;
    height: 8px;
    background: #2a2a3a;
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #6c5ce7, #a855f7);
    border-radius: 4px;
    transition: width 0.3s;
}

.progress-text {
    font-size: 14px;
    color: #aaa;
    min-width: 40px;
}

.download-btn {
    display: inline-block;
    margin-top: 20px;
    padding: 14px 48px;
    background: linear-gradient(135deg, #3dd68c, #2ecc71);
    color: #fff;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
    transition: transform 0.2s;
}

.download-btn:hover {
    transform: translateY(-2px);
}

.clear-btn {
    margin-top: 10px;
    padding: 6px 14px;
    background: transparent;
    color: #e74c3c;
    border: 1px solid rgba(231, 76, 60, 0.4);
    border-radius: 8px;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.2s;
}

.clear-btn:hover {
    background: rgba(231, 76, 60, 0.1);
}

.download-wrap {
    display: flex;
    gap: 16px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 20px;
}

.download-btn-alt {
    background: linear-gradient(135deg, #3498db, #2980b9) !important;
}

.kis-cell {
    font-family: monospace;
    font-size: 11px;
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #bbb;
}

/* Error */
.error-section {
    margin-bottom: 24px;
}

.error-msg {
    background: rgba(231, 76, 60, 0.1);
    border: 1px solid rgba(231, 76, 60, 0.3);
    border-radius: 12px;
    padding: 16px 24px;
    color: #e74c3c;
    font-size: 14px;
}

/* Responsive */
@media (max-width: 768px) {
    .upload-section {
        grid-template-columns: 1fr;
    }
}

#scroll-bottom-btn {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 9999;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    background: #111;
    color: #fff;
    font-size: 20px;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 8px 25px rgba(0,0,0,0.25);
    backdrop-filter: blur(6px);
    transition: all 0.2s ease;
    opacity: 0;
    pointer-events: none;
}

#scroll-bottom-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 30px rgba(0,0,0,0.35);
    opacity: 1;
}

#scroll-bottom-btn:active {
    transform: scale(0.95);
}

/* CHZ inspect modal */
.chz-inspect-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.72);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.chz-inspect-modal[hidden] {
    display: none;
}

.chz-inspect-panel {
    width: min(1180px, calc(100vw - 32px));
    height: min(900px, calc(100vh - 32px));
    max-height: calc(100vh - 32px);
    background: #15151f;
    border: 1px solid #2a2a3a;
    border-radius: 12px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-height: 0;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

.chz-inspect-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.chz-inspect-header h2 {
    font-size: 20px;
    color: #fff;
}

.chz-inspect-close {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 8px;
    background: #242433;
    color: #ccc;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
}

.chz-inspect-close:hover {
    background: #2f2f42;
    color: #fff;
}

.chz-inspect-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chz-inspect-filter {
    padding: 8px 14px;
    border-radius: 8px;
    border: 1px solid #33334a;
    background: #1a1a24;
    color: #bbb;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.chz-inspect-filter.active {
    border-color: #6c5ce7;
    background: rgba(108, 92, 231, 0.18);
    color: #fff;
}

.chz-inspect-tabs {
    display: flex;
    gap: 6px;
    padding: 4px;
    border: 1px solid #2a2a3a;
    border-radius: 10px;
    background: #101018;
    overflow-x: auto;
}

.chz-inspect-tab {
    flex: 0 0 auto;
    padding: 8px 14px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: #9aa0b5;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
}

.chz-inspect-tab.active {
    background: #242433;
    border-color: #3a3a52;
    color: #fff;
}

.chz-inspect-view {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chz-inspect-view[hidden] {
    display: none;
}

.chz-inspect-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.chz-inspect-delete-btn {
    padding: 8px 14px;
    border-radius: 8px;
    border: 1px solid #7a2e2e;
    background: rgba(231, 76, 60, 0.15);
    color: #ff8a7a;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.chz-inspect-delete-btn:hover:not(:disabled) {
    background: rgba(231, 76, 60, 0.28);
    color: #fff;
}

.chz-inspect-delete-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.chz-inspect-check-col {
    width: 36px;
    text-align: center;
}

.chz-inspect-table-wrap input[type="checkbox"] {
    width: 15px;
    height: 15px;
    cursor: pointer;
}

.chz-inspect-summary {
    font-size: 13px;
    color: #999;
}

.chz-inspect-status {
    font-size: 13px;
    min-height: 18px;
    color: #888;
}

.chz-inspect-status.error {
    color: #e74c3c;
}

.chz-inspect-table-wrap {
    flex: 1;
    min-height: 0;
    max-height: none;
    overflow: auto;
}

.chz-inspect-table-wrap td.kis-cell {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 11px;
    max-width: 260px;
    word-break: break-all;
}

.chz-inspect-table-wrap td.filename-cell {
    max-width: 180px;
    word-break: break-all;
}

.badge-uploaded {
    background: rgba(52, 152, 219, 0.18);
    color: #3498db;
}

.badge-original {
    background: rgba(168, 85, 247, 0.15);
    color: #a855f7;
}

.chz-inspect-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    flex: 0 0 auto;
}

.chz-inspect-page-btn {
    padding: 8px 16px;
    border-radius: 8px;
    border: 1px solid #33334a;
    background: #242433;
    color: #ddd;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.chz-inspect-page-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.chz-inspect-page-info {
    font-size: 13px;
    color: #aaa;
    min-width: 120px;
    text-align: center;
}

.chz-inspect-upload-pdf {
    padding: 8px 14px;
    font-size: 13px;
}

.chz-pdf-status-box {
    display: none;
    max-height: 180px;
    overflow: auto;
    background: #101018;
    border: 1px solid #2a2a3a;
    border-radius: 10px;
    padding: 12px;
    font-size: 11px;
    line-height: 1.45;
    color: #9fd7ff;
    white-space: pre-wrap;
    word-break: break-all;
}

.chz-pdf-status-box.visible {
    display: block;
}

.chz-stock-box {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chz-stock-summary {
    display: grid;
    grid-template-columns: repeat(4, minmax(150px, 1fr));
    gap: 10px;
}

.chz-import-report-note {
    margin: 10px 0 16px;
    color: #667085;
    font-size: 13px;
    line-height: 1.45;
}

.chz-report-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chz-report-header-actions .upload-btn {
    min-height: 36px;
    padding: 8px 14px;
}

#chz-import-report-modal .chz-inspect-panel {
    width: min(1120px, calc(100vw - 32px));
}

#chz-import-report-modal h3 {
    margin: 22px 0 10px;
}

.chz-stock-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chz-stock-filters input,
.chz-stock-filters select {
    flex: 1 1 240px;
    min-width: 200px;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid #33334a;
    background: #11111a;
    color: #ddd;
    font-size: 12px;
    outline: none;
}

.chz-stock-filters input:focus,
.chz-stock-filters select:focus {
    border-color: #6c5ce7;
}

.chz-report-file-col {
    width: 18%;
    max-width: 220px;
}

.stock-count {
    font-weight: 800;
}

.chz-stock-row.stock-count-low {
    background: rgba(231, 76, 60, 0.08);
}

.stock-count.stock-count-low {
    color: #ff8a7a;
}

.chz-stock-table-wrap {
    flex: 1;
    min-height: 0;
    max-height: none;
    overflow: auto;
}

.chz-stock-table-wrap td,
.chz-stock-table-wrap th {
    font-size: 12px;
}

.chz-stock-table-wrap td:nth-child(3) {
    max-width: 280px;
    word-break: break-word;
}

.chz-stock-table-wrap td:nth-child(9) {
    max-width: 240px;
    word-break: break-all;
}

.chz-stock-expand,
.chz-stock-expand-placeholder {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    margin-right: 6px;
    vertical-align: middle;
}

.chz-stock-expand {
    border: 1px solid #33334a;
    border-radius: 6px;
    background: #242433;
    color: #ddd;
    font-weight: 800;
    cursor: pointer;
}

.chz-stock-expand:hover {
    border-color: #6c5ce7;
    color: #fff;
}

.chz-stock-detail-row {
    background: rgba(255, 255, 255, 0.025);
}

.chz-stock-expandable {
    cursor: pointer;
}

.chz-stock-expandable:hover {
    background: rgba(108, 92, 231, 0.08);
}

.chz-stock-detail-row td {
    color: #c5c8d6;
}

.stock-row-note {
    margin-top: 3px;
    color: #8f93a8;
    font-size: 11px;
}

.stock-detail-prefix {
    color: #8f93a8;
    margin-right: 6px;
}

.chz-inspect-table-wrap thead th,
.chz-stock-table-wrap thead th,
.chz-history-table-wrap thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #1a1a24;
}

.chz-stock-card {
    border: 1px solid #2a2a3a;
    border-radius: 8px;
    padding: 10px 12px;
    background: #101018;
}

.chz-stock-card-label {
    color: #8f93a8;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
}

.chz-stock-card-value {
    margin-top: 5px;
    color: #fff;
    font-size: 20px;
    font-weight: 800;
}

.chz-stock-card-note {
    margin-top: 3px;
    color: #9aa0b5;
    font-size: 12px;
}

.stock-status-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 92px;
    padding: 5px 8px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 800;
    white-space: nowrap;
}

.stock-status-deficit {
    background: rgba(231, 76, 60, 0.16);
    color: #ff8a7a;
}

.stock-status-ok {
    background: rgba(61, 214, 140, 0.14);
    color: #62e6a3;
}

.stock-status-surplus {
    background: rgba(52, 152, 219, 0.16);
    color: #6fc0ff;
}

.stock-delta-deficit {
    color: #ff8a7a;
    font-weight: 800;
}

.stock-delta-ok {
    color: #62e6a3;
    font-weight: 800;
}

.stock-delta-surplus {
    color: #6fc0ff;
    font-weight: 800;
}

.chz-history-summary {
    display: grid;
    grid-template-columns: repeat(3, minmax(160px, 1fr));
    gap: 10px;
}

.chz-history-table-wrap {
    flex: 1;
    min-height: 0;
    overflow: auto;
}

.chz-history-empty {
    padding: 24px;
    color: #8f93a8;
    text-align: center;
}

.chz-history-legacy {
    color: #8f93a8;
    font-size: 11px;
}

.chz-history-days {
    grid-column: 1 / -1;
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
}

.chz-history-day {
    flex: 0 0 150px;
    border: 1px solid #2a2a3a;
    border-radius: 8px;
    padding: 8px 10px;
    background: #101018;
}

.chz-history-day strong,
.chz-history-day span,
.chz-history-day small {
    display: block;
}

.chz-history-day strong {
    color: #fff;
    font-size: 12px;
}

.chz-history-day span {
    margin-top: 4px;
    color: #62e6a3;
    font-size: 18px;
    font-weight: 800;
}

.chz-history-day small {
    margin-top: 2px;
    color: #8f93a8;
    font-size: 11px;
}

@media (max-width: 760px) {
    .chz-inspect-modal {
        padding: 8px;
    }

    .chz-inspect-panel {
        width: calc(100vw - 16px);
        height: calc(100vh - 16px);
        padding: 14px;
    }

    .chz-stock-summary,
    .chz-history-summary {
        grid-template-columns: 1fr;
    }
}
