/* The tracker page's styles (plan section 4). Colours follow the device's
   light or dark setting (spec 6.4). */
:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --fg: #1d1f23;
  --muted: #6b7079;
  --line: #e3e5e8;
  --area-bg: #f3f4f6;
  --accent: #b54708;
  --accent-bg: #fff1e0;
  --tag-bg: #eceef1;
  --bar-bg: #dcdfe4;
  --bar-fill: #2f7d4f;
  --flash: #fff3b0;
  --ok: #2f7d4f;
  --danger: #c4320a;
  --danger-bg: #fdebe6;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17191c;
    --fg: #e6e7e9;
    --muted: #9298a2;
    --line: #2d3036;
    --area-bg: #22252a;
    --accent: #ffb366;
    --accent-bg: #3d2a14;
    --tag-bg: #2b2f35;
    --bar-bg: #3a3e45;
    --bar-fill: #5cbf85;
    --flash: #4a4320;
    --ok: #5cbf85;
    --danger: #ff8a6b;
    --danger-bg: #3f1d14;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
}

#app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px 48px;
}

button {
  font: inherit;
  color: inherit;
}

/* --- Live dot and warning bars (spec 6.4/2): red dot and a bar while the
   service cannot be reached; a bar for an old or missing snapshot --- */

.live {
  order: 1;
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.9em;
}

.live-dot {
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: var(--muted);
}

.live.up .live-dot {
  background: var(--ok);
}

.live.down .live-dot {
  background: var(--danger);
}

.live.down {
  color: var(--danger);
}

.banner {
  margin: 0;
  padding: 0.4rem 16px;
  background: var(--danger-bg);
  color: var(--danger);
  border-top: 1px solid var(--line);
  text-align: center;
  overflow-wrap: anywhere;
}

/* --- Rows (spec 6.1): one flat list, the indent grows with the depth --- */

.tree,
.rows {
  list-style: none;
  margin: 0;
  padding: 0;
}

.row {
  --indent: 0;
  border-bottom: 1px solid var(--line);
  padding-left: calc(var(--indent) * 1.5rem);
}

.line {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.35rem 0;
}

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

.title {
  overflow-wrap: anywhere;
}

.key {
  margin-left: 0.5rem;
  font-family: ui-monospace, monospace;
  font-size: 0.85em;
  color: var(--muted);
}

