/* ===== CSS Variables ===== */
:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface-hover: #f8fafc;
  --primary: #2563eb;
  --primary-light: #dbeafe;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --success-light: #dcfce7;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --text: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.1), 0 4px 10px rgba(0,0,0,0.04);
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 16px;
  --sidebar-w: 220px;
  --transition: 0.2s ease;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; border: none; outline: none; }
input, select { font-family: inherit; outline: none; }
a { text-decoration: none; color: inherit; cursor: pointer; }
table { border-collapse: collapse; width: 100%; }

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

.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 20px;
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  border-bottom: 1px solid var(--border-light);
}
.logo-icon { font-size: 22px; }

.nav {
  flex: 1;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-weight: 500;
  transition: all var(--transition);
}
.nav-item:hover { background: var(--surface-hover); color: var(--text); }
.nav-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.nav-icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--primary-light);
  border-radius: var(--radius-sm);
  margin-bottom: 4px;
}
.sidebar-user-icon { font-size: 18px; }
.sidebar-user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar-user-role {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
}

.btn-text {
  background: none;
  color: var(--text-muted);
  font-size: 12px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  text-align: left;
  cursor: pointer;
  border: none;
}
.btn-text:hover { color: var(--primary); background: var(--primary-light); }
.btn-text.danger:hover { color: var(--danger); background: var(--danger-light); }

.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  padding: 28px 32px;
  max-width: 100%;
  overflow-x: hidden;
}

/* ===== Views ===== */
.view { display: none; }
.view.active { display: block; animation: fadeIn 0.25s ease; }

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

.view-header {
  margin-bottom: 24px;
}
.view-header h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 4px;
}
.view-desc { color: var(--text-secondary); font-size: 13px; }
.view-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 16px;
  flex-wrap: wrap;
}
.view-title-row {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* ===== Cards ===== */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 16px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-light);
}
.card-header h3 {
  font-size: 15px;
  font-weight: 600;
}

.card-body { padding: 12px 20px 20px; }

/* ===== Badges ===== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-info { background: var(--primary-light); color: var(--primary); }
.badge-muted { background: var(--border-light); color: var(--text-secondary); }

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

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

.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-light);
  font-size: 13px;
  white-space: nowrap;
}
.data-table tbody tr:hover { background: var(--surface-hover); }
.data-table tbody tr:last-child td { border-bottom: none; }

.cell-strong { font-weight: 600; }
.cell-muted { color: var(--text-muted); }
.cell-link { color: var(--primary); cursor: pointer; font-weight: 500; }
.cell-link:hover { text-decoration: underline; }

/* ===== Stock Bar ===== */
.stock-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 140px;
}
.stock-bar-track {
  flex: 1;
  height: 6px;
  background: var(--border-light);
  border-radius: 3px;
  overflow: hidden;
  min-width: 60px;
}
.stock-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
}
.stock-bar-fill.high { background: var(--success); }
.stock-bar-fill.mid { background: var(--warning); }
.stock-bar-fill.low { background: var(--danger); }
.stock-bar-num { font-size: 13px; font-weight: 600; min-width: 50px; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(0.9); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(0.9); }
.btn-ghost { background: var(--surface-hover); color: var(--text-secondary); }
.btn-ghost:hover { background: var(--border-light); color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon {
  padding: 5px 8px;
  background: none;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  font-size: 16px;
  transition: all var(--transition);
}
.btn-icon:hover { background: var(--surface-hover); color: var(--text); }
.btn-icon.danger:hover { color: var(--danger); background: var(--danger-light); }

/* ===== Action Links (text buttons) ===== */
.action-cell {
  display: flex;
  gap: 8px;
  align-items: center;
}

.action-link {
  font-size: 13px;
  color: var(--primary);
  cursor: pointer;
  font-weight: 500;
  padding: 2px 4px;
  border-radius: 3px;
  transition: all var(--transition);
}
.action-link:hover { background: var(--primary-light); text-decoration: underline; }
.action-link.danger { color: var(--text-muted); }
.action-link.danger:hover { color: var(--danger); background: var(--danger-light); }

/* ===== Filter Select ===== */
.filter-select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
  min-width: 120px;
  cursor: pointer;
  transition: border var(--transition);
}
.filter-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}

/* ===== Clickable Item Name ===== */
.item-clickable {
  cursor: pointer;
  color: var(--primary);
  font-weight: 500;
  transition: all var(--transition);
  border-bottom: 1px dashed var(--primary-light);
}
.item-clickable:hover { color: var(--primary-dark); border-bottom-color: var(--primary); }

