/* Logger — styles.
   Sections: tokens · base · layout & nav · cards & text · buttons & inputs · log view ·
   timeline · bars · stats · friends · settings · sheet · toast · auth · motion */

/* ---- tokens ---- */
:root {
  color-scheme: light dark;
  --bg: #fafafa;
  --card: #ffffff;
  --field: #f2f2f2;
  --fg: #151515;
  --muted: #6b6b6b;
  --border: #e4e4e4;
  --accent: #2563eb;
  --accent-fg: #ffffff;
  --danger: #c0392b;
  --overlay: rgba(0, 0, 0, 0.4);
  --radius: 12px;
  --sp-1: 8px;
  --sp-2: 16px;
  --sp-3: 24px;
  --sp-4: 32px;
  --tap: 44px;
  --nav-h: 56px;
  --font: -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --card: #1c1c1c;
    --field: #262626;
    --fg: #ececec;
    --muted: #9b9b9b;
    --border: #2e2e2e;
    --accent: #6ea0ff;
    --accent-fg: #0b1220;
    --danger: #ff7b6b;
    --overlay: rgba(0, 0, 0, 0.6);
  }
}

/* ---- base ---- */
* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}

body.no-scroll { overflow: hidden; }

h1, h2, h3 { margin: 0; font-weight: 600; line-height: 1.3; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; font-weight: 500; }
p { margin: 0 0 var(--sp-1); }
p:last-child { margin-bottom: 0; }
a { color: inherit; text-decoration: none; }
code { font-family: var(--mono); }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.prewrap { white-space: pre-wrap; overflow-wrap: anywhere; }
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* ---- layout & nav ---- */
.view {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(var(--sp-2) + env(safe-area-inset-top)) var(--sp-2)
           calc(var(--nav-h) + env(safe-area-inset-bottom) + var(--sp-3));
}

.nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-inner { display: flex; width: 100%; }

.nav a {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--nav-h);
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  touch-action: manipulation;
}

.nav a.active { color: var(--accent); }
.nav .brand { display: none; }

@media (min-width: 720px) {
  .nav {
    position: sticky;
    top: 0;
    bottom: auto;
    border-top: 0;
    border-bottom: 1px solid var(--border);
    padding: 0 var(--sp-2);
  }
  .nav-inner { max-width: 720px; margin: 0 auto; gap: var(--sp-1); }
  .nav a { flex: 0 0 auto; padding: 0 var(--sp-2); min-height: 52px; font-size: 15px; }
  .nav .brand { display: flex; align-items: center; margin-right: auto; font-weight: 700; }
  .view { padding-top: var(--sp-3); padding-bottom: var(--sp-4); }
}

/* ---- cards & text ---- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-2);
  margin-bottom: var(--sp-2);
}

.card > h2 { margin-bottom: var(--sp-1); }

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--sp-1);
  margin-bottom: var(--sp-1);
}

.row-between {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--sp-1);
}

.pagehead {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: var(--tap);
  margin-bottom: var(--sp-2);
}

/* The back link truncates with an ellipsis (a block container, not a flex item that would be
   blockified to `flex`, where text-overflow does not apply) so a long label never pushes
   the friend's name off the screen. */
.pagehead .back {
  display: block;
  min-width: 0;
  max-width: 60%;
  line-height: var(--tap);
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pagehead h1 { min-width: 0; overflow-wrap: anywhere; }

.sect { margin: var(--sp-3) 0 var(--sp-1); }

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--c, var(--muted));
  margin-right: 6px;
  flex: 0 0 auto;
}

/* ---- buttons & inputs ---- */
button, input, select, textarea { font: inherit; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 0 var(--sp-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--fg);
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
}

.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn.danger { color: var(--danger); }
.btn.icon { width: var(--tap); padding: 0; font-size: 24px; line-height: 1; }
.btn.small { padding: 0 12px; font-size: 14px; }
.btn.wide { width: 100%; margin-top: var(--sp-1); }
.btn:disabled { opacity: 0.5; cursor: default; }

.linkbtn {
  min-height: var(--tap);
  padding: 0 var(--sp-1);
  border: 0;
  background: none;
  color: var(--accent);
  cursor: pointer;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-1);
  margin-top: var(--sp-1);
}

