/* Pääpaletti: pinkki #FFA8CD, valkoinen #F9F8F5, musta #0B051D, persikka #FFCBA4.
   --jam-edge ja --gain-edge ovat saman sävyn tummempia versioita viivoille ja reunoille,
   jotta vaaleat värit erottuvat vaalealla pohjalla. */
:root {
  --pink: #FFA8CD; --white: #F9F8F5; --black: #0B051D; --peach: #FFCBA4;
  --bg: var(--white); --surface: #ffffff; --ink: var(--black); --ink2: #4a4560; --muted: #77728a;
  --line: #e6e3ec; --grid: #efedf2; --zero: #8a8599;
  --jam: var(--pink); --jam-edge: #D63F86;
  --long: var(--black);
  --gain: var(--peach); --gain-edge: #C9773B; --drain: #cdc9d7;
  --accent: var(--pink); --accent-ink: var(--black); --link: var(--black);
  --good: #2e7d4f; --warn: #a8640b; --bad: #b3261e;
  --radius: 12px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--black); --surface: #170F2E; --ink: var(--white); --ink2: #c9c5d6; --muted: #8f89a6;
    --line: #2c2448; --grid: #221a3b; --zero: #7d7796;
    --jam: var(--pink); --jam-edge: var(--pink);
    --long: var(--peach);
    --gain: var(--peach); --gain-edge: var(--peach); --drain: #4d4568;
    --accent: var(--pink); --accent-ink: var(--black); --link: var(--pink);
    --good: #7fd6a0; --warn: #f2b45c; --bad: #ff8a80;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 system-ui, "Segoe UI", Roboto, sans-serif; }
a { color: var(--link); }
h1 { font-size: 1.3rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 .6rem; }
small, .muted, .hint { color: var(--muted); }
.hint { font-size: .88rem; margin: .4rem 0; }
.center { text-align: center; margin: .2rem 0 .6rem; }

header { position: sticky; top: 0; z-index: 5; background: var(--surface); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 1rem; padding: .5rem 1rem; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: .45rem; font-weight: 700; color: var(--ink); text-decoration: none; }
nav { display: flex; gap: .25rem; flex-wrap: wrap; }
nav a { padding: .4rem .7rem; border-radius: 8px; text-decoration: none; color: var(--ink2); }
nav a.active { background: var(--accent); color: var(--accent-ink); }
main { max-width: 860px; margin: 0 auto; padding: 1rem; padding-bottom: 5rem; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; margin-bottom: 1rem; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .4rem; }
.pager h1 { text-align: center; }
.pager h1 small { font-weight: 400; font-size: .85rem; }
.pager button { font-size: 1.1rem; min-width: 3rem; }

button, .btn { font: inherit; padding: .5rem .9rem; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); cursor: pointer; text-decoration: none; display: inline-block; }
button:hover, .btn:hover { border-color: var(--zero); }
.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.danger { color: var(--bad); }
button.link { border: 0; background: none; padding: 0; color: var(--link); text-decoration: underline; }
button.link.danger { color: var(--bad); }
.actions { display: flex; gap: .6rem; margin-top: 1rem; }
.actions.wrap { flex-wrap: wrap; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: .4rem; }
.row-between h1, .row-between h2 { margin: 0; }

