*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 13px/1.45 'Google Sans', Roboto, -apple-system, 'Segoe UI', sans-serif;
  color: #1f2430; background: #fafbfd;
}
u { text-decoration: underline; }
.muted { color: #8a92a6; }

/* screens */
#screen-loading, #screen-setup {
  height: 100%; display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 12px;
}
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid #dfe5f1; border-top-color: #4285F4;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.setup-card { max-width: 460px; background: #fff; border: 1px solid #e3e8f2; border-radius: 12px; padding: 20px 24px; }
.setup-problems li { margin: 6px 0; }
.setup-problems .hint { color: #8a92a6; list-style: none; margin-top: 12px; }
.error { color: #c5221f; padding: 24px; }

#screen-main { display: none; flex-direction: column; height: 100%; }

/* banner */
.banner, .bar, .footer, #context-strip { flex-shrink: 0; }
.banner {
  padding: 5px 14px; font-size: 12px; color: #5f6a80;
  background: #f1f4fa; border-bottom: 1px solid #e3e8f2;
}
.banner.warn { background: #fef7e0; color: #7a5d00; }
.banner.demo { background: #e8f0fe; color: #1a56c4; }
.banner a { color: inherit; font-weight: 600; }

/* toolbar rows */
.bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px 0 14px; flex-wrap: wrap;
}
.bar .label { width: 104px; font-weight: 600; color: #5f6a80; font-size: 12px; cursor: help; }
.help-btn {
  width: 22px; height: 22px; border-radius: 50%; border: 1px solid #c3cbdc;
  background: #fff; color: #5f6a80; font: 600 12px/1 inherit; font-family: inherit; cursor: pointer;
}
.help-btn:hover { background: #eef3fd; color: #4285F4; }

.chip {
  border: 1px dashed #c3cbdc; border-radius: 8px; background: #eef1f7;
  padding: 6px 12px; font: inherit; cursor: pointer; color: #1f2430;
  transition: background .12s, border-color .12s;
}
.chip:hover { background: #e3e9f5; }
.chip.metric.active { background: #d7ecd9; border-color: #34A853; font-weight: 600; }
.chip.dim {
  border-style: solid; position: relative; padding-right: 26px;
  clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 50%, calc(100% - 10px) 100%, 0 100%);
  padding-right: 34px; border: none; background: #e6ebf5;
}
.chip.dim.all { background: #dbe6fb; }
.chip.dim:hover { background: #d5ddef; }
.chip .share { color: #5f6a80; font-size: 11px; margin-left: 4px; }
.chip .x { margin-left: 8px; color: #9aa3b8; font-weight: 700; }
.chip .x:hover { color: #c5221f; }
.chip.add { min-width: 34px; color: #5f6a80; }
.swap { border: none; background: none; cursor: pointer; color: #9aa3b8; font-size: 14px; padding: 0 2px; }
.swap:hover { color: #4285F4; }

.top-controls { margin-left: auto; display: flex; gap: 6px; align-items: center; }
select {
  font: inherit; padding: 5px 8px; border: 1px solid #c3cbdc; border-radius: 6px; background: #fff;
}

/* chart area — canvas lives in an absolutely-positioned holder so
   Chart.js resizing can never influence the page layout */
.chart-wrap { flex: 1 1 0; min-height: 120px; margin: 10px 14px; position: relative; }
#chart-holder {
  position: absolute; inset: 0; background: #fff;
  border: 1px solid #e3e8f2; border-radius: 12px; padding: 8px;
}
#context-strip { padding: 4px 16px 8px; font-size: 12px; color: #5f6a80; }

/* footer */
.footer {
  display: flex; gap: 6px; padding: 8px 14px; border-top: 1px solid #e3e8f2; background: #fff;
  align-items: center;
}
.btn {
  font: inherit; border: 1px solid #c3cbdc; background: #fff; color: #1f2430;
  border-radius: 6px; padding: 6px 12px; cursor: pointer; text-decoration: none;
}
.btn:hover { background: #f1f4fa; }
.btn.primary { background: #4285F4; border-color: #4285F4; color: #fff; font-weight: 600; }
.btn.primary:hover { background: #3367d6; }
.btn.on { background: #fef3d7; border-color: #f2b600; }
.kbd-hint { margin-left: auto; color: #a8b0c2; font-size: 11px; }
kbd {
  background: #eef1f7; border: 1px solid #d5dbe8; border-bottom-width: 2px;
  border-radius: 4px; padding: 0 5px; font-size: 11px;
}

/* dropdown menu */
#menu {
  display: none; position: fixed; z-index: 50; min-width: 240px; max-width: 330px;
  max-height: 380px; overflow-y: auto; background: #fff;
  border: 1px solid #d5dbe8; border-radius: 10px; box-shadow: 0 8px 28px rgba(20,30,60,.18);
  padding: 4px;
}
.menu-item {
  padding: 7px 10px; border-radius: 6px; cursor: pointer; display: flex; align-items: center; gap: 6px;
}
.menu-item .share { margin-left: auto; color: #8a92a6; font-size: 11px; }
.menu-item:hover { background: #eef3fd; }
.menu-item.sel { background: #dbe6fb; font-weight: 600; }
.menu-item.all { border-bottom: 1px solid #e8ecf4; margin-bottom: 3px; }
.menu-item.muted { cursor: default; color: #8a92a6; }
.menu-item .x { margin-left: 6px; color: #9aa3b8; }
.tr { font-size: 10px; width: 13px; display: inline-block; }
.tr.up { color: #188038; }
.tr.down { color: #c5221f; }
.tr.flat { color: #b7bece; }

/* history */
#history-panel {
  display: none; position: absolute; right: 22px; top: 16px; z-index: 40;
  width: 320px; max-height: 70%; overflow-y: auto;
  background: #fff; border: 1px solid #d5dbe8; border-radius: 10px;
  box-shadow: 0 8px 28px rgba(20,30,60,.18); padding: 6px;
}
.hist-item { padding: 7px 9px; border-radius: 6px; cursor: pointer; font-size: 12px; }
.hist-item:hover { background: #eef3fd; }

/* modal */
#modal {
  display: none; position: fixed; inset: 0; background: rgba(15,20,35,.45);
  align-items: center; justify-content: center; z-index: 100;
}
.modal-card {
  background: #fff; border-radius: 12px; padding: 20px 24px; width: 420px; max-width: 92vw;
  box-shadow: 0 16px 48px rgba(10,16,32,.3);
}
.modal-card.wide { width: 640px; }
.modal-card h3 { margin: 0 0 8px; }
.modal-card .row { display: flex; align-items: center; gap: 10px; margin: 10px 0; }
.modal-card .row label { width: 110px; color: #5f6a80; }
.modal-card .row select { flex: 1; }
.row3 { display: flex; gap: 12px; margin: 12px 0; }
.row3 > div { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.row3 label { font-size: 11px; color: #5f6a80; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* data panel */
.modal-card.data { width: 760px; max-width: 94vw; max-height: 86vh; overflow-y: auto; }
.modal-card.data h4 { margin: 18px 0 8px; font-size: 13.5px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.data-table th { text-align: left; color: #8a92a6; font-weight: 600; padding: 4px 8px; border-bottom: 1px solid #e3e8f2; }
.data-table td { padding: 6px 8px; border-bottom: 1px solid #f0f2f8; vertical-align: top; }
.data-table td.num { text-align: right; white-space: nowrap; color: #5f6a80; }
.data-table td.samples { color: #5f6a80; }
.tagb {
  font-size: 10px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  background: #eef1f7; color: #5f6a80; border-radius: 4px; padding: 1px 5px; margin-left: 4px;
}
.hier { font-size: 13px; background: #eef6ee; border: 1px solid #cfe6d2; border-radius: 8px; padding: 8px 12px; margin: 10px 0 4px; }
.sugg-list { display: grid; gap: 8px; }
.sugg {
  text-align: left; font: inherit; font-family: inherit; border: 1px solid #d6def0;
  background: #f6f9ff; border-radius: 8px; padding: 9px 12px; cursor: pointer;
  display: flex; flex-direction: column; gap: 2px;
}
.sugg:hover { background: #e9f0fe; border-color: #a9c4f5; }
.sugg span { font-size: 12px; color: #8a92a6; }

/* intro overlay */
.modal-card.intro { width: 520px; }
.intro-row { display: flex; gap: 14px; align-items: center; margin: 16px 0; font-size: 14.5px; }
.intro-chip-demo { flex-shrink: 0; width: 168px; }
.intro-chip-demo .chip { cursor: default; pointer-events: none; }

/* demo walkthrough */
#walk {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 58px; z-index: 90;
  width: 560px; max-width: 94vw; background: #fff; border: 1px solid #d5dbe8;
  border-radius: 14px; box-shadow: 0 14px 44px rgba(20,30,60,.28); padding: 16px 18px 12px;
}
.walk-text { font-size: 14px; line-height: 1.55; }
.walk-text kbd { margin: 0 1px; }
.walk-foot { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.walk-dots { display: flex; gap: 5px; margin-right: auto; }
.walk-dots i { width: 8px; height: 8px; border-radius: 50%; background: #dfe5f1; }
.walk-dots i.on { background: #4285F4; }

/* demo tour */
#tour {
  position: fixed; right: 18px; bottom: 64px; z-index: 60; width: 270px;
  background: #fff; border: 1px solid #d5dbe8; border-radius: 12px;
  box-shadow: 0 10px 32px rgba(20,30,60,.2); padding: 12px;
}
.tour-title { font-weight: 600; font-size: 13px; margin-bottom: 8px; display: flex; }
.tour-close { margin-left: auto; cursor: pointer; color: #9aa3b8; font-size: 15px; }
.tour-close:hover { color: #c5221f; }
.tour-step {
  display: flex; gap: 8px; align-items: center; width: 100%; text-align: left;
  font: 12.5px/1.35 inherit; font-family: inherit; border: 1px solid #e3e8f2; background: #fafbfd;
  border-radius: 8px; padding: 7px 9px; margin: 4px 0; cursor: pointer;
}
.tour-step:hover { background: #eef3fd; border-color: #b9cdf8; }
.tour-step .n {
  flex-shrink: 0; width: 18px; height: 18px; border-radius: 50%; background: #4285F4; color: #fff;
  font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center;
}
.tour-step.done { opacity: .55; }
.tour-step.done .n { background: #34A853; }
.tour-foot { font-size: 11px; color: #8a92a6; margin-top: 6px; }

/* explain-change table */
.xc-table { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 8px; }
.xc-table th { text-align: left; color: #8a92a6; font-weight: 600; padding: 4px 8px; border-bottom: 1px solid #e3e8f2; }
.xc-table td { padding: 5px 8px; border-bottom: 1px solid #f0f2f8; }
.xc-table td.pos { color: #188038; }
.xc-table td.neg { color: #c5221f; }
.bar-cell { width: 120px; }
.xc-bar { height: 8px; border-radius: 4px; }
.xc-bar.pos { background: #81c995; }
.xc-bar.neg { background: #f28b82; }

/* insights */
.sugg.locked { opacity: .75; background: #f4f2ea; border-color: #ddd8c8; }
.pin-it { margin-left: 8px; cursor: pointer; opacity: .55; }
.pin-it:hover { opacity: 1; }

/* AI insights extras */
.pri { font-size: 9.5px; font-weight: 800; letter-spacing: .05em; border-radius: 4px; padding: 1px 6px; vertical-align: 1px; margin-left: 6px; }
.pri.hi { background: #fde0de; color: #b3261e; }
.pri.md { background: #fef3d7; color: #7a5d00; }
.sugg .cause { color: #188038; font-weight: 600; font-size: 12.5px; }
.sugg .method { color: #a8b0c2; font-size: 11.5px; font-style: italic; }
.menu-item .ck { cursor: pointer; font-size: 13px; }
.menu-item .ck:hover { color: #4285F4; }
