/* Next — single style sheet.
   No preprocessor and no build: native CSS variables and nothing else.
   The base (sign-in, fields, buttons, notices, dialogs) is the one of the
   sibling apps; what is Next's own is the step line and the overview. */

:root {
  --accent: #4f5bd5;
  --accent-soft: #e6e8fb;
  --accent-text: #ffffff;

  /* How long a branch has gone without moving. The same colours on the board,
     in the project view and in the overview. */
  --fresh: #2e9d62;
  --stalled: #d9870b;
  --stuck: #d1453b;
  --paused: #8a90a0;

  --bg: #f4f5f9;
  --panel: #ffffff;
  --hover: #eceef4;
  --text: #1b1e28;
  --text-muted: #5d6475;
  --border: #dfe2ea;
  --shadow: 0 1px 3px rgba(16, 20, 40, .10), 0 6px 20px rgba(16, 20, 40, .06);

  --radius: 10px;
  --topbar-height: 56px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* The dark theme hangs from `data-theme`, which is always "light" or "dark":
   theme.js resolves it before painting, and then the user's saved theme. */
:root { color-scheme: light; }

:root[data-theme="dark"] {
  color-scheme: dark;
  --accent: #8d95ff;
  --accent-soft: #262a4d;
  --accent-text: #10122a;
  --fresh: #4cc184;
  --stalled: #f0a531;
  --stuck: #f06a60;
  --paused: #7d8394;
  --bg: #13151c;
  --panel: #1c1f28;
  --hover: #262a36;
  --text: #e7e9f0;
  --text-muted: #9aa1b2;
  --border: #2e323f;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }
::selection { background: var(--accent); color: #fff; }

/* The hidden attribute wins over any display below: without this, a rule of
   our own with display beats the browser's and hiding doesn't hide. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;              /* only the central area scrolls */
  overscroll-behavior: none;
}

body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }

/* -------------------------------- sign-in -------------------------------- */

.login {
  height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(150deg, var(--accent) 0%, #1c2150 100%);
}

.login__card {
  width: min(380px, 100%);
  background: var(--panel);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 28px 24px;
  display: grid;
  gap: 14px;
}

.login__brand { display: flex; align-items: center; gap: 14px; margin-bottom: 6px; }
.login__brand img { border-radius: 12px; }
.login__brand h1 { font-size: 22px; margin: 0; }
.login__tagline { margin: 2px 0 0; color: var(--text-muted); font-size: 13.5px; }
.login__error { margin: 0; color: var(--stuck); font-size: 14px; }

.field { display: grid; gap: 5px; }
.field > span, .field > label { font-size: 13px; color: var(--text-muted); }
.field > label { justify-self: start; cursor: pointer; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}
.field textarea { resize: vertical; min-height: 44px; line-height: 1.4; }
.field input:focus-visible, .field select:focus-visible, .field textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.field__hint { color: var(--text-muted); font-size: 12.5px; margin: 0; }

/* -------------------------------- buttons -------------------------------- */

.btn {
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  cursor: pointer;
  transition: background .12s ease;
}
.btn:hover { background: var(--hover); }
.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}
.btn--primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn--danger { background: var(--stuck); border-color: var(--stuck); color: #fff; font-weight: 600; }
.btn--danger:hover { filter: brightness(1.08); background: var(--stuck); }
.btn[disabled] { opacity: .55; cursor: default; }
.btn--small { padding: 6px 12px; font-size: 14px; }

.icon-btn {
  width: 40px;
  height: 40px;
  flex: none;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  font-size: 18px;
  text-decoration: none;
}
.icon-btn:hover { background: var(--hover); }

.link-btn {
  border: 0;
  background: none;
  padding: 4px 2px;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.link-btn:hover { text-decoration: underline; }
.link-btn--danger { color: var(--stuck); }

.chip {
  flex: none;
  padding: 6px 13px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  font-size: 13.5px;
  cursor: pointer;
  white-space: nowrap;
}
.chip:hover { background: var(--hover); }
.chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.status-chip {
  flex: none;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--hover);
  color: var(--text-muted);
}
.status-chip--closed { text-decoration: line-through; }

.caption {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .03em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* ------------------------------- structure ------------------------------- */

.app { height: 100%; display: flex; flex-direction: column; }

.topbar {
  flex: 0 0 auto;
  height: calc(var(--topbar-height) + var(--safe-top));
  padding: var(--safe-top) 8px 0 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 17px;
  text-decoration: none;
}
.topbar__brand img { border-radius: 6px; }

.tabs { flex: 1; display: flex; justify-content: center; gap: 4px; min-width: 0; }
.tab {
  padding: 7px 14px;
  border-radius: 999px;
  text-decoration: none;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 14.5px;
  white-space: nowrap;
}
.tab:hover { background: var(--hover); }
.tab[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }

@media (max-width: 480px) {
  .topbar__brand span { display: none; }
  .tabs { justify-content: flex-start; }
}

.banner {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 7px 12px;
  font-size: 13.5px;
  text-align: center;
}
.banner button {
  border: 0;
  background: transparent;
  color: inherit;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
  padding: 2px 4px;
}
.banner--offline { background: color-mix(in srgb, var(--stalled) 22%, var(--panel)); }
.banner--update { background: var(--accent); color: var(--accent-text); }

.main-area {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 14px 14px calc(96px + var(--safe-bottom));
}

.fab {
  position: fixed;
  right: 18px;
  bottom: calc(18px + var(--safe-bottom));
  z-index: 25;
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 18px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 28px;
  line-height: 1;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 45%, transparent);
  cursor: pointer;
}
.fab:hover { filter: brightness(1.08); }

.loading { color: var(--text-muted); text-align: center; margin-top: 12vh; }

.empty {
  max-width: 460px;
  margin: 10vh auto 0;
  text-align: center;
  color: var(--text-muted);
}
.empty h2 { color: var(--text); font-size: 20px; margin: 0 0 8px; }
.empty p { margin: 0 0 18px; }
.empty__note { font-size: 13.5px; margin-top: 18px !important; }
.empty--short { margin-top: 6vh; }

/* --------------------------------- board --------------------------------- */

.board, .overview, .project-view { max-width: 1100px; margin: 0 auto; }

.filters {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 12px;
  scrollbar-width: none;
}
.filters::-webkit-scrollbar { display: none; }

.projects { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }

.project {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 12px 8px;
  transition: opacity .15s ease;
}
/* What has been idle for a while is still there, but doesn't compete for attention. */
.project.is-dimmed { opacity: .6; }
.project.is-dimmed:hover, .project.is-dimmed:focus-within { opacity: 1; }

.project__header {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 10px;
  margin-bottom: 4px;
}
.project__name {
  font-weight: 700;
  font-size: 16px;
  text-decoration: none;
  min-width: 0;
  overflow-wrap: anywhere;
}
.project__name:hover { text-decoration: underline; }
.project__meta { margin-left: auto; font-size: 12.5px; color: var(--text-muted); white-space: nowrap; }
.project__meta a { text-decoration: none; }
.project__meta a:hover { text-decoration: underline; }

/* -------------------------------- the line ------------------------------- */

.graph {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(150px, 46%);
  align-items: start;
}
@media (min-width: 760px) {
  .graph { grid-template-columns: minmax(0, 1fr) 340px; }
}

.graph__line {
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  /* What is left on the left fades out: there is more history, but what
     matters is on the right, next to the cards. */
  mask-image: linear-gradient(to right, transparent 0, #000 22px);
  -webkit-mask-image: linear-gradient(to right, transparent 0, #000 22px);
}
/* margin-left:auto and not justify-content:flex-end: with the latter, what
   overflows on the left is out of scrolling reach. */
.graph__svg { display: block; flex: none; margin-left: auto; overflow: visible; }

.graph__segment.is-abandoned { stroke-dasharray: 3 5; opacity: .55; }
.graph__dot { cursor: pointer; outline: none; }
.graph__dot:hover .graph__disc, .graph__dot:focus-visible .graph__disc {
  stroke: var(--text);
  stroke-width: 2;
}

.graph__cards { position: relative; min-width: 0; }

.card {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 7px 10px 7px 11px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--branch-color, var(--accent));
  border-radius: 10px;
  background: color-mix(in srgb, var(--branch-color, var(--accent)) 7%, var(--panel));
  text-align: left;
  overflow: hidden;
  cursor: pointer;
  transition: transform .1s ease, box-shadow .1s ease;
}
.card:hover { box-shadow: var(--shadow); }
.card:active { transform: scale(.99); }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.card__header {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 11.5px;
  line-height: 1.3;
  color: var(--text-muted);
}
.card__branch {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--branch-color, var(--accent));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card__when { flex: none; }
.card__text {
  font-weight: 600;
  font-size: 14px;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.card__text.is-empty { font-weight: 400; font-style: italic; color: var(--text-muted); }
.card__detail { font-size: 11.5px; color: var(--branch-color, var(--accent)); font-weight: 600; }

.card.is-stalled .card__when { color: var(--stalled); font-weight: 700; }
.card.is-stuck .card__when { color: var(--stuck); font-weight: 700; }
.card.is-stuck { border-color: color-mix(in srgb, var(--stuck) 45%, var(--border)); }

/* --------------------------------- bubble -------------------------------- */

.bubble {
  position: fixed;
  z-index: 70;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: var(--shadow);
  font-size: 14px;
  line-height: 1.4;
  animation: fade-in .12s ease;
}
.bubble p { margin: 6px 0 0; overflow-wrap: anywhere; white-space: pre-line; }
.bubble__header { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.bubble__branch { margin-left: auto; color: var(--text-muted); font-size: 12px; }
.bubble__mark { color: var(--text-muted); font-style: italic; font-size: 13px; }
.bubble__next { color: var(--text-muted); }
.bubble__detail { color: var(--text-muted); font-size: 13px; max-height: 40vh; overflow-y: auto; }

/* The pending step, with its detail, above the log form. */
.pending {
  display: grid;
  gap: 2px;
  padding: 10px 12px;
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent-soft);
}
.pending p { margin: 4px 0 0; white-space: pre-line; overflow-wrap: anywhere; font-size: 14px; }

.color-dot {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

/* ------------------------------ project view ----------------------------- */

.project-view__header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin-bottom: 10px;
}
.project-view__header h1 {
  flex: 1 1 200px;
  margin: 0;
  font-size: 21px;
  overflow-wrap: anywhere;
}
.project-view__meta { color: var(--text-muted); font-size: 13px; margin: 0 0 12px; }
.project-view__actions { display: flex; gap: 4px; }

.segmented {
  display: inline-flex;
  padding: 3px;
  border-radius: 999px;
  background: var(--hover);
}
.segmented button {
  padding: 5px 12px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  font-size: 13.5px;
  cursor: pointer;
  color: var(--text-muted);
}
.segmented button[aria-pressed="true"] {
  background: var(--panel);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .12);
}

.section { margin-top: 22px; }
.section > h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  margin: 0 0 8px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 12px;
}

.closed-branches { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.closed-branch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--hover);
  font-size: 13px;
}

.day { margin-top: 14px; }
.day__title { font-size: 12.5px; font-weight: 700; color: var(--text-muted); margin: 0 0 4px 4px; }

.entry {
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr);
  gap: 4px 10px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.entry:hover { background: var(--hover); }
.entry:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.entry .color-dot { margin-top: 6px; }
.entry__header { display: flex; flex-wrap: wrap; gap: 2px 8px; font-size: 12.5px; color: var(--text-muted); }
.entry__branch { font-weight: 700; color: var(--branch-color, var(--accent)); }
.entry__mark { font-style: italic; }
.entry__done, .entry__next { margin: 2px 0 0; overflow-wrap: anywhere; white-space: pre-line; }
.entry__next { color: var(--text-muted); }
.entry__next::before { content: "→ "; }
.entry__body { min-width: 0; }
.entry__detail { margin-top: 4px; font-size: 13.5px; color: var(--text-muted); }
.entry__detail summary { cursor: pointer; font-weight: 600; color: var(--branch-color, var(--accent)); }
.entry__detail p { margin: 4px 0 0; white-space: pre-line; overflow-wrap: anywhere; }

/* -------------------------------- overview ------------------------------- */

.overview__bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.overview__bar .filters { margin: 0; }

.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
}
.stat { padding: 12px 14px; }
.stat strong { display: block; font-size: 26px; line-height: 1.1; }
.stat span { font-size: 13px; color: var(--text-muted); }
.stat.is-alert strong { color: var(--stuck); }

