/* ==========================================================================
   Improve components. Reusable on any screen: include tokens.css first.
   Every class starts with "imp-" so it can't collide with copied app code.
   ========================================================================== */

/* ---- Base ---------------------------------------------------------------- */
:where(.imp-root), :where(.imp-root) *, :where(.imp-root) *::before, :where(.imp-root) *::after { box-sizing: border-box; }
.imp-root {
  margin: 0; min-height: 100vh; min-height: 100dvh;
  background: var(--imp-bg); color: var(--imp-text);
  font: 400 var(--imp-fs-body)/1.4 var(--imp-font-body);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation; /* no double-tap zoom */
  transition: background-color .35s var(--imp-ease), color .35s var(--imp-ease);
}
/* Dark: a faint red glow at the top so the page has depth instead of flat black */
:root[data-theme="dark"] .imp-root { background-image: radial-gradient(120% 420px at 50% -120px, rgba(79, 140, 255, .09), transparent 70%); background-repeat: no-repeat; }
:where(.imp-root) :where(button) { font: inherit; color: inherit; background: none; border: 0; padding: 0; margin: 0; cursor: pointer; text-align: inherit; }
:where(.imp-root) :where(a) { color: inherit; text-decoration: none; }
:where(.imp-root) :where(h1, h2, h3, p) { margin: 0; font-size: inherit; font-weight: inherit; }
.imp-num { font-variant-numeric: tabular-nums; }

.imp-frame { border: 1px solid var(--imp-frame); border-radius: var(--imp-radius-sm); }

/* ---- Icon ----------------------------------------------------------------
   <svg class="imp-icon"><use href="assets/icons/icons.svg#body"></use></svg> */
.imp-icon { display: inline-block; width: 1em; height: 1em; flex: none; vertical-align: -0.125em; }

/* ---- Text helpers --------------------------------------------------------- */
.imp-label { font: 600 var(--imp-fs-xs)/1.3 var(--imp-font-head); letter-spacing: .02em; color: var(--imp-muted); }
.imp-title { font: 700 var(--imp-fs-md)/1.2 var(--imp-font-head); letter-spacing: -.01em; }
.imp-accent { color: var(--imp-accent); }
.imp-muted { color: var(--imp-muted); }

/* ---- Card (panel) ---------------------------------------------------------
   <section class="imp-panel">
     <header class="imp-panel__head"><h2 class="imp-panel__title">Daily</h2><span class="imp-panel__meta">3/7</span></header>
     <div class="imp-panel__body">…</div>
   </section> */
.imp-panel {
  background: var(--imp-surface); border: 1px solid var(--imp-frame); border-radius: var(--imp-radius);
  box-shadow: var(--imp-shadow); overflow: hidden;
  transition: background-color .35s var(--imp-ease), border-color .35s var(--imp-ease);
}
.imp-panel__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px var(--imp-pad) 4px; }
.imp-panel__title { font: 700 13px/1.2 var(--imp-font-head); color: var(--imp-muted); text-transform: uppercase; letter-spacing: .06em; }
.imp-panel__meta { display: inline-flex; align-items: center; gap: 6px; font: 600 13px var(--imp-font-body); color: var(--imp-muted); font-variant-numeric: tabular-nums; }
.imp-panel__body { padding: 4px var(--imp-pad) 10px; }
.imp-panel__sub { display: flex; align-items: center; gap: 6px; padding: 14px 0 4px; font: 600 var(--imp-fs-xs) var(--imp-font-head); color: var(--imp-faint); letter-spacing: .02em; }
.imp-panel__sub .imp-icon { width: 14px; height: 14px; }

/* ---- Level badge (kept for old screens; levels are hidden) ---------------- */
.imp-lvl { flex: none; width: 52px; height: 52px; display: grid; place-items: center; align-content: center; border-radius: 14px; background: var(--imp-accent-dim); color: var(--imp-accent); }
.imp-lvl__label { font: 700 9px var(--imp-font-head); letter-spacing: .1em; }
.imp-lvl__num { font: 800 22px/1 var(--imp-font-head); }

