/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --color-bg: #FAFAFA;
    --color-surface: #FFFFFF;
    --color-sidebar: #1E1E2E;
    --color-sidebar-text: #CDD6F4;
    --color-sidebar-hover: #313244;
    --color-primary: #6366F1;
    --color-primary-hover: #4F46E5;
    --color-success: #10B981;
    --color-success-bg: #D1FAE5;
    --color-warning: #F59E0B;
    --color-warning-bg: #FEF3C7;
    --color-danger: #EF4444;
    --color-danger-bg: #FEE2E2;
    --color-info: #3B82F6;
    --color-info-bg: #DBEAFE;
    --color-text: #1F2937;
    --color-text-secondary: #6B7280;
    --color-text-tertiary: #9CA3AF;
    --color-border: #E5E7EB;
    --color-border-light: #F3F4F6;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

body {
    font-family: var(--font);
    font-size: 14px;
    color: var(--color-text);
    background: var(--color-bg);
    line-height: 1.5;
}

/* ===== Layout ===== */
.app-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 220px;
    background: var(--color-sidebar);
    color: var(--color-sidebar-text);
    padding: 0;
    flex-shrink: 0;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    overflow-y: auto;
    z-index: 100;
}

.sidebar-header {
    padding: 24px 20px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-header h2 {
    font-size: 18px;
    font-weight: 600;
    color: #FFF;
    margin-bottom: 4px;
}

.sidebar-header p {
    font-size: 12px;
    color: var(--color-sidebar-text);
    opacity: 0.6;
}

.nav-menu { list-style: none; padding: 8px 0; }

.nav-menu li a {
    display: block;
    padding: 10px 20px;
    color: var(--color-sidebar-text);
    text-decoration: none;
    font-size: 14px;
    transition: background 0.15s;
    border-left: 3px solid transparent;
}

.nav-menu li a:hover { background: var(--color-sidebar-hover); }
.nav-menu li a.active {
    background: var(--color-sidebar-hover);
    border-left-color: var(--color-primary);
    color: #FFF;
}

.main-content {
    margin-left: 220px;
    flex: 1;
    padding: 24px 32px;
    min-width: 0;
}

/* ===== Page Header ===== */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.page-header h1 {
    font-size: 22px;
    font-weight: 600;
    color: var(--color-text);
}

/* ===== Stats Grid ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
    border: 1px solid var(--color-border);
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--color-primary);
    line-height: 1.2;
}

.stat-label {
    font-size: 12px;
    color: var(--color-text-secondary);
    margin-top: 4px;
}

.stat-warning { border-color: var(--color-warning); }
.stat-warning .stat-value { color: var(--color-warning); }

/* ===== Content Panels ===== */
.content-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.content-panel {
    background: var(--color-surface);
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
    overflow: hidden;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--color-border);
}

.panel-header h2 { font-size: 15px; font-weight: 600; }

.section-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--color-text);
}

.order-info {
    display: flex;
    gap: 24px;
    padding: 8px 16px 12px;
    font-size: 13px;
    color: var(--color-text-secondary);
}

/* ===== Data Tables ===== */
.table-container {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table thead {
    background: var(--color-border-light);
}

.data-table th {
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    color: var(--color-text-secondary);
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
    font-size: 12px;
}

.data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--color-border-light);
    vertical-align: middle;
}

.data-table tbody tr:hover {
    background: var(--color-border-light);
}

.data-table tbody tr.row-warning {
    background: var(--color-warning-bg);
}

.data-table .empty-row {
    text-align: center;
    color: var(--color-text-tertiary);
    padding: 24px !important;
}

.data-table .actions {
    white-space: nowrap;
}

.data-table .actions .btn + .btn { margin-left: 4px; }

/* ===== Buttons ===== */
.btn {
    display: inline-block;
    padding: 8px 16px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 13px;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: all 0.15s;
    font-family: inherit;
    line-height: 1.4;
}

.btn:hover { background: var(--color-border-light); }

.btn-primary {
    background: var(--color-primary);
    color: #FFF;
    border-color: var(--color-primary);
}

.btn-primary:hover { background: var(--color-primary-hover); }

.btn-success {
    background: var(--color-success);
    color: #FFF;
    border-color: var(--color-success);
}

.btn-success:hover { background: #059669; }

.btn-warning {
    background: var(--color-warning);
    color: #FFF;
    border-color: var(--color-warning);
}

.btn-danger {
    background: var(--color-danger);
    color: #FFF;
    border-color: var(--color-danger);
}

.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-secondary { background: var(--color-border-light); }

/* ===== Badges ===== */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
}