.note,
.meta {
  color: var(--muted);
  font-size: 0.9em;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.mark,
.toggle,
.toggle-space {
  flex: none;
  width: 1.5rem;
  text-align: center;
}

.toggle {
  border: 0;
  padding: 0;
  background: none;
  cursor: pointer;
}

.row.area {
  background: var(--area-bg);
  margin-top: 1rem;
}

.row.area .line {
  padding: 0.5rem;
}

.row.area .title {
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Done and dropped: struck through, faded (spec 6.1, 6.3/2). Faded is the
   muted colour, not opacity, so the text keeps a 4.5:1 contrast; the tags
   keep their own colours. */
.row.status-done .title,
.row.status-dropped .title {
  text-decoration: line-through;
}

.row.status-done .main,
.row.status-dropped .main,
.row.status-done .mark,
.row.status-dropped .mark {
  color: var(--muted);
}

/* --- Tags at the row's right edge (spec 6.1) --- */

.tags {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 0.35rem;
}

.tag {
  padding: 0.05rem 0.45rem;
  border-radius: 0.6rem;
  background: var(--tag-bg);
  font-size: 0.85em;
  white-space: nowrap;
}

.tag.status-waiting,
.tag.prio-high,
.tag.due-near {
  background: var(--accent-bg);
  color: var(--accent);
  font-weight: 600;
}

.tag.due {
  color: var(--accent);
}

/* Faint (spec 6.3) but readable: muted text needs the page background for
   4.5:1, not the tag's. */
.tag.prio-low {
  background: none;
  color: var(--muted);
}

.star {
  color: var(--accent);
}

.progress {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85em;
  white-space: nowrap;
}

.bar {
  display: inline-block;
  width: 4rem;
  height: 0.4rem;
  border-radius: 0.2rem;
  background: var(--bar-bg);
  overflow: hidden;
}

.fill {
  display: block;
  height: 100%;
  background: var(--bar-fill);
}

/* --- Header and tabs (spec 6.4/1): stays at the top while scrolling --- */

.top-bar {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.top-bar-inner {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.5rem 16px;
}

.brand {
  font-weight: 700;
}

.tabs {
  display: flex;
  gap: 0.5rem;
}

.tab {
  padding: 0.3rem 0.8rem;
  border-radius: 0.4rem;
  color: var(--muted);
  text-decoration: none;
}

.tab.active {
  background: var(--tag-bg);
  color: var(--fg);
  font-weight: 600;
}

/* --- Header menu (spec 13.8): "Gépek" and "Kilépés", at the right end of
   the header; on a phone beside the tabs --- */

.menu {
  order: 2;
  position: relative;
}

.menu-button {
  padding: 0.3rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 0.4rem;
  background: var(--bg);
  cursor: pointer;
}

.menu-button[aria-expanded="true"] {
  background: var(--tag-bg);
}

.menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 0.35rem);
  z-index: 2;
  width: 15rem;
  display: flex;
  flex-direction: column;
  padding: 0.35rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  box-shadow: 0 4px 16px rgb(0 0 0 / 0.15);
}

.menu-panel[hidden] {
  display: none;
}

.menu-item {
  display: block;
  padding: 0.5rem 0.6rem;
  border: 0;
  border-radius: 0.3rem;
  background: none;
  color: var(--fg);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.menu-item:hover,
.menu-item:focus-visible {
  background: var(--tag-bg);
}

.menu-note {
  margin: 0;
  padding: 0 0.6rem 0.35rem;
  color: var(--muted);
  font-size: 0.85em;
}

/* --- "Gépek" view (spec 13.8): a new token, then the list --- */

.machines-view {
  max-width: 44rem;
  padding-top: 1rem;
}

.machines-title {
  margin: 0 0 1rem;
  font-size: 1.2rem;
}

.machine-new-line {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.3rem;
}

.machine-new-line .text-input {
  flex: 1;
  min-width: 0;
}

.machine-new .field-error {
  margin-top: 0.3rem;
}

.machine-created {
  margin-top: 1rem;
  padding: 0.75rem;
  border: 1px solid var(--accent);
  border-radius: 0.5rem;
  background: var(--accent-bg);
}

.machine-created p {
  margin: 0 0 0.5rem;
}

/* The box has the primary button's background: the border keeps the
   button visible on it. */
.machine-created .action {
  border-color: var(--accent);
}

.machine-token {
  display: block;
  margin-bottom: 0.5rem;
  padding: 0.5rem;
  border-radius: 0.3rem;
  background: var(--bg);
  overflow-wrap: anywhere;
  user-select: all;
}

.machine-created .machine-howto {
  margin: 0.6rem 0 0.3rem;
}

.machine-created .machine-warning {
  margin: 0;
  font-weight: 600;
}

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

.machine,
.machines-empty {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--line);
}

.machines-empty {
  color: var(--muted);
}

.machine-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.machine-name {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.machine-meta {
  color: var(--muted);
  font-size: 0.9em;
}

.machine-confirm {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}

/* --- Top view (spec 6.2): four blocks, 2 x 2 --- */

.blocks {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.block {
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  padding: 0 0.75rem 0.5rem;
}

.block-head {
  display: flex;
  justify-content: space-between;
  margin: 0;
  padding: 0.6rem 0;
  font-size: 1rem;
  border-bottom: 1px solid var(--line);
}

.block-count {
  color: var(--muted);
}

.block .row:last-child {
  border-bottom: 0;
}

.empty {
  color: var(--muted);
  margin: 0.6rem 0;
}

.path {
  display: block;
  border: 0;
  padding: 0;
  background: none;
  color: var(--muted);
  font-size: 0.85em;
  text-align: left;
  cursor: pointer;
}

.path:hover {
  text-decoration: underline;
}

/* The row the top view jumped to lights up for a moment (spec 6.4/1). */
.row.flash {
  animation: flash 2s ease-out;
}

@keyframes flash {
  from {
    background: var(--flash);
  }
}

/* --- Status mark and the editor (spec 6.3/1, 6.3/2) --- */

.row > .line {
  cursor: pointer;
}

button.mark {
  border: 0;
  padding: 0;
  background: none;
  cursor: pointer;
}

.editor-row {
  --indent: 0;
  padding-left: calc(var(--indent) * 1.5rem);
  border-bottom: 1px solid var(--line);
}

.editor {
  position: relative;
  margin: 0.25rem 0 0.6rem 2rem;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--area-bg);
}

.editor-close {
  position: absolute;
  top: 0.25rem;
  right: 0.4rem;
  border: 0;
  background: none;
  font-size: 1.2rem;
  cursor: pointer;
}

.field {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.field-label {
  flex: none;
  width: 6.5rem;
  padding-top: 0.25rem;
  color: var(--muted);
}

.field-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.text-input {
  width: 100%;
  font: inherit;
  padding: 0.25rem 0.4rem;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 0.3rem;
}

textarea.text-input {
  min-height: 3.5rem;
  resize: vertical;
}

/* A one-line field that wraps a long text and grows with it (app.js
   lineInput sets the height). */
textarea.line-input {
  min-height: 0;
  resize: none;
  overflow: hidden;
}

.field-key .text-input {
  width: 12rem;
}

.date-input {
  font: inherit;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 0.3rem;
}

.choices {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.choice,
.action {
  padding: 0.2rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 0.8rem;
  background: var(--bg);
  cursor: pointer;
}

.choice.on {
  background: var(--accent-bg);
  color: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}

.action:disabled {
  opacity: 0.4;
  cursor: default;
}

.action.primary {
  background: var(--accent-bg);
  color: var(--accent);
  font-weight: 600;
}

.action.danger {
  color: var(--accent);
}

.hint,
.computed {
  color: var(--muted);
  font-size: 0.9em;
}

.field-error {
  flex-basis: 100%;
  margin: 0;
  color: var(--accent);
  font-size: 0.9em;
}

.editor-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--line);
}

.editor-moves,
.editor-texts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.editor-foot {
  margin: 0.6rem 0 0;
  color: var(--muted);
  font-size: 0.85em;
}

/* --- Bottom bar: undo and messages (spec 6.3/5) --- */

.notice {
  position: fixed;
  left: 50%;
  bottom: 1rem;
  z-index: 2;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  max-width: calc(100% - 2rem);
  padding: 0.5rem 0.9rem;
  border-radius: 0.5rem;
  background: var(--fg);
  color: var(--bg);
}

.notice[hidden] {
  display: none;
}

.notice-text {
  overflow-wrap: anywhere;
}

.notice-action {
  flex: none;
  border: 1px solid var(--bg);
  border-radius: 0.4rem;
  background: none;
  color: var(--bg);
  padding: 0.15rem 0.6rem;
  cursor: pointer;
}

/* --- New item and child (spec 6.3/3): the "+" is always shown, faintly
   (spec 6.4/1) --- */

.add {
  flex: none;
  width: 1.6rem;
  border: 0;
  padding: 0;
  background: none;
  font-size: 1.1rem;
  line-height: 1.2;
  color: var(--muted);
  cursor: pointer;
}

.add:hover,
.add:focus-visible {
  color: var(--fg);
}

.add-row,
.add-item {
  --indent: 0;
  padding: 0.3rem 0 0.3rem calc(var(--indent) * 1.5rem + 2rem);
  border-bottom: 1px solid var(--line);
}

/* A new area: its input starts where the area titles do (.row.area .line's
   padding), not after a toggle and a mark. */
.add-row.top-level {
  padding-left: 0.5rem;
}

.add-line {
  border: 0;
  padding: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
}

#add-area {
  margin-top: 1rem;
}

/* --- Move, and the "Törölt elemek" list (spec 6.3/4, 6.3/5) --- */

.action.on {
  border-color: var(--accent);
  color: var(--accent);
}

.targets {
  list-style: none;
  margin: 0.6rem 0 0;
  padding: 0.3rem 0;
  max-height: 18rem;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 0.4rem;
  background: var(--bg);
}

.target {
  --indent: 0;
  padding-left: calc(var(--indent) * 1rem);
}

.target-button {
  width: 100%;
  border: 0;
  padding: 0.2rem 0.5rem;
  background: none;
  text-align: left;
  overflow-wrap: anywhere;
  cursor: pointer;
}

.target-button:hover:not(:disabled) {
  background: var(--tag-bg);
}

.target-button:disabled {
  opacity: 0.4;
  cursor: default;
}

.tree-foot {
  margin-top: 0.75rem;
}

.deleted-list {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
}

.deleted-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--line);
}