/* ===== Search ===== */
.search-box {
  position: relative;
  display: flex;
  align-items: center;
}
.search-icon {
  position: absolute;
  left: 10px;
  font-size: 13px;
  opacity: 0.5;
}
.search-box input {
  padding: 8px 12px 8px 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  width: 240px;
  background: var(--surface);
  transition: border var(--transition);
}
.search-box input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }

/* ===== Filter Row (Orders) ===== */
.filter-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  margin-top: 12px;
  flex-wrap: wrap;
}
.filter-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.filter-item label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
}
.filter-item input {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: var(--surface);
  width: 160px;
  transition: border var(--transition);
}
.filter-item input:focus { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-light); }
.filter-item input[type="date"] { width: 145px; }

/* ===== Filter / Sort Controls ===== */
.filter-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}
.filter-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}
.sort-select {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: border var(--transition);
}
.sort-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}

/* ===== Modal ===== */
.modal-root {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
}
.modal-root.active { display: block; }

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
  animation: fadeIn 0.15s ease;
}

.modal {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 850px;
  max-width: 92vw;
  height: auto;
  max-height: 90vh;
  min-height: 320px;
  display: flex;
  flex-direction: column;
  animation: modalIn 0.2s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: translate(-50%, -46%); }
  to { opacity: 1; transform: translate(-50%, -50%); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-light);
}
.modal-header h3 { font-size: 17px; font-weight: 700; }

.modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid var(--border-light);
}

/* ===== Forms ===== */
.form-row {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
}
.form-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.form-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}
.form-group input,
.form-group select {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: var(--surface);
  transition: border var(--transition);
}
.form-group input:focus,
.form-group select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
.input {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
  transition: border var(--transition);
  box-sizing: border-box;
}
.input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
  outline: none;
}

/* ===== Order Items Editor ===== */
.order-items-editor {
  margin-top: 8px;
}
.order-items-editor .editor-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}
.order-item-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
  padding: 10px;
  background: var(--surface-hover);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
}
.order-item-row .item-info {
  font-size: 12px;
  color: var(--text-muted);
  flex: 1;
  min-width: 0;
}
.order-item-row .btn-icon {
  flex-shrink: 0;
}

/* ===== Order Detail ===== */
.order-info-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}
.order-info-item {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.order-info-item .label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.order-info-item .value {
  font-size: 16px;
  font-weight: 600;
}

/* ===== BOM Chips ===== */
.bom-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.bom-chip {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px 9px;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}
.bom-chip .chip-qty {
  font-weight: 700;
  font-size: 11px;
  opacity: 0.9;
}

.bom-preview {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bom-preview .bom-chip {
  font-size: 11px;
  padding: 2px 6px;
  margin-right: 2px;
}

/* ===== Material Source ===== */
.material-source {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.6;
}
.source-line { display: block; }

/* ===== Order Material Preview ===== */
#order-preview { margin-top: 12px; }
.preview-line {
  padding: 4px 0;
  font-size: 12px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-light);
}
.preview-line:last-child { border-bottom: none; }
.preview-line strong { color: var(--text); }

/* ===== Toast ===== */
.toast-root {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--surface);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  padding: 12px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 500;
  animation: toastIn 0.25s ease;
  border-left: 4px solid var(--primary);
  min-width: 240px;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
.toast.fade-out { animation: toastOut 0.25s ease forwards; }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes toastOut {
  to { opacity: 0; transform: translateX(20px); }
}

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}
.empty-state-icon { font-size: 36px; margin-bottom: 10px; }
.empty-state-text { font-size: 13px; }

/* ===== Mini List (dashboard) ===== */
.mini-list { display: flex; flex-direction: column; gap: 8px; }
.mini-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--surface-hover);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
}
.mini-list-item:hover { background: var(--border-light); }
.mini-list-item .item-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.mini-list-item .item-name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mini-list-item .item-sub {
  font-size: 12px;
  color: var(--text-muted);
}
.mini-list-item .item-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.item-clickable {
  cursor: pointer;
  color: var(--primary);
  font-weight: 500;
  border-bottom: 1px dashed var(--primary-light);
  transition: all var(--transition);
}
.item-clickable:hover { color: var(--primary-dark); border-bottom-color: var(--primary); }

/* ===== Dashboard Top Bar ===== */
.dash-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  padding: 18px 22px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  flex-wrap: wrap;
}

.dash-alert-kpi {
  display: flex;
  align-items: center;
  gap: 14px;
}

.dash-alert-icon { font-size: 32px; }
.dash-alert-label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}
.dash-alert-value {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.3;
}

.btn-lg {
  padding: 10px 22px;
  font-size: 15px;
  font-weight: 600;
  border-radius: var(--radius);
}

