:root {
    --primary-turquoise: #1ABC9C;
    --primary-yellow: #FBC02D;
    --bg-white: #FFFFFF;
    --bg-light: #F4F7F6;
    --text-main: #2C3E50;
    --text-zh: #16A085;
    --text-muted: #7F8C8D;
    --border-color: #DCDDE1;
    --sidebar-bg: #2F3640;
    --sidebar-width: 280px;
    
    /* Status Colors */
    --status-none: #FF2D55;
    --status-not-sure: #FFD60A;
    --status-sourced: #8E8E93;
    --status-quoting: #30D158;
    --status-selected: #34C759;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { 
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--text-main); 
    background-color: var(--bg-white); 
    height: 100vh; 
    overflow: hidden;
    font-size: 14px;
}

.app-container { display: flex; height: 100vh; }

/* Sidebar */
.sidebar { 
    width: var(--sidebar-width); 
    background-color: var(--sidebar-bg); 
    color: white; 
    display: flex; 
    flex-direction: column; 
    flex-shrink: 0;
    z-index: 100;
}
.sidebar-header { padding: 20px; border-bottom: 1px solid rgba(255,255,255,0.1); position: relative; }
.sidebar-header h1 { font-size: 1.2rem; color: #FFFFFF; text-transform: uppercase; letter-spacing: 1px; }
.sidebar-header p { font-size: 0.75rem; color: rgba(255,255,255,0.6); }
.version-badge { position: absolute; top: 10px; right: 10px; font-size: 10px; background: var(--primary-turquoise); padding: 2px 6px; border-radius: 10px; font-weight: bold; }
.logo { width: 40px; margin-bottom: 10px; border-radius: 50%; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 5px 0; }
.nav-item { 
    padding: 12px 15px; 
    cursor: pointer; 
    font-size: 0.85rem; 
    border-bottom: 1px solid rgba(255,255,255,0.05); 
    display: flex; 
    flex-direction: column;
    transition: 0.2s;
}
.nav-item:hover { background: rgba(255,255,255,0.1); }
.nav-item.active { background: var(--primary-turquoise); color: white; border-left: 5px solid var(--primary-yellow); }
.nav-item .lang-fr { color: #FFFFFF !important; font-weight: bold; }
.nav-zh { font-size: 0.75rem; color: #00E5FF; opacity: 1; font-weight: 600; }

/* Main Content */
.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: white; }
.content-header { 
    padding: 15px 20px; 
    background: white; 
    border-bottom: 2px solid var(--border-color); 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
}
#current-category-title { font-size: 1.1rem; font-weight: bold; display: flex; align-items: center; gap: 10px; }
.header-actions { display: flex; gap: 10px; align-items: center; }

.header-left { display: flex; flex-direction: column; gap: 6px; }
.grand-total { font-size: 1.2rem; font-weight: 800; color: #E67E22; background: #FFF3E0; padding: 6px 15px; border-radius: 4px; border: 1px solid #FFE0B2; }

.stats-badge {
    background: var(--sidebar-bg);
    color: white;
    padding: 6px 15px;
    border-radius: 4px;
    font-weight: 700;
    font-size: 1rem;
    display: flex;
    align-items: center;
    border: 1px solid rgba(255,255,255,0.1);
}

/* Table Styles */
.content-body { flex: 1; overflow: auto; padding: 0; position: relative; }
.product-table { 
    width: 100%; 
    border-collapse: collapse; 
    font-size: 13px; 
    table-layout: fixed; 
    min-width: 1400px; 
    border: 1px solid var(--border-color); 
}

.product-table th { 
    position: sticky; top: 0; background: #EDF1F2; z-index: 50;
    padding: 12px 10px; text-align: left; border: 1px solid var(--border-color);
    font-weight: 600; text-transform: uppercase; color: #475569;
    user-select: none;
    overflow: hidden;
}

.product-table td { 
    padding: 12px 10px; 
    border: 1px solid var(--border-color); 
    vertical-align: middle; 
    line-height: 1.4;
    word-wrap: break-word;
}

.product-table tr:hover { background-color: #F8FAFB; }

/* Resizer */
.resizer { position: absolute; top: 0; right: 0; width: 5px; cursor: col-resize; user-select: none; height: 100%; }
.resizer:hover, .resizing { border-right: 3px solid var(--primary-turquoise); }

/* Typography */
.lang-fr { color: var(--text-main); font-weight: 600; display: block; line-height: 1.3; font-size: 14px; }
.product-name-fr { color: var(--text-main); font-weight: 600; display: block; line-height: 1.3; font-size: 14px; }
.product-name-zh { color: var(--primary-turquoise); font-weight: 600; font-size: 13px; margin-top: 4px; }
.product-name-zh-input { color: var(--primary-turquoise) !important; font-weight: 600 !important; font-size: 13px !important; margin-top: 4px !important; border-bottom: 1px dashed var(--primary-turquoise) !important; }

/* Image Styles */
.item-thumb { 
    width: 140px; height: 110px; object-fit: contain; border-radius: 4px; 
    border: 1px solid #ddd; background: #f8f9fa; cursor: pointer;
    transition: background 0.2s;
}
.item-thumb:hover { border-color: var(--primary-turquoise); background: #eee; }

.image-wrapper { position: relative; display: inline-block; }
.image-label { display: none; } /* Internal logic only */

/* Modal Viewer */
.image-viewer-modal {
    display: none; position: fixed; z-index: 3000; inset: 0; background: rgba(0,0,0,0.85);
    align-items: center; justify-content: center; cursor: zoom-out;
}
.image-viewer-modal img { max-width: 90%; max-height: 90%; object-fit: contain; border: 2px solid white; box-shadow: 0 0 30px rgba(0,0,0,0.5); }
.image-viewer-close { position: absolute; top: 20px; right: 30px; color: white; font-size: 40px; cursor: pointer; }

/* Inline Inputs */
.cell-input { width: 100%; border: 1px solid transparent; background: transparent; font-size: 14px; padding: 6px; border-radius: 4px; outline: none; transition: 0.1s; }
.cell-input:focus { background: white; border: 1px solid var(--primary-turquoise); box-shadow: inset 0 1px 3px rgba(0,0,0,0.1); }
textarea.cell-input { height: 60px; resize: vertical; }

.price-input { font-weight: 700; text-align: right; border-bottom: 2px dashed #ccc !important; }
.total-cell { font-weight: 700; color: #27ae60; text-align: right; }
.qty-pill { background: #E2E8F0; padding: 4px 8px; border-radius: 4px; font-weight: 700; }

/* Status */
.status-select { 
    width: 100%; 
    padding: 6px 10px; 
    border-radius: 20px; 
    border: none; 
    font-size: 11px; 
    font-weight: 800; 
    cursor: pointer; 
    color: white; 
    appearance: none; 
    text-align: center;
    text-transform: uppercase;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.status-none { background-color: var(--status-none); }
.status-not_sure { background-color: var(--status-not-sure); color: #000; }
.status-sourced { background-color: var(--status-sourced); }
.status-quoting { background-color: var(--status-quoting); color: #000; }
.status-selected { background-color: var(--status-selected); }

/* Global Buttons */
.btn { border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer; font-size: 14px; font-weight: 600; display: inline-flex; align-items: center; gap: 8px; transition: 0.2s; }
.btn-primary { background: var(--primary-turquoise); color: white; }
.btn-primary:hover { background: #16a085; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-outline { background: transparent; border: 1px solid var(--primary-turquoise); color: var(--primary-turquoise); }
.btn-outline:hover { background: var(--primary-turquoise); color: white; }

/* Utils */
.sub-header { background: #F1F4F6; font-weight: 700; border-bottom: 3px solid var(--primary-turquoise); padding: 8px 15px; font-size: 14px; color: #2D3436; margin-top: 10px; }
.last-updated { font-size: 9px; color: #bdc3c7; display: block; margin-top: 4px; font-style: italic; }
.col-image-edit { display: flex; flex-direction: column; gap: 4px; }
.image-url-input { font-size: 10px !important; color: var(--text-muted); }

/* Workflow Actions */
.workflow-actions { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.btn-action { 
    padding: 4px 8px; font-size: 11px; background: #f1f2f6; border: 1px solid #ced4da; 
    border-radius: 3px; color: #4b4b4b; cursor: pointer; transition: 0.2s;
    display: flex; align-items: center; gap: 4px;
}
.btn-action:hover { background: #e2e4e9; border-color: #a4b0be; }
.btn-action i { font-size: 10px; }
.btn-action.prompt { color: #8e44ad; border-color: #dcdde1; }
.btn-action.search-alibaba { color: #2980b9; }
.btn-action.copy { color: #27ae60; }

/* Drag and Drop Image Zone */
.col-image-edit { position: relative; }
.image-drop-zone {
    border: 2px dashed #dcdde1;
    border-radius: 4px;
    padding: 5px;
    text-align: center;
    background: #fdfdfd;
    transition: 0.2s;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    color: var(--text-muted);
    cursor: pointer;
}
.image-drop-zone.dragover { background: #e1f5fe; border-color: var(--primary-turquoise); }

/* Supplier Link */
.supplier-link-input { font-size: 10px !important; color: #2980b9 !important; text-decoration: underline; cursor: pointer; }

/* Desktop-only Table Stability (Professional Fixed Layout) */
.content-body {
    flex: 1;
    overflow: auto;
    padding: 0;
    position: relative;
    -webkit-overflow-scrolling: touch;
}

.product-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed; /* Crucial for fixed widths */
}

/* Precise Column Widths */
.col-index { width: 50px; text-align: center; }
.col-qty { width: 70px; text-align: center; }
.col-name { width: 180px; }
.col-specs { width: 220px; }
.col-material { width: 180px; }
.col-image { width: 200px; text-align: center; }
.col-price { width: 90px; text-align: right; }
.col-total { width: 110px; text-align: right; }
.col-prod-time { width: 120px; text-align: center; }
.col-status { width: 130px; text-align: center; }
.col-supplier { width: 180px; }
.col-notes { width: 200px; }
.col-comments { width: 220px; }

/* Image Container Stability */
.col-image {
    padding: 5px !important;
}

.img-preview-container {
    width: 100%;
    height: 150px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f8f9fa;
    border-radius: 4px;
    border: 1px solid #ddd;
    position: relative;
    overflow: hidden;
}

.img-preview {
    max-width: 180px;
    max-height: 140px;
    object-fit: contain;
    display: block;
    margin: auto;
    cursor: pointer;
    transition: transform 0.2s;
}

.img-preview:hover {
    transform: scale(1.02);
}

.img-upload-zone {
    width: 100%;
    height: 150px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: 2px dashed var(--border-color);
    border-radius: 4px;
    background: #fdfdfd;
    font-size: 11px;
    color: var(--text-muted);
    cursor: pointer;
    transition: 0.2s;
}

.img-upload-zone:hover {
    border-color: var(--primary-turquoise);
    background: #f1f8f7;
}

/* Comments System */
.comments-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 300px;
    overflow-y: auto;
    padding: 5px;
}
.comment-history {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 8px;
}
.comment-entry {
    font-size: 11px;
    line-height: 1.4;
    padding: 6px 8px;
    border-radius: 6px;
    background: #f8f9fa;
    border-left: 3px solid #ccc;
}
.comment-header {
    font-weight: 800;
    margin-bottom: 2px;
    font-size: 10px;
}
.comment-text {
    word-break: break-word;
}
.comment-internal { 
    background: #ebf3ff;
    border-left-color: #1D3557;
}
.comment-internal .comment-header { color: #1D3557; }

.comment-client { 
    background: #eefbff;
    border-left-color: #007AFF;
}
.comment-client .comment-header { color: #007AFF; }

.comment-input-area {
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.comment-input {
    width: 100%;
    height: 50px;
    font-size: 12px;
    padding: 6px;
    border: 1px solid #ddd;
    border-radius: 4px;
    resize: none;
}
.btn-comment {
    align-self: flex-end;
    padding: 4px 10px;
    font-size: 11px;
    background: var(--primary-turquoise);
    color: white;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    font-weight: 600;
}
.btn-comment:hover { background: #16a085; }

/* Content Wrapping Rules */
.product-table td, .product-table th {
    white-space: normal;
    overflow-wrap: break-word;
    word-break: break-word;
    vertical-align: middle;
}

.pdf-export-mode .product-table { border: 1px solid #eee; }
.pdf-export-mode .product-table th { background: #fcfcfc; border-bottom: 2px solid #333; }