.stuck-list { display: grid; gap: 8px; }
.stuck {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--stalled);
  border-radius: 10px;
  background: var(--panel);
  text-decoration: none;
}
.stuck.is-stuck { border-left-color: var(--stuck); }
.stuck:hover { box-shadow: var(--shadow); }
.stuck__where { font-size: 13px; color: var(--text-muted); overflow-wrap: anywhere; }
.stuck__where strong { color: var(--text); }
.stuck__days { grid-row: span 2; align-self: center; font-weight: 700; color: var(--stalled); white-space: nowrap; font-size: 13.5px; }
.stuck.is-stuck .stuck__days { color: var(--stuck); }
.stuck__next { font-weight: 600; overflow-wrap: anywhere; }
.stuck-list__none { color: var(--text-muted); margin: 0; }

.timeline { overflow: hidden; }
.timeline svg { display: block; width: 100%; height: auto; overflow: visible; }
.timeline__axis { font-size: 11px; fill: var(--text-muted); }
.timeline__grid { stroke: var(--border); stroke-width: 1; }
.timeline__today { stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 3 3; }
.timeline__name { font-size: 12.5px; font-weight: 700; fill: var(--text); }
.timeline__name.is-paused { fill: var(--text-muted); font-weight: 600; }
.timeline__wait { stroke-width: 3; stroke-dasharray: 2 4; stroke-linecap: round; }
.timeline a { cursor: pointer; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; color: var(--text-muted); margin-top: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; width: 18px; height: 0; border-top: 3px dotted currentColor; }

