/* Calm, list-first interface: a sidebar of lists, a white sheet of rows, one round plus button.
   Light by default, dark follows the system. */
:root {
  color-scheme: light dark;
  --side: #f5f6f8; --bg: #ffffff; --surface: #ffffff; --surface-2: #f2f3f5; --line: #e6e7ea; --hover: #f0f3f8;
  --text: #1d1d1f; --text-2: #54565c; --muted: #8e9199;
  --accent: #1a7cf9; --series: #2a78d6; --on: #dfe9fb;
  --good: #0ca30c; --warn: #e3a008; --crit: #d03b3b; --star: #f5b800;
  --shadow: 0 10px 40px rgba(20, 30, 50, .18), 0 1px 3px rgba(20, 30, 50, .12);
}
@media (prefers-color-scheme: dark) {
  :root {
    --side: #1c1e22; --bg: #24262b; --surface: #24262b; --surface-2: #2e3137; --line: #383b42; --hover: #2c3038;
    --text: #f2f2f3; --text-2: #c2c5cb; --muted: #8b8f98;
    --accent: #3d8bfd; --series: #3987e5; --on: #2f4468;
    --shadow: 0 10px 40px rgba(0, 0, 0, .55), 0 1px 3px rgba(0, 0, 0, .4);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased; }
a { color: inherit; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: var(--surface-2); border-radius: 9px; padding: .5rem .9rem; }
button.primary { background: var(--accent); color: #fff; font-weight: 600; }
button.ghost { background: none; color: var(--muted); padding: .4rem .6rem; border-radius: 8px; }
button.ghost:hover { background: var(--surface-2); color: var(--text); }
button.danger { color: var(--crit); background: none; }
button.icon { background: none; font-size: 1.1rem; padding: .3rem .5rem; }
button:disabled { opacity: .45; cursor: default; }
input, textarea, select { background: var(--surface-2); border: 1px solid transparent; border-radius: 9px; padding: .6rem .75rem; width: 100%; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
label { display: block; font-size: .82rem; color: var(--muted); margin: .9rem 0 .25rem; }
h1, h2, h3, p { margin: 0; }
small { color: var(--muted); }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }

/* layout */
.app { display: grid; grid-template-columns: 270px minmax(0, 1fr); min-height: 100dvh; }
#side { background: var(--side); padding: 1rem .7rem 1rem; position: sticky; top: 0; height: 100dvh; overflow-y: auto; display: flex; flex-direction: column; }
#view { padding: 2.2rem clamp(1.2rem, 5vw, 4rem) 7rem; max-width: 900px; width: 100%; margin: 0 auto; }
.brand { display: flex; gap: .55rem; align-items: center; font-weight: 700; font-size: 1.05rem; text-decoration: none; padding: .3rem .6rem 1rem; }
nav { flex: 1; }
.nav { display: flex; align-items: center; gap: .6rem; width: 100%; text-align: left; text-decoration: none; padding: .42rem .6rem; border-radius: 8px; background: none; font-size: .97rem; }
.nav:hover { background: var(--hover); }
.nav.on { background: var(--on); }
.nav .nt { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav .nc { color: var(--muted); font-size: .85rem; }
.navhead { font-size: .75rem; font-weight: 700; color: var(--muted); padding: 1.2rem .6rem .35rem; }
.nav.settings { color: var(--text-2); margin-top: .6rem; }
.empty { color: var(--muted); font-size: .88rem; padding: .3rem .6rem; }
.empty.warn { color: var(--crit); }
.ni { width: 1.35rem; text-align: center; font-size: 1rem; line-height: 1; color: var(--muted); flex: none; }
.ni.star, .ni.top { color: var(--star); }
.ni.plus { color: var(--accent); font-weight: 700; }
.ni.good { color: var(--good); }
.ni.high { color: var(--crit); }
.ni.big { font-size: 1.5rem; width: auto; margin-right: .55rem; }
.back { display: none; color: var(--accent); text-decoration: none; margin-bottom: .6rem; }

#fab { position: fixed; right: max(1.4rem, env(safe-area-inset-right)); bottom: max(1.4rem, env(safe-area-inset-bottom)); width: 56px; height: 56px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 1.7rem; line-height: 1; padding: 0; box-shadow: 0 6px 18px rgba(26, 124, 249, .45); z-index: 6; }
#fab:active { transform: scale(.94); }
body[data-route=new] #fab { display: none; }

@media (max-width: 899px) {
  .app { display: block; }
  #side { position: static; height: auto; min-height: 100dvh; padding: 1rem .9rem 6rem; }
  .nav { padding: .7rem .6rem; font-size: 1.05rem; }
  body:not([data-route=home]) #side { display: none; }
  body[data-route=home] #view { display: none; }
  .back { display: inline-block; }
  #view { padding: 1rem 1.1rem 7rem; }
}

/* a list page */
.title { display: flex; align-items: center; font-size: 1.75rem; font-weight: 700; letter-spacing: -.01em; }
.head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.note { color: var(--text-2); margin-top: .6rem; max-width: 68ch; }
.foot { color: var(--muted); font-size: .8rem; margin-top: .6rem; }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .8rem; }
.chip { font-size: .8rem; padding: .12rem .6rem; border-radius: 999px; background: var(--surface-2); color: var(--text-2); }
.advice { margin-top: 1.1rem; padding: .8rem 1rem; border-radius: 12px; background: var(--surface-2); color: var(--text-2); font-size: .95rem; }
.advice b { color: var(--text); }
.advice p { margin-top: .25rem; }
.heading { font-size: 1rem; font-weight: 700; color: var(--accent); margin-top: 1.9rem; padding-bottom: .35rem; border-bottom: 1px solid var(--line); }
.rows.first { margin-top: 1.4rem; border-top: 1px solid var(--line); }
.row { display: grid; grid-template-columns: 22px 46px minmax(0, 1fr) 120px auto; gap: .8rem; align-items: center; width: 100%; text-align: left;
  background: none; border-radius: 10px; padding: .6rem .5rem; border-bottom: 1px solid var(--line); border-radius: 0; }
.row:hover { background: var(--hover); border-radius: 10px; border-bottom-color: transparent; }
.row.dim { opacity: .55; }
.row img, .row .noimg { width: 46px; height: 46px; object-fit: contain; background: #fff; border-radius: 8px; padding: 2px; }
.row .noimg { background: var(--surface-2); }
.row .main { display: flex; flex-direction: column; min-width: 0; }
.row .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sub { font-size: .82rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .why { font-size: .86rem; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .price { display: flex; flex-direction: column; align-items: flex-end; white-space: nowrap; }
.row .now { font-weight: 700; font-size: 1.1rem; }
.row .vs { font-size: .76rem; color: var(--muted); }
.row .vs i { font-style: normal; }
.fav { color: var(--star); }
/* the round mark in checkbox position: shape + fill carry the verdict, the text sits at the right */
.mark { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--muted); display: grid; place-items: center; font-size: 11px; line-height: 1; color: #fff; }
.mark.top { background: var(--good); border-color: var(--good); }
.mark.good { border-color: var(--good); box-shadow: inset 0 0 0 3px var(--bg), inset 0 0 0 10px var(--good); }
.mark.high { border-color: var(--crit); }
.mark.unknown { border-style: dashed; }
.spark { width: 120px; height: 36px; display: block; }
.toolbar { display: flex; flex-wrap: wrap; gap: .2rem; margin-top: 1.6rem; align-items: center; }
.toolbar select { width: auto; margin-left: auto; background: none; color: var(--muted); padding: .4rem .3rem; }
details.fold { margin-top: 1.4rem; color: var(--text-2); }
details.fold summary { cursor: pointer; color: var(--muted); font-weight: 600; font-size: .92rem; }
details.fold ul { margin: .5rem 0 0; padding-left: 1.2rem; }
.blank { text-align: center; color: var(--muted); padding: 4.5rem 1rem; }
.blankicon { font-size: 3rem; opacity: .35; line-height: 1; margin-bottom: .6rem; }
.blank p { color: var(--text-2); font-weight: 600; }
.notice { margin-top: 1rem; padding: .7rem 1rem; border-radius: 12px; background: var(--surface-2); color: var(--text-2); font-size: .95rem; }
.notice.err { box-shadow: inset 3px 0 0 var(--crit); }
.notice.busy { box-shadow: inset 3px 0 0 var(--accent); }
.spin { display: inline-block; width: .85em; height: .85em; border: 2px solid var(--accent); border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -.1em; margin-right: .4em; }
.ni .spin { margin: 0; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (max-width: 640px) {
  .row { grid-template-columns: 22px 42px minmax(0, 1fr) auto; }
  .row .sparkcell { display: none; }
  .row .name { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .row .vs i { display: none; }
  .row img, .row .noimg { width: 42px; height: 42px; }
  .title { font-size: 1.5rem; }
  .toolbar select { margin-left: 0; }
}

/* new search: borderless, like writing a note */
.compose { margin-top: 1.4rem; border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); padding: 1rem; }
.compose textarea { background: none; border: 0; padding: .2rem; min-height: 8rem; resize: vertical; font-size: 1.05rem; }
.composebar { display: flex; gap: .6rem; align-items: center; border-top: 1px solid var(--line); padding-top: .8rem; margin-top: .4rem; }
.composebar input { max-width: 14rem; }
.composebar button { margin-left: auto; white-space: nowrap; }

/* badges (dialog header): status colour + label, text in text ink */
.badge { display: inline-flex; align-items: center; gap: .35em; padding: .12rem .6rem; border-radius: 999px; font-size: .8rem; font-weight: 600; background: var(--surface-2); color: var(--text); white-space: nowrap; }
.badge::before { content: ""; width: .6em; height: .6em; border-radius: 50%; background: var(--muted); }
.badge.top::before, .badge.good::before { background: var(--good); }
.badge.top { box-shadow: inset 0 0 0 1.5px var(--good); }
.badge.high::before { background: var(--crit); }
.badge.budget::before { background: var(--warn); }

/* dialogs: a card lifting off the list */
dialog { border: 0; background: var(--surface); color: var(--text); border-radius: 18px; padding: 0; width: min(880px, 96vw); max-height: 92dvh; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(10, 14, 20, .35); }
dialog#modal { width: min(520px, 94vw); }
.dlg { padding: 1.4rem; }
.dlg > .x { position: sticky; top: .2rem; float: right; z-index: 2; background: var(--surface-2); border-radius: 50%; width: 2.1rem; height: 2.1rem; padding: 0; color: var(--muted); }
.dlg h2 { font-size: 1.35rem; }
.dlg h3 { font-size: .95rem; margin: 1.6rem 0 .5rem; color: var(--accent); padding-bottom: .3rem; border-bottom: 1px solid var(--line); }
.phead { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 1.1rem; align-items: center; }
.phead img { width: 110px; height: 110px; object-fit: contain; background: #fff; border-radius: 12px; padding: 6px; }
.actions { display: flex; flex-wrap: wrap; gap: .45rem; margin-top: .7rem; }
.actions a, .actions button { font-size: .88rem; text-decoration: none; background: var(--surface-2); border-radius: 9px; padding: .4rem .75rem; }
.actions button.primary { background: var(--accent); }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: .6rem; margin-top: 1.1rem; }
.tile { background: var(--surface-2); border-radius: 12px; padding: .7rem .85rem; }
.tile .k { font-size: .76rem; color: var(--muted); }
.tile .v { font-size: 1.3rem; font-weight: 700; }
.tile .s { font-size: .78rem; color: var(--text-2); }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 640px) { .cols { grid-template-columns: 1fr; } .phead { grid-template-columns: 76px 1fr; } .phead img { width: 76px; height: 76px; } .dlg { padding: 1.1rem; } }
ul.pm { list-style: none; margin: 0; padding: 0; font-size: .92rem; color: var(--text-2); }
ul.pm li { padding: .15rem 0 .15rem 1.3rem; position: relative; }
ul.pm li::before { position: absolute; left: 0; font-weight: 700; }
ul.pm.plus li::before { content: "+"; color: var(--good); }
ul.pm.min li::before { content: "−"; color: var(--crit); }
details.box { background: var(--surface-2); border-radius: 12px; padding: .7rem 1rem; margin-top: .7rem; color: var(--text-2); }
details.box summary { cursor: pointer; color: var(--text); font-weight: 600; font-size: .92rem; }
details.box ul { margin: .5rem 0 0; padding-left: 1.2rem; }

table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: .76rem; padding: .3rem .5rem; border-bottom: 1px solid var(--line); }
td { padding: .55rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
td.r, th.r { text-align: right; white-space: nowrap; }
td small { display: block; }
tr.best td { background: var(--on); }
.tag { font-size: .72rem; border-radius: 6px; padding: 0 .35rem; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.tag.warn { box-shadow: inset 0 0 0 1px var(--warn); }

/* chart */
.chart { position: relative; border: 1px solid var(--line); border-radius: 12px; padding: .6rem .4rem .2rem; }
.chart svg { display: block; width: 100%; height: 260px; touch-action: pan-y; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke: var(--series); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--series); opacity: .1; }
.chart .ref { stroke: var(--muted); stroke-width: 1; }
.chart .reflabel { fill: var(--text-2); font-size: 11px; paint-order: stroke; stroke: var(--surface); stroke-width: 4px; }
.chart .endlabel { fill: var(--text); font-size: 12px; font-weight: 700; paint-order: stroke; stroke: var(--surface); stroke-width: 4px; }
.chart .cross { stroke: var(--muted); stroke-width: 1; }
.chart .dot { fill: var(--series); stroke: var(--surface); stroke-width: 2; }
.tip { position: absolute; pointer-events: none; background: var(--text); color: var(--bg); border-radius: 8px; padding: .3rem .55rem; font-size: .8rem; white-space: nowrap; transform: translate(-50%, -120%); display: none; z-index: 3; }
.tip b { display: block; font-size: .95rem; }
.ranges { display: flex; gap: .25rem; justify-content: flex-end; margin-bottom: .4rem; }
.ranges button { padding: .2rem .6rem; font-size: .8rem; background: none; color: var(--muted); }
.ranges button[aria-pressed=true] { background: var(--on); color: var(--text); font-weight: 600; }
.specs { columns: 2 280px; font-size: .86rem; color: var(--text-2); }
.specs div { break-inside: avoid; padding: .1rem 0; }
.specs b { color: var(--text); font-weight: 600; }

#toast { position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%); background: var(--text); color: var(--bg); border-radius: 12px; padding: .6rem 1rem; display: none; z-index: 50; max-width: 90vw; box-shadow: var(--shadow); }
.login { max-width: 340px; margin: 14vh auto; padding: 0 1.2rem; text-align: center; }
.login h1 { margin-top: .6rem; }
.login form { display: grid; gap: .6rem; margin-top: 1.4rem; text-align: left; }
.login p { color: var(--text-2); font-size: .9rem; }
.err { color: var(--crit); }
code { background: var(--surface-2); padding: .05rem .3rem; border-radius: 5px; font-size: .88em; word-break: break-all; }
.rowline { display: flex; gap: .5rem; align-items: center; }
.rowline > :first-child { flex: 1; min-width: 0; }
