:root {
  --gold: #ffd400; --gold-deep: #e8b400; --ink: #111318; --ink-2: #1b1e26; --line: #e6e8ee;
  --muted: #667085; --bg: #f5f6f8; --white: #fff; --danger: #c62828; --ok: #15803d;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.5 Inter, "Segoe UI", system-ui, "Microsoft YaHei", sans-serif; color: var(--ink); background: var(--bg); }
a { color: inherit; }
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.side { background: var(--ink); color: #cdd1da; padding: 20px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side img { height: 34px; margin: 0 8px 22px; display: block; }
.side h6 { margin: 18px 10px 6px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: #7d8491; font-weight: 600; }
.side a { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; border-radius: 8px; text-decoration: none; }
.side a:hover { background: var(--ink-2); color: #fff; }
.side a.on { background: var(--gold); color: var(--ink); font-weight: 600; }
.menu-group { margin-top: 6px; }
.menu-group summary {
  display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: 8px; cursor: pointer; list-style: none;
  font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: #9aa1ad;
}
.menu-group summary::-webkit-details-marker { display: none; }
.menu-group summary::after { content: ''; margin-left: auto; width: 7px; height: 7px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(-45deg); transition: transform .2s; }
.menu-group[open] summary::after { transform: rotate(45deg); }
.menu-group summary:hover { background: var(--ink-2); color: #fff; }
.menu-group summary:focus-visible { outline: 2px solid var(--gold); outline-offset: -2px; }
/* The group total only matters while the group is closed; open, each link shows its own. */
.menu-group[open] summary .badge { display: none; }
.menu-group a { margin-left: 8px; padding-left: 12px; border-left: 1px solid #2c303b; border-radius: 0 8px 8px 0; }
.badge { background: var(--gold); color: var(--ink); border-radius: 99px; padding: 0 7px; font-size: 11px; font-weight: 700; }
.main { padding: 26px 30px 60px; min-width: 0; }
.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
h1 { font-size: 22px; margin: 0; }
.card { background: var(--white); border: 1px solid var(--line); border-radius: 12px; padding: 18px; margin-bottom: 16px; }
.card h2 { margin: 0 0 12px; font-size: 15px; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat b { display: block; font-size: 26px; }
.stat span { color: var(--muted); font-size: 13px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
.btn { display: inline-block; border: 1px solid var(--line); background: var(--white); border-radius: 8px; padding: 7px 13px; font: inherit; cursor: pointer; text-decoration: none; color: var(--ink); }
.btn:hover { border-color: var(--ink); }
.btn.primary { background: var(--gold); border-color: var(--gold); font-weight: 600; }
.btn.primary:hover { background: var(--gold-deep); border-color: var(--gold-deep); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 3px 9px; font-size: 13px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
form.inline { display: inline; }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-weight: 600; margin-bottom: 4px; font-size: 13px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], input[type=url], input[type=date], input[type=datetime-local], select, textarea {
  width: 100%; border: 1px solid #d0d5dd; border-radius: 8px; padding: 8px 10px; font: inherit; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold); outline-offset: 0; border-color: var(--gold-deep); }
textarea { resize: vertical; }
.check { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; font-weight: 600; font-size: 13px; }
.tr-group { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 14px; }
.tr-group legend { font-weight: 600; font-size: 13px; padding: 0 6px; }
.tr-row { display: grid; grid-template-columns: 34px 1fr; gap: 8px; align-items: start; margin-bottom: 8px; }
.tr-row:last-child { margin-bottom: 0; }
.tr-row em { font-style: normal; font-size: 11px; font-weight: 700; background: var(--ink); color: var(--gold); border-radius: 6px; text-align: center; padding: 4px 0; margin-top: 4px; }
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; }
.alert.ok { background: #e9f8ee; color: var(--ok); }
.alert.err { background: #fdecec; color: var(--danger); }
.muted { color: var(--muted); }
.pill { font-size: 12px; padding: 1px 9px; border-radius: 99px; background: #eef0f4; white-space: nowrap; }
.pill.gold { background: #fff5bf; }
.pager { display: flex; justify-content: space-between; margin-top: 12px; }
.chat { display: flex; flex-direction: column; gap: 8px; max-height: 60vh; overflow-y: auto; }
.msg { max-width: 75%; padding: 8px 12px; border-radius: 10px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg small { display: block; color: var(--muted); font-size: 11px; margin-bottom: 2px; }
.msg.user { background: #eef0f4; align-self: flex-start; }
.msg.assistant { background: #fff8d6; align-self: flex-end; }
.msg.admin { background: var(--ink); color: #fff; align-self: flex-end; }
.msg.admin small { color: #aab; }
.msg.system { align-self: center; font-size: 12px; color: var(--muted); }
.login { min-height: 100vh; display: grid; place-items: center; background: var(--ink); padding: 16px; }
.login .card { width: 100%; max-width: 380px; }
.login img { height: 40px; display: block; margin: 0 auto 18px; }
/* Statistics. Series colours are the validated categorical slots 1 and 2 against the white card. */
.viz-root { --surface: #fff; --series-1: #2a78d6; --series-2: #eb6834; --grid: #eceef2; --axis: #c3c2b7; --ink-muted: #6b7280; }
.range { display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: 10px; background: var(--white); }
.range a { padding: 5px 12px; border-radius: 7px; text-decoration: none; font-size: 13px; color: var(--muted); }
.range a:hover { background: var(--bg); color: var(--ink); }
.range a.on { background: var(--ink); color: #fff; font-weight: 600; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { margin: 0; display: flex; flex-direction: column; gap: 2px; }
.kpi span { color: var(--muted); font-size: 13px; }
.kpi b { font-size: 28px; line-height: 1.2; }
.kpi.hero b { font-size: 48px; }
.delta { font-size: 12px; font-weight: 600; }
.delta.up { color: #006300; }
.delta.down { color: #b42318; }
.viz-legend { display: flex; gap: 16px; margin-bottom: 6px; font-size: 13px; color: var(--muted); }
.viz-legend span { display: inline-flex; align-items: center; gap: 6px; }
.viz-legend i { width: 14px; height: 2px; border-radius: 2px; }
.viz-chart { position: relative; }
.viz-chart svg { display: block; width: 100%; height: auto; overflow: visible; touch-action: pan-y; }
.viz-grid { stroke: var(--grid); stroke-width: 1; }
.viz-base { stroke: var(--axis); stroke-width: 1; }
.viz-tick { font-size: 11px; fill: var(--ink-muted); font-variant-numeric: tabular-nums; }
.viz-label { font-size: 12px; font-weight: 600; fill: var(--ink); }
.viz-cross { stroke: var(--axis); stroke-width: 1; pointer-events: none; }
.viz-hit { cursor: crosshair; }
.viz-tip { position: absolute; top: 0; pointer-events: none; min-width: 170px; padding: 8px 10px; border-radius: 8px; background: var(--ink); color: #fff; font-size: 12px; box-shadow: 0 6px 20px rgba(0,0,0,.18); }
.viz-tip-date { color: #aab; margin-bottom: 4px; }
.viz-tip-row { display: flex; align-items: center; gap: 8px; }
.viz-tip-row i { width: 12px; height: 2px; border-radius: 2px; }
.viz-tip-row b { font-size: 14px; min-width: 36px; }
.viz-table { margin-top: 10px; font-size: 13px; }
.viz-table summary { cursor: pointer; color: var(--muted); }
.viz-table table { margin-top: 8px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.grid-3 .card { margin: 0; }
.rank { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.rank-row { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; margin-bottom: 4px; }
.rank-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-value { font-weight: 600; font-variant-numeric: tabular-nums; }
.rank-track { height: 8px; border-radius: 99px; background: #e8f0fb; }
.rank-bar { height: 100%; border-radius: 99px; background: var(--series-1); }
.viz-note { font-size: 12px; margin: 16px 0 28px; }
.section-title { font-size: 16px; margin: 0 0 12px; }
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .grid-3 { grid-template-columns: minmax(0, 1fr); }
  /* Below this width the axis text would shrink unreadably; the chart scrolls inside its card instead. */
  .viz-chart { overflow-x: auto; }
  .viz-chart svg { min-width: 600px; }
  .kpi.hero b { font-size: 40px; }
}
.captcha-row { display: flex; gap: 8px; margin-bottom: 14px; }
.captcha-image { flex: 1; min-width: 0; height: 56px; overflow: hidden; border-radius: 8px; background: #1e2028; }
/* Same colour as the captcha's own background, so the box reads as one image at any width. */
.login .captcha-image img { width: 100%; height: 100%; margin: 0; object-fit: contain; }
.captcha-refresh { display: grid; flex-shrink: 0; width: 56px; height: 56px; place-items: center; border: 1px solid #d0d5dd; border-radius: 8px; color: var(--ink); transition: background .2s, border-color .2s; }
.captcha-refresh:hover { border-color: var(--gold-deep); background: var(--gold); }
.captcha-refresh:focus-visible { outline: 2px solid var(--gold-deep); outline-offset: 2px; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.milestone-form { display: grid; grid-template-columns: 70px 1fr 150px auto; gap: 8px; align-items: start; padding: 10px 0; border-bottom: 1px solid var(--line); }
.milestone-form textarea { grid-column: 2 / 4; }
.comment-box { margin-top: 8px; padding: 10px; border-radius: 8px; background: var(--bg); }
.comment { padding: 7px 10px; margin-bottom: 6px; border-radius: 8px; background: #fff; white-space: pre-wrap; overflow-wrap: anywhere; }
.comment.client { background: #fff8d6; }
.comment small { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); white-space: normal; margin-bottom: 2px; }
.reply-form { display: flex; gap: 6px; align-items: flex-start; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
@media (max-width: 1100px) {
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .milestone-form { grid-template-columns: 60px 1fr; }
  .milestone-form textarea, .milestone-form select { grid-column: 1 / -1; }
}
@media (max-width: 800px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; }
  .main { padding: 18px 16px 40px; }
}