/* ---- Progress bar -----------------------------------------------------------
   <div class="imp-xpbar" style="--p:62%"><div class="imp-xpbar__fill"></div></div> */
.imp-xpbar { --p: 0%; position: relative; height: 8px; border-radius: 99px; background: var(--imp-sunken); overflow: hidden; }
.imp-xpbar__fill { position: absolute; inset: 0 auto 0 0; width: var(--p); border-radius: inherit; background: var(--imp-accent); transition: width .5s var(--imp-ease); }
.imp-xpbar--sm { height: 6px; }

/* ---- Stat row + stat bar ---------------------------------------------------- */
.imp-stat { display: grid; grid-template-columns: 22px 72px 1fr 40px; align-items: center; gap: 10px; padding: 6px 0; }
.imp-stat__icon { width: 18px; height: 18px; color: var(--imp-muted); }
.imp-stat__name { font: 500 var(--imp-fs-sm) var(--imp-font-head); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.imp-stat__val { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.imp-statbar { --p: 0%; position: relative; height: 6px; border-radius: 99px; background: var(--imp-sunken); overflow: hidden; }
.imp-statbar__fill { position: absolute; inset: 0 auto 0 0; width: var(--p); border-radius: inherit; background: var(--imp-accent); transition: width .5s var(--imp-ease); }

/* ---- Checkbox --------------------------------------------------------------
   <span class="imp-check is-on"><svg class="imp-icon"><use href="…#check"/></svg></span> */
.imp-check {
  flex: none; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 7px;
  border: 2px solid var(--imp-faint); color: var(--imp-on-accent); background: transparent;
  transition: background-color .2s var(--imp-ease), border-color .2s var(--imp-ease), transform .2s var(--imp-ease);
}
.imp-check > * { grid-area: 1 / 1; }
.imp-check .imp-icon { width: 15px; height: 15px; visibility: hidden; stroke-width: 3; }
.imp-check.is-on { background: var(--imp-accent); border-color: var(--imp-accent); }
.imp-check.is-on .imp-icon { visibility: visible; animation: imp-tick .25s var(--imp-ease); }
@keyframes imp-tick { from { transform: scale(.4); opacity: 0; } to { transform: none; opacity: 1; } }
/* Partial progress (e.g. 2/5): show the count instead of a tick */
.imp-check__count { font: 700 12px var(--imp-font-body); color: var(--imp-accent); }
.imp-check.is-on .imp-check__count { display: none; }
.imp-check:has(.imp-check__count) { border-color: var(--imp-accent); }

/* ---- Small value tag (was the XP chip) -------------------------------------- */
.imp-chip { flex: none; white-space: nowrap; font: 600 13px var(--imp-font-body); color: var(--imp-muted); font-variant-numeric: tabular-nums; }
.imp-chip small { font-size: 11px; margin-left: 2px; }

/* ---- Progress pips (multi-count habits) ------------------------------------ */
.imp-pips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.imp-pip { width: 8px; height: 8px; border-radius: 50%; background: var(--imp-sunken); box-shadow: inset 0 0 0 1.5px var(--imp-frame); }
.imp-pip.is-on { background: var(--imp-accent); box-shadow: none; }
.imp-pip.is-over { background: var(--imp-danger); box-shadow: none; }

/* ---- List row (checklist item) --------------------------------------------- */
.imp-row {
  position: relative; width: 100%; display: flex; align-items: center; gap: 14px; padding: 12px 0; min-height: 54px;
  border-bottom: 1px solid var(--imp-divider);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: manipulation;
  transition: opacity .2s;
}
.imp-row:last-child { border-bottom: 0; }
.imp-row:active { opacity: .6; }
.imp-row__main { flex: 1; min-width: 0; display: grid; gap: 2px; text-align: left; }
.imp-row__title { font: 500 16px/1.3 var(--imp-font-body); overflow-wrap: anywhere; }
.imp-row.is-done .imp-row__title { color: var(--imp-faint); text-decoration: line-through; text-decoration-color: var(--imp-faint); }
.imp-row__sub { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; font: 500 var(--imp-fs-xs)/1.3 var(--imp-font-head); color: var(--imp-muted); }
.imp-row__sub .imp-icon { width: 13px; height: 13px; }
.imp-row__end { flex: none; color: var(--imp-faint); }
.imp-row__note { font: 500 12px/1.35 var(--imp-font-head); color: var(--imp-faint); }

/* Floating feedback text (e.g. "+1"). */
.imp-float { position: absolute; right: 8px; top: 4px; pointer-events: none; font: 700 13px var(--imp-font-head); color: var(--imp-accent); animation: imp-float .9s var(--imp-ease) forwards; }
.imp-float.is-neg { color: var(--imp-muted); }
@keyframes imp-float { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(-24px); } }

/* ---- Buttons ---------------------------------------------------------------
   Variants: --primary --secondary --ghost --danger. Sizes: --sm --block */
.imp-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border-radius: var(--imp-radius-sm);
  font: 600 15px/1.2 var(--imp-font-head); padding: 12px 16px; min-height: 44px; text-align: center;
  transition: transform .1s var(--imp-ease), background-color .2s, opacity .2s;
}
.imp-btn .imp-icon { width: 17px; height: 17px; }
.imp-btn:active { transform: scale(.97); }
.imp-btn:disabled { opacity: .4; pointer-events: none; }
.imp-btn--primary { background: var(--imp-accent); color: var(--imp-on-accent); }
.imp-btn--primary:active { background: var(--imp-accent-deep); }
.imp-btn--secondary { background: var(--imp-sunken); color: var(--imp-text); }
.imp-btn--ghost { color: var(--imp-muted); }
.imp-btn--danger { background: var(--imp-danger); color: #fff; }
.imp-btn--sm { padding: 7px 12px; min-height: 34px; font-size: 13px; border-radius: 9px; }
.imp-btn--block { display: flex; width: 100%; }
.imp-btn-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

/* ---- Form fields ----------------------------------------------------------- */
.imp-field { display: grid; gap: 6px; }
.imp-input, .imp-select {
  width: 100%; margin: 0; padding: 10px 12px; min-height: 46px; border: 1px solid var(--imp-frame); border-radius: var(--imp-radius-sm);
  font: 400 16px var(--imp-font-body); color: var(--imp-text); background: var(--imp-surface);
  -webkit-appearance: none; appearance: none; transition: border-color .15s, box-shadow .15s;
}
.imp-input::placeholder { color: var(--imp-faint); }
.imp-input:focus, .imp-select:focus { outline: none; border-color: var(--imp-accent); box-shadow: 0 0 0 3px var(--imp-accent-dim); }
.imp-select { background-image: linear-gradient(45deg, transparent 50%, var(--imp-muted) 50%), linear-gradient(135deg, var(--imp-muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 52%, calc(100% - 13px) 52%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 34px; }
.imp-field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Segmented choice (radio group) */
.imp-seg { display: flex; gap: 2px; padding: 3px; border-radius: 12px; background: var(--imp-sunken); }
.imp-seg button { flex: 1; padding: 8px 4px; border-radius: 9px; font: 600 13px var(--imp-font-head); color: var(--imp-muted); text-align: center; transition: background-color .2s, color .2s; }
.imp-seg button.is-on { background: var(--imp-surface); color: var(--imp-text); box-shadow: 0 1px 3px rgba(16, 24, 40, .12); }

/* Icon picker grid */
.imp-icon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 8px; }
.imp-icon-grid button { display: grid; place-items: center; height: 44px; border-radius: 10px; background: var(--imp-sunken); color: var(--imp-muted); }
.imp-icon-grid button.is-on { background: var(--imp-accent); color: var(--imp-on-accent); }
.imp-icon-grid .imp-icon { width: 22px; height: 22px; }

/* ---- Bottom sheet (modal) --------------------------------------------------- */
.imp-sheet { position: fixed; inset: 0; z-index: 50; display: none; }
.imp-sheet.is-open { display: block; }
.imp-sheet__backdrop { position: absolute; inset: 0; background: rgba(10, 12, 16, .45); backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); animation: imp-fade .2s; }
.imp-sheet__panel {
  position: absolute; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 480px;
  max-height: 90vh; max-height: 90dvh; display: flex; flex-direction: column;
  border-radius: 22px 22px 0 0; border-bottom: 0; box-shadow: var(--imp-shadow-lg);
  animation: imp-sheet-in .3s var(--imp-ease);
}
.imp-sheet__panel::before { content: ""; position: absolute; top: 8px; left: 50%; width: 36px; height: 5px; margin-left: -18px; border-radius: 99px; background: var(--imp-frame); }
.imp-sheet__panel > .imp-panel__head { padding: 22px var(--imp-pad) 8px; }
.imp-sheet__panel .imp-panel__title { font: 700 18px var(--imp-font-head); color: var(--imp-text); text-transform: none; letter-spacing: -.01em; }
.imp-sheet__body { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 10px var(--imp-pad) calc(22px + env(safe-area-inset-bottom)); display: grid; gap: 16px; }
@keyframes imp-sheet-in { from { transform: translateY(100%); } to { transform: none; } }
@keyframes imp-fade { from { opacity: 0; } to { opacity: 1; } }

/* ---- Tab bar ---------------------------------------------------------------- */
.imp-tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: flex; justify-content: space-around;
  padding: 6px max(6px, env(safe-area-inset-left)) calc(6px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--imp-surface) 86%, transparent); border-top: 1px solid var(--imp-frame);
  backdrop-filter: saturate(1.6) blur(18px); -webkit-backdrop-filter: saturate(1.6) blur(18px);
}
.imp-tab { flex: 1; max-width: 96px; min-width: 0; display: grid; justify-items: center; gap: 3px; padding: 6px 0 2px; font: 600 10px var(--imp-font-head); color: var(--imp-faint); transition: color .2s; }
.imp-tab .imp-icon { width: 23px; height: 23px; }
.imp-tab.is-active { color: var(--imp-accent); }

