/* ============================================================
   运营后台样式
   ============================================================ */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #1f2937;
  --text-muted: #6b7280;
  --text-faint: #9ca3af;
  --accent: #2b5cff;
  --accent-soft: #eef2ff;
  --accent-strong: #1e46d6;
  --sidebar-bg: #1c2536;
  --sidebar-text: #cbd5e1;
  --sidebar-active: #2b5cff;
  --success: #16a34a;
  --success-soft: #f0fdf4;
  --warning: #d97706;
  --warning-soft: #fffbeb;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --info: #0891b2;
  --info-soft: #ecfeff;
  --radius: 10px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

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

.sidebar {
  width: 220px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 1px;
}
.brand-name { font-size: 15px; font-weight: 600; color: #fff; }
.brand-sub { font-size: 12px; color: var(--sidebar-text); opacity: 0.7; }

.sidebar-nav { flex: 1; padding: 12px 8px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-radius: 8px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 14px;
  margin-bottom: 4px;
  transition: background 0.15s, color 0.15s;
  cursor: pointer;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.06); }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-icon { width: 8px; height: 8px; border-radius: 50%; background: currentColor; opacity: 0.5; flex-shrink: 0; }

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.operator-name { font-size: 13px; color: #fff; font-weight: 600; }
.operator-role { font-size: 11px; color: var(--sidebar-text); opacity: 0.7; margin-top: 2px; }
.logout-btn {
  margin-top: 12px;
  width: 100%;
  padding: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--sidebar-text);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}
.logout-btn:hover { background: rgba(255, 255, 255, 0.14); }

/* ============ 主区域 ============ */
.main {
  flex: 1;
  margin-left: 220px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-title { font-size: 18px; font-weight: 600; }

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--text-faint);
  display: inline-block;
  position: relative;
}
.status-dot[data-state="online"] { background: var(--success); }
.status-dot[data-state="offline"] { background: var(--danger); }
.status-dot[data-state="online"]::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  background: var(--success);
  opacity: 0.25;
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0% { transform: scale(0.7); opacity: 0.4; }
  70% { transform: scale(1.4); opacity: 0; }
  100% { opacity: 0; }
}

.content { padding: 24px; flex: 1; }

/* ============ 通用组件 ============ */
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filter-chip {
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}
.filter-chip:hover { border-color: var(--accent); color: var(--accent); }
.filter-chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.btn {
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-strong); color: #fff; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* 表格 */
.table-wrap {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left;
  padding: 12px 16px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  background: #fafafa;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr { cursor: pointer; transition: background 0.1s; }
tbody tr:hover { background: #fafbfc; }

/* 状态标签 */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}
.badge-pending { background: var(--warning-soft); color: var(--warning); }
.badge-processing { background: var(--accent-soft); color: var(--accent); }
.badge-completed { background: var(--success-soft); color: var(--success); }
.badge-replied { background: var(--info-soft); color: var(--info); }
.badge-closed { background: #f3f4f6; color: var(--text-muted); }
.badge-plain { background: #f3f4f6; color: var(--text-muted); }
.badge-paid { background: var(--info-soft); color: var(--info); }
.badge-shipped { background: var(--accent-soft); color: var(--accent); }
.badge-cancelled { background: #f3f4f6; color: var(--text-muted); }
.badge-refunded { background: #f3f4f6; color: var(--text-muted); }

.text-price { color: var(--danger); font-weight: 600; }
.cell-shrink { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link { color: var(--accent); cursor: pointer; }
.link:hover { text-decoration: underline; }

/* 空/加载/错误状态 */
.state-box {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.state-empty .state-icon { font-size: 40px; margin-bottom: 12px; }
.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 详情卡 */
.detail-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
  overflow: hidden;
}
.detail-card-head {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.detail-card-body { padding: 20px; }

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}
.detail-item label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.detail-item .value { font-size: 14px; }

/* 料号条目 */
.material-row {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 12px;
  overflow: hidden;
}
.material-row-head {
  padding: 12px 16px;
  background: #fafafa;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.material-row-title { font-weight: 600; font-size: 14px; }
.material-row-body { padding: 12px 16px; }
.stock-list { margin-top: 8px; }
.stock-list-item {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-top: 1px dashed var(--border);
  font-size: 13px;
}
.stock-list-item:first-child { border-top: none; }

.no-stock {
  color: var(--text-faint);
  font-size: 12px;
  font-style: italic;
  margin-top: 8px;
}

/* 对话框字段 */
.form-field { margin-bottom: 12px; }
.form-field label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.form-field input,
.form-field textarea,
.form-field select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  background: var(--surface);
}
.form-field input:focus,
.form-field textarea:focus,
.form-field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ============ 抽屉（消息流） ============ */
.drawer-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 40;
}
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 480px;
  max-width: 90vw;
  background: var(--surface);
  z-index: 50;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.15);
  transform: translateX(100%);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
.drawer.open { transform: translateX(0); }
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.drawer-title { font-size: 16px; font-weight: 600; }
.icon-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  font-size: 22px;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 6px;
  line-height: 1;
}
.icon-btn:hover { background: #f3f4f6; }

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}

/* 消息气泡 */
.msg-list { display: flex; flex-direction: column; gap: 12px; }
.msg-item { display: flex; flex-direction: column; max-width: 80%; }
.msg-item.self { align-self: flex-end; }
.msg-item.other { align-self: flex-start; }
.msg-meta { font-size: 11px; color: var(--text-faint); margin-bottom: 4px; padding: 0 4px; }
.msg-bubble {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  word-break: break-word;
}
.msg-item.self .msg-bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg-item.other .msg-bubble { background: #f3f4f6; color: var(--text); border-bottom-left-radius: 4px; }
.msg-item.self .msg-meta { text-align: right; }

.msg-input-wrap {
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  gap: 8px;
}
.msg-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  resize: none;
}
.msg-input:focus { outline: none; border-color: var(--accent); }
.msg-send {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0 18px;
  font-size: 13px;
  cursor: pointer;
}
.msg-send:hover { background: var(--accent-strong); }

/* ============ Toast ============ */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #1f2937;
  color: #fff;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 100;
  box-shadow: var(--shadow-md);
  animation: toast-in 0.2s ease;
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, -10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* 回复框 */
.reply-box {
  border-top: 1px solid var(--border);
  padding: 16px 20px;
}

/* 响应式 */
@media (max-width: 768px) {
  .sidebar { width: 64px; }
  .sidebar-brand .brand-text,
  .nav-item span:last-child,
  .sidebar-footer { display: none; }
  .main { margin-left: 64px; }
  .drawer { width: 100vw; max-width: 100vw; }
}
