* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --primary: #1b4332;
  --primary-light: #2d6a4f;
  --primary-bg: #d8f3dc;
  --accent: #40916c;
  --bg: #f0f4f8;
  --card-bg: #ffffff;
  --text: #1a1a2e;
  --text-sec: #6c757d;
  --border: #e0e6ed;
  --success: #28a745;
  --warning: #f59e0b;
  --danger: #dc3545;
  --info: #17a2b8;
  --sidebar-w: 220px;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
}
body { font-family: -apple-system, "Microsoft YaHei", "Segoe UI", sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.6; }
.hidden { display: none !important; }

/* ===== Login ===== */
.login-screen { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, #1b4332, #2d6a4f); }
.login-card { background: white; padding: 40px; border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,0.3); text-align: center; width: 380px; }
.login-logo { width: 64px; height: 64px; background: var(--primary); color: white; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 24px; font-weight: 700; margin: 0 auto 16px; }
.login-card h1 { font-size: 20px; font-weight: 600; color: var(--text); }
.login-card p { color: var(--text-sec); font-size: 13px; margin-bottom: 24px; }
.login-form input { width: 100%; padding: 12px 16px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 14px; margin-bottom: 12px; outline: none; transition: border-color 0.2s; }
.login-form input:focus { border-color: var(--accent); }
.login-hint { margin-top: 16px; font-size: 12px; color: var(--text-sec); line-height: 1.8; text-align: left; background: var(--bg); padding: 12px; border-radius: var(--radius); }
.login-divider { height: 1px; background: var(--border); margin: 16px 0; }
.btn-wecom { background: #07C160; color: white; border: none; padding: 10px 20px; border-radius: var(--radius); cursor: pointer; font-size: 14px; display: flex; align-items: center; justify-content: center; gap: 8px; transition: background 0.2s; }
.btn-wecom:hover { background: #06AD56; }
.wecom-icon { font-size: 18px; }
.wecom-config-card { background: white; border-radius: var(--radius-lg); padding: 24px; }
.wecom-config-row { display: flex; gap: 12px; margin-bottom: 12px; align-items: center; }
.wecom-config-row label { min-width: 120px; font-weight: 500; font-size: 13px; }
.wecom-config-row input { flex: 1; }
.wecom-status-badge { display: inline-flex; padding: 4px 12px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.wecom-status-on { background: #d4edda; color: #155724; }
.wecom-status-off { background: #f8d7da; color: #721c24; }
.wecom-push-btn { padding: 8px 16px; border-radius: var(--radius); border: none; cursor: pointer; font-size: 13px; margin-right: 8px; transition: all 0.2s; }
.wecom-push-checkin { background: #E6F1FB; color: #0C447C; }
.wecom-push-stock { background: #FAEEDA; color: #854F0B; }
.wecom-push-project { background: #EEEDFE; color: #534AB7; }
.wecom-push-approval { background: #EAF3DE; color: #3B6D11; }

/* ===== Buttons ===== */
.btn-primary { background: var(--primary); color: white; border: none; padding: 10px 20px; border-radius: var(--radius); cursor: pointer; font-size: 14px; transition: background 0.2s; }
.btn-primary:hover { background: var(--primary-light); }
.btn-full { width: 100%; }
.btn-secondary { background: white; color: var(--text); border: 1px solid var(--border); padding: 8px 16px; border-radius: var(--radius); cursor: pointer; font-size: 13px; }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger { background: var(--danger); color: white; border: none; padding: 8px 16px; border-radius: var(--radius); cursor: pointer; font-size: 13px; }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-text { background: none; border: none; color: var(--text-sec); cursor: pointer; font-size: 13px; padding: 4px 8px; }
.btn-text:hover { color: var(--danger); }

/* ===== Layout ===== */
.app { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-w); background: var(--primary); color: #d8f3dc; display: flex; flex-direction: column; position: fixed; top: 0; bottom: 0; left: 0; z-index: 100; transition: transform 0.3s; }
.sidebar-header { padding: 20px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid rgba(255,255,255,0.1); }
.logo { background: var(--accent); color: white; padding: 4px 10px; border-radius: 6px; font-weight: 700; font-size: 16px; }
.logo-text { font-size: 14px; font-weight: 500; }
.nav { flex: 1; padding: 12px 8px; overflow-y: auto; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 10px 14px; color: #b7e4c7; text-decoration: none; border-radius: var(--radius); margin-bottom: 4px; font-size: 14px; transition: all 0.2s; }
.nav-item:hover { background: rgba(255,255,255,0.1); color: white; }
.nav-item.active { background: var(--accent); color: white; }
.nav-icon { width: 20px; text-align: center; font-size: 16px; }
.sidebar-footer { padding: 16px; border-top: 1px solid rgba(255,255,255,0.1); }
.user-info { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.user-avatar { width: 36px; height: 36px; background: var(--accent); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 14px; }
.user-name { font-size: 14px; font-weight: 500; color: white; }
.user-role { font-size: 12px; color: #b7e4c7; }
.sidebar-footer .btn-text { color: #b7e4c7; }
.sidebar-footer .btn-text:hover { color: white; }
.sidebar-close { display: none; background: none; border: none; color: white; font-size: 24px; cursor: pointer; margin-left: auto; line-height: 1; padding: 0 4px; }
.sidebar-backdrop { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.45); z-index: 99; opacity: 0; transition: opacity 0.3s; }
.sidebar-backdrop:not(.hidden) { opacity: 1; }

.main { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-height: 100vh; }
.topbar { background: white; padding: 0 24px; height: 56px; display: flex; align-items: center; gap: 16px; border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 50; }
.topbar h2 { font-size: 16px; font-weight: 600; flex: 1; }
.menu-toggle { display: none; background: none; border: none; font-size: 20px; cursor: pointer; }
.date-display { font-size: 13px; color: var(--text-sec); }
.content { padding: 24px; flex: 1; }

/* ===== Cards & Metrics ===== */
.card { background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px; }
.card-title { font-size: 15px; font-weight: 600; margin-bottom: 16px; display: flex; align-items: center; justify-content: space-between; }
.metric-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 24px; }
.metric-card { background: white; border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); border-left: 4px solid var(--accent); cursor: pointer; transition: transform 0.15s, box-shadow 0.15s; }
.metric-card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.12); }
.metric-card.danger { border-left-color: var(--danger); }
.metric-card.warning { border-left-color: var(--warning); }
.metric-card.info { border-left-color: var(--info); }
.metric-label { font-size: 13px; color: var(--text-sec); margin-bottom: 8px; }
.metric-value { font-size: 28px; font-weight: 700; color: var(--text); }
.metric-sub { font-size: 12px; color: var(--text-sec); margin-top: 4px; }

/* ===== Table ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; padding: 10px 12px; background: var(--bg); color: var(--text-sec); font-weight: 600; white-space: nowrap; border-bottom: 2px solid var(--border); }
td { padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
tr:hover { background: #f8fafc; }
.table-actions { display: flex; gap: 8px; }

/* ===== Badges ===== */
.badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 12px; font-weight: 500; }
.badge-success { background: #d4edda; color: #155724; }
.badge-warning { background: #fff3cd; color: #856404; }
.badge-danger { background: #f8d7da; color: #721c24; }
.badge-info { background: #d1ecf1; color: #0c5460; }
.badge-secondary { background: #e2e3e5; color: #383d41; }
.badge-primary { background: var(--primary-bg); color: var(--primary); }
.badge-A { background: #d4edda; color: #155724; }
.badge-B { background: #cce5ff; color: #004085; }
.badge-C { background: #fff3cd; color: #856404; }
.badge-D { background: #f8d7da; color: #721c24; }

/* ===== Forms ===== */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; color: var(--text); }
.form-group input, .form-group select, .form-group textarea { width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 14px; outline: none; transition: border-color 0.2s; font-family: inherit; }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: var(--accent); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 20px; }

/* ===== Modal ===== */
.modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal { background: white; border-radius: 12px; width: 90%; max-width: 600px; max-height: 85vh; display: flex; flex-direction: column; }
.modal-wide { width: 95%; max-width: 95vw; }
.modal-wide .modal-body { overflow: auto; }
.modal-header { padding: 16px 24px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-sec); }
.modal-body { padding: 24px; overflow-y: auto; }

/* ===== Kanban ===== */
.kanban { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.kanban-col { min-width: 240px; flex-shrink: 0; }
.kanban-col-header { padding: 8px 12px; border-radius: var(--radius) var(--radius) 0 0; font-weight: 600; font-size: 13px; display: flex; align-items: center; justify-content: space-between; }
.kanban-col-body { background: var(--bg); border-radius: 0 0 var(--radius) var(--radius); padding: 8px; min-height: 60px; }
.kanban-card { background: white; border-radius: 6px; padding: 12px; margin-bottom: 8px; box-shadow: 0 1px 2px rgba(0,0,0,0.06); cursor: pointer; transition: box-shadow 0.2s; }
.kanban-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.12); }
.kanban-card-title { font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.kanban-card-info { font-size: 12px; color: var(--text-sec); }
.kanban-card-amount { font-size: 15px; font-weight: 700; color: var(--primary); margin: 6px 0; }
.kanban-card-overdue { border-left: 3px solid var(--danger); }

/* ===== Toast ===== */
.toast { position: fixed; top: 20px; right: 20px; background: var(--text); color: white; padding: 12px 20px; border-radius: var(--radius); z-index: 2000; font-size: 14px; box-shadow: 0 4px 12px rgba(0,0,0,0.2); animation: slideIn 0.3s ease; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ===== Misc ===== */
.chart-container { position: relative; height: 280px; margin-top: 12px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-8 { gap: 8px; }
.gap-16 { gap: 16px; }
.mb-16 { margin-bottom: 16px; }
.mt-16 { margin-top: 16px; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-sec { color: var(--text-sec); }
.fw-700 { font-weight: 700; }
.fs-12 { font-size: 12px; }
.fs-16 { font-size: 16px; }
.fs-20 { font-size: 20px; }
.p-12 { padding: 12px; }
.empty-state { text-align: center; padding: 40px; color: var(--text-sec); }
.search-bar { display: flex; gap: 12px; margin-bottom: 16px; align-items: center; }
.search-bar input, .search-bar select { padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 13px; outline: none; }
.search-bar input { flex: 1; }
.filter-tag { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; background: var(--bg); border-radius: 16px; font-size: 12px; cursor: pointer; }
.filter-tag:hover { background: var(--border); }
.stat-row { display: flex; gap: 24px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.stat-row:last-child { border-bottom: none; }
.stat-row-label { width: 100px; color: var(--text-sec); font-size: 13px; }
.stat-row-value { font-weight: 600; }
.timeline { position: relative; padding-left: 20px; }
.timeline::before { content: ''; position: absolute; left: 6px; top: 0; bottom: 0; width: 2px; background: var(--border); }
.timeline-item { position: relative; padding-bottom: 16px; }
.timeline-item::before { content: ''; position: absolute; left: -17px; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); border: 2px solid white; }
.timeline-date { font-size: 12px; color: var(--text-sec); }
.timeline-content { font-size: 13px; margin-top: 2px; }
.progress-bar { height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; }
.progress-bar-fill { height: 100%; background: var(--accent); border-radius: 4px; transition: width 0.3s; }
.progress-bar-fill.danger { background: var(--danger); }
.progress-bar-fill.warning { background: var(--warning); }
.inventory-bar { display: flex; align-items: center; gap: 8px; }
.inventory-bar .progress-bar { flex: 1; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); width: 260px; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: block; }
  .main { margin-left: 0; }
  .menu-toggle { display: block; }
  .content { padding: 16px; }
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .metric-value { font-size: 22px; }
  /* 手机端弹窗全屏宽度，库存表等表格尽量占满屏幕 */
  .modal { width: 100vw; max-width: 100vw; border-radius: 0; max-height: 94vh; }
  .modal-wide { width: 100vw; max-width: 100vw; }
  .modal-header { padding: 12px 14px; }
  .modal-body { padding: 14px 10px; }
  .modal-body .table-wrap { margin: 0 -4px; }
  .table-wrap table { min-width: 100%; }
  .inv-cell-model { white-space: normal; word-break: break-all; max-width: 150px; }
  .inv-fold-table th, .inv-fold-table td { padding: 8px 6px; }
}
@media (min-width: 769px) {
  .sidebar-backdrop { display: none !important; }
}

/* ===== User Management ===== */
.perm-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.perm-grid label { display: flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.perm-grid input[type="checkbox"] { width: 16px; height: 16px; }
.user-status { padding: 2px 8px; border-radius: 4px; font-size: 12px; }
.user-status.active { background: #d8f3dc; color: #1b4332; }
.user-status.disabled { background: #ffe0e0; color: #c0392b; }

/* ===== Check-in Photo ===== */
.check-photo-thumb { width: 60px; height: 60px; object-fit: cover; border-radius: 4px; cursor: pointer; border: 1px solid var(--border); }
.check-photo-preview { max-width: 200px; max-height: 200px; border-radius: 8px; margin-top: 8px; }
.photo-upload-wrap { display: flex; align-items: center; gap: 12px; }
.photo-upload-wrap img { max-width: 120px; max-height: 120px; border-radius: 8px; border: 1px solid var(--border); }
.location-link { font-size: 12px; color: var(--primary); }

/* ===== Tabs ===== */
.daily-tab.active, .qi-tab.active { background: var(--primary); color: white; border-color: var(--primary); }

/* ===== Quick Order Form ===== */
.qo-item-row input { width: 100%; }
.qo-item-row button { padding: 4px; }

/* ===== Text helpers ===== */
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }

/* ===== Company Switcher ===== */
.company-switcher { padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius); background: white; font-size: 13px; color: var(--text); cursor: pointer; margin-right: 12px; }

/* ===== Todo List ===== */
.todo-list { display: flex; flex-direction: column; gap: 10px; }
.todo-item { display: flex; align-items: center; gap: 10px; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius); background: white; }
.todo-item.todo-done { opacity: 0.7; background: #f8f9fa; }
.todo-item.todo-overdue { border-color: var(--danger); background: #fff5f5; }
.todo-item input[type="checkbox"] { width: 18px; height: 18px; cursor: pointer; flex-shrink: 0; }
.todo-content { flex: 1; min-width: 0; }
.todo-title { font-weight: 500; word-break: break-all; }
.todo-done .todo-title { text-decoration: line-through; color: var(--text-sec); }
.todo-meta { font-size: 12px; color: var(--text-sec); margin-top: 2px; }

/* Todo Kanban Board */
.todo-board { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.todo-col { min-width: 0; }
.todo-col > .card { margin-bottom: 0; }
@media (max-width: 720px) { .todo-board { grid-template-columns: 1fr; } }

/* Clickable card (hover effect for entry tiles) */
.card-clickable { cursor: pointer; transition: box-shadow 0.15s, transform 0.15s; }
.card-clickable:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.08); transform: translateY(-1px); }

/* ===== Inventory foldable table ===== */
.inv-row-main td { cursor: default; }
.inv-row-clickable { cursor: pointer; transition: background 0.12s; }
.inv-row-clickable:hover { background: #f8fafc; }
.inv-cell-model { font-family: 'SF Mono','Consolas',monospace; font-size: 12px; color: var(--text-sec); white-space: nowrap; }
.inv-toggle { cursor: pointer; user-select: none; display: inline-flex; align-items: center; gap: 4px; padding: 4px 12px; border-radius: 6px; background: var(--primary-bg); color: var(--primary); font-weight: 700; transition: background 0.15s; }
.inv-toggle:hover { background: #b7e4c7; }
.inv-toggle::after { content: '▸'; font-size: 12px; transition: transform 0.2s; }
.inv-toggle.expanded::after { content: '▾'; }
.inv-detail-row { background: #f8fafc; }
.inv-detail-row td { padding: 0; border-bottom: none; }
.inv-detail-cell { padding: 10px 12px; }
.inv-detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.inv-detail-item { background: white; border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; text-align: center; }
.inv-detail-item .wh-name { font-size: 12px; color: var(--text-sec); margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inv-detail-item .wh-qty { font-size: 16px; font-weight: 700; color: var(--text); }
.inv-detail-item .wh-qty.low { color: var(--danger); }
.inv-detail-empty { color: var(--text-sec); font-size: 13px; padding: 8px 0; }
@media (max-width: 768px) {
  .inv-fold-table { font-size: 13px; }
  .inv-fold-table th, .inv-fold-table td { padding: 8px 4px; }
  .inv-cell-model { font-size: 11px; }
  .inv-toggle { padding: 6px 10px; font-size: 14px; }
  .inv-detail-grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; }
  .inv-detail-item { padding: 6px 4px; }
  .inv-detail-item .wh-name { font-size: 11px; }
  .inv-detail-item .wh-qty { font-size: 14px; }
}

/* ===== Alert ===== */
.alert { padding: 14px 16px; border-radius: var(--radius); border-left: 4px solid; }
.alert-danger { background: #fff5f5; border-color: var(--danger); color: #721c24; }
.alert-warning { background: #fffbeb; border-color: var(--warning); color: #854f0b; }