/* ===== Image Thumbnail ===== */
.img-thumb {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition);
  background: var(--border-light);
}
.img-thumb:hover { transform: scale(1.15); box-shadow: 0 2px 8px rgba(0,0,0,0.15); }
.img-thumb-placeholder {
  width: 40px; height: 40px;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; color: var(--text-muted); background: var(--surface-hover);
}

/* ===== Image Modal (Viewer) ===== */
.image-modal {
  display: none;
  position: fixed; inset: 0;
  z-index: 3000;
  background: rgba(0,0,0,0.75);
  align-items: center; justify-content: center;
  cursor: pointer;
  animation: fadeIn 0.2s ease;
}
.image-modal.active { display: flex; }
.image-modal img {
  max-width: 90vw; max-height: 85vh;
  border-radius: var(--radius);
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
  object-fit: contain;
}
.image-modal-close {
  position: absolute; top: 20px; right: 30px;
  font-size: 32px; color: #fff;
  cursor: pointer; z-index: 3001;
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  transition: background var(--transition);
}
.image-modal-close:hover { background: rgba(255,255,255,0.3); }

/* ===== Editable SKU Cell ===== */
.sku-editable {
  cursor: pointer;
  padding: 2px 6px; border-radius: 3px;
  transition: background var(--transition);
  display: inline-block;
}
.sku-editable:hover { background: var(--primary-light); }
.sku-editable.editing {
  background: var(--surface);
  outline: 2px solid var(--primary); outline-offset: 1px;
  cursor: text; min-width: 80px;
}
.sku-editable input {
  border: none; outline: none;
  font-size: 13px; font-weight: 600;
  background: transparent; width: 100%;
  font-family: inherit;
}

/* ===== Image Upload Field ===== */
.img-upload-row { display: flex; align-items: center; gap: 12px; }
.img-upload-preview {
  width: 60px; height: 60px;
  border-radius: var(--radius-sm);
  object-fit: cover; border: 1px solid var(--border);
}
.img-upload-placeholder {
  width: 60px; height: 60px;
  border-radius: var(--radius-sm);
  border: 2px dashed var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; color: var(--text-muted);
  background: var(--surface-hover);
}
.img-upload-input { flex: 1; font-size: 13px; }

/* ===== Searchable Dropdown (SDD) ===== */
.sdd-wrapper {
  position: relative;
  flex: 1;
  min-width: 0;
}
.sdd-input-wrap {
  display: flex;
  align-items: center;
  position: relative;
}
.sdd-search-input {
  width: 100%;
  padding: 7px 28px 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: var(--surface);
  transition: border var(--transition);
}
.sdd-search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}
.sdd-arrow {
  position: absolute;
  right: 8px;
  font-size: 10px;
  color: var(--text-muted);
  pointer-events: none;
}
.sdd-dropdown {
  position: absolute;
  top: 100%;
  left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  max-height: 280px;
  overflow-y: auto;
  z-index: 1100;
  box-shadow: var(--shadow-lg);
}
.sdd-dropdown.hidden { display: none; }
.sdd-option {
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: background var(--transition);
}
.sdd-option:hover { background: var(--primary-light); color: var(--primary); }
.sdd-option.selected { background: var(--primary-light); font-weight: 600; }
.sdd-option.sdd-empty {
  color: var(--text-muted);
  cursor: default;
  text-align: center;
  font-style: italic;
}
.sdd-option.sdd-empty:hover { background: transparent; color: var(--text-muted); }

/* ===== Stock Adjust Popup ===== */
.adjust-info {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
  padding: 12px 16px;
  background: var(--surface-hover);
  border-radius: var(--radius-sm);
}
.adjust-info-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.adjust-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
}
.adjust-stock-now {
  display: flex;
  align-items: center;
  gap: 6px;
}
.adjust-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.adjust-tab {
  flex: 1;
  padding: 10px;
  text-align: center;
  font-size: 14px;
  font-weight: 500;
  background: var(--surface-hover);
  color: var(--text-secondary);
  transition: all var(--transition);
}
.adjust-tab.active {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}
.adjust-tab:hover:not(.active) { background: var(--border-light); }
.adjust-form.hidden { display: none; }
.adjust-preview {
  margin-top: 10px;
  padding: 10px 14px;
  background: var(--primary-light);
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.adjust-preview strong { color: var(--primary); }

/* ===== Log Detail ===== */
.log-detail-info {
  display: flex;
  gap: 20px;
  font-size: 13px;
  color: var(--text-secondary);
  flex-wrap: wrap;
}
.log-detail-info span { display: flex; align-items: center; gap: 4px; }
.log-summary {
  margin-top: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}

/* ===== Cost Sections (Product/Order Modals) ===== */
.cost-section {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border-light);
}
.cost-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.cost-row input[type="text"].cost-name { width: 100px; }
.cost-row input[type="number"].cost-price { width: 75px; }
.cost-row input[type="number"].cost-qty { width: 65px; }
.cost-row input[type="text"].cost-unit { width: 55px; }
.cost-row .cost-subtotal {
  min-width: 70px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  text-align: right;
}
.cost-section .btn {
  font-size: 12px;
  padding: 4px 12px;
}