/* ---- Empty state ------------------------------------------------------------ */
.imp-empty { display: grid; justify-items: center; gap: 10px; padding: 32px 16px; text-align: center; }
.imp-empty__icon { width: 44px; height: 44px; color: var(--imp-faint); }
.imp-empty__text { color: var(--imp-muted); max-width: 30ch; }
.imp-blink { animation: imp-blink 1.2s ease-in-out infinite; }
@keyframes imp-blink { 50% { opacity: .3; } }

/* ---- Toast ------------------------------------------------------------------ */
.imp-toast[hidden] { display: none; }
.imp-toast { position: fixed; left: 50%; bottom: calc(var(--imp-tabbar-h) + 20px + env(safe-area-inset-bottom)); z-index: 60;
  transform: translateX(-50%); padding: 10px 16px; border-radius: 99px; background: var(--imp-text); color: var(--imp-bg);
  font: 600 14px var(--imp-font-head); box-shadow: var(--imp-shadow-lg); white-space: nowrap; animation: imp-toast .25s var(--imp-ease); }
@keyframes imp-toast { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

@media (prefers-reduced-motion: reduce) {
  .imp-root *, .imp-root *::before, .imp-root *::after { animation: none !important; transition: none !important; }
}

/* ---- Meter row (label + bar + value) ----------------------------------------- */
.imp-meter { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; }
.imp-meter__label { font: 600 var(--imp-fs-xs) var(--imp-font-head); color: var(--imp-muted); }
.imp-meter__val { display: inline-flex; align-items: center; gap: 3px; font: 600 14px var(--imp-font-body); white-space: nowrap; font-variant-numeric: tabular-nums; }
.imp-meter__val .imp-icon { width: 15px; height: 15px; }

/* ---- Streak tag -------------------------------------------------------------- */
.imp-streak { display: inline-flex; align-items: center; gap: 3px; font: 600 var(--imp-fs-xs) var(--imp-font-head); color: var(--imp-warn); }
.imp-streak .imp-icon { width: 13px; height: 13px; }
.imp-streak.is-pending { color: var(--imp-faint); }

/* ---- Category row (icon, name, bar) ------------------------------------------ */
.imp-attr { display: grid; grid-template-columns: 26px 1fr; gap: 4px 10px; align-items: center; padding: 8px 0; }
.imp-attr__icon { grid-row: span 2; width: 20px; height: 20px; color: var(--imp-muted); }
.imp-attr__top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.imp-attr__name { font: 500 var(--imp-fs-sm) var(--imp-font-head); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.imp-attr__lv { font: 600 var(--imp-fs-xs) var(--imp-font-head); color: var(--imp-accent); white-space: nowrap; }
.imp-attr__xp { font-size: 13px; color: var(--imp-muted); white-space: nowrap; }
.imp-attr .imp-meter { grid-template-columns: 1fr auto; }

/* ---- Big moment overlay (Perfect Day) ------------------------------------------ */
.imp-burst { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; padding: 24px; background: rgba(10, 12, 16, .5); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); animation: imp-fade .2s; }
.imp-burst__box { min-width: 260px; max-width: 340px; text-align: center; padding: 28px 24px 22px; border-radius: 24px; background: var(--imp-surface); display: grid; gap: 8px; justify-items: center; box-shadow: var(--imp-shadow-lg); animation: imp-pop .35s var(--imp-ease); }
.imp-burst__icon { width: 56px; height: 56px; padding: 12px; border-radius: 50%; color: var(--imp-on-accent); background: var(--imp-accent); }
.imp-burst__title { font: 800 22px var(--imp-font-head); letter-spacing: -.01em; }
.imp-burst__big { font: 800 30px/1.1 var(--imp-font-head); }
.imp-burst__sub { color: var(--imp-muted); font-size: 15px; }
.imp-burst__hint { font: 500 var(--imp-fs-xs) var(--imp-font-head); color: var(--imp-faint); margin-top: 8px; }
@keyframes imp-pop { from { transform: scale(.85); opacity: 0; } to { transform: none; opacity: 1; } }

/* Bar color variants: protein (orange) and over goal (red) */
.imp-xpbar--protein .imp-xpbar__fill { background: var(--imp-protein); }
.imp-xpbar--over .imp-xpbar__fill { background: var(--imp-danger); }

/* ---- Confirm pop-up ------------------------------------------------------------ */
.imp-dialog { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 24px; background: rgba(10, 12, 16, .5); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); animation: imp-fade .2s; }
.imp-dialog__box { width: 100%; max-width: 340px; display: grid; gap: 8px; justify-items: center; text-align: center; padding: 24px 20px 18px; border-radius: 22px; background: var(--imp-surface); box-shadow: var(--imp-shadow-lg); animation: imp-pop .25s var(--imp-ease); }
.imp-dialog__icon { width: 44px; height: 44px; padding: 10px; border-radius: 50%; color: var(--imp-accent); background: var(--imp-accent-dim); }
.imp-dialog__title { font: 700 17px var(--imp-font-head); color: var(--imp-text); line-height: 1.3; }
.imp-dialog__text { font-size: 15px; color: var(--imp-muted); }
.imp-dialog__btns { display: flex; gap: 10px; margin-top: 10px; width: 100%; }
.imp-dialog__btns .imp-btn { flex: 1; }

/* The hidden attribute always wins over component display rules */
.imp-root [hidden] { display: none !important; }

/* A habit's rule, under its name */
.imp-row__rule { display: block; font: 500 12.5px/1.35 var(--imp-font-head); color: var(--imp-muted); margin-top: 1px; }
