/* ===== Reset & Base ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --success: #16a34a;
  --success-light: #dcfce7;
  --gray: #6b7280;
  --gray-light: #f3f4f6;
  --gray-border: #e5e7eb;
  --text: #1f2937;
  --text-light: #6b7280;
  --bg: #f9fafb;
  --card-bg: #ffffff;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --sidebar-w: 220px;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

/* ===== Login ===== */
.login-wrap {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.login-card {
  background: #fff; border-radius: 16px; padding: 40px;
  width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}
.login-card h1 { font-size: 22px; text-align: center; margin-bottom: 4px; }
.login-card .subtitle { text-align: center; color: var(--text-light); margin-bottom: 28px; font-size: 13px; }
.login-card .form-group { margin-bottom: 16px; }
.login-card label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; }
.login-card input {
  width: 100%; padding: 10px 14px; border: 1px solid var(--gray-border);
  border-radius: 8px; font-size: 14px; transition: border-color .2s;
}
.login-card input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.login-card .btn-login {
  width: 100%; padding: 12px; background: var(--primary); color: #fff;
  border: none; border-radius: 8px; font-size: 15px; font-weight: 600;
  cursor: pointer; transition: background .2s; margin-top: 8px;
}
.login-card .btn-login:hover { background: var(--primary-dark); }

