/* ===== CSS Variables ===== */
:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #16a34a;
  --warning: #f59e0b;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
}

/* ===== Reset ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; color: var(--gray-800); background: var(--gray-50); }
a { color: var(--primary); text-decoration: none; }

/* ===== Layout ===== */
.app-layout { display: flex; min-height: 100vh; }
.sidebar { width: 220px; background: var(--gray-900); color: #fff; padding: 0; flex-shrink: 0; display: flex; flex-direction: column; }
.sidebar-brand { padding: 16px 20px; font-size: 18px; font-weight: 700; border-bottom: 1px solid rgba(255,255,255,0.1); }
.sidebar-nav { flex: 1; padding: 8px 0; }
.sidebar-nav a { display: block; padding: 10px 20px; color: rgba(255,255,255,0.7); font-size: 14px; transition: all 0.15s; }
.sidebar-nav a:hover, .sidebar-nav a.active { color: #fff; background: rgba(255,255,255,0.1); }
.sidebar-nav a.active { border-left: 3px solid var(--primary); }
.sidebar-user { padding: 12px 20px; border-top: 1px solid rgba(255,255,255,0.1); font-size: 13px; color: rgba(255,255,255,0.6); }
.sidebar-user .user-name { color: #fff; font-weight: 500; }
.main-content { flex: 1; padding: 20px 24px; overflow-y: auto; }

/* ===== Login Page ===== */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%); }
.login-card { background: #fff; border-radius: 12px; padding: 40px; width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
.login-card h1 { font-size: 24px; margin-bottom: 8px; color: var(--gray-900); }
.login-card p { color: var(--gray-500); margin-bottom: 24px; font-size: 14px; }

/* ===== Forms ===== */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; color: var(--gray-700); margin-bottom: 4px; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 8px 12px; border: 1px solid var(--gray-300); border-radius: var(--radius);
  font-size: 14px; transition: border-color 0.15s; outline: none;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.form-group textarea { resize: vertical; min-height: 60px; }
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }

/* ===== Buttons ===== */
.btn { display: inline-flex; align-items: center; justify-content: center; padding: 8px 16px; border-radius: var(--radius); font-size: 14px; font-weight: 500; border: none; cursor: pointer; transition: all 0.15s; gap: 6px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-outline { background: #fff; color: var(--gray-700); border: 1px solid var(--gray-300); }
.btn-outline:hover { background: var(--gray-50); }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-lg { padding: 10px 24px; font-size: 16px; }

/* ===== Tables ===== */
.table-wrapper { overflow-x: auto; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { background: var(--gray-50); padding: 10px 12px; text-align: left; font-weight: 600; color: var(--gray-600); font-size: 13px; border-bottom: 1px solid var(--gray-200); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--gray-100); }
tr:hover td { background: var(--gray-50); }

/* ===== Cards ===== */
.card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px; }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-title { font-size: 16px; font-weight: 600; }

/* ===== Badges ===== */
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 500; }
.badge-pending_purchase { background: #fef3c7; color: #92400e; }
.badge-pending_admin { background: #dbeafe; color: #1e40af; }
.badge-priced { background: #d1fae5; color: #065f46; }
.badge-price_adjusted { background: #ede9fe; color: #5b21b6; }
.badge-rejected { background: #fee2e2; color: #991b1b; }

.status-label { font-size: 12px; }
.status-pending_purchase { color: #92400e; }
.status-pending_admin { color: #1e40af; }
.status-priced { color: #065f46; }
.status-price_adjusted { color: #5b21b6; }
.status-rejected { color: #991b1b; }

/* ===== Tax Toggle ===== */
.tax-toggle { display: inline-flex; border: 1px solid var(--gray-300); border-radius: var(--radius); overflow: hidden; }
.tax-toggle button { padding: 4px 12px; font-size: 13px; border: none; background: #fff; cursor: pointer; transition: all 0.15s; }
.tax-toggle button.active { background: var(--primary); color: #fff; }

/* ===== Local Tax Switch (form internal) ===== */
.tax-switch { display: inline-flex; border: 1px solid var(--gray-300); border-radius: var(--radius); overflow: hidden; vertical-align: middle; margin-left: 6px; }
.tax-btn { padding: 2px 8px; font-size: 12px; border: none; background: #fff; cursor: pointer; transition: all 0.15s; color: var(--gray-600); }
.tax-btn.active { background: var(--primary); color: #fff; }

/* ===== Supplier Row ===== */
.supplier-row { background: var(--gray-50); border-radius: var(--radius); padding: 8px; }

/* ===== Stat Warning ===== */
.stat-warning { border: 1px solid var(--warning); }
.stat-warning .stat-value { color: var(--warning); }

/* ===== Page Header ===== */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.page-title { font-size: 20px; font-weight: 700; }

/* ===== Stats ===== */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.stat-card .stat-value { font-size: 28px; font-weight: 700; color: var(--gray-900); }
.stat-card .stat-label { font-size: 13px; color: var(--gray-500); margin-top: 4px; }

/* ===== Quick Links (工作台快捷卡片) ===== */
.quick-links { display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.quick-link { display: flex; flex-direction: column; align-items: center; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 20px; min-width: 120px; text-decoration: none; transition: all 0.15s; cursor: pointer; border: 2px solid transparent; }
.quick-link:hover { border-color: var(--primary); box-shadow: var(--shadow-md); }
.ql-value { font-size: 24px; font-weight: 700; color: var(--gray-900); }
.ql-label { font-size: 12px; color: var(--gray-500); margin-top: 2px; }

/* ===== 列宽拖拽 ===== */
.resizable-th { user-select: none; }
.col-resizer:hover { background: var(--primary) !important; opacity: 0.5; }

/* ===== Modal ===== */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal { background: #fff; border-radius: 12px; padding: 24px; width: 90%; max-width: 560px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
.modal h2 { font-size: 18px; margin-bottom: 16px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* ===== Price Info Box ===== */
.price-compare { background: var(--gray-50); border-radius: var(--radius); padding: 16px; margin: 12px 0; }
.price-compare h4 { font-size: 14px; color: var(--gray-600); margin-bottom: 8px; }
.price-row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 14px; }
.price-row .label { color: var(--gray-500); }
.price-up { color: var(--danger); font-weight: 600; }
.price-down { color: var(--success); font-weight: 600; }

/* ===== Logs ===== */
.log-timeline { border-left: 2px solid var(--gray-200); padding-left: 16px; margin: 12px 0; }
.log-item { position: relative; padding: 8px 0; font-size: 13px; }
.log-item::before { content: ''; position: absolute; left: -21px; top: 12px; width: 8px; height: 8px; border-radius: 50%; background: var(--gray-300); }
.log-item .log-time { color: var(--gray-400); font-size: 12px; }
.log-item .log-user { font-weight: 500; }

/* ===== Empty State ===== */
.empty-state { text-align: center; padding: 40px; color: var(--gray-400); }
.empty-state p { margin-top: 8px; font-size: 14px; }

/* ===== Toast ===== */
.toast { position: fixed; top: 20px; right: 20px; padding: 12px 20px; border-radius: var(--radius); color: #fff; font-size: 14px; z-index: 2000; animation: slideIn 0.3s; }
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .app-layout { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; overflow-x: auto; align-items: center; }
  .sidebar-brand { padding: 10px 16px; font-size: 14px; white-space: nowrap; border-bottom: none; border-right: 1px solid rgba(255,255,255,0.1); }
  .sidebar-nav { display: flex; padding: 0; }
  .sidebar-nav a { padding: 10px 14px; white-space: nowrap; border-left: none !important; border-bottom: 3px solid transparent; }
  .sidebar-nav a.active { border-bottom-color: var(--primary); border-left: none !important; }
  .sidebar-user { display: none; }
  .main-content { padding: 12px; }
  .form-row { flex-direction: column; gap: 0; }
  .page-header { flex-direction: column; align-items: flex-start; gap: 8px; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .modal { width: 96%; padding: 16px; }
  th, td { padding: 8px; font-size: 13px; }
}