/* -------------------------------- notices -------------------------------- */

.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(86px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 80;
  display: grid;
  gap: 8px;
  width: min(420px, calc(100vw - 24px));
}

.toast {
  background: #23262f;
  color: #fff;
  padding: 11px 14px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 12px;
  animation: fade-in .16s ease;
}
.toast--error { background: var(--stuck); }
.toast button {
  border: 0;
  background: transparent;
  color: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* -------------------------------- dialogs -------------------------------- */

.dialog {
  width: min(94vw, 480px);
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: 0;
  border-radius: 16px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgba(0, 0, 0, .45); }
.dialog__form { display: flex; flex-direction: column; max-height: calc(100dvh - 90px); }

.dialog__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 10px 10px 20px;
  border-bottom: 1px solid var(--border);
}
.dialog__header h2 { margin: 6px 0 0; font-size: 17px; }
.dialog__subtitle { margin: 2px 0 0; font-size: 13px; color: var(--text-muted); overflow-wrap: anywhere; }
.dialog__body { padding: 16px 20px; overflow-y: auto; }
.dialog__text { margin: 0; white-space: pre-line; }
.dialog__error { margin: 12px 0 0; color: var(--stuck); font-size: 14px; }
.dialog__extra { padding: 0 20px 10px; }
.dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px calc(14px + var(--safe-bottom));
  border-top: 1px solid var(--border);
}

/* On the phone the dialog slides up from the bottom: it stays within thumb
   reach and the keyboard doesn't cover it. */
@media (max-width: 560px) {
  .dialog {
    width: 100vw;
    max-width: 100vw;
    margin: auto 0 0;
    border-radius: 18px 18px 0 0;
    animation: slide-up .18s ease;
  }
}
@keyframes slide-up {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.stack { display: grid; gap: 14px; }
.branch-actions { display: flex; flex-wrap: wrap; gap: 4px 16px; }

.settings__block { display: grid; gap: 10px; }
.settings__block + .settings__block { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.settings__block h3 { margin: 0; font-size: 14px; }
.settings__row { display: flex; gap: 10px; align-items: flex-end; }
.settings__row .field { flex: 1; }
.token {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius);
  background: var(--bg);
  font-size: 14px;
}
.token__info { flex: 1; min-width: 0; }
.token__info small { display: block; color: var(--text-muted); }
.token-new {
  padding: 10px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  font-size: 13.5px;
  display: grid;
  gap: 6px;
}
code, .code {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 12.5px;
  word-break: break-all;
  user-select: all;
}
.version { color: var(--text-muted); font-size: 12.5px; text-align: center; margin: 16px 0 0; }
