:root {
  --navy: #1a2942;
  --navy-light: #24365a;
  --blue: #2563eb;
  --blue-light: #eff6ff;
  --green: #059669;
  --green-light: #ecfdf5;
  --amber: #d97706;
  --amber-light: #fffbeb;
  --red: #dc2626;
  --red-light: #fef2f2;
  --gray-900: #111827;
  --gray-700: #374151;
  --gray-500: #6b7280;
  --gray-300: #d1d5db;
  --gray-100: #f3f4f6;
  --gray-50: #f9fafb;
  --border: #e5e7eb;
  --radius: 10px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  font-size: 14px;
  line-height: 1.5;
}
.shell { max-width: 1180px; margin: 0 auto; min-height: 100vh; display: flex; }
[hidden] { display: none !important; }
.table-scroll { overflow-x: auto; }

/* ===== Sidebar ===== */
.sidebar {
  width: 220px; background: var(--navy); color: #fff; min-height: 100vh;
  flex-shrink: 0; padding: 20px 0; display: flex; flex-direction: column;
}
.sidebar-brand { padding: 0 20px 20px; font-size: 16px; font-weight: 600; border-bottom: 1px solid rgba(255,255,255,0.1); margin-bottom: 12px; }
.sidebar-brand .sub { font-size: 11px; color: #93a5c4; font-weight: 400; margin-top: 2px; }
.sidebar-user { display: flex; align-items: center; gap: 10px; padding: 12px 20px; margin-bottom: 8px; }
.sidebar-avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--blue); display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 12px; flex-shrink: 0; }
.sidebar-user-name { font-size: 13px; font-weight: 500; }
.sidebar-user-role { font-size: 11px; color: #93a5c4; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 20px;
  font-size: 13px; color: #c3cee3; cursor: pointer; border-left: 3px solid transparent;
}
.nav-item:hover { background: rgba(255,255,255,0.05); }
.nav-item.active { background: rgba(37,99,235,0.15); border-left-color: var(--blue); color: #fff; font-weight: 500; }
.nav-icon { width: 16px; text-align: center; }
.sidebar-footer { margin-top: auto; padding: 12px 20px 4px; }
.logout-link { font-size: 12px; color: #93a5c4; cursor: pointer; text-decoration: underline; }
.logout-link:hover { color: #fff; }

/* ===== Content ===== */
.content { flex: 1; padding: 28px 32px; min-width: 0; }
.page { display: none; }
.page.active { display: block; }

.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; flex-wrap: wrap; gap: 12px; }
.page-title { font-size: 20px; font-weight: 600; }
.page-sub { font-size: 13px; color: var(--gray-500); margin-top: 4px; }

.btn {
  padding: 9px 16px; border-radius: 8px; font-size: 13px; font-weight: 500;
  cursor: pointer; border: 1px solid var(--border); background: #fff; color: var(--gray-700);
}
.btn-primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-light); }
.btn:hover { background: var(--gray-50); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-danger-outline { color: var(--red); border-color: #fecaca; }
.btn-danger-outline:hover { background: var(--red-light); }

.tier-badge { display: inline-flex; align-items: center; padding: 4px 12px; border-radius: 6px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.tier-A { background: var(--green-light); color: var(--green); }
.tier-B { background: var(--blue-light); color: var(--blue); }
.tier-C { background: var(--amber-light); color: var(--amber); }
.tier-D { background: var(--red-light); color: var(--red); }
.role-badge { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 6px; font-size: 11px; font-weight: 600; }
.role-anchor { background: var(--blue-light); color: var(--blue); }
.role-admin { background: var(--navy); color: #fff; }

.card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.diag-card { background: var(--blue-light); border: 1px solid #bfdbfe; border-radius: var(--radius); padding: 18px 20px; margin-bottom: 20px; }
.diag-card.danger { background: var(--red-light); border-color: #fecaca; }
.diag-card.success { background: var(--green-light); border-color: #a7f3d0; }
.diag-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--gray-500); margin-bottom: 8px; font-weight: 600; }
.diag-text { font-size: 15px; line-height: 1.7; }

.section-title { font-size: 13px; font-weight: 600; color: var(--gray-700); margin: 24px 0 10px; }

.metric-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 20px; }
.metric-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.metric-label { font-size: 12px; color: var(--gray-500); margin-bottom: 8px; }
.metric-value { font-size: 26px; font-weight: 600; }
.metric-sub { font-size: 11px; color: var(--gray-500); margin-top: 4px; }
.metric-delta { font-size: 12px; margin-top: 4px; font-weight: 500; }
.metric-delta.up { color: var(--green); }
.metric-delta.down { color: var(--red); }

.two-col { display: grid; grid-template-columns: 1.3fr 1fr; gap: 16px; }
.chart-wrap { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; height: 220px; }

.advice-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.advice-item { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 12px; font-size: 13px; line-height: 1.6; }
.advice-item:last-child { margin-bottom: 0; }
.advice-check { color: var(--green); flex-shrink: 0; font-weight: 600; }

.status-pill { display: inline-block; padding: 3px 10px; border-radius: 5px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.status-improve { background: var(--green-light); color: var(--green); }
.status-flat { background: var(--amber-light); color: var(--amber); }
.status-worse { background: var(--red-light); color: var(--red); }

.costream-note {
  font-size: 12px; color: var(--gray-500); background: var(--gray-50); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px; margin-top: 10px; line-height: 1.6;
}

@media (max-width: 820px) {
  .shell { flex-direction: column; }
  .sidebar {
    width: 100%; min-height: 0; flex-direction: row; flex-wrap: wrap;
    align-items: center; padding: 10px 16px; gap: 4px 14px;
  }
  .sidebar-brand { padding: 0; border-bottom: none; margin-bottom: 0; }
  .sidebar-brand .sub { display: none; }
  .sidebar-user { padding: 0; margin-bottom: 0; }
  #navAnchor, #navAdmin { display: flex; flex-wrap: wrap; gap: 2px; }
  .nav-item { padding: 6px 10px; border-left: none; border-radius: 6px; }
  .nav-item.active { border-left: none; }
  .sidebar-footer { margin-top: 0; padding: 0; margin-left: auto; }
  .content { padding: 18px 16px; }
}

@media (max-width: 700px) {
  .metric-grid { grid-template-columns: 1fr; }
  .two-col { grid-template-columns: 1fr; }
  table.data-table { display: block; overflow-x: auto; white-space: nowrap; }
  .diag-editor-row { grid-template-columns: 1fr; }
}

table.data-table { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
table.data-table th { background: var(--gray-50); font-size: 12px; color: var(--gray-500); padding: 10px 14px; text-align: left; font-weight: 500; border-bottom: 1px solid var(--border); }
table.data-table td { padding: 10px 14px; font-size: 13px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data-table tr:last-child td { border-bottom: none; }

.field-label { font-size: 11px; color: var(--gray-500); margin-bottom: 4px; display: block; font-weight: 500; }
textarea, input[type=text], input[type=password], select {
  width: 100%; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
  font-size: 13px; font-family: inherit; resize: vertical;
}
textarea:focus, input:focus, select:focus { outline: none; border-color: var(--blue); }

.demo-banner {
  background: var(--amber-light); color: var(--amber); font-size: 12px; padding: 8px 14px;
  border-radius: 8px; margin-bottom: 20px; border: 1px solid #fde68a;
}

/* ===== Login / password screens ===== */
.center-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--gray-50); padding: 20px;
}
.center-box {
  width: 400px; background: #fff; border: 1px solid var(--border); border-radius: 12px;
  padding: 36px 32px;
}
.center-brand { font-size: 18px; font-weight: 600; color: var(--navy); margin-bottom: 4px; text-align: center; }
.center-brand-sub { font-size: 12px; color: var(--gray-500); text-align: center; margin-bottom: 28px; }
.form-field { margin-bottom: 16px; }
.form-field label { font-size: 12px; color: var(--gray-700); margin-bottom: 6px; display: block; font-weight: 500; }
.form-hint { font-size: 11px; color: var(--gray-500); margin-top: 6px; }
.form-error {
  background: var(--red-light); color: var(--red); font-size: 12px; padding: 8px 12px;
  border-radius: 8px; margin-bottom: 14px;
}
.form-success {
  background: var(--green-light); color: var(--green); font-size: 12px; padding: 8px 12px;
  border-radius: 8px; margin-bottom: 14px;
}
.big-btn {
  width: 100%; padding: 11px; border-radius: 8px; border: none;
  background: var(--navy); color: #fff; font-size: 14px; font-weight: 500;
  cursor: pointer; margin-top: 6px;
}
.big-btn:hover { background: var(--navy-light); }
.big-btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* ===== Account management (admin) ===== */
.temp-password-box {
  display: flex; align-items: center; gap: 10px; background: var(--gray-50);
  border: 1px dashed var(--gray-300); border-radius: 8px; padding: 12px 14px; margin-top: 10px;
}
.temp-password-value { font-family: "Consolas", monospace; font-size: 16px; font-weight: 600; letter-spacing: 0.03em; }
.copy-btn { font-size: 12px; padding: 5px 10px; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(17,24,39,0.4);
  display: flex; align-items: center; justify-content: center; z-index: 200;
}
.modal-box {
  width: 420px; background: #fff; border-radius: 12px; padding: 24px; max-width: 90vw;
}
.modal-title { font-size: 15px; font-weight: 600; margin-bottom: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

.diag-editor-row { display: grid; grid-template-columns: 160px 1fr; gap: 16px; align-items: flex-start; padding: 16px 0; border-bottom: 1px solid var(--border); }
.diag-editor-row:last-child { border-bottom: none; }
.anchor-cell { display: flex; align-items: center; gap: 10px; }
.anchor-avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--navy); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 12px; flex-shrink: 0; }
.anchor-name { font-weight: 500; font-size: 13px; }
.anchor-stat { font-size: 11px; color: var(--gray-500); }
.diag-row-status { font-size: 11px; padding: 2px 8px; border-radius: 5px; font-weight: 600; }
.diag-row-status.filled { background: var(--green-light); color: var(--green); }
.diag-row-status.empty { background: var(--gray-100); color: var(--gray-500); }

.coming-soon {
  text-align: center; padding: 60px 20px; color: var(--gray-500);
}
.coming-soon-title { font-size: 15px; font-weight: 600; color: var(--gray-700); margin-bottom: 6px; }