.actions .grow { flex: 1; }

/* A link-style button inside a sentence: text-sized, with a taller invisible tap area. */
p .linkbtn { display: inline; min-height: 0; margin: -10px 0; padding: 10px 2px; text-align: left; }

label {
  display: block;
  margin-bottom: var(--sp-1);
  font-size: 13px;
  color: var(--muted);
}

label > input, label > select, label > textarea { margin-top: 4px; }
label > small { display: block; margin-top: 4px; }

input:not([type="color"]), select, textarea {
  display: block;
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  font-size: 16px;
  color: var(--fg);
  background: var(--field);
  border: 1px solid var(--border);
  border-radius: 10px;
}

textarea { resize: vertical; line-height: 1.4; }

input[type="color"] {
  width: var(--tap);
  height: var(--tap);
  padding: 3px;
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--field);
}

input:focus-visible, select:focus-visible, textarea:focus-visible,
.btn:focus-visible, .chip:focus-visible, .linkbtn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ---- log view ---- */
.daynav {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  margin-bottom: var(--sp-2);
}

.daynav h1 { flex: 1; text-align: center; font-size: 18px; }

.now { border-left: 4px solid var(--c, var(--border)); }

.now-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-1);
}

.now-head .n { display: inline-flex; align-items: center; font-size: 18px; }
.now-head .since { margin-left: var(--sp-1); font-size: 15px; }
.now .now-head + p { margin-top: var(--sp-1); }

.now-since {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: var(--sp-1) 0;
}

/* `input.inline-time` so this outranks the generic input rule above (same specificity, later). */
input.inline-time { display: inline-block; width: auto; padding: 4px 8px; }

.save-ind { min-height: 16px; font-size: 12px; text-align: right; }

.chipsec { margin-bottom: var(--sp-2); }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-1);
  margin-bottom: var(--sp-1);
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--card);
  color: var(--fg);
  cursor: pointer;
  touch-action: manipulation;
}

.chip.active {
  padding: 0 13px;
  border: 2px solid var(--c);
  background: color-mix(in srgb, var(--c) 14%, var(--card));
  font-weight: 600;
}

/* ---- timeline ---- */
.tl { display: flex; flex-direction: column; }

.tl .row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 6px;
  width: 100%;
  min-height: var(--tap);
  padding: 10px 0;
  border: 0;
  border-top: 1px solid var(--border);
  background: none;
  color: var(--fg);
  font-size: 15px;
  text-align: left;
  cursor: pointer;
}

.tl .row:first-child { border-top: 0; }
.tl div.row { cursor: default; }
.tl .sep, .tl .d { color: var(--muted); }
.tl .t, .tl .d { font-variant-numeric: tabular-nums; }
.tl .n { display: inline-flex; align-items: center; }

