:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-sub: #475569;
  --text-muted: #64748b;
  --emerald: #059669;
  --emerald-bg: #ecfdf5;
  --emerald-border: #a7f3d0;
  --amber: #d97706;
  --amber-bg: #fffbeb;
  --rose: #e11d48;
  --rose-bg: #fff1f2;
  --blue: #0284c7;
  --blue-bg: #f0f9ff;
  --radius-lg: 18px;
  --radius-md: 12px;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Be Vietnam Pro', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

.container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 20px 64px;
}

/* PIN Overlay */
.pin-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(15, 23, 42, 0.72);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.pin-overlay.hidden { display: none; }
.pin-card {
  background: var(--surface);
  border-radius: 22px;
  padding: 32px 28px;
  width: 100%;
  max-width: 360px;
  text-align: center;
  box-shadow: 0 24px 48px rgba(15, 23, 42, 0.22);
}
.pin-logo {
  width: 56px;
  height: 56px;
  margin: 0 auto 14px;
  border-radius: 14px;
}
.pin-card h2 { font-size: 19px; font-weight: 700; margin-bottom: 6px; }
.pin-card p { font-size: 13.5px; color: var(--text-sub); margin-bottom: 20px; }
.pin-input {
  width: 180px;
  height: 52px;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 10px;
  text-align: center;
  border: 2px solid var(--border-strong);
  border-radius: 12px;
  outline: none;
  transition: border-color 0.15s;
}
.pin-input:focus { border-color: var(--text); }
.pin-btn {
  display: block;
  width: 100%;
  margin-top: 14px;
  padding: 12px;
  background: #0f172a;
  color: #fff;
  border: none;
  border-radius: 11px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.pin-error { color: var(--rose); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* Header */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}
.title-group h1 { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
.meta-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-sub);
}
.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--emerald);
  display: inline-block;
}
.controls-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.mode-tabs {
  display: inline-flex;
  background: #e2e8f0;
  padding: 4px;
  border-radius: 12px;
  gap: 4px;
}
.mode-tab {
  border: none;
  background: transparent;
  color: var(--text-sub);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 13px;
  border-radius: 9px;
  cursor: pointer;
  transition: all 0.15s;
}
.mode-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}
.ghost-btn {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
}
.ghost-btn:hover { background: var(--surface-soft); }

