/* 智能MES系统 - 明道云风格 CRUD 表单与列表 */

/* ---------- 列表页工具栏 ---------- */
.crud-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  margin-bottom: 16px;
  padding: 12px 16px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-xs);
}
.crud-toolbar-left,
.crud-toolbar-right {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.crud-search-box {
  position: relative; display: flex; align-items: center;
  min-width: 260px; max-width: 360px;
}
.crud-search-box .ic {
  position: absolute; left: 12px; font-size: 14px; opacity: .55; pointer-events: none;
}
.crud-search-box input {
  width: 100%; height: 36px; padding: 0 12px 0 36px;
  border: 1.5px solid var(--line); border-radius: var(--r-md);
  background: var(--gray-25); color: var(--txt);
  font-size: 13px; outline: none; transition: all var(--t-fast);
}
.crud-search-box input:focus {
  border-color: var(--brand-500); background: #fff;
  box-shadow: 0 0 0 3px rgba(30,111,255,.1);
}
.crud-btn-record {
  display: inline-flex; align-items: center; gap: 5px;
  height: 36px; padding: 0 16px;
  border-radius: var(--r-md); border: none;
  background: var(--success-500); color: #fff;
  font-size: 13px; font-weight: 600; cursor: pointer;
  box-shadow: 0 2px 6px rgba(16,185,129,.25);
  transition: all var(--t-fast);
}
.crud-btn-record:hover {
  background: var(--success-600);
  box-shadow: 0 4px 10px rgba(16,185,129,.35);
  transform: translateY(-1px);
}
.crud-btn-record svg { width: 14px; height: 14px; }
.crud-tabs {
  display: flex; align-items: center; gap: 6px;
}
.crud-tab {
  padding: 6px 14px; border-radius: var(--r-full);
  font-size: 13px; color: var(--gray-600); cursor: pointer;
  background: transparent; border: 1px solid transparent;
  transition: all var(--t-fast);
}
.crud-tab:hover { background: var(--gray-100); color: var(--gray-800); }
.crud-tab.active { background: var(--brand-500); color: #fff; font-weight: 600; }
.crud-count {
  font-size: 13px; color: var(--sub); white-space: nowrap;
}

/* ---------- 列表表格增强 ---------- */
.crud-table-wrap { overflow-x: auto; }
.crud-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; }
.crud-table thead th {
  background: var(--gray-50); color: var(--gray-600); font-weight: 600; font-size: 13px;
  padding: 12px 16px; text-align: left; white-space: nowrap;
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 1;
}
.crud-table thead th:first-child { padding-left: 22px; }
.crud-table tbody td {
  padding: 12px 16px; border-bottom: 1px solid var(--line-soft);
  color: var(--gray-800); white-space: nowrap; vertical-align: middle;
}
.crud-table tbody td:first-child { padding-left: 22px; }
.crud-table tbody tr { transition: background var(--t-fast); }
.crud-table tbody tr:hover { background: var(--brand-50); }
.crud-table tbody tr:hover td { color: var(--gray-800); }
.crud-table tbody tr:last-child td { border-bottom: none; }

/* ---------- 分页 ---------- */
.crud-pager {
  display: flex; align-items: center; justify-content: flex-end;
  gap: 6px; padding: 14px 22px;
  border-top: 1px solid var(--line-soft); background: var(--gray-25);
}
.crud-pager-info { margin-right: auto; font-size: 13px; color: var(--sub); }
.crud-pager-info strong { color: var(--gray-800); font-weight: 600; }
.crud-pager-btn {
  min-width: 32px; height: 32px; padding: 0 8px;
  border-radius: var(--r-md); border: 1px solid var(--line);
  background: #fff; color: var(--gray-600); font-size: 13px;
  cursor: pointer; transition: all var(--t-fast);
}
.crud-pager-btn:hover { border-color: var(--brand-300); color: var(--brand-600); background: var(--brand-50); }
.crud-pager-btn:disabled { opacity: .5; cursor: not-allowed; }
.crud-pager-cur {
  width: 50px; padding: 5px 8px; text-align: center; font-size: 12px;
  border: 1.5px solid var(--line); border-radius: var(--r-sm); outline: none;
}
.crud-pager-cur:focus { border-color: var(--brand-500); }

/* ---------- 明道云风格弹窗 ---------- */
.md-modal-mask {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(15,23,42,.55); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  animation: mdMaskIn .2s ease;
}
@keyframes mdMaskIn { from { opacity: 0; } to { opacity: 1; } }
.md-modal {
  width: 920px; max-width: 94vw; max-height: 92vh;
  background: var(--card); border-radius: var(--r-xl);
  box-shadow: var(--shadow-2xl);
  display: flex; flex-direction: column;
  animation: mdModalIn .25s cubic-bezier(.16,1,.3,1);
  overflow: hidden;
}
.md-modal.wide { width: 1080px; }
@keyframes mdModalIn { from { opacity: 0; transform: scale(.96) translateY(12px); } to { opacity: 1; transform: scale(1) translateY(0); } }
.md-modal-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 16px 22px;
  border-bottom: 1px solid var(--line); background: var(--gray-25);
}
.md-modal-title {
  font-size: 16px; font-weight: 700; color: var(--gray-900);
  display: flex; align-items: center; gap: 8px;
}
.md-modal-title::before {
  content: ''; display: inline-block;
  width: 4px; height: 16px; background: var(--brand-500); border-radius: 2px;
}
.md-modal-actions {
  display: flex; align-items: center; gap: 8px;
}
.md-modal-actions button {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: var(--r-md);
  border: 1px solid var(--line); background: #fff; color: var(--gray-600);
  cursor: pointer; transition: all var(--t-fast);
}
.md-modal-actions button:hover { background: var(--gray-100); color: var(--gray-900); border-color: var(--line-strong); }
.md-modal-actions button.ai-fill {
  width: auto; gap: 5px; padding: 0 12px;
  border-color: var(--brand-200); color: var(--brand-700); font-size: 13px; font-weight: 600;
  background: var(--brand-50);
}
.md-modal-actions button.ai-fill:hover { background: var(--brand-100); border-color: var(--brand-300); }
.md-modal-actions button.ai-fill svg { width: 14px; height: 14px; }
.md-modal-actions button.close:hover { background: var(--danger-50); color: var(--danger-600); border-color: var(--danger-200); }