/* lomakkeet */
.field { display: flex; flex-direction: column; gap: .25rem; margin: .7rem 0; }
.field > span { font-size: .92rem; color: var(--ink2); }
.field small { font-size: .8rem; }
input, select { font: inherit; padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); }
input[type=range] { padding: 0; accent-color: var(--accent); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.types { border: 0; padding: 0; margin: .8rem 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .45rem; }
.types legend { font-size: .92rem; color: var(--ink2); margin-bottom: .35rem; }
.type-btn { text-align: left; display: flex; flex-direction: column; gap: .1rem; }
.type-btn small { font-size: .75rem; }
.type-btn.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.type-btn.on small { color: inherit; opacity: .85; }
.quick { display: flex; gap: .35rem; flex-wrap: wrap; }
.quick button { padding: .25rem .6rem; font-size: .85rem; }
.effect { background: var(--bg); border-radius: 8px; padding: .6rem .8rem; margin: .8rem 0 0; }
.inline { display: flex; gap: .4rem; align-items: center; font-size: .92rem; }
.params { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 0 1rem; }

/* purkit */
.jars { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.jar { margin: 0; display: flex; flex-direction: column; align-items: center; text-align: center; }
.jar svg { width: 110px; height: auto; }
.jar figcaption { display: flex; flex-direction: column; gap: .1rem; font-size: .92rem; }
.jar figcaption span { color: var(--ink2); }
.jar-lid { fill: var(--peach); stroke: var(--ink2); stroke-width: 1.5; }
.jar-glass { fill: var(--bg); }
.jar-outline { fill: none; stroke: var(--ink2); stroke-width: 2.5; }
.jar-over { stroke: var(--bad); stroke-dasharray: 6 4; }
.jar-num { font-size: 26px; font-weight: 700; fill: var(--ink); paint-order: stroke; stroke: var(--surface); stroke-width: 5px; }

.status { border-radius: 10px; padding: .6rem .9rem; margin: 0 0 1rem; border: 1px solid var(--line); background: var(--surface); }
.status.bad { color: var(--bad); border-color: var(--bad); }
.status.warn { color: var(--warn); border-color: var(--warn); }
.status.good { color: var(--good); border-color: var(--good); }

/* kaaviot */
.chart-wrap { width: 100%; }
.chart { width: 100%; height: auto; display: block; touch-action: pan-y; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .zero { stroke: var(--zero); stroke-width: 1.2; }
.chart .tick { font-size: 11px; fill: var(--muted); }
.chart .tick.strong { fill: var(--ink); font-weight: 700; }
.chart .tick.feel { fill: var(--ink2); }
.chart .series-day { fill: none; stroke: var(--jam-edge); stroke-width: 2; stroke-linejoin: round; }
.chart .area { fill: var(--jam); opacity: .35; }
.chart .gain { fill: var(--gain); stroke: var(--gain-edge); stroke-width: 1; }
.chart .drain { fill: var(--drain); }
.chart .t-gain { fill: var(--gain-edge); }
.chart .t-drain { fill: var(--drain); }
.chart .cross { stroke: var(--ink2); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .cross-dot { fill: var(--jam-edge); stroke: var(--surface); stroke-width: 2; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .bar-day { fill: var(--jam); stroke: var(--jam-edge); stroke-width: 1; }
.chart .bar-over { fill: url(#hatch); stroke: var(--jam-edge); stroke-width: 1.5; }
.chart .hatch-bg { fill: var(--surface); }
.chart .hatch-line { stroke: var(--jam-edge); stroke-width: 3; }
.chart .bar-long { fill: var(--long); }
.chart .series-long { fill: none; stroke: var(--long); stroke-width: 2; stroke-linejoin: round; }
.chart .dot-long { fill: var(--long); stroke: var(--surface); stroke-width: 2; }
.chart .dot-long.hollow { fill: var(--surface); stroke: var(--long); }
.chart .hit-band { fill: transparent; cursor: pointer; }
.chart .hit-band:hover { fill: var(--ink); opacity: .04; }

.legend { display: flex; gap: 1.1rem; flex-wrap: wrap; font-size: .85rem; color: var(--ink2); margin-bottom: .4rem; }
.legend span { display: inline-flex; align-items: center; gap: .4rem; }
.sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.sw-day { background: var(--jam); border: 1px solid var(--jam-edge); }
.sw-over { border: 1.5px solid var(--jam-edge); background: repeating-linear-gradient(45deg, var(--jam-edge) 0 2px, transparent 2px 5px); }
.sw-line { width: 18px; height: 2px; background: var(--long); display: inline-block; position: relative; }
.sw-line::after { content: ""; position: absolute; left: 5px; top: -3px; width: 8px; height: 8px; border-radius: 50%; background: var(--long); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .7rem; margin-bottom: 1rem; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem .9rem; display: flex; flex-direction: column; gap: .1rem; }
.tile span { font-size: .85rem; color: var(--ink2); }
.tile b { font-size: 1.5rem; }
.tile small { font-size: .8rem; }

table { border-collapse: collapse; width: 100%; font-size: .9rem; margin-top: .5rem; }
th, td { text-align: left; padding: .35rem .4rem; border-bottom: 1px solid var(--line); }
.types-table input { width: 100%; }
.types-table td:last-child { width: 2rem; text-align: center; }
details summary { cursor: pointer; color: var(--link); margin-top: .5rem; }

.feel { display: flex; gap: .5rem; }
.feel button { width: 3rem; height: 3rem; font-size: 1.1rem; }
.feel button.on { background: var(--long); color: var(--surface); border-color: var(--long); }

.entries { list-style: none; padding: 0; margin: 0; }
.entries li { display: grid; grid-template-columns: 1fr auto auto; gap: .3rem 1rem; align-items: center; padding: .6rem 0; border-bottom: 1px solid var(--line); }
.entries li:last-child { border-bottom: 0; }
.entries .eff { font-size: .85rem; color: var(--ink2); white-space: nowrap; }
.entries .note { font-size: .85rem; color: var(--ink2); font-style: italic; }
.row-actions { display: flex; gap: .8rem; font-size: .88rem; }
.hist-date { font-size: 1rem; margin: 1.1rem 0 .2rem; display: flex; gap: .7rem; flex-wrap: wrap; align-items: baseline; }
.hist-date span { font-weight: 400; font-size: .85rem; }

/* v2: pikavalinnat, kopiointi, kalibrointi, varmuuskopiomuistutus */
.recent { margin: .4rem 0 .2rem; }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .3rem; }
.chip { padding: .35rem .7rem; border-radius: 999px; font-size: .88rem; }
.chip small { font-size: .78rem; }
.copy-box { display: flex; gap: .7rem; align-items: center; flex-wrap: wrap; margin-top: .7rem; padding-top: .7rem; border-top: 1px dashed var(--line); }
.banner { display: flex; gap: .7rem; align-items: center; flex-wrap: wrap; }
.banner button { padding: .3rem .7rem; }
.link-card { display: flex; flex-direction: column; gap: .2rem; text-decoration: none; color: var(--ink); }
.link-card:hover { border-color: var(--zero); }
.hints { padding-left: 1.1rem; margin: .3rem 0; }
.hints li { margin-bottom: .5rem; }
.chart-small { max-width: 560px; }
section.status { margin-bottom: 1rem; }

/* v3: käyttäjät ja synkronointi */
#status-bar { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; margin-left: auto; order: 2; }
header nav { order: 3; }
.pill { display: inline-flex; align-items: center; gap: .3rem; font-size: .8rem; padding: .2rem .6rem; border-radius: 999px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink2); text-decoration: none; line-height: 1.4; }
button.pill { cursor: pointer; }
.pill.warn { color: var(--warn); border-color: var(--warn); }
.profiles { list-style: none; padding: 0; margin: .4rem 0 .8rem; }
.profiles li { display: flex; justify-content: space-between; align-items: center; gap: .6rem; flex-wrap: wrap; padding: .5rem 0; border-bottom: 1px solid var(--line); }
.profiles li .row-actions button { padding: .3rem .7rem; }
.profiles li .row-actions button.link { padding: 0; }
.mt { margin-top: 1.2rem; }
code { font-size: .85em; background: var(--bg); padding: .05rem .3rem; border-radius: 4px; }

#tip { position: fixed; z-index: 20; pointer-events: none; background: var(--ink); color: var(--bg); font-size: .82rem;
  padding: .35rem .55rem; border-radius: 6px; max-width: 280px; }
#toast { position: fixed; z-index: 30; left: 50%; bottom: 1.2rem; transform: translateX(-50%); background: var(--ink); color: var(--bg);
  padding: .6rem 1rem; border-radius: 10px; }

@media (max-width: 640px) {
  header { padding: .4rem .6rem; }
  nav { position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface); border-top: 1px solid var(--line);
    justify-content: space-around; padding: .35rem .2rem calc(.35rem + env(safe-area-inset-bottom)); gap: 0; }
  nav a { font-size: .85rem; padding: .45rem .5rem; }
  main { padding: .7rem; padding-bottom: 6rem; }
  #toast { bottom: 4.5rem; }
  .entries li { grid-template-columns: 1fr; }
  .chart-wrap { overflow-x: auto; }
  .chart { min-width: 560px; }
  .chart.chart-small { min-width: 0; }
  /* isommat kosketusalueet ja tallennusnappi aina näkyvissä */
  .type-btn { min-height: 52px; }
  .quick button { padding: .45rem .7rem; }
  #entry-form .actions { position: sticky; bottom: calc(3.6rem + env(safe-area-inset-bottom)); background: var(--surface);
    margin: 1rem -1.1rem -1rem; padding: .7rem 1.1rem; border-top: 1px solid var(--line); border-radius: 0 0 var(--radius) var(--radius); }
  #entry-form .actions .primary { flex: 1; padding: .75rem; }
  .pager button { min-width: 3.2rem; min-height: 2.8rem; }
  .row-actions { gap: 1.4rem; }
  .row-actions a, .row-actions button { padding: .3rem 0; }
  .entries .eff { white-space: normal; }
}
