/* LogBook's stylesheet.
 *
 * One file, no build step, no framework -- the same rule the Animals repo keeps, for
 * the same reason: what is in the repository is exactly what the browser gets.
 *
 * Written mobile-first. The screens this application has are a form, a list and a
 * chart, and all three want the same narrow measure on a phone as on a laptop, so
 * there is one column and a max-width rather than a set of breakpoints.
 */

:root {
  --ink: #1a1c1f;
  --ink-soft: #5a6169;
  --paper: #fbfbfa;
  --card: #ffffff;
  --rule: #dfe1e4;
  --accent: #2f5d8a;
  --accent-ink: #ffffff;
  --danger: #a3372c;
  --warn-bg: #fdf3d8;
  --warn-ink: #6b5310;
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e9eaec;
    --ink-soft: #a2a9b2;
    --paper: #16181b;
    --card: #1e2125;
    --rule: #33373d;
    --accent: #7db0e0;
    --accent-ink: #12161a;
    --danger: #e9857a;
    --warn-bg: #3a3320;
    --warn-ink: #e8d9a6;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 1rem;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

#page {
  max-width: 34rem;
  margin: 0 auto;
}

/* --- the environment banner ---------------------------------------------- */
/* Absent entirely in production (web.py sends no name), so this can be loud. */
.environment {
  margin: 0 0 0.75rem;
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius);
  background: var(--warn-bg);
  color: var(--warn-ink);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-align: center;
}

/* --- header --------------------------------------------------------------- */

header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 1.25rem;
}

h1 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: -0.01em;
}

h1 a {
  color: inherit;
  text-decoration: none;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: var(--radius);
  color: var(--ink-soft);
  font-size: 1.1rem;
  text-decoration: none;
  cursor: pointer;
}

.icon-button:hover { background: var(--rule); }

/* The cog's own marker would sit beside the glyph. */
.settings > summary { list-style: none; }
.settings > summary::-webkit-details-marker { display: none; }

.settings {
  position: relative;
}

.settings-panel {
  position: absolute;
  right: 0;
  z-index: 10;
  min-width: min(20rem, 85vw);
  margin-top: 0.4rem;
  padding: 0.75rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: 0 6px 20px rgb(0 0 0 / 12%);
}

/* The sign-out form is lifted onto the disclosure's summary line: inside the summary
   it would toggle the disclosure, and inside the body it would vanish when closed. */
.control-with-action {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
}

.control { flex: 1; min-width: 0; }

.control > summary {
  cursor: pointer;
  list-style-position: outside;
}

.control .label {
  display: block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
}

.control .value {
  display: block;
  overflow-wrap: anywhere;
}

.control-body { padding: 0.5rem 0 0; }

.control-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.not-you {
  margin-left: 0.4rem;
  font-size: 0.85rem;
  color: var(--accent);
}

.describe {
  margin: 0;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

/* --- text ----------------------------------------------------------------- */

.prompt {
  font-size: 1.15rem;
  font-weight: 600;
  margin-top: 0;
}

.note {
  font-size: 0.875rem;
  color: var(--ink-soft);
}

.error {
  padding: 0.6rem 0.75rem;
  border-left: 3px solid var(--danger);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: color-mix(in srgb, var(--danger) 8%, transparent);
  color: var(--danger);
}

code {
  padding: 0.1em 0.3em;
  border-radius: 4px;
  background: var(--rule);
  font-size: 0.9em;
}

a { color: var(--accent); }

/* --- forms ---------------------------------------------------------------- */

form { margin: 1rem 0; }

label {
  display: block;
  margin-bottom: 0.3rem;
  font-size: 0.875rem;
  font-weight: 600;
}

input[type="email"],
input[type="text"],
input[type="date"],
input[type="time"],
input[type="number"] {
  width: 100%;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink);
  /* 16px or larger, or iOS Safari zooms the page when the field is focused. */
  font-size: 1rem;
}

input:focus-visible,
button:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.remember {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.75rem 0;
  font-weight: 400;
}

.remember input { width: auto; }