.badge-confirmed { background: var(--color-info-bg); color: var(--color-info); }
.badge-in_progress { background: var(--color-warning-bg); color: #B45309; }
.badge-completed, .badge-received { background: var(--color-success-bg); color: var(--color-success); }
.badge-active, .badge-available { background: var(--color-success-bg); color: var(--color-success); }
.badge-inactive, .badge-depleted { background: var(--color-border-light); color: var(--color-text-tertiary); }
.badge-pending, .badge-pending_inspection { background: var(--color-warning-bg); color: #856404; }
.badge-in_stock { background: var(--color-success-bg); color: var(--color-success); }
.badge-shipped { background: var(--color-info-bg); color: var(--color-info); }
.badge-in { background: var(--color-success-bg); color: var(--color-success); }
.badge-out { background: var(--color-warning-bg); color: #B45309; }
.badge-issued { background: var(--color-info-bg); color: var(--color-info); }
.badge-partial { background: var(--color-warning-bg); color: #B45309; }

/* ===== Forms ===== */
.form-group { margin-bottom: 12px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 4px; color: var(--color-text-secondary); }
.form-group .required { color: var(--color-danger); }
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 13px;
    font-family: inherit;
    background: var(--color-surface);
    color: var(--color-text);
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(99,102,241,0.15);
}
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }

.filter-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
    font-size: 13px;
}

.filter-bar label { color: var(--color-text-secondary); }
.filter-bar select {
    padding: 6px 10px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 13px;
    background: var(--color-surface);
}

.filter-hint { color: var(--color-text-tertiary); margin-left: auto; font-size: 12px; }

/* ===== Modal ===== */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.hidden { display: none; }

.modal-content {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    width: 480px;
    max-width: 90vw;
    max-height: 80vh;
    overflow-y: auto;
    overflow-x: hidden;
    box-shadow: 0 12px 40px rgba(0,0,0,0.15);
}

.modal-large { width: 700px; }

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-border);
}

.modal-header h2 { font-size: 16px; font-weight: 600; }

.modal-close {
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: var(--color-text-tertiary);
    line-height: 1;
    padding: 0 4px;
}

.modal-close:hover { color: var(--color-text); }

.modal-body { padding: 20px; }

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid var(--color-border);
    background: var(--color-border-light);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ===== Credential Display ===== */
.cred-field {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}
.cred-field label {
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text-secondary);
    width: 56px;
    flex-shrink: 0;
}
.cred-field input {
    flex: 1;
    padding: 8px 10px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: monospace;
    background: var(--color-border-light);
    color: var(--color-text);
    outline: none;
}
.cred-field input:focus {
    border-color: var(--color-primary);
    background: var(--color-surface);
}
.cred-copy-btn {
    flex-shrink: 0;
    padding: 6px 12px;
    font-size: 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    cursor: pointer;
    color: var(--color-text-secondary);
    white-space: nowrap;
    transition: all 0.15s;
}
.cred-copy-btn:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
}
.cred-copy-btn.copied {
    background: #27ae60;
    border-color: #27ae60;
    color: #fff;
}
.cred-notice {
    font-size: 12px;
    color: var(--color-text-tertiary);
    margin-top: 4px;
    line-height: 1.5;
}

/* ===== Alert ===== */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    border: 1px solid;
    margin-bottom: 16px;
}

.alert-warning {
    background: var(--color-warning-bg);
    border-color: var(--color-warning);
    color: #92400E;
}

.alert ul { padding-left: 20px; margin-top: 4px; }

/* ===== Alert Cards (inventory warnings) ===== */
.alert-cards {
    background: var(--color-warning-bg);
    border: 1px solid var(--color-warning);
    border-radius: var(--radius);
    margin-bottom: 16px;
    overflow: hidden;
}

.alert-cards-header {
    padding: 10px 14px;
    font-weight: 600;
    font-size: 14px;
    color: #92400E;
    border-bottom: 1px solid var(--color-warning);
    background: rgba(245, 158, 11, 0.15);
}

.alert-card-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 14px;
    font-size: 13px;
    border-bottom: 1px solid rgba(245, 158, 11, 0.2);
}

.alert-card-item:last-child {
    border-bottom: none;
}

.alert-card-name {
    font-weight: 600;
    color: #92400E;
    min-width: 120px;
}

.alert-card-spec {
    color: var(--color-text-secondary);
    font-size: 12px;
}

.alert-card-stats {
    margin-left: auto;
    font-size: 13px;
    white-space: nowrap;
}

.text-danger { color: var(--color-danger); }

/* ===== Filter Bar ===== */
.filter-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 0;
    margin-bottom: 4px;
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.filter-group label {
    font-size: 13px;
    color: var(--color-text-secondary);
    white-space: nowrap;
}

.filter-group select {
    padding: 6px 10px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 13px;
    background: var(--color-surface);
    min-width: 160px;
}

.filter-stats {
    margin-left: auto;
    display: flex;
    gap: 16px;
    font-size: 13px;
    color: var(--color-text-secondary);
}

.filter-stats strong {
    color: var(--color-text);
}

.filter-hint {
    font-size: 13px;
    color: var(--color-text-secondary);
}

/* ===== Toast ===== */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 13px;
    z-index: 2000;
    color: #FFF;
    animation: toastIn 0.3s ease;
}

.toast.hidden { display: none; }
.toast.info { background: var(--color-info); }
.toast.success { background: var(--color-success); }
.toast.error { background: var(--color-danger); }

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

/* ===== Process Steps ===== */
.process-steps-container { padding: 16px; }

.process-step {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 8px;
    border: 1px solid var(--color-border);
}

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