.tl .note {
  flex-basis: 100%;
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Read-only timelines (a friend's day) have no edit sheet to reveal the full note, so it wraps. */
.tl.ro .note { white-space: pre-wrap; overflow-wrap: anywhere; }

/* Idle stretches and off periods: quieter than entries. */
.tl .gap { color: var(--muted); font-size: 13px; }

/* ---- bars (plain divs, one segment per category) ---- */
.bar {
  display: flex;
  gap: 2px;
  width: 100%;
  height: 8px;
  margin: var(--sp-1) 0;
}

.bar.track { background: var(--field); border-radius: 4px; }
.bar .seg { border-radius: 4px; min-width: 2px; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  font-size: 13px;
  color: var(--muted);
}

.legend span { display: inline-flex; align-items: center; }

/* ---- stats ---- */
.segtabs {
  display: flex;
  margin-bottom: var(--sp-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--card);
}

.segtabs button {
  flex: 1;
  min-height: var(--tap);
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
  touch-action: manipulation;
}

.segtabs button.active { background: var(--fg); color: var(--bg); }

.tiles {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--sp-1);
  margin-bottom: var(--sp-2);
}

@media (min-width: 560px) {
  .tiles { grid-template-columns: repeat(4, 1fr); }
}

.tile {
  padding: 12px 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
}

.tiles.three { grid-template-columns: repeat(3, 1fr); }

.tile .v { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.tile .k { font-size: 12px; color: var(--muted); }

.li {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 2px 12px;
  align-items: center;
  padding: 6px 0;
}

/* A block container, not flex: text-overflow only ellipsizes a block's own inline content. */
.li .n {
  display: block;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.li .n .dot { vertical-align: middle; }

.li .v, .li .p { font-variant-numeric: tabular-nums; }
.li .p { min-width: 3.5ch; text-align: right; }
.li .bar { grid-column: 1 / -1; margin: 2px 0 2px; }

.dayrow {
  display: grid;
  grid-template-columns: 64px 1fr 68px;
  gap: var(--sp-1);
  align-items: center;
  min-height: var(--tap);
  border-top: 1px solid var(--border);
}

.dayrow:first-of-type { border-top: 0; }
.dayrow .k { font-size: 14px; }
.dayrow .v { font-size: 14px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }

/* ---- friends ---- */
.listrow {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--sp-1);
  min-height: var(--tap);
  padding: 6px 0;
  border-top: 1px solid var(--border);
}

.listrow:first-child { border-top: 0; }

.invite {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-1);
}

.invite code {
  flex: 1;
  font-size: 18px;
  letter-spacing: 1px;
  -webkit-user-select: all;
  user-select: all;
}

.card > .invite { margin: var(--sp-1) 0; }

.sharenote { margin-bottom: var(--sp-2); }

/* "What friends see" in Settings: one row per friend, with the category boxes underneath. */
.sharerow { padding: var(--sp-1) 0; border-top: 1px solid var(--border); }
.sharerow:first-of-type { border-top: 0; }
.sharerow .row-between { align-items: center; }
.sharerow select { width: auto; max-width: 72%; flex: 0 0 auto; }
.sharerow strong { min-width: 0; overflow-wrap: anywhere; }
.checks { display: flex; flex-wrap: wrap; gap: 0 var(--sp-2); margin-top: 4px; }

label.check {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  margin: 0;
  font-size: 15px;
  color: var(--fg);
  cursor: pointer;
}

/* After the generic input rule: a checkbox is a small box, not a full-width field. */
input[type="checkbox"] {
  display: inline-block;
  width: 22px;
  height: 22px;
  min-height: 0;
  margin: 0 8px 0 0;
  padding: 0;
  flex: 0 0 auto;
  accent-color: var(--accent);
}

.member { display: block; }
.member .bar { margin-bottom: 0; }
.member .now-line { display: flex; align-items: center; gap: 4px; margin: 4px 0; }

/* ---- settings ---- */
.editrow {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  margin-bottom: var(--sp-1);
}

.editrow input:not([type="color"]) { flex: 1; min-width: 0; }
.editrow select { flex: 0 1 40%; min-width: 0; }
.editrow .btn { flex: 0 0 auto; }
.card h3 { display: flex; align-items: center; margin: var(--sp-1) 0 4px; }

/* ---- sheet (entry add / edit) ---- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: var(--overlay);
}

.sheet {
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  overflow: auto;
  padding: var(--sp-2) var(--sp-2) calc(var(--sp-2) + env(safe-area-inset-bottom));
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  animation: rise 0.2s ease-out;
}

.sheet h2 { margin-bottom: var(--sp-2); }

@media (min-width: 720px) {
  .overlay { align-items: center; padding: var(--sp-2); }
  .sheet { max-width: 480px; border-radius: var(--radius); }
}

@keyframes rise {
  from { transform: translateY(24px); opacity: 0; }
}

/* ---- toast ---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + var(--sp-2));
  z-index: 30;
  max-width: calc(100% - 32px);
  padding: 12px 16px;
  transform: translateX(-50%);
  background: var(--fg);
  color: var(--bg);
  border-radius: 10px;
  font-size: 14px;
  text-align: center;
}

@media (min-width: 720px) {
  .toast { bottom: var(--sp-3); }
}

/* ---- auth ---- */
.auth {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-2);
}

.authbox {
  width: 100%;
  max-width: 360px;
  padding: var(--sp-3);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
}

.authbox h1 { margin-bottom: var(--sp-2); font-size: 24px; }
.authbox label { text-align: left; }
.err { min-height: 20px; margin: 0 0 var(--sp-1); color: var(--danger); font-size: 14px; }

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