/* --- Phone (spec 6.4/1): one column, tags under the title, a smaller
   indent, bigger touch targets, a full-width editor with the field names
   above the fields. The switch is the width, not the pointer, so a narrow
   desktop window shows it too (plan section 4). --- */

@media (max-width: 640px) {
  .top-bar-inner {
    flex-wrap: wrap;
    row-gap: 0.25rem;
  }

  /* The same header as on a wide screen: title and live dot on top, the
     two tabs under them, the menu beside the tabs (spec 13.8). */
  .top-bar-inner::after {
    content: "";
    order: 2;
    flex-basis: 100%;
  }

  .tabs {
    order: 3;
    flex: 1 1 auto;
  }

  .menu {
    order: 4;
  }

  .menu-button {
    min-height: 2.75rem;
    padding: 0.55rem 1rem;
  }

  .menu-item {
    min-height: 2.75rem;
  }

  .tab {
    padding: 0.55rem 1rem;
  }

  .blocks {
    grid-template-columns: minmax(0, 1fr);
  }

  /* No side frame, so a block's rows and editor get the full width. */
  .block {
    padding: 0 0 0.5rem;
    border-width: 1px 0;
    border-radius: 0;
  }

  .row,
  .editor-row,
  .add-item {
    padding-left: calc(var(--indent) * 0.75rem);
  }

  /* A row: mark, title and "+" on the first line, the tags under the title. */
  .row:not(.area) > .line {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    column-gap: 0.4rem;
    row-gap: 0.2rem;
    align-items: start;
  }

  .row:not(.area) > .line > :first-child {
    grid-column: 1;
    grid-row: 1 / span 2;
  }

  .row:not(.area) > .line > .main {
    grid-column: 2;
    grid-row: 1;
  }

  .row:not(.area) > .line > .tags {
    grid-column: 2;
    grid-row: 2;
    justify-content: flex-start;
  }

  .row:not(.area) > .line > .tags:empty {
    display: none;
  }

  .row:not(.area) > .line > .add {
    grid-column: 3;
    grid-row: 1;
  }

  .mark,
  .toggle,
  .toggle-space,
  .add {
    width: 2.75rem;
    min-height: 2.75rem;
  }

  .mark,
  .toggle {
    font-size: 1.2rem;
  }

  .row:not(.area) > .line > .main {
    padding-top: 0.65rem;
  }

  .row.area .line {
    padding: 0 0 0 0.5rem;
    align-items: center;
  }

  .choice,
  .action,
  .notice-action {
    min-height: 2.75rem;
    padding: 0.4rem 0.9rem;
  }

  .add-line {
    min-height: 2.75rem;
  }

  .target-button {
    min-height: 2.5rem;
  }

  .editor-row {
    padding-left: 0;
  }

  /* The input starts where its level's titles do: the indent, then the mark
     column (2.75rem) and the grid gap (0.4rem) of a phone row. A new area
     keeps .add-row.top-level's padding, which outranks this rule. */
  .add-row {
    padding-left: calc(var(--indent) * 0.75rem + 3.15rem);
  }

  .editor {
    margin: 0.25rem 0 0.6rem;
  }

  .editor-close {
    width: 2.75rem;
    height: 2.75rem;
    top: 0;
    right: 0;
  }

  .field {
    flex-direction: column;
    gap: 0.25rem;
  }

  .field-label {
    width: auto;
    padding-top: 0;
  }

  .field-key .text-input,
  .add-row .text-input {
    width: 100%;
    max-width: none;
  }

  /* 16 px keeps a phone from zooming in when a field gets the focus. */
  .text-input,
  textarea.line-input,
  .date-input {
    font-size: 16px;
    min-height: 2.75rem;
  }
}

/* --- Login page (spec 13.4, 13.8): the name, a message if the last login
   failed, and one link to the login. A plain link, not a form button. --- */

.login {
  max-width: 22rem;
  margin: 18vh auto 0;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
  text-align: center;
}

.login-brand {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 600;
}

.login-error {
  margin: 0;
  width: 100%;
  padding: 0.6rem 0.8rem;
  border-radius: 0.4rem;
  background: var(--danger-bg);
  color: var(--danger);
}

.login-link {
  display: inline-block;
  min-height: 2.75rem;
  padding: 0.7rem 1.2rem;
  border: 1px solid var(--line);
  border-radius: 0.4rem;
  background: var(--tag-bg);
  color: var(--fg);
  font-weight: 600;
  text-decoration: none;
}

.login-link:hover,
.login-link:focus-visible {
  border-color: var(--muted);
}