.step-header strong { font-size: 14px; }

.step-detail {
    display: flex;
    gap: 16px;
    font-size: 12px;
    color: var(--color-text-secondary);
    margin: 6px 0;
}

.step-actions { margin-top: 8px; }
.step-actions .btn + .btn { margin-left: 6px; }

/* ===== BOM & Route Tabs ===== */
.tab-bar { display: flex; gap: 0; margin-bottom: 16px; border-bottom: 2px solid var(--color-border); }

.tab-btn {
    padding: 8px 16px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 13px;
    color: var(--color-text-secondary);
    font-family: inherit;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
}

.tab-btn.active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
    font-weight: 500;
}

.tab-content.hidden { display: none; }

/* ===== Process Cards (Integrated BOM View) ===== */
.process-card {
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    margin-bottom: 10px;
    background: var(--color-surface);
    overflow: hidden;
}

.process-card-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: var(--color-border-light);
    cursor: pointer;
    user-select: none;
    transition: background 0.15s;
}
.process-card-header:hover { background: #E8ECF0; }

.process-card-header .process-seq {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px; height: 24px;
    border-radius: 50%;
    background: var(--color-primary);
    color: #FFF;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
}

.process-card-header .process-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--color-text);
}

.process-card-header .process-workshop {
    font-size: 12px;
    color: var(--color-text-tertiary);
}

.process-card-header .process-meta {
    font-size: 11px;
    color: var(--color-text-tertiary);
    margin-left: auto;
}

.process-card-header .collapse-arrow {
    font-size: 10px;
    color: var(--color-text-tertiary);
    transition: transform 0.2s;
    flex-shrink: 0;
}

.process-card-header.collapsed .collapse-arrow {
    transform: rotate(-90deg);
}

.process-card-actions {
    display: flex;
    gap: 2px;
    align-items: center;
    flex-shrink: 0;
}

.process-card-actions button {
    background: none;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    padding: 2px 6px;
    cursor: pointer;
    font-size: 12px;
    color: var(--color-text-secondary);
    line-height: 1.4;
}
.process-card-actions button:hover {
    background: var(--color-border-light);
    color: var(--color-text);
}

.process-card-body {
    padding: 10px 14px 14px;
    background: #FFF;
    transition: max-height 0.2s;
}

.process-card-body.collapsed { display: none; }

.process-card-body .empty-hint {
    font-size: 12px;
    color: var(--color-text-tertiary);
    padding: 8px 0;
}

/* Bom row inside process card */
.bom-row {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 6px;
}

.bom-row select {
    flex: 2;
    min-width: 0;
    padding: 6px 8px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 13px;
    font-family: inherit;
}

.bom-row input[type="number"] {
    width: 70px;
    flex-shrink: 0;
    padding: 6px 8px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 13px;
    font-family: inherit;
}

.bom-row input[type="text"] {
    flex: 1;
    min-width: 60px;
    padding: 6px 8px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 13px;
    font-family: inherit;
}

/* Add process bar */
.add-process-bar {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 10px;
    padding: 10px 0;
    border-top: 1px dashed var(--color-border);
}

.add-process-bar select {
    flex: 1;
    padding: 8px 10px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 13px;
    font-family: inherit;
    background: var(--color-surface);
}

/* Save bar */
.save-bar {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--color-border);
}

/* ===== PO Items ===== */
.po-items { margin-bottom: 8px; }

.po-item-row {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 8px;
}

.po-mat { flex: 2; }
.po-qty, .po-price { width: 120px; }

.po-item-row select,
.po-item-row input {
    padding: 6px 8px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 13px;
    font-family: inherit;
}

.receive-item {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 8px;
}

.text-right { text-align: right; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .sidebar { width: 60px; }
    .sidebar-header h2 { font-size: 14px; }
    .sidebar-header p { display: none; }
    .nav-menu li a { padding: 10px 12px; font-size: 12px; }
    .main-content { margin-left: 60px; padding: 16px; }
    .content-grid { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ===== Utilities ===== */
.inline-form { display: inline; }
.inline-form select { padding: 6px 10px; border: 1px solid var(--color-border); border-radius: var(--radius); font-size: 13px; }
.text-secondary { color: var(--color-text-secondary); font-size: 12px; }

/* ===== Purchase Receipt ===== */
.receive-info {
    padding: 10px 14px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 4px;
}
.receive-subtotal {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* ===== Process Worker Assignment ===== */
.worker-row select,
.worker-row input { font-size: 12px; padding: 4px 6px; border: 1px solid var(--color-border); border-radius: var(--radius); }
.worker-wage { font-family: var(--font-mono, monospace); font-weight: 600; }

/* ===== Process Price Config ===== */
.process-price-label { font-size: 12px; color: var(--color-text-secondary); margin-left: 8px; }
.process-unit-price { width: 70px; font-size: 12px; padding: 2px 6px; border: 1px solid var(--color-border); border-radius: var(--radius); }

/* ===== Badges for wage status ===== */
.badge-verified { background: var(--color-success-bg); color: var(--color-success); }
.badge-paid { background: #E8F0FE; color: #1A73E8; }