button {
  padding: 0.6rem 1.1rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

button:hover { filter: brightness(1.08); }

/* A button that is really a link: used where a GET form is the no-script way to
   reach another screen. */
button.plain {
  padding: 0.3rem 0;
  border: none;
  background: none;
  color: var(--accent);
  font-weight: 400;
  text-decoration: underline;
}

button.danger { background: var(--danger); }
button.plain.danger { background: none; color: var(--danger); }

.choices {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.summary-action { margin: 0; }

/* --- the heading's back arrow -------------------------------------------- */

.heading {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.icon-button.back {
  /* A little larger than the cog: it is the control people reach for most, and on a
     phone it is the one they reach for with a thumb. */
  font-size: 1.25rem;
  margin-left: -0.35rem;
}

h2 {
  margin: 1.75rem 0 0.5rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--rule);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

/* --- lists of things ------------------------------------------------------ */

.rows {
  margin: 0.5rem 0 1.25rem;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--rule);
}

.rows > li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--rule);
}

.row-name {
  flex: 1;
  min-width: 8rem;
  font-weight: 600;
  /* Only a link is coloured like one. A row whose name is not clickable -- the Event
     Date metric, or any metric on the Entry screen -- must not look as though it is. */
  color: inherit;
  text-decoration: none;
  overflow-wrap: anywhere;
}

a.row-name { color: var(--accent); }
a.row-name:hover { text-decoration: underline; }

/* The Event Date metric, which is not a link because there is nothing to change. */
.row-name.fixed {
  color: var(--ink-soft);
  font-weight: 400;
}

.metrics > li { align-items: baseline; }

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  justify-content: flex-end;
}

.tag {
  padding: 0.1rem 0.45rem;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--card);
  font-size: 0.75rem;
  color: var(--ink-soft);
  white-space: nowrap;
}

.tag.link {
  border-color: var(--accent);
  color: var(--accent);
  text-decoration: none;
}

.tag.link:hover { text-decoration: underline; }

/* --- forms that sit on one line ------------------------------------------- */

.inline {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
}

.inline input[type="text"] { flex: 1; min-width: 6rem; }

.choices > li { padding: 0.35rem 0; }

select {
  width: 100%;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink);
  font-size: 1rem;
}

.only {
  font-weight: 400;
  color: var(--ink-soft);
}

.danger-link { color: var(--danger); }

/* Present to a screen reader, invisible on screen: a label every field needs but that
   would be noise repeated down a list of identical rows. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* --- the entry form ------------------------------------------------------- */

.saved {
  margin: 0 0 1rem;
  padding: 0.5rem 0.75rem;
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  font-size: 0.9rem;
}

/* The date, and the button that re-reads the day it names. */
.day {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  margin-top: 1rem;
}

.day-field { flex: 1; }
.day-field label { margin-bottom: 0.3rem; }
.day button { padding-bottom: 0.7rem; }

.field { margin-top: 1rem; }

/* A field the last Update could not accept keeps what was typed and says why. */
.field-wrong input,
.field-wrong select,
.field-wrong textarea { border-color: var(--danger); }

.field-error {
  margin: 0.35rem 0 0;
  padding: 0.35rem 0.5rem;
  font-size: 0.85rem;
}

textarea {
  width: 100%;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
  resize: vertical;
}

/* Update is the only thing on this screen that writes, so it stands alone. */
.field + button[value="update"] { margin-top: 1.5rem; }

/* --- trends --------------------------------------------------------------- */

/* Revealed by static/trends.js. Hidden until then, because an empty grey box is
   worse than no box: the table below carries the same numbers either way. */
.chart {
  position: relative;
  height: 320px;
  margin: 1rem 0 1.5rem;
  padding: 0.5rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--card);
}

.ticks > li { align-items: center; }

.tick {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex: 1;
  margin: 0;
  font-weight: 400;
  cursor: pointer;
}

.tick input { width: auto; }

.range {
  display: flex;
  gap: 0.75rem;
  margin: 0.5rem 0 1rem;
}

.range .day-field { flex: 1; }

.plain-link {
  color: var(--accent);
  font-size: 0.9rem;
}

.go-to-trends {
  margin-top: 1.25rem;
}

.go-to-trends a {
  display: inline-block;
  padding: 0.5rem 1rem;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.go-to-trends a:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }

/* A wide table scrolls inside its own box rather than pushing the page sideways. */
.table-scroll {
  overflow-x: auto;
  margin-bottom: 1.5rem;
}

.readings {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.readings th,
.readings td {
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--rule);
  text-align: left;
  white-space: nowrap;
}

.readings thead th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
}

.readings tbody th { font-weight: 600; }