/* Hero Recommendation Banner */
.hero-banner {
  background: linear-gradient(135deg, #ffffff 0%, #f0fdf4 100%);
  border: 1.5px solid var(--emerald-border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-md);
}
.hero-left {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1 1 320px;
}
.avatar-wrap {
  position: relative;
  flex-shrink: 0;
}
.avatar-img {
  width: 54px;
  height: 54px;
  border-radius: 15px;
  object-fit: cover;
  display: block;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.14);
}
.avatar-img.lg { width: 62px; height: 62px; border-radius: 17px; }
.slot-pill {
  position: absolute;
  bottom: -5px;
  right: -5px;
  background: #0f172a;
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 99px;
  border: 2px solid #fff;
}
.hero-kicker {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--emerald);
  background: var(--emerald-bg);
  padding: 3px 9px;
  border-radius: 99px;
  margin-bottom: 5px;
}
.hero-title { font-size: 19px; font-weight: 800; color: var(--text); }
.hero-reason { font-size: 13.5px; color: var(--text-sub); margin-top: 3px; }
.primary-cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: #0f172a;
  color: #fff;
  text-decoration: none;
  font-size: 14px;
  font-weight: 700;
  padding: 12px 18px;
  border-radius: 12px;
  transition: transform 0.12s, background 0.15s;
  white-space: nowrap;
}
.primary-cta:hover { background: #1e293b; transform: translateY(-1px); }

/* Maturity Notice */
.maturity-bar {
  background: var(--blue-bg);
  border: 1px solid #bae6fd;
  color: #0c4a6e;
  padding: 11px 16px;
  border-radius: 12px;
  font-size: 13px;
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Account Ranking List / Table */
.rank-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 28px;
}
.rank-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  display: grid;
  grid-template-columns: 64px 235px 1fr 1fr 175px 158px;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.rank-card.rank-1 {
  border-left: 5px solid var(--emerald);
  background: linear-gradient(90deg, #f0fdf4 0%, #ffffff 28%);
}
.rank-num {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
}
.rank-badge {
  font-size: 20px;
  font-weight: 800;
  color: var(--text);
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
}
.rank-card.rank-1 .rank-badge {
  background: var(--emerald);
  color: #fff;
  border-color: var(--emerald);
}
.rank-subtag {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--emerald);
}

.acc-cell {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.acc-info { min-width: 0; }
.acc-name { font-size: 15.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acc-email { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.family-chip {
  display: inline-block;
  margin-top: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 99px;
  background: var(--surface-soft);
  color: var(--text-sub);
  border: 1px solid var(--border);
}
.family-chip.high { background: var(--rose-bg); color: var(--rose); border-color: #fecdd3; }
.family-chip.low { background: var(--emerald-bg); color: var(--emerald); border-color: var(--emerald-border); }

/* Quota Group Bars */
.q-group { min-width: 0; }
.q-group-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 12px;
  margin-bottom: 5px;
}
.q-group-name { font-weight: 700; color: var(--text); }
.q-allowance { font-size: 11.5px; color: var(--text-muted); }
.bar-row { margin-bottom: 6px; }
.bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  margin-bottom: 3px;
}
.bar-pct { font-weight: 700; }
.bar-reset { color: var(--text-muted); font-size: 11.5px; }
.progress-track {
  height: 7px;
  background: #e2e8f0;
  border-radius: 99px;
  overflow: hidden;
}
.progress-fill { height: 100%; border-radius: 99px; transition: width 0.3s ease; }
.fill-good { background: #10b981; }
.fill-warn { background: #f59e0b; }
.fill-low { background: #ef4444; }
.model-subnote { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* Burn & Action Cells */
.burn-cell { font-size: 12.5px; color: var(--text-sub); }
.burn-val { font-size: 14px; font-weight: 700; color: var(--text); margin-bottom: 2px; }
.why-note { font-size: 11.5px; color: var(--text-muted); line-height: 1.4; }
.remote-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 11px;
  border: 1.5px solid #0f172a;
  background: var(--surface);
  color: #0f172a;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  transition: all 0.14s;
}
.rank-card.rank-1 .remote-btn { background: #0f172a; color: #fff; }
.remote-btn:hover { background: #0f172a; color: #fff; }

/* Lower Grid: History Chart + Logic Explanation */
.section-grid {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 20px;
  margin-top: 8px;
}
.panel-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-sm);
}
.panel-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.panel-head h2 { font-size: 17px; font-weight: 800; }
.legend-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 12px;
  color: var(--text-sub);
  margin-bottom: 12px;
}
.legend-item { display: inline-flex; align-items: center; gap: 5px; font-weight: 600; }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

.chart-box {
  width: 100%;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 14px;
}
.chart-svg { width: 100%; height: 210px; display: block; }

.log-table-wrap { overflow-x: auto; }
.log-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
.log-table th, .log-table td {
  padding: 8px 8px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.log-table th { color: var(--text-muted); font-weight: 600; font-size: 11.5px; }

/* Logic Cards */
.logic-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.logic-item {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px 15px;
}
.logic-item h3 {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--text);
}
.logic-item p {
  font-size: 13px;
  color: var(--text-sub);
  line-height: 1.55;
}

/* Responsive */
@media (max-width: 1060px) {
  .rank-card {
    grid-template-columns: 52px 1fr 1fr;
    gap: 14px;
  }
  .burn-cell, .action-cell { grid-column: span 1; }
  .section-grid { grid-template-columns: 1fr; }
}

@media (max-width: 680px) {
  .container { padding: 18px 14px 48px; }
  .title-group h1 { font-size: 20px; }
  .mode-tabs { width: 100%; justify-content: space-between; }
  .mode-tab { flex: 1; text-align: center; padding: 8px 6px; font-size: 12px; }
  .hero-banner { padding: 16px; }
  .primary-cta { width: 100%; }
  .rank-card {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 15px;
  }
  .rank-num {
    flex-direction: row;
    justify-content: flex-start;
    gap: 8px;
  }
  .rank-badge { width: 34px; height: 34px; font-size: 16px; }
}