.md-modal-body {
  flex: 1; overflow: auto; padding: 22px 26px;
  background: var(--bg-soft);
}
.md-modal-foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 14px 22px;
  border-top: 1px solid var(--line); background: var(--card);
}
.md-modal-foot-left {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--gray-600);
}
.md-modal-foot-left input[type=checkbox] {
  width: 16px; height: 16px; cursor: pointer;
}
.md-modal-foot-right {
  display: flex; align-items: center; gap: 10px;
}
.md-modal-foot .btn {
  height: 36px; padding: 0 18px; font-size: 13px; font-weight: 600;
}
.md-modal-foot .btn.primary {
  background: var(--success-500); color: #fff; border-color: transparent;
  box-shadow: 0 2px 6px rgba(16,185,129,.25);
}
.md-modal-foot .btn.primary:hover { background: var(--success-600); }
.md-modal-foot .btn.secondary {
  background: var(--brand-500); color: #fff; border-color: transparent;
  box-shadow: 0 2px 6px rgba(30,111,255,.25);
}
.md-modal-foot .btn.secondary:hover { background: var(--brand-600); }

/* ---------- 表单分区 ---------- */
.md-form-section {
  background: #fff; border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 18px 20px; margin-bottom: 18px;
  box-shadow: var(--shadow-xs);
}
.md-form-section-title {
  font-size: 14px; font-weight: 700; color: var(--gray-900);
  margin-bottom: 16px; padding-bottom: 10px;
  border-bottom: 1px dashed var(--line-soft);
  display: flex; align-items: center; gap: 6px;
}
.md-form-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px 18px;
}
.md-form-grid.two { grid-template-columns: repeat(2, 1fr); }
.md-form-grid.four { grid-template-columns: repeat(4, 1fr); }
.md-form-field {
  display: flex; flex-direction: column; gap: 6px;
}
.md-form-field.full { grid-column: 1 / -1; }
.md-form-field label {
  font-size: 12px; font-weight: 600; color: var(--gray-900);
  display: flex; align-items: center; gap: 3px;
}
.md-form-field label .req { color: var(--danger-500); font-weight: 700; }
.md-form-field input,
.md-form-field select,
.md-form-field textarea {
  width: 100%; min-height: 36px; padding: 7px 11px;
  border: 1.5px solid var(--gray-300); border-radius: var(--r-md);
  background: #fff; color: var(--gray-900); font-size: 13px;
  outline: none; transition: all var(--t-fast);
}
.md-form-field input:hover,
.md-form-field select:hover,
.md-form-field textarea:hover { border-color: var(--gray-400); }
.md-form-field input:focus,
.md-form-field select:focus,
.md-form-field textarea:focus {
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px rgba(30,111,255,.1);
}
.md-form-field input::placeholder,
.md-form-field textarea::placeholder { color: var(--gray-500); font-size: 13px; }
.md-form-field textarea { min-height: 72px; resize: vertical; }
.md-form-field input[type=checkbox] {
  width: 18px; height: 18px; min-height: auto; cursor: pointer;
}
.md-form-field.hint { font-size: 11px; color: var(--subtle); margin-top: 2px; }

