/* Loaded only by a note with a demo (after style.css, so its tokens are there). */

/* the demos in a note (demos.ts): quiet like the text around them, a column on phones */
.sim {
  margin: 1.75rem 0;
  padding: 0.9rem 0;
  font-size: 0.9rem;
}

article .sim p {
  margin: 0;
}

[data-by="A"] {
  --by: var(--client-a);
}

[data-by="B"] {
  --by: var(--client-b);
}

[data-by="C"] {
  --by: var(--client-c);
}

/* who wrote a line: a small square in the client's colour, filled on the card */
.sim-msg[data-by]::before,
.sim-list-title[data-by]::before,
.sim-head strong[data-by]::before {
  content: "";
  display: inline-block;
  width: 0.55em;
  height: 0.55em;
  margin-right: 0.45em;
  vertical-align: 0.08em;
  border: 2px solid var(--by);
  border-radius: 2px;
}

.sim-head strong[data-by]::before {
  background: var(--by);
}

/* the changes under the title: what the document went through, smaller than the document itself */
.sim-log {
  padding-top: 0.4rem;
  font-size: 0.85rem;
  border-top: 1px dashed var(--rule);
}

/* a title that lost a conflict: kept, but not shown as the title */
.sim-msg.sim-lost {
  color: var(--muted);
  text-decoration: line-through;
}

/* a message not synced yet: its mark dashed */
.sim-msg.sim-pending {
  color: var(--muted);
}

.sim-msg.sim-pending::before {
  border-style: dashed;
}

/* a line without the key: the lock in its author's colour */
.sim-locked[data-by]::before {
  background: var(--by);
}


/* where A rotated the key on a removal: above it stays readable, below is locked (Lucide's rotate-ccw, ISC) */
.sim-locked.sim-rotated {
  position: relative;
  border-top: 1px dashed var(--line);
}

.sim-locked.sim-rotated::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  width: 0.9em;
  height: 0.9em;
  background: var(--muted);
  transform: translateY(-50%);
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8'/%3E%3Cpath d='M3 3v5h5'/%3E%3C/svg%3E") center / contain no-repeat;
}

.sim-state,
.sim-empty,
.sim-locked {
  color: var(--muted);
}

/* one card per device, like a phone: a status bar in its client's colour on top (the name, the network), its actions
   on one line at the bottom, the same height whatever it holds */
.sim-devices {
  display: grid;
  grid-template-columns: repeat(var(--devices, 3), 1fr);
  gap: 0.75rem;
  margin: 0.75rem 0;
}

.sim-device {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  min-width: 0;
  padding: 0 0.85rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.sim-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0 -0.85rem;
  padding: 0.35rem 0.6rem 0.35rem 0.85rem;
  background: color-mix(in srgb, var(--by) 14%, var(--bg));
  border-radius: 5px 5px 0 0;
}

/* offline: cut off from the others, so dashed like everything that has not got through yet, and its bar grey */
.sim-device:has(.sim-net.offline) {
  border-style: dashed;
  border-color: var(--muted);
}

.sim-device:has(.sim-net.offline) .sim-head {
  background: color-mix(in srgb, var(--muted) 12%, var(--bg));
}

.sim-head strong {
  white-space: nowrap;
}

.sim-state {
  margin-left: auto;
}

/* on the tinted bar the muted grey is too faint */
.sim-head .sim-state {
  color: var(--body);
}

/* the network switch: wifi while online, crossed out and muted while offline */
.sim-net {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  color: var(--text);
  background: none;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
}

.sim-net:hover:not(:disabled) {
  background: var(--accent-tint);
}

.sim-net .ico {
  width: 1.1rem;
  height: 1.1rem;
}

.sim-net.offline {
  color: var(--muted);
}

.sim-net .when-offline,
.sim-net.offline .when-online {
  display: none;
}

.sim-net.offline .when-offline {
  display: block;
}

/* what just arrived or changed lights up for a moment */
.sim-new {
  border-radius: 3px;
  animation: sim-arrive 1.4s ease-out;
}

@keyframes sim-arrive {
  from {
    background: var(--accent-tint);
  }
}

@media (prefers-reduced-motion: reduce) {
  .sim-new {
    animation: none;
  }
}

.sim-lists {
  display: flex;
  flex: 1;
  min-height: calc(var(--rows, 4) * 1lh); /* room for the latest few: the card keeps its height */
  flex-direction: column;
  gap: 0.4rem;
}

.sim-list {
  display: flex;
  flex-direction: column;
}

.sim-list-title {
  font-size: 1.1rem;
  font-weight: 600;
}

.sim-list-head {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.sim-icon[hidden] {
  display: none;
}

/* a control as an icon, in its place, drawn like the wifi switch */
.sim-icon {
  position: relative;
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  color: var(--text);
  background: none;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
}

/* on a share button: whom it is for, in their colour */
.sim-badge {
  position: absolute;
  right: -0.1rem;
  bottom: -0.15rem;
  font-size: 0.62rem;
  font-weight: 600;
  line-height: 1;
  color: var(--by);
}

.sim-icon .ico {
  width: 0.95rem;
  height: 0.95rem;
}

.sim-icon:hover:not(:disabled) {
  background: var(--accent-tint);
}

.sim-icon:disabled,
.sim-net:disabled {
  color: var(--muted);
  opacity: 0.45;
  cursor: default;
}

/* "try me": until the first click in a demo, a ring spreads from each control once every 5 seconds */
.sim-net {
  position: relative;
}

.sim-hint .sim-icon:not(:disabled)::after,
.sim-hint .sim-net:not(:disabled)::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 1.5px solid var(--accent);
  border-radius: 50%;
  opacity: 0;
  animation: sim-wave 5s ease-out 1s infinite;
  pointer-events: none;
}

@keyframes sim-wave {
  0% {
    opacity: 0.9;
    transform: scale(0.8);
  }
  24%,
  100% {
    opacity: 0;
    transform: scale(1.9);
  }
}

@media (prefers-reduced-motion: reduce) {
  .sim-hint .sim-icon:not(:disabled)::after,
  .sim-hint .sim-net::after {
    animation: none;
  }
}

/* Lucide's lock (ISC), drawn in the text colour through a mask */
.sim-locked::before {
  content: "";
  display: inline-block;
  width: 0.95em;
  height: 0.95em;
  margin-right: 0.35em;
  vertical-align: -0.12em;
  background: currentColor;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect width='18' height='11' x='3' y='11' rx='2'/%3E%3Cpath d='M7 11V7a5 5 0 0 1 10 0v4'/%3E%3C/svg%3E") center / contain no-repeat;
}

.sim-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: auto;
  padding-top: 0.6rem;
  border-top: 1px solid var(--rule);
}

.sim-buttons:empty {
  display: none;
}

.sim-actions {
  display: flex;
  justify-content: center;
}

.sim-button:has(.ico) {
  display: inline-flex;
  gap: 0.35em;
  align-items: center;
}

.sim-button .ico {
  width: 0.95em;
  height: 0.95em;
}

/* buttons that read like the links around them */
.sim-button {
  min-height: 1.6rem;
  padding: 0;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: none;
  border: 0;
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 2px;
  text-underline-offset: 0.25em;
  cursor: pointer;
}

.sim-button:hover:not(:disabled) {
  background: var(--accent-tint);
}

.sim-button:disabled {
  color: var(--muted);
  text-decoration: none;
  cursor: default;
}

@media (max-width: 720px) {
  .sim-devices {
    grid-template-columns: 1fr;
  }
}
