/* 色丽雅车间 MES · 工业简洁风 */
:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --sidebar: #0f1c24;
  --sidebar-2: #152530;
  --teal: #0f766e;
  --teal-d: #0d5f59;
  --teal-l: #14b8a6;
  --amber: #d97706;
  --red: #dc2626;
  --blue: #2563eb;
  --green: #16a34a;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 4px 12px rgba(15, 23, 42, 0.04);
  --radius: 10px;
  --sidebar-w: 240px;
  --font: "PingFang SC", "Noto Sans SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }

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

/* —— Sidebar —— */
.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--sidebar) 0%, #0a141a 100%);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  transition: transform 0.2s ease;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.brand-mark {
  width: 36px; height: 36px;
  border-radius: 8px;
  background: var(--teal);
  color: #fff;
  font-weight: 700;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.brand-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.brand-text strong { color: #f8fafc; font-size: 15px; }
.brand-text span { font-size: 11px; color: #94a3b8; }
.sidebar-close {
  display: none;
  background: transparent;
  border: 0;
  color: #94a3b8;
  font-size: 22px;
  cursor: pointer;
  padding: 0 4px;
}

.nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #94a3b8;
  font: inherit;
  font-size: 13.5px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: rgba(255,255,255,0.05); color: #e2e8f0; }
.nav-item.active { background: rgba(15, 118, 110, 0.35); color: #fff; }
.nav-ico { width: 18px; text-align: center; opacity: 0.85; font-size: 13px; }

.sidebar-foot { padding: 12px 14px 18px; border-top: 1px solid rgba(255,255,255,0.06); }

/* —— Main —— */
.main-wrap {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100vh;
}
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.menu-btn {
  display: none;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 36px; height: 36px;
  cursor: pointer;
  font-size: 16px;
}
.topbar-title { flex: 1; min-width: 0; }
.topbar-title h1 { margin: 0; font-size: 18px; font-weight: 650; }
.topbar-title p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.topbar-meta { display: flex; gap: 8px; align-items: center; }

.content { padding: 18px 22px 28px; flex: 1; }
.footer {
  padding: 12px 22px 20px;
  font-size: 11.5px;
  color: var(--muted);
  border-top: 1px solid var(--border);
}

/* —— Cards / layout —— */
.grid { display: grid; gap: 14px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.card-h {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.card-h h2, .card-h h3 {
  margin: 0;
  font-size: 14.5px;
  font-weight: 650;
}
.card-h .hint { font-size: 12px; color: var(--muted); font-weight: 400; }

.stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat .label { font-size: 12px; color: var(--muted); }
.stat .value { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }
.stat .sub { font-size: 12px; color: var(--muted); }
.stat.warn .value { color: var(--amber); }
.stat.danger .value { color: var(--red); }
.stat.ok .value { color: var(--green); }
.stat.info .value { color: var(--teal); }

/* —— Pills / badges —— */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  background: #f1f5f9;
  color: var(--muted);
  white-space: nowrap;
}
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-待排产 { background: #e2e8f0; color: #475569; }
.badge-生产中 { background: #ccfbf1; color: #0f766e; }
.badge-待检 { background: #fef3c7; color: #b45309; }
.badge-已完工 { background: #dcfce7; color: #15803d; }
.badge-已发货 { background: #dbeafe; color: #1d4ed8; }
.badge-priority-高 { background: #fee2e2; color: #b91c1c; }
.badge-priority-中 { background: #ffedd5; color: #c2410c; }
.badge-priority-低 { background: #f1f5f9; color: #64748b; }
.badge-risk { background: #fee2e2; color: #b91c1c; }
.badge-ok { background: #dcfce7; color: #15803d; }
.badge-warn { background: #fef3c7; color: #b45309; }

/* —— Buttons —— */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  font: inherit;
  font-size: 13px;
  font-weight: 560;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--teal-d); }
.btn-secondary { background: #fff; border-color: var(--border); color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: #f8fafc; }
.btn-danger { background: #fff; border-color: #fecaca; color: var(--red); }
.btn-danger:hover:not(:disabled) { background: #fef2f2; }
.btn-ghost {
  background: transparent;
  border-color: rgba(255,255,255,0.15);
  color: #94a3b8;
  width: 100%;
}
.btn-ghost:hover { background: rgba(255,255,255,0.06); color: #e2e8f0; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

.icon-btn {
  background: transparent;
  border: 0;
  font-size: 22px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 0 4px;
}

/* —— Forms —— */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.field { display: flex; flex-direction: column; gap: 4px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12px; color: var(--muted); font-weight: 560; }
.field input, .field select, .field textarea {
  font: inherit;
  font-size: 13.5px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid rgba(15, 118, 110, 0.25);
  border-color: var(--teal);
}
.field textarea { min-height: 72px; resize: vertical; }
.field .hint { font-size: 11px; color: var(--muted); }

/* —— Table —— */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.data th, table.data td {
  padding: 10px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.data th {
  font-size: 11.5px;
  text-transform: none;
  letter-spacing: 0;
  color: var(--muted);
  font-weight: 600;
  background: #f8fafc;
  white-space: nowrap;
}
table.data tr:hover td { background: #fafbfc; }
table.data .actions { white-space: nowrap; }
table.data .actions .btn { margin-right: 4px; }

/* —— Progress bars —— */
.bar-track {
  height: 8px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
  min-width: 80px;
}
.bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--teal);
  transition: width 0.3s ease;
}
.bar-fill.warn { background: var(--amber); }
.bar-fill.danger { background: var(--red); }
.bar-fill.ok { background: var(--green); }

.stage-row {
  display: grid;
  grid-template-columns: 72px 1fr 42px;
  gap: 8px;
  align-items: center;
  margin-bottom: 6px;
  font-size: 12px;
}
.stage-row .name { color: var(--muted); }

/* —— Capacity / schedule —— */
.cap-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.cap-row .name { width: 72px; font-size: 13px; font-weight: 560; flex-shrink: 0; }
.cap-row .bar-track { flex: 1; height: 14px; }
.cap-row .pct { width: 48px; text-align: right; font-size: 12px; color: var(--muted); }

.week-grid {
  display: grid;
  grid-template-columns: 80px repeat(7, 1fr);
  gap: 4px;
  font-size: 12px;
}
.week-grid .hd {
  padding: 6px 4px;
  text-align: center;
  color: var(--muted);
  font-weight: 600;
  background: #f8fafc;
  border-radius: 6px;
}
.week-grid .line-label {
  display: flex;
  align-items: center;
  font-weight: 600;
  font-size: 12px;
  padding: 4px;
}
.week-cell {
  min-height: 64px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.week-chip {
  background: #ccfbf1;
  color: #0f766e;
  border-radius: 4px;
  padding: 3px 5px;
  font-size: 10.5px;
  line-height: 1.3;
  cursor: default;
  overflow: hidden;
}
.week-chip.rush { background: #fee2e2; color: #b91c1c; }
.week-chip.high { background: #ffedd5; color: #c2410c; }
.week-chip.empty { background: transparent; border: 1px dashed #cbd5e1; color: #94a3b8; text-align: center; padding: 12px 4px; }

/* —— Option cards (rush) —— */
.option-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.option-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  background: #fff;
  cursor: default;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.option-card:hover { border-color: var(--teal-l); box-shadow: var(--shadow); }
.option-card h4 { margin: 0 0 6px; font-size: 14px; }
.option-card .tag {
  display: inline-block;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 4px;
  background: #f0fdfa;
  color: var(--teal);
  margin-bottom: 8px;
  font-weight: 600;
}
.option-card ul { margin: 0; padding-left: 18px; font-size: 12.5px; color: var(--muted); }
.option-card li { margin-bottom: 4px; }
.option-card .cost { margin-top: 10px; font-size: 13px; font-weight: 650; color: var(--text); }

/* —— Alert list —— */
.alert-list { display: flex; flex-direction: column; gap: 8px; }
.alert-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;
  border-radius: 8px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  font-size: 13px;
}
.alert-item.danger { background: #fef2f2; border-color: #fecaca; }
.alert-item.ok { background: #f0fdf4; border-color: #bbf7d0; }
.alert-item .ico { font-size: 16px; line-height: 1.2; }

/* —— Kitting —— */
.kit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}
.kit-card .bom-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid #f1f5f9;
  font-size: 12.5px;
}
.kit-card .bom-row:last-child { border-bottom: 0; }
.kit-card .bom-name { font-weight: 560; }
.kit-card .bom-nums { color: var(--muted); font-variant-numeric: tabular-nums; }
.shortage { color: var(--red); font-weight: 650; }

/* —— Empty / note —— */
.empty {
  text-align: center;
  padding: 36px 16px;
  color: var(--muted);
  font-size: 13.5px;
}
.note-box {
  background: #f0fdfa;
  border: 1px solid #99f6e4;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12.5px;
  color: #0f766e;
  margin-bottom: 14px;
}
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
  align-items: center;
}
.filters select, .filters input {
  font: inherit;
  font-size: 13px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

/* —— Modal —— */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 100;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
}
.modal-backdrop[hidden] { display: none !important; }
.modal {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 560px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.2);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-body { padding: 16px; }
.modal-foot {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* —— Toast —— */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #0f172a;
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}
.toast[hidden] { display: none !important; }

/* —— Responsive —— */
@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .option-cards { grid-template-columns: 1fr; }
  .week-grid { grid-template-columns: 64px repeat(7, minmax(70px, 1fr)); min-width: 640px; }
}
@media (max-width: 800px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: block; }
  .menu-btn { display: inline-flex; align-items: center; justify-content: center; }
  .main-wrap { margin-left: 0; }
  .grid-3, .grid-2, .form-grid { grid-template-columns: 1fr; }
  .content { padding: 14px; }
  .topbar { padding: 12px 14px; }
  .backdrop-nav {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    z-index: 35;
  }
}
@media (max-width: 480px) {
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .stat .value { font-size: 22px; }
}

/* —— Login —— */
.login-screen {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(ellipse at 20% 20%, rgba(20, 184, 166, 0.18), transparent 50%),
    radial-gradient(ellipse at 80% 80%, rgba(15, 118, 110, 0.22), transparent 45%),
    linear-gradient(160deg, #0a141a 0%, #0f1c24 50%, #12263a 100%);
}
.login-screen[hidden] { display: none !important; }
.login-card {
  width: min(400px, 100%);
  background: var(--surface);
  border-radius: 14px;
  padding: 28px 26px 22px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.35);
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}
.login-brand strong {
  display: block;
  font-size: 17px;
  color: var(--text);
}
.login-brand span {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}
.login-card .field { margin-bottom: 14px; }
.login-card label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}
.login-card input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  font-size: 14px;
}
.login-card input:focus {
  outline: 2px solid rgba(15, 118, 110, 0.25);
  border-color: var(--teal);
}
.btn-block { width: 100%; justify-content: center; margin-top: 4px; }
.login-error {
  color: var(--red);
  font-size: 13px;
  margin: 0 0 10px;
}
.login-hint {
  margin: 16px 0 0;
  font-size: 11.5px;
  color: var(--muted);
  text-align: center;
}

.user-chip {
  padding: 10px 12px;
  margin-bottom: 8px;
  border-radius: 8px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.06);
}
.user-chip-name {
  color: #f1f5f9;
  font-size: 13px;
  font-weight: 600;
}
.user-chip-role {
  color: #94a3b8;
  font-size: 11px;
  margin-top: 2px;
}
.sidebar-foot .btn-ghost {
  width: 100%;
  margin-bottom: 6px;
  justify-content: center;
}
#appShell[hidden] { display: none !important; }
.nav-item[hidden], [data-need][hidden] { display: none !important; }
.btn[disabled], button[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}