/* ===== Layout ===== */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); background: #1e293b; color: #cbd5e1;
  display: flex; flex-direction: column; position: fixed; top: 0; left: 0;
  height: 100vh; z-index: 100;
}
.sidebar .logo { padding: 20px 18px; font-size: 16px; font-weight: 700; color: #fff; border-bottom: 1px solid #334155; }
.sidebar .logo span { color: var(--primary-light); }
.sidebar nav { flex: 1; padding: 12px 0; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 20px; color: #94a3b8; text-decoration: none;
  font-size: 14px; transition: all .15s; border-left: 3px solid transparent;
}
.sidebar nav a:hover { background: #334155; color: #e2e8f0; }
.sidebar nav a.active { background: #334155; color: #fff; border-left-color: var(--primary); }
.sidebar nav a .icon { font-size: 16px; width: 20px; text-align: center; }
.sidebar .user-info { padding: 16px 20px; border-top: 1px solid #334155; font-size: 12px; }
.sidebar .user-info .name { color: #fff; font-weight: 600; font-size: 14px; }
.sidebar .user-info .role { color: #64748b; }
.sidebar .user-info .btn-logout { margin-top: 8px; color: #94a3b8; cursor: pointer; font-size: 12px; }
.sidebar .user-info .btn-logout:hover { color: #ef4444; }

.main { flex: 1; margin-left: var(--sidebar-w); padding: 24px 32px; }

/* ===== Page Header ===== */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.page-header h2 { font-size: 20px; font-weight: 700; }
.page-header .actions { display: flex; gap: 8px; }

/* ===== Buttons ===== */
.btn { padding: 8px 16px; border: none; border-radius: 8px; font-size: 13px; font-weight: 500; cursor: pointer; transition: all .15s; display: inline-flex; align-items: center; gap: 6px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { opacity: .9; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: .9; }
.btn-outline { background: #fff; border: 1px solid var(--gray-border); color: var(--text); }
.btn-outline:hover { background: var(--gray-light); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ===== Cards ===== */
.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; }

/* ===== Stat Cards ===== */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: #fff; border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.stat-card .stat-icon { font-size: 28px; margin-bottom: 8px; }
.stat-card .stat-value { font-size: 28px; font-weight: 700; line-height: 1.2; }
.stat-card .stat-label { font-size: 13px; color: var(--text-light); margin-top: 4px; }
.stat-card.danger { border-left: 4px solid var(--danger); }
.stat-card.warning { border-left: 4px solid var(--warning); }
.stat-card.success { border-left: 4px solid var(--success); }
.stat-card.primary { border-left: 4px solid var(--primary); }
.stat-card.gray { border-left: 4px solid var(--gray); }
.stat-card.clickable { cursor: pointer; transition: transform .15s, box-shadow .15s; }
.stat-card.clickable:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
table th, table td { padding: 10px 12px; text-align: left; font-size: 13px; border-bottom: 1px solid var(--gray-border); }
table th { background: var(--gray-light); font-weight: 600; white-space: nowrap; color: var(--text-light); }
table tbody tr:hover { background: #f8fafc; }
table tbody tr { cursor: pointer; }

/* ===== Badges ===== */
.badge { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.badge-red { background: var(--danger-light); color: var(--danger); }
.badge-orange { background: var(--warning-light); color: #b45309; }
.badge-green { background: var(--success-light); color: var(--success); }
.badge-gray { background: var(--gray-light); color: var(--gray); }
.badge-blue { background: var(--primary-light); color: var(--primary); }

/* ===== Filters ===== */
.filters { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; align-items: center; }
.filters select, .filters input[type="text"] {
  padding: 7px 12px; border: 1px solid var(--gray-border); border-radius: 8px;
  font-size: 13px; background: #fff; min-width: 120px;
}
.filters select:focus, .filters input:focus { outline: none; border-color: var(--primary); }
.filters .search-input { flex: 1; min-width: 200px; }

/* ===== Modal ===== */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 200; align-items: center; justify-content: center; }
.modal-overlay.show { display: flex; }
.modal { background: #fff; border-radius: 12px; width: 600px; max-width: 90vw; max-height: 85vh; overflow-y: auto; }
.modal.modal-lg { width: 800px; }
.modal-header { padding: 16px 24px; border-bottom: 1px solid var(--gray-border); display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-header .close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--gray); }
.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--gray-border); display: flex; justify-content: flex-end; gap: 8px; }

/* ===== Forms ===== */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 5px; }
.form-group label .req { color: var(--danger); }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 8px 12px; border: 1px solid var(--gray-border);
  border-radius: 8px; font-size: 14px; font-family: inherit;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light);
}
.form-group .hint { font-size: 12px; color: var(--text-light); margin-top: 4px; }
.form-group.full { grid-column: 1 / -1; }

/* ===== Detail View ===== */
.detail-section { margin-bottom: 24px; }
.detail-section h4 { font-size: 14px; font-weight: 600; margin-bottom: 12px; color: var(--text); border-left: 3px solid var(--primary); padding-left: 10px; }
.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.info-item { padding: 10px 14px; background: var(--gray-light); border-radius: 8px; }
.info-item .label { font-size: 12px; color: var(--text-light); margin-bottom: 2px; }
.info-item .value { font-size: 14px; font-weight: 500; }

/* Timeline for inspections */
.timeline { position: relative; padding-left: 24px; }
.timeline::before { content: ''; position: absolute; left: 8px; top: 4px; bottom: 4px; width: 2px; background: var(--gray-border); }
.timeline-item { position: relative; margin-bottom: 16px; }
.timeline-item::before { content: ''; position: absolute; left: -20px; top: 4px; width: 12px; height: 12px; border-radius: 50%; background: var(--primary); border: 2px solid #fff; box-shadow: 0 0 0 2px var(--primary); }
.timeline-item .tl-date { font-weight: 600; font-size: 14px; }
.timeline-item .tl-info { font-size: 13px; color: var(--text-light); }
.timeline-item .tl-result { margin-top: 4px; }

/* ===== Charts ===== */
.chart-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.chart-container { position: relative; height: 240px; }

/* ===== Tabs ===== */
.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 2px solid var(--gray-border); }
.tab { padding: 8px 16px; cursor: pointer; font-size: 14px; font-weight: 500; color: var(--text-light); border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all .15s; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ===== Warning List ===== */
.warning-list { display: flex; flex-direction: column; gap: 12px; }
.warning-item { display: flex; align-items: center; gap: 16px; padding: 14px 16px; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); border-left: 4px solid; cursor: pointer; transition: transform .15s; }
.warning-item:hover { transform: translateX(4px); }
.warning-item.danger { border-left-color: var(--danger); }
.warning-item.warning { border-left-color: var(--warning); }
.warning-item .w-icon { font-size: 24px; }
.warning-item .w-content { flex: 1; }
.warning-item .w-title { font-weight: 600; font-size: 14px; }
.warning-item .w-sub { font-size: 12px; color: var(--text-light); }
.warning-item .w-days { font-size: 13px; font-weight: 600; text-align: right; }

/* ===== Empty State ===== */
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-light); }
.empty-state .icon { font-size: 48px; margin-bottom: 12px; }
.empty-state .msg { font-size: 15px; }

/* ===== Pivot Table ===== */
.pivot-section { margin-top: 24px; }
.pivot-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: #fff; border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 16px; flex-wrap: wrap; gap: 10px;
}
.pivot-label { font-size: 14px; font-weight: 600; }
.pivot-selectors { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.pivot-selectors select {
  padding: 6px 10px; border: 1px solid var(--gray-border); border-radius: 6px;
  font-size: 13px; background: #fff; cursor: pointer;
}
.pivot-selectors select:focus { outline: none; border-color: var(--primary); }

/* Pivot cross table */
.pivot-table-wrap { overflow-x: auto; margin-bottom: 8px; }
.pivot-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
  background: #fff; border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow);
}
.pivot-table th, .pivot-table td { padding: 10px 14px; text-align: center; border: 1px solid var(--gray-border); }
.pivot-table thead th { font-weight: 600; font-size: 12px; white-space: nowrap; }
.pivot-row-hdr { background: var(--gray-light); color: var(--text-light); min-width: 100px; text-align: left !important; }
.pivot-col-hdr { background: #f8fafc; color: var(--text); }
.pivot-total-hdr { background: #f1f5f9; color: var(--text-light); }
.pivot-row-label { background: #fafafa; font-weight: 500; color: var(--text); text-align: left !important; }
.pivot-cell { transition: background .15s; position: relative; }
.pivot-cell .cell-val { font-weight: 600; font-size: 15px; }
.pivot-cell:hover { filter: brightness(0.95); }
.pivot-total { background: #f1f5f9; }
.pivot-grand { font-weight: 700; }
.pivot-table tfoot td { border-top: 2px solid #cbd5e1; font-weight: 600; }

/* Cell status colors */
.pivot-cell.cell-danger { background: #fee2e2; color: #991b1b; }
.pivot-cell.cell-warn { background: #fef3c7; color: #92400e; }
.pivot-cell.cell-normal { background: #dcfce7; color: #166534; }
.pivot-cell.cell-gray { background: #f9fafb; color: #6b7280; }
.pivot-cell.cell-zero { background: transparent !important; color: #d1d5db; }
.pivot-cell.cell-zero .cell-val { font-weight: 400; }

/* Column header status colors */
.pivot-col-hdr.cell-danger { background: #fee2e2; color: #991b1b; }
.pivot-col-hdr.cell-warn { background: #fef3c7; color: #92400e; }
.pivot-col-hdr.cell-normal { background: #dcfce7; color: #166534; }
.pivot-col-hdr.cell-gray { background: #f3f4f6; color: #6b7280; }

/* Legend */
.pivot-legend {
  display: flex; gap: 16px; align-items: center; font-size: 12px;
  color: var(--text-light); padding: 8px 0;
}
.legend-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; }
.dot-danger { background: #dc2626; }
.dot-warn { background: #f59e0b; }
.dot-normal { background: #16a34a; }
.dot-gray { background: #9ca3af; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .sidebar .logo { font-size: 0; padding: 20px 0; text-align: center; }
  .sidebar .logo span:first-letter { font-size: 20px; }
  .sidebar nav a { padding: 12px 0; justify-content: center; font-size: 0; }
  .sidebar nav a .icon { font-size: 18px; }
  /* 手机端：侧边栏收窄为图标栏，用户名/角色文字隐藏，
     但保留并可点击「退出登录」图标按钮（原 display:none 导致手机无法登出） */
  .sidebar .user-info { display: flex; flex-direction: column; align-items: center; padding: 12px 4px; }
  .sidebar .user-info .name,
  .sidebar .user-info .role { display: none; }
  .sidebar .user-info .btn-logout {
    margin-top: 0; padding: 10px 6px; font-size: 0; text-align: center;
    background: rgba(239,68,68,.12); border-radius: 8px; width: 100%;
  }
  .sidebar .user-info .btn-logout::before { content: '🚪'; font-size: 20px; }
  .sidebar .user-info .btn-logout:active { background: rgba(239,68,68,.3); }
  .main { margin-left: 60px; padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .chart-row { grid-template-columns: 1fr; }
  .pivot-bar { flex-direction: column; align-items: flex-start; }
  .pivot-selectors { flex-wrap: wrap; }
}
