/* htrack — minimal mobile-first stylesheet. No framework. */

* { box-sizing: border-box; }

:root {
  --bg: #0f0f10;
  --panel: #1a1a1c;
  --panel-2: #141416;
  --border: #2a2a2c;
  --text: #e8e8e8;
  --muted: #888;
  --accent: #3a7afe;
  --accent-2: #6a78ff;
  --danger: #e66;
  --success: #6ee2a0;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

/* ---------------------------------------------------------------- header */
header {
  padding: 1rem 1rem 0.75rem;
  border-bottom: 1px solid var(--border);
  max-width: 640px;
  margin: 0 auto;
}
.header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
}
header h1 {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}
header h1 #display-name {
  color: var(--muted);
  font-weight: 400;
  font-size: 0.9em;
  margin-left: 0.4rem;
}
#today-date {
  color: var(--muted);
  font-size: 0.9rem;
}

.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  font-size: 1.35rem;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 8px;
  cursor: pointer;
  line-height: 1;
  flex-shrink: 0;
}
.icon-btn:hover, .icon-btn:focus {
  background: var(--panel);
  border-color: var(--border);
  outline: none;
}

/* ------------------------------------------------------------------ main */
main {
  max-width: 640px;
  margin: 0 auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* ------------------------------------------------------------- fast card */
.fast-card {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  padding: 0.85rem 1rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  transition: background 200ms ease, border-color 200ms ease;
}
.fast-card.fasting {
  background: linear-gradient(180deg, #152520, var(--panel));
  border-color: #2d5a46;
}
.fast-info { flex: 1; min-width: 0; }
.fast-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.fast-card.fasting .fast-label { color: var(--success); }
.fast-time {
  font-size: 1.45rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}
.fast-sub {
  font-size: 0.8rem;
  color: var(--muted);
}
.fast-btn {
  font: inherit;
  font-weight: 600;
  padding: 0 1rem;
  min-height: 2.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.fast-card.fasting .fast-btn {
  background: #3a2a2a;
  border-color: #6a3a3a;
  color: #ffbbbb;
}
.fast-btn:active { transform: translateY(1px); }
.fast-btn:disabled { opacity: 0.5; cursor: wait; }

/* ----------------------------------------------------------- quick entry */
.quick-entry {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.entry-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.entry-form .row-main {
  display: flex;
  gap: 0.5rem;
  align-items: end;
}
.entry-form .grow { flex: 1; }
.entry-form label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.entry-form label span {
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.entry-form input[type="number"],
.entry-form input[type="text"],
.entry-form select {
  font: inherit;
  padding: 0.65rem 0.75rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-height: 2.75rem;
  width: 100%;
}
.entry-form select {
  width: auto;
  min-width: 4rem;
  padding-right: 1.5rem;
}
.entry-form input:focus,
.entry-form select:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}
.entry-form button {
  font: inherit;
  font-weight: 600;
  padding: 0 1.25rem;
  background: var(--accent);
  color: white;
  border: 0;
  border-radius: 8px;
  min-height: 2.75rem;
  cursor: pointer;
  white-space: nowrap;
}
.entry-form button:disabled { opacity: 0.5; cursor: wait; }
.entry-form button:active { transform: translateY(1px); }

/* ----------------------------------------------------------------- today */
.today h2,
.trends-head h2 {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: #ccc;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.stat {
  padding: 0.75rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  min-width: 0;
}
.stat .label {
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.stat .value {
  font-size: 1.35rem;
  font-weight: 600;
  margin-top: 0.25rem;
  font-variant-numeric: tabular-nums;
  word-break: break-word;
}
.stat .sub {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

/* ----------------------------------------------------------- entry list */
.entry-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.entry-list li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.6rem 0.5rem 0.75rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
}
.entry-list li.empty {
  color: var(--muted);
  justify-content: center;
  text-align: center;
  padding: 1rem;
  font-style: italic;
}
.entry-body {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem 0.6rem;
  flex: 1;
  min-width: 0;
}
.entry-body .t {
  color: var(--muted);
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}
.entry-body .k {
  color: #aaa;
  font-size: 0.82rem;
}
.entry-body .v {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.entry-body .n {
  color: var(--muted);
  font-size: 0.85rem;
  flex-basis: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.entry-list .del {
  background: transparent;
  border: 0;
  color: #555;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  width: 2rem;
  height: 2rem;
  border-radius: 6px;
  flex-shrink: 0;
}
.entry-list .del:hover,
.entry-list .del:focus {
  background: var(--border);
  color: var(--danger);
  outline: none;
}

/* ---------------------------------------------------------------- trends */
.trends {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.trends-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.trends-head h2 { margin-bottom: 0; }

.range-picker {
  display: flex;
  gap: 0.2rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.2rem;
}
.range-picker button {
  font: inherit;
  padding: 0.3rem 0.75rem;
  background: transparent;
  color: var(--muted);
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 500;
}
.range-picker button.active {
  background: var(--accent);
  color: white;
}

.chart {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem 0.75rem 0.4rem;
}
.chart-label {
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.25rem;
}
.chart-svg {
  width: 100%;
  height: auto;
  display: block;
  aspect-ratio: 640 / 200;
  max-height: 240px;
}

/* ---------------------------------------------------------------- modal */
.modal {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 50;
}
.modal.show { display: block; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}
.modal-panel {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(92vw, 420px);
  max-height: 92vh;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}
.modal-head h2 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.settings-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.settings-form label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.settings-form label span {
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.settings-form input,
.settings-form select {
  font: inherit;
  padding: 0.65rem 0.75rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-height: 2.75rem;
  width: 100%;
}
.settings-form input:focus,
.settings-form select:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}
.settings-form .two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}
.modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 0.5rem;
}
.btn-primary, .btn-ghost {
  font: inherit;
  font-weight: 600;
  padding: 0.65rem 1.25rem;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid var(--border);
  min-height: 2.75rem;
}
.btn-primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.btn-primary:disabled { opacity: 0.5; cursor: wait; }
.btn-ghost {
  background: transparent;
  color: var(--text);
}

/* --------------------------------------------------------------- toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%) translateY(2rem);
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 150ms ease, transform 150ms ease;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  z-index: 100;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast[data-kind="err"] {
  border-color: var(--danger);
  color: #ffd0d0;
}

@media (max-width: 420px) {
  .stats { grid-template-columns: 1fr; }
  .fast-time { font-size: 1.3rem; }
}

/* --------------------------------------------------------------- auth ui */
.header-actions {
  display: flex;
  gap: 0.25rem;
}

.auth-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.auth-overlay[hidden] { display: none; }

body.unauth main,
body.unauth header .icon-btn {
  visibility: hidden;
}

.auth-panel {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
}
.auth-panel h2 {
  margin: 0 0 1rem 0;
  font-size: 1.25rem;
  text-align: center;
  letter-spacing: 0.02em;
}
.auth-panel p {
  margin: 0 0 1rem;
  color: var(--muted);
  text-align: center;
}
.auth-cta {
  display: inline-block;
  text-align: center;
  text-decoration: none;
  width: 100%;
}
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.auth-form[hidden] { display: none; }
.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.auth-form input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
  padding: 0.6rem 0.75rem;
}
.auth-form input:focus {
  border-color: var(--accent);
  outline: none;
}
.auth-switch {
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
  margin-top: 0.25rem;
}
.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  padding: 0;
  cursor: pointer;
  font-size: inherit;
}
.btn-link:hover { text-decoration: underline; }
.auth-error {
  background: rgba(230, 102, 102, 0.12);
  color: var(--danger);
  border: 1px solid rgba(230, 102, 102, 0.35);
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
}
.auth-error[hidden] { display: none; }

/* -------------------------------------------------------- admin invites */
.admin-invites {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.admin-invites[hidden] { display: none; }
.admin-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}
.admin-head h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}
.invite-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.invite-list .empty {
  color: var(--muted);
  font-size: 0.85rem;
}
.invite-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
}
.invite-code {
  font-family: ui-monospace, monospace;
  background: transparent;
  color: var(--text);
  flex: 1;
  overflow-wrap: anywhere;
}
.invite-status {
  color: var(--muted);
  font-size: 0.8rem;
}

/* ── mobile touch handling ───────────────────────────────────────── */
/* On touch devices, treat drags as scrolls — kill long-press text
   selection on UI chrome and the 300ms double-tap-to-zoom delay. Keep
   form inputs selectable so copy-to-clipboard still works there. */
@media (pointer: coarse) {
  body {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    user-select: none;
    -webkit-user-select: none;
  }
  * { touch-action: manipulation; }
  input, textarea, [contenteditable] {
    user-select: text;
    -webkit-user-select: text;
  }
}