/* ---------- 子表 / Tab ---------- */
.md-subtabs {
  display: flex; align-items: center; gap: 4px;
  border-bottom: 1px solid var(--line); margin-bottom: 14px;
}
.md-subtab {
  padding: 9px 16px; font-size: 13px; font-weight: 500;
  color: var(--gray-600); cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: all var(--t-fast);
  display: inline-flex; align-items: center; gap: 6px;
}
.md-subtab:hover { color: var(--gray-800); }
.md-subtab.active { color: var(--brand-600); border-bottom-color: var(--brand-500); }
.md-subtab .count {
  font-size: 11px; padding: 1px 6px; border-radius: 10px;
  background: var(--gray-100); color: var(--gray-600);
}
.md-subtab.active .count { background: var(--brand-100); color: var(--brand-600); }
.md-subtable {
  background: #fff; border: 1px solid var(--line);
  border-radius: var(--r-md); overflow: hidden;
}
.md-subtable table { width: 100%; font-size: 13px; border-collapse: collapse; }
.md-subtable th,
.md-subtable td {
  padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line-soft);
  white-space: nowrap;
}
.md-subtable th { background: var(--gray-50); color: var(--gray-600); font-weight: 600; font-size: 12px; }
.md-subtable tbody tr:last-child td { border-bottom: none; }
.md-subtable tbody tr:hover { background: var(--brand-50); }
.md-subtable input,
.md-subtable select {
  width: 100%; padding: 6px 8px; font-size: 13px;
  border: 1.5px solid var(--line); border-radius: var(--r-sm);
  outline: none; background: #fff; color: var(--gray-900);
}
.md-subtable input:focus,
.md-subtable select:focus { border-color: var(--brand-500); }
.md-subtable-actions { display: flex; align-items: center; justify-content: space-between; padding: 12px; }
.md-subtable-add {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 6px 12px; border-radius: var(--r-md);
  border: 1px dashed var(--line-strong); background: #fff; color: var(--gray-600);
  font-size: 13px; cursor: pointer; transition: all var(--t-fast);
}
.md-subtable-add:hover { border-color: var(--brand-400); color: var(--brand-600); background: var(--brand-50); }
.md-subtable-del {
  padding: 4px 8px; border-radius: var(--r-sm);
  border: none; background: transparent; color: var(--danger-500);
  font-size: 12px; cursor: pointer;
}
.md-subtable-del:hover { background: var(--danger-50); }

