/* =============================================
   大聚农牧CRM — 全局样式系统
   v1.0 Phase 1
   ============================================= */

:root {
  /* 主色 */
  --primary: #2563eb;
  --primary-dark: #1e40af;
  --primary-light: #dbeafe;
  --green: #16a34a;
  --green-light: #dcfce7;
  --orange: #ea580c;
  --orange-light: #fed7aa;
  --red: #dc2626;
  --red-light: #fecaca;
  --gray: #64748b;
  --gray-light: #f1f5f9;
  /* 中性 */
  --bg: #f8fafc;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  /* 阴影 */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.08);
  /* 圆角 */
  --radius: 8px;
  --radius-lg: 12px;
}

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

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

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

/* ===== Layout ===== */
.app-layout { display: flex; min-height: 100vh; }
.app-nav { width: 220px; background: #1e293b; color: #cbd5e1; flex-shrink: 0; display: flex; flex-direction: column; }
.app-nav-brand { padding: 20px 16px; font-size: 16px; font-weight: 700; color: #fff; border-bottom: 1px solid #334155; }
.app-nav-items { flex: 1; padding: 8px 0; overflow-y: auto; }
.nav-group-label { padding: 16px 16px 6px; font-size: 11px; color: #64748b; text-transform: uppercase; letter-spacing: 0.5px; }
.nav-item { padding: 10px 16px; cursor: pointer; display: flex; align-items: center; gap: 10px; font-size: 14px; transition: all .15s; border-left: 3px solid transparent; }
.nav-item:hover { background: #334155; color: #fff; }
.nav-item.active { background: #334155; color: #fff; border-left-color: var(--primary); }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }

.app-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.app-header { height: 56px; background: var(--card); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 24px; flex-shrink: 0; }
.header-title { font-size: 18px; font-weight: 600; }
.header-right { display: flex; align-items: center; gap: 12px; }
.user-info { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.user-avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 600; }
.user-name { font-size: 13px; font-weight: 500; }
.user-role { font-size: 11px; color: var(--gray); }
.app-content { flex: 1; padding: 24px; overflow-y: auto; }

/* ===== Cards ===== */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); margin-bottom: 16px; }
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-title { font-size: 15px; font-weight: 600; }
.card-body { padding: 20px; }

/* ===== Buttons ===== */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border: 1px solid transparent; border-radius: var(--radius); font-size: 13px; font-weight: 500; cursor: pointer; transition: all .15s; white-space: nowrap; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { background: transparent; border-color: var(--border); color: var(--text-secondary); }
.btn-outline:hover { background: var(--gray-light); border-color: var(--gray); }
.btn-green { background: var(--green); color: #fff; }
.btn-green:hover { background: #15803d; }
.btn-orange { background: var(--orange); color: #fff; }
.btn-danger { background: var(--red); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-lg { padding: 10px 24px; font-size: 15px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== Forms ===== */
.form-group { margin-bottom: 16px; }
.form-label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 500; color: var(--text-secondary); }
.form-label .required { color: var(--red); }
.form-control { width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 14px; outline: none; transition: border-color .15s; background: #fff; }
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
textarea.form-control { resize: vertical; min-height: 70px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ===== Tables ===== */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { background: var(--gray-light); padding: 10px 12px; text-align: left; font-weight: 600; color: var(--text-secondary); border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:hover td { background: #f8fafc; }
.table-actions { display: flex; gap: 6px; }

/* ===== Badges ===== */
.badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; }
.badge-primary { background: var(--primary-light); color: var(--primary-dark); }
.badge-success { background: var(--green-light); color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: var(--red-light); color: #991b1b; }
.badge-gray { background: var(--gray-light); color: var(--text-secondary); }

/* Status colors */
.status-new { background: #dbeafe; color: #1e40af; }
.status-draft { background: var(--gray-light); color: var(--gray); }
.status-sent { background: #fef3c7; color: #92400e; }
.status-confirmed { background: var(--green-light); color: #166534; }
.status-ordered { background: var(--green-light); color: #166534; }
.status-expired { background: var(--red-light); color: #991b1b; }
.status-void { background: #f3f4f6; color: #6b7280; }

/* ===== Tabs ===== */
.tabs { display: flex; gap: 2px; border-bottom: 2px solid var(--border); margin-bottom: 16px; }
.tab-item { padding: 8px 16px; cursor: pointer; font-size: 14px; color: var(--gray); border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all .15s; }
.tab-item:hover { color: var(--text); }
.tab-item.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* ===== Modal ===== */
.modal-mask { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal-box { background: #fff; border-radius: var(--radius-lg); width: 500px; max-width: 90vw; max-height: 85vh; display: flex; flex-direction: column; }
.modal-box.modal-lg { width: 720px; }
.modal-box.modal-xl { width: 960px; }
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; }
.modal-title { font-size: 16px; font-weight: 600; }
.modal-close { cursor: pointer; color: var(--gray); font-size: 20px; padding: 4px; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; flex-shrink: 0; }

/* ===== Stat Cards ===== */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 16px; }
.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px; box-shadow: var(--shadow-sm); }
.stat-label { font-size: 12px; color: var(--gray); margin-bottom: 4px; }
.stat-value { font-size: 24px; font-weight: 700; }
.stat-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.stat-value.green { color: var(--green); }
.stat-value.blue { color: var(--primary); }
.stat-value.orange { color: var(--orange); }
.stat-value.red { color: var(--red); }

/* ===== Progress ===== */
.progress { height: 8px; background: var(--gray-light); border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; border-radius: 999px; transition: width .3s; }
.progress-bar.green { background: var(--green); }
.progress-bar.blue { background: var(--primary); }
.progress-bar.orange { background: var(--orange); }

/* ===== Misc ===== */
.text-sm { font-size: 12px; }
.text-gray { color: var(--gray); }
.text-danger { color: var(--red); }
.text-success { color: var(--green); }
.text-warning { color: var(--orange); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.font-medium { font-weight: 500; }
.font-bold { font-weight: 700; }
.mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; } .mb-16 { margin-bottom: 16px; }
.flex { display: flex; } .items-center { align-items: center; } .justify-between { justify-content: space-between; }
.gap-4 { gap: 4px; } .gap-8 { gap: 8px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; }
.flex-1 { flex: 1; }
.cursor-pointer { cursor: pointer; }
.text-ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.relative { position: relative; }

/* Checkbox */
.checkbox-group { display: flex; flex-direction: column; gap: 8px; }
.checkbox-item { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; transition: all .15s; }
.checkbox-item:hover { border-color: var(--primary); }
.checkbox-item.checked { border-color: var(--primary); background: var(--primary-light); }
.checkbox-item input { width: 16px; height: 16px; accent-color: var(--primary); }
.checkbox-item .item-price { margin-left: auto; font-size: 12px; color: var(--gray); }

/* Radio group */
.radio-group { display: flex; gap: 8px; flex-wrap: wrap; }
.radio-item { padding: 8px 16px; border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; transition: all .15s; font-size: 13px; }
.radio-item:hover { border-color: var(--primary); }
.radio-item.selected { border-color: var(--primary); background: var(--primary-light); color: var(--primary-dark); font-weight: 600; }

/* Search input */
.search-box { position: relative; }
.search-box input { padding-left: 32px; }
.search-box svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--gray); }

/* Toast */
.toast { position: fixed; top: 20px; right: 20px; padding: 12px 20px; border-radius: var(--radius); color: #fff; font-size: 14px; z-index: 2000; box-shadow: var(--shadow-md); animation: slideIn .2s; }
.toast.success { background: var(--green); }
.toast.error { background: var(--red); }
.toast.warning { background: var(--orange); }
@keyframes slideIn { from { transform: translateX(100%); } to { transform: translateX(0); } }

/* Empty state */
.empty-state { text-align: center; padding: 40px; color: var(--text-muted); }
.empty-state svg { width: 48px; height: 48px; margin-bottom: 8px; }

/* Login */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #1e40af 0%, #2563eb 50%, #3b82f6 100%); }
.login-card { background: #fff; border-radius: 16px; padding: 40px; width: 400px; max-width: 90vw; box-shadow: 0 20px 60px rgba(0,0,0,0.15); }
.login-logo { text-align: center; margin-bottom: 24px; }
.login-logo h1 { font-size: 20px; color: var(--primary-dark); }
.login-logo p { font-size: 13px; color: var(--gray); margin-top: 4px; }
.login-form .form-group { margin-bottom: 16px; }
.login-form .form-control { height: 42px; }
.login-form .btn { width: 100%; justify-content: center; height: 42px; }
.login-roles { margin-top: 20px; padding-top: 16px; border-top: 1px dashed var(--border); }
.login-roles p { font-size: 12px; color: var(--gray); margin-bottom: 8px; }
.login-roles-item { font-size: 12px; color: var(--text-muted); padding: 2px 0; }

/* Timeline */
.timeline { position: relative; padding-left: 24px; }
.timeline::before { content: ''; position: absolute; left: 7px; top: 4px; bottom: 4px; width: 2px; background: var(--border); }
.timeline-item { position: relative; margin-bottom: 16px; }
.timeline-dot { position: absolute; left: -24px; top: 4px; width: 12px; height: 12px; border-radius: 50%; background: var(--primary); border: 2px solid #fff; box-shadow: 0 0 0 2px var(--primary-light); }
.timeline-time { font-size: 12px; color: var(--gray); margin-bottom: 2px; }
.timeline-content { font-size: 13px; }

/* Quote items */
.quote-config-panel { background: var(--gray-light); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.quote-summary { position: sticky; bottom: 0; background: #fff; border-top: 2px solid var(--border); padding: 16px 0; }
.quote-summary-row { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; }
.quote-summary-row .label { color: var(--gray); font-size: 13px; }
.quote-summary-row .value { font-weight: 600; }

/* BOM tree */
.bom-node { padding: 8px 12px; border-left: 2px solid var(--border); margin-left: 8px; }
.bom-node.child { margin-left: 24px; }

/* Filter bar */
.filter-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; align-items: center; }
.filter-bar .form-control { width: auto; min-width: 140px; }

/* Step indicator */
.steps { display: flex; align-items: center; margin-bottom: 24px; }
.step { display: flex; align-items: center; gap: 8px; color: var(--gray); font-size: 13px; }
.step-num { width: 28px; height: 28px; border-radius: 50%; background: var(--gray-light); color: var(--gray); display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 13px; flex-shrink: 0; }
.step.active .step-num { background: var(--primary); color: #fff; }
.step.active { color: var(--primary); font-weight: 600; }
.step.done .step-num { background: var(--green); color: #fff; }
.step.done { color: var(--green); }
.step-line { flex: 1; height: 2px; background: var(--border); margin: 0 12px; min-width: 20px; }
.step-line.done { background: var(--green); }

/* Progress bar */
.progress-bar { height: 8px; background: var(--gray-light); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--green); border-radius: 4px; transition: width 0.3s; }

/* Production flow */
.production-flow { display: flex; flex-direction: column; gap: 16px; }
.production-step { display: flex; gap: 16px; align-items: flex-start; }
.step-dot { width: 36px; height: 36px; border-radius: 50%; background: var(--gray-light); color: var(--gray); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; flex-shrink: 0; border: 2px solid var(--border); }
.production-step.done .step-dot { background: var(--green); color: #fff; border-color: var(--green); }
.production-step.active .step-dot { background: var(--primary); color: #fff; border-color: var(--primary); animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(37,99,235,0.4); } 50% { box-shadow: 0 0 0 8px rgba(37,99,235,0); } }
.step-content { flex: 1; }
.step-name { font-weight: 600; margin-bottom: 4px; }

/* Card warning */
.card-warning { background: var(--orange-light); border-left: 4px solid var(--orange); padding: 16px; border-radius: var(--radius); color: var(--orange); }

/* Stat text colors */
.stat-value.red { color: var(--red); }
.text-red { color: var(--red); }
.text-warning { color: var(--orange); }

/* mt classes */
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-20 { margin-top: 20px; }
.mt-24 { margin-top: 24px; }

/* Font mono */
.font-mono { font-family: 'Courier New', monospace; }