/* ===== Order Profit Preview ===== */
#order-profit-preview {
  line-height: 1.8;
}
#order-profit-preview hr {
  border: none;
  border-top: 1px solid rgba(0,0,0,0.1);
  margin: 6px 0;
}
#order-profit-preview .prev-profit-line {
  font-size: 13px;
  display: flex;
  justify-content: space-between;
}

/* ===== Cost Detail Card ===== */
.cost-detail-card {
  margin: 16px 0;
}
.cost-detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.cost-detail-item {
  display: flex;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--surface-hover);
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.cost-detail-item .cd-label { color: var(--text-secondary); }
.cost-detail-item .cd-value { font-weight: 600; }
.cost-detail-total {
  display: flex;
  justify-content: space-between;
  padding: 10px 14px;
  font-weight: 700;
  font-size: 14px;
  border-radius: var(--radius-sm);
  margin-top: 4px;
}
.cost-detail-profit {
  display: flex;
  justify-content: space-between;
  padding: 12px 14px;
  font-weight: 700;
  font-size: 15px;
  border-radius: var(--radius-sm);
  margin-top: 4px;
}

/* ===== Product Price Input ===== */
.prod-price-input {
  width: 100px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: var(--surface);
  transition: border var(--transition);
  font-family: inherit;
}
.prod-price-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
  outline: none;
}
.prod-price-input::placeholder { color: var(--text-muted); font-size: 12px; }

/* ===== Drag & Drop (Product Table) ===== */
.drag-handle-cell {
  width: 36px;
  padding: 0 !important;
  text-align: center;
  vertical-align: middle;
}
.drag-handle {
  display: inline-block;
  cursor: grab;
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  letter-spacing: -2px;
  user-select: none;
  padding: 4px;
  border-radius: 3px;
  transition: all var(--transition);
}
.drag-handle:hover { color: var(--primary); background: var(--primary-light); }
.drag-handle:active { cursor: grabbing; }

tr.prod-row.dragging {
  opacity: 0.4;
  background: var(--surface-hover);
}
tr.prod-row.drag-over {
  border-top: 2px solid var(--primary);
  background: var(--primary-light);
}

/* ===== 订单统计卡片 ===== */
.ord-stats-bar {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.ord-stat-card {
  flex: 1;
  min-width: 160px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: box-shadow var(--transition);
}
.ord-stat-card:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.ord-stat-label {
  font-size: 13px;
  color: var(--text-muted);
}
.ord-stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
}

/* ===== 配方计算 ===== */
.recipe-layout {
  display: flex;
  gap: 20px;
  min-height: 480px;
}
.recipe-panel {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.recipe-panel .card {
  flex: 1;
}
.recipe-calc-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.recipe-calc-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.recipe-calc-row label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}
.recipe-calc-input-row {
  display: flex;
  gap: 10px;
  align-items: center;
}
.recipe-calc-input-row input {
  min-width: 0;
}
#recipe-result-card {
  animation: fadeIn 0.35s ease;
}
#recipe-result-summary {
  color: var(--text-secondary);
  font-size: 13px;
}
#recipe-result-tbody td:nth-child(4) {
  font-weight: 700;
  color: var(--primary);
  font-size: 16px;
}
.card-subtitle {
  color: var(--text-secondary);
  font-size: 12px;
  margin-left: auto;
}
#recipe-calc-btn {
  transition: background var(--transition);
}
#recipe-calc-btn:hover {
  opacity: 0.9;
}
.recipe-ing-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
.recipe-ing-row input {
  flex: 1;
  min-width: 0;
}
.recipe-ing-row input[type="number"] {
  flex: 0 0 auto;
}

@media (max-width: 900px) {
  .recipe-layout {
    flex-direction: column;
  }
  .recipe-panel {
    min-width: 100%;
  }
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .order-info-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  .sidebar { width: 60px; }
  .logo-text, .nav-item span:not(.nav-icon), .sidebar-footer { display: none; }
  .main { margin-left: 60px; padding: 16px; }
  .search-box input { width: 140px; }
}

/* ===== Sync Indicator ===== */
.sync-indicator { transition: all 0.3s; }
.sync-indicator.sync-ok { color: #4ade80 !important; }
.sync-indicator.sync-error { color: #f87171 !important; }