/* ---------- 查看弹窗 ---------- */
.md-kv-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px 24px;
}
.md-kv-item {
  display: flex; flex-direction: column; gap: 4px;
  padding: 10px 0; border-bottom: 1px dashed var(--line-soft);
}
.md-kv-item .k { font-size: 12px; color: var(--sub); }
.md-kv-item .v { font-size: 13px; color: var(--gray-800); font-weight: 500; word-break: break-all; }

/* ---------- 深色主题覆盖 ---------- */
body.dark-theme .crud-toolbar,
body.dark-theme .md-form-section,
body.dark-theme .md-subtable,
body.dark-theme .md-modal {
  background: rgba(255,255,255,.04); border-color: rgba(255,255,255,.1);
}
body.dark-theme .crud-search-box input,
body.dark-theme .md-form-field input,
body.dark-theme .md-form-field select,
body.dark-theme .md-form-field textarea,
body.dark-theme .md-subtable input,
body.dark-theme .md-subtable select,
body.dark-theme .md-modal-actions button,
body.dark-theme .crud-pager-btn,
body.dark-theme .md-subtable-add {
  background: rgba(255,255,255,.05); border-color: rgba(255,255,255,.12); color: #e2e8f0;
}
body.dark-theme .crud-search-box input:focus,
body.dark-theme .md-form-field input:focus,
body.dark-theme .md-form-field select:focus,
body.dark-theme .md-form-field textarea:focus,
body.dark-theme .md-subtable input:focus,
body.dark-theme .md-subtable select:focus {
  border-color: var(--brand-400); box-shadow: 0 0 0 3px rgba(59,130,246,.2);
}
body.dark-theme .crud-table thead th,
body.dark-theme .md-subtable th,
body.dark-theme .crud-pager,
body.dark-theme .md-modal-head { background: rgba(255,255,255,.05); }
body.dark-theme .crud-table thead th,
body.dark-theme .md-subtable th { color: #cbd5e1; }
body.dark-theme .crud-table tbody td,
body.dark-theme .md-subtable td,
body.dark-theme .md-form-section-title,
body.dark-theme .md-kv-item { border-color: rgba(255,255,255,.08); }
body.dark-theme .crud-table tbody td,
body.dark-theme .md-subtable td { color: #e2e8f0; }
body.dark-theme .crud-table tbody tr:hover td { color: #f1f5f9; }
body.dark-theme .crud-pager-info { color: #94a3b8; }
body.dark-theme .crud-pager-info strong { color: #e8ecf3; }
body.dark-theme .crud-table tbody tr:hover,
body.dark-theme .md-subtable tbody tr:hover { background: rgba(59,130,246,.1); }
body.dark-theme .md-modal-title,
body.dark-theme .md-form-section-title,
body.dark-theme .md-form-field label,
body.dark-theme .md-kv-item .v { color: #f1f5f9; }
body.dark-theme .md-form-field input,
body.dark-theme .md-form-field select,
body.dark-theme .md-form-field textarea {
  background: #0f172a; color: #f1f5f9; border-color: #334155;
}
body.dark-theme .md-form-field input::placeholder,
body.dark-theme .md-form-field textarea::placeholder { color: #94a3b8; }
body.dark-theme .crud-tab { color: #94a3b8; }
body.dark-theme .crud-tab.active { color: #fff; }

@media (max-width: 900px) {
  .md-form-grid,
  .md-form-grid.two,
  .md-form-grid.four { grid-template-columns: 1fr; }
  .md-kv-grid { grid-template-columns: 1fr; }
  .md-modal { width: 96vw; }
}
