@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&display=swap");

:root {
  --bg: #f1f4f8;
  --card: #ffffff;
  --ink: #111827;
  --text: #1f2430;
  --muted: #8b92a4;
  --line: #e9edf3;
  --line-soft: #f1f4f8;
  --blue: #4b9dff;
  --blue-soft: #eaf3ff;
  --purple: #b98bff;
  --purple-soft: #f2eaff;
  --green: #28bd83;
  --green-soft: #e3f7ee;
  --amber: #ff9f43;
  --amber-soft: #fff1e0;
  --red: #ff5d6c;
  --r-lg: 22px;
  --r-md: 16px;
  --r-pill: 999px;
}

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

body {
  font-family: "Poppins", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

#loginScreen .login-error:not(:empty) { color: var(--red); font-weight: 600; }

/* ====================== APP SHELL ====================== */
#app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 252px minmax(0, 1fr);
}

/* ---------- Sidebar ---------- */
#sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 26px 18px 20px;
  background: var(--card);
  border-right: 1px solid var(--line);
}

.sbBrand { display: flex; flex-direction: column; gap: 6px; padding: 0 8px; }
.sbLogo { width: 124px; height: auto; }
.sbTag {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding-left: 2px;
}

.sbChild {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 24px 0 18px;
  padding: 12px;
  border-radius: var(--r-md);
  background: var(--line-soft);
}
.avatar {
  width: 44px; height: 44px;
  flex: 0 0 auto;
  display: grid; place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--blue), var(--purple));
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.sbChildMeta { min-width: 0; }
.sbChildName {
  font-size: 14px; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sbChildClass { font-size: 12px; color: var(--muted); }

.sbNav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.navItem, .sbLogout {
  display: flex; align-items: center; gap: 12px;
  width: 100%;
  padding: 12px 14px;
  border: none; background: transparent;
  border-radius: 14px;
  color: #5b6273;
  font: 600 14px "Poppins", sans-serif;
  cursor: pointer;
  text-align: left;
  transition: background .15s ease, color .15s ease;
}
.navItem:hover { background: var(--line-soft); color: var(--text); }
.navItem.active { background: var(--ink); color: #fff; }
.navIco { width: 19px; height: 19px; flex: 0 0 auto; fill: currentColor; }
.sbLogout { color: var(--muted); margin-top: 8px; }
.sbLogout:hover { background: #fff0f1; color: var(--red); }

/* ---------- Main ---------- */
#main { padding: 26px clamp(18px, 3vw, 40px) 56px; }
#topbar {
  display: flex; align-items: center; gap: 16px;
  margin-bottom: 24px;
}
.tbText { flex: 1; min-width: 0; }
.tbGreeting { font-size: clamp(22px, 2.6vw, 30px); font-weight: 600; letter-spacing: -0.02em; color: var(--text); }
.tbSub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.scopeWrap { flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.scopeToggle {
  display: inline-flex;
  padding: 4px;
  border-radius: var(--r-pill);
  background: var(--card);
  border: 1px solid var(--line);
}
.scopeBtn {
  border: none;
  background: transparent;
  padding: 8px 16px;
  border-radius: var(--r-pill);
  color: var(--muted);
  font: 600 12.5px "Poppins", sans-serif;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s ease, color .15s ease;
}
.scopeBtn:hover { color: var(--text); }
.scopeBtn.active { background: var(--ink); color: #fff; }
.scopeChapter {
  font-size: 12px;
  font-weight: 600;
  color: var(--blue);
  max-width: 280px;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.menuToggle { display: none; }

/* ---------- Views ---------- */
.view { display: none; flex-direction: column; gap: 18px; animation: fade .25s ease; }
.view.active { display: flex; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 24px 26px;
}
.cardHead { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; margin-bottom: 18px; }
.cardHead h2 { font-size: 16px; font-weight: 600; color: var(--text); letter-spacing: -0.01em; }
.hint { font-size: 12px; color: var(--muted); font-weight: 500; text-align: right; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

/* ---------- KPI ---------- */
.kpiRow { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.kpi {
  display: flex; align-items: center; gap: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 18px 20px;
}
.kpiIco {
  width: 46px; height: 46px; flex: 0 0 auto;
  display: grid; place-items: center;
  border-radius: 14px;
}
.kpiIco svg { width: 22px; height: 22px; }
.ico-blue { background: var(--blue-soft); color: var(--blue); }
.ico-green { background: var(--green-soft); color: var(--green); }
.ico-amber { background: var(--amber-soft); color: var(--amber); }
.ico-purple { background: var(--purple-soft); color: var(--purple); }
.kpiVal { font-size: 26px; font-weight: 700; line-height: 1; letter-spacing: -0.03em; color: var(--text); }
.kpiLbl { font-size: 13px; color: var(--text); font-weight: 500; margin-top: 4px; }
.kpiSub { font-size: 11px; color: var(--muted); margin-top: 1px; }

/* ---------- Ring ---------- */
.heroCard { display: flex; flex-direction: column; }
.ringWrap { position: relative; width: 180px; height: 180px; margin: 6px auto 4px; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ringBg { fill: none; stroke: var(--line); stroke-width: 12; }
.ringArc {
  fill: none; stroke: url(#ringGrad); stroke-width: 12; stroke-linecap: round;
  stroke-dasharray: 364.4; stroke-dashoffset: 364.4;
  transition: stroke-dashoffset .9s cubic-bezier(.16,1,.3,1);
}
.ringCenter { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ringPct { font-size: 34px; font-weight: 700; letter-spacing: -0.04em; color: var(--text); }
.ringLbl { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; }
.ringFoot { text-align: center; font-size: 12px; color: var(--muted); margin-top: 6px; }

/* ---------- Weekly bars ---------- */
.weekBars { display: grid; grid-template-columns: repeat(7, 1fr); gap: 10px; align-items: end; height: 150px; }
.wb { display: flex; flex-direction: column; align-items: center; gap: 8px; height: 100%; justify-content: flex-end; }
.wbCol { width: 100%; max-width: 30px; border-radius: 8px 8px 4px 4px; background: var(--line); transition: height .6s cubic-bezier(.16,1,.3,1); min-height: 6px; }
.wbCol.has { background: linear-gradient(180deg, var(--blue), var(--purple)); }
.wbCol.today { outline: 2px solid var(--blue); outline-offset: 2px; }
.wbDay { font-size: 11px; color: var(--muted); font-weight: 600; }
.weekFoot { font-size: 12px; color: var(--muted); margin-top: 12px; }
.streakPill { font-size: 12px; font-weight: 700; color: var(--amber); background: var(--amber-soft); padding: 6px 12px; border-radius: var(--r-pill); }

/* ---------- Insights ---------- */
.insights { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.insights li {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--line-soft);
  font-size: 13.5px; line-height: 1.5; color: var(--text);
}
.insights li .iEmoji { font-size: 18px; line-height: 1.4; flex: 0 0 auto; }
.insights li strong { font-weight: 600; }

/* ---------- Trend chart ---------- */
.trendChart { width: 100%; height: 230px; }
.trendChart svg { width: 100%; height: 100%; display: block; }
.trendEmpty, .tEmpty, .vEmpty { color: var(--muted); font-size: 13px; text-align: center; padding: 30px 10px; }

/* ---------- Type bars ---------- */
.typeBars { display: flex; flex-direction: column; gap: 16px; }
.typeRow { display: grid; grid-template-columns: 130px 1fr 46px; align-items: center; gap: 14px; }
.typeLbl { font-size: 13px; font-weight: 500; color: var(--text); }
.bar { height: 12px; border-radius: var(--r-pill); background: var(--line); overflow: hidden; }
.fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--green), #7fe3b8); transition: width .7s cubic-bezier(.16,1,.3,1); }
.typePct { font-size: 13px; font-weight: 700; text-align: right; color: var(--text); }

/* ---------- Best day ---------- */
.bestDay { margin-bottom: 16px; }
.bestDayName { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; color: var(--text); }
.bestDaySub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.dowBars { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; align-items: end; height: 96px; }
.dow { display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.dowCol { width: 100%; max-width: 26px; border-radius: 6px; background: var(--blue-soft); transition: height .6s ease; min-height: 4px; }
.dowCol.best { background: linear-gradient(180deg, var(--blue), var(--purple)); }
.dowLbl { font-size: 10px; color: var(--muted); font-weight: 600; }

/* ---------- Tables ---------- */
.tableWrap { width: 100%; overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl thead th {
  text-align: left; padding: 0 14px 14px; color: var(--muted);
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; white-space: nowrap;
  border-bottom: 1px solid var(--line);
}
.tbl th.num, .tbl td.num { text-align: right; }
.tbl tbody td { padding: 15px 14px; border-bottom: 1px solid var(--line-soft); color: var(--text); vertical-align: middle; }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl tbody tr.me { background: var(--blue-soft); }
.tbl tbody tr.me td { font-weight: 600; }
.rateCol { width: 150px; }
.rateBar { height: 8px; border-radius: var(--r-pill); background: var(--line); overflow: hidden; }
.rateBar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--amber), var(--red)); }
.meTag { display: inline-block; margin-left: 8px; padding: 2px 8px; border-radius: var(--r-pill); background: var(--blue); color: #fff; font-size: 10px; font-weight: 700; }

/* ---------- Comparison ---------- */
.cmpGrid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px 28px; }
.cmpTitle { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 12px; }
.cmpRow { display: grid; grid-template-columns: 86px 1fr 60px; align-items: center; gap: 12px; margin-bottom: 9px; }
.cmpWho { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 600; color: var(--text); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }
.dot.me { background: linear-gradient(135deg, var(--blue), var(--purple)); }
.dot.avg { background: #c2cbda; }
.fill.me { background: linear-gradient(90deg, var(--blue), var(--purple)); }
.fill.avg { background: #cdd5e1; }
.cmpV { font-size: 12px; font-weight: 700; text-align: right; color: var(--text); }

/* ---------- Podium ---------- */
.podium { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; align-items: end; margin-bottom: 22px; }
.podCol { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 18px 10px; border-radius: var(--r-md); background: var(--line-soft); text-align: center; }
.podCol.p1 { background: linear-gradient(180deg, #fff6dc, #fffdf5); order: 2; padding-top: 26px; border: 1px solid #f4e3a8; }
.podCol.p2 { order: 1; }
.podCol.p3 { order: 3; }
.podRank { font-size: 18px; }
.podAvatar { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; background: linear-gradient(135deg, var(--blue), var(--purple)); color: #fff; font-weight: 700; font-size: 15px; }
.podName { font-size: 13px; font-weight: 600; color: var(--text); line-height: 1.25; }
.podPts { font-size: 12px; color: var(--muted); font-weight: 600; }
.podCol.isMe { outline: 2px solid var(--blue); }

/* ---------- Calendar ---------- */
.calNav { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.calBtn, .calToday { border: 1px solid var(--line); background: var(--card); cursor: pointer; border-radius: 12px; transition: background .15s ease; }
.calBtn { width: 36px; height: 36px; font-size: 18px; color: var(--text); }
.calBtn:hover, .calToday:hover { background: var(--line-soft); }
.calTitle { font-size: 16px; font-weight: 700; text-transform: capitalize; min-width: 150px; text-align: center; }
.calToday { margin-left: auto; height: 36px; padding: 0 16px; font-size: 12px; font-weight: 600; color: var(--text); border-radius: var(--r-pill); }
.calWeek { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; margin-bottom: 8px; }
.calWeek span { text-align: center; font-size: 11px; font-weight: 700; color: var(--muted); }
.calGrid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.calDay { aspect-ratio: 1; border-radius: 12px; display: grid; place-items: center; font-size: 12px; font-weight: 600; color: var(--muted); background: var(--line); }
.calDay.empty { background: transparent; }
.calDay.today { outline: 2px solid var(--blue); outline-offset: -2px; color: var(--blue); }
.calDay.lvl-1 { background: #cdeede; color: #1c5a3c; }
.calDay.lvl-2 { background: #8ddcb4; color: #11422c; }
.calDay.lvl-3 { background: #45c98e; color: #fff; }
.calDay.lvl-4 { background: linear-gradient(135deg, #1f9b6a, #34d399); color: #fff; }
.calLoading, .calError { grid-column: 1 / -1; text-align: center; padding: 20px; color: var(--muted); font-size: 12px; }
.calError { color: var(--red); }
.calLegend { display: flex; align-items: center; gap: 6px; justify-content: flex-end; margin-top: 14px; font-size: 11px; color: var(--muted); font-weight: 600; }
.calLegend .cell { width: 14px; height: 14px; border-radius: 4px; }
.cell.lvl-0 { background: var(--line); }
.cell.lvl-1 { background: #cdeede; }
.cell.lvl-2 { background: #8ddcb4; }
.cell.lvl-3 { background: #45c98e; }
.cell.lvl-4 { background: linear-gradient(135deg, #1f9b6a, #34d399); }

/* ---------- Scrim ---------- */
.scrim { position: fixed; inset: 0; background: rgba(17,24,39,.4); z-index: 40; }

/* ====================== RESPONSIVE ====================== */
@media (max-width: 980px) {
  #app { grid-template-columns: 1fr; }
  #sidebar {
    position: fixed; top: 0; left: 0; z-index: 50;
    width: 252px;
    transform: translateX(-100%);
    transition: transform .25s ease;
  }
  #app.navOpen #sidebar { transform: none; }
  .menuToggle {
    display: inline-flex; flex-direction: column; justify-content: center; gap: 4px;
    width: 42px; height: 42px; flex: 0 0 auto;
    border: 1px solid var(--line); background: var(--card); border-radius: 12px; cursor: pointer;
  }
  .menuToggle span { display: block; height: 2px; width: 18px; margin: 0 auto; background: var(--text); border-radius: 2px; }
  .grid2 { grid-template-columns: 1fr; }
  .kpiRow { grid-template-columns: 1fr 1fr; }
  .cmpGrid { grid-template-columns: 1fr; gap: 18px; }
}

@media (max-width: 560px) {
  #main { padding: 18px 16px 48px; }
  .kpiRow { grid-template-columns: 1fr; }
  .card { padding: 20px 18px; }
  .cardHead { flex-direction: column; gap: 4px; }
  .hint { text-align: left; }
  .typeRow { grid-template-columns: 110px 1fr 40px; gap: 10px; }
  .podName { font-size: 12px; }
  #topbar { flex-wrap: wrap; }
  .scopeWrap { width: 100%; align-items: stretch; }
  .scopeToggle { width: 100%; }
  .scopeBtn { flex: 1; }
  .scopeChapter { text-align: left; max-width: 100%; }
}
