/* doot components. Needs tokens.css and base.css first. Plain CSS, no build step. */

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  min-height: var(--tap);
  padding: 0 var(--s-5);
  border: 1px solid transparent;
  border-radius: var(--r-full);
  background: var(--accent);
  color: var(--on-accent);
  font-size: var(--fs-md);
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  position: relative;
  transition: transform var(--dur-fast) var(--ease), background var(--dur) var(--ease), opacity var(--dur) var(--ease);
}
.btn:active:not([disabled]) { transform: scale(0.97); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
.btn-secondary { background: var(--surface-2); color: var(--text); }
.btn-ghost { background: transparent; color: var(--text); }
.btn-outline { background: transparent; color: var(--text); border-color: var(--line); }
.btn-danger { background: var(--danger); color: var(--on-danger); }
.btn-sm { min-height: 36px; padding: 0 var(--s-4); font-size: var(--fs-base); }
.btn-lg { min-height: 52px; padding: 0 var(--s-7); font-size: var(--fs-lg); }
.btn-block { width: 100%; }
.btn-icon { width: var(--tap); padding: 0; border-radius: 50%; }
.btn-icon.btn-sm { width: 36px; }
.btn[aria-busy="true"] { color: transparent; pointer-events: none; }
.btn[aria-busy="true"]::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  border: 2.5px solid var(--on-accent);
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.btn-secondary[aria-busy="true"]::after, .btn-ghost[aria-busy="true"]::after, .btn-outline[aria-busy="true"]::after { border-color: var(--text); border-right-color: transparent; }
@media (hover: hover) {
  .btn:hover:not([disabled]) { filter: brightness(1.08); }
  .btn-secondary:hover:not([disabled]), .btn-ghost:hover:not([disabled]), .btn-outline:hover:not([disabled]) { background: var(--surface-2); filter: none; }
}

/* ---------- form fields ---------- */
.field { display: grid; gap: 6px; }
.field > label, .label { font-size: var(--fs-sm); font-weight: 600; color: var(--dim); }
.input, .textarea {
  width: 100%;
  min-height: 48px;
  padding: 0 var(--s-4);
  background: var(--surface);
  color: var(--text);
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  font-size: 16px; /* 16px stops iOS zooming into the field */
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.input::placeholder, .textarea::placeholder { color: var(--dim); opacity: 0.8; }
.input:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input[aria-invalid="true"] { border-color: var(--danger); }
.textarea { padding: var(--s-3) var(--s-4); min-height: 96px; resize: vertical; line-height: var(--lh); }
.hint { font-size: var(--fs-sm); color: var(--dim); }
.hint.err { color: var(--danger); }
.hint.ok { color: var(--ok); }
.input-wrap { position: relative; }
.input-wrap .input { padding-right: 52px; }
.input-wrap .btn-icon { position: absolute; right: 2px; top: 2px; width: 44px; min-height: 44px; color: var(--dim); }
.code-input { text-align: center; font-size: 1.75rem; font-weight: 650; letter-spacing: 0.5em; padding-left: 0.5em; font-variant-numeric: tabular-nums; min-height: 60px; }

/* switch: <label class="switch"><input type="checkbox" role="switch"><i></i></label> */
.switch { position: relative; display: inline-block; width: 50px; height: 30px; flex: none; }
.switch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; z-index: 1; }
.switch i { position: absolute; inset: 0; border-radius: var(--r-full); background: var(--track); transition: background var(--dur) var(--ease); }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-1); transition: transform var(--dur) var(--ease-pop); }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(20px); }
.switch input:focus-visible + i { outline: 2px solid var(--accent); outline-offset: 2px; }

/* segmented control */
.seg { display: inline-flex; background: var(--surface-2); border-radius: var(--r-full); padding: 3px; gap: 2px; }
.seg button { border: 0; background: none; min-height: 34px; padding: 0 var(--s-4); border-radius: var(--r-full); font-size: var(--fs-base); font-weight: 600; color: var(--dim); display: inline-flex; align-items: center; gap: 6px; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); }

/* ---------- avatar + badges ---------- */
.avatar {
  --h: 200;
  --sz: 44px;
  width: var(--sz);
  height: var(--sz);
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: hsl(var(--h) var(--av-s) var(--av-l));
  color: #fff;
  font-size: calc(var(--sz) * 0.42);
  font-weight: 650;
  line-height: 1;
  text-transform: lowercase;
  user-select: none;
}
.avatar-sm { --sz: 32px; }
.avatar-lg { --sz: 72px; }
.badge {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--r-full);
  background: var(--accent);
  color: var(--on-accent);
  font-size: var(--fs-xs);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.badge-attn { background: var(--attention); color: var(--on-attention); }
.badge.pop { animation: badge-pop var(--dur-slow) var(--ease-pop); }

/* ---------- bars + navigation ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  min-height: calc(var(--topbar-h) + var(--safe-t));
  padding: var(--safe-t) calc(var(--s-3) + var(--safe-r)) 0 calc(var(--s-3) + var(--safe-l));
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { flex: 1; min-width: 0; font-size: var(--fs-lg); letter-spacing: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .sub { font-size: var(--fs-sm); color: var(--dim); font-weight: 400; }

.tabbar {
  display: flex;
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: var(--surface);
  border-top: 1px solid var(--line);
  z-index: var(--z-bar);
}
.tab {
  flex: 1;
  position: relative;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 2px;
  background: none;
  border: 0;
  color: var(--dim);
  font-size: 11px;
  font-weight: 600;
  text-decoration: none;
}
.tab .icon { width: 24px; height: 24px; transition: transform var(--dur) var(--ease-pop); }
.tab[aria-current="page"] { color: var(--accent); }
.tab[aria-current="page"] .icon { transform: translateY(-1px) scale(1.08); }
.tab .badge { position: absolute; top: 4px; left: calc(50% + 6px); }

.rail {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: var(--s-2);
  width: var(--rail-w);
  padding: var(--s-4) 0;
  background: var(--surface);
  border-right: 1px solid var(--line);
}
.rail .logo { width: 40px; height: 40px; margin-bottom: var(--s-4); }
.rail .spacer { flex: 1; }
.rail .tab { flex: none; width: 52px; height: 52px; border-radius: var(--r-md); }
.rail .tab[aria-current="page"] { background: var(--accent-soft); }
@media (hover: hover) { .rail .tab:hover { background: var(--surface-2); } }

/* page frame: phone = one pane + tab bar; desktop = rail + list + thread */
.shell { height: 100dvh; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
.pane { min-height: 0; display: flex; flex-direction: column; background: var(--bg); }
.pane-list { border-right: 1px solid var(--line); }
.scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
@media (min-width: 900px) {
  .shell { grid-template-columns: var(--rail-w) var(--list-w) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
  .shell > .tabbar { display: none; }
  .shell > .rail { display: flex; }
  .pane-thread .thread, .pane-thread .composer-inner { width: 100%; max-width: var(--thread-max); margin-inline: auto; }
}

/* ---------- chat list ---------- */
.chat-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: var(--s-3);
  align-items: center;
  min-height: 68px;
  padding: var(--s-3) var(--s-4);
  color: inherit;
  text-decoration: none;
  background: none;
  border: 0;
  width: 100%;
  text-align: left;
  border-radius: var(--r-md);
}
.chat-row[aria-current="true"] { background: var(--accent-soft); }
.chat-row .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-row .preview { display: flex; align-items: center; gap: 4px; color: var(--dim); font-size: var(--fs-base); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.chat-row .meta { display: grid; justify-items: end; gap: 6px; font-size: var(--fs-xs); color: var(--dim); }
.chat-row.unread .preview { color: var(--text); font-weight: 600; }
.chat-row.unread .meta .time { color: var(--accent); font-weight: 600; }
@media (hover: hover) { .chat-row:hover { background: var(--surface-2); } .chat-row[aria-current="true"]:hover { background: var(--accent-soft); } }

/* ---------- thread + messages ---------- */
.thread { display: flex; flex-direction: column; gap: 2px; padding: var(--s-4) calc(var(--s-4) + var(--safe-r)) var(--s-4) calc(var(--s-4) + var(--safe-l)); }
.bubble {
  align-self: flex-start;
  max-width: min(80%, 34rem);
  padding: 8px 12px;
  border-radius: var(--r-lg);
  background: var(--theirs);
  color: var(--text);
  box-shadow: var(--shadow-1);
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  line-height: 1.35;
}
.bubble.new { animation: pop-in var(--dur) var(--ease); }
.bubble.mine { align-self: flex-end; background: var(--mine); color: var(--on-mine); }
.bubble + .bubble:not([data-pos="first"]):not([data-pos="single"]) { margin-top: 0; }
.bubble[data-pos="first"], .bubble[data-pos="single"] { margin-top: var(--s-2); }
.bubble:not(.mine)[data-pos="first"] { border-bottom-left-radius: 6px; }
.bubble:not(.mine)[data-pos="mid"] { border-radius: 6px var(--r-lg) var(--r-lg) 6px; }
.bubble:not(.mine)[data-pos="last"] { border-top-left-radius: 6px; }
.bubble.mine[data-pos="first"] { border-bottom-right-radius: 6px; }
.bubble.mine[data-pos="mid"] { border-radius: var(--r-lg) 6px 6px var(--r-lg); }
.bubble.mine[data-pos="last"] { border-top-right-radius: 6px; }
.bubble .meta { float: right; display: inline-flex; align-items: center; gap: 3px; margin: 8px 0 -3px 12px; font-size: 11px; color: var(--dim); white-space: nowrap; }
.bubble.mine .meta { color: var(--mine-dim); }
.tick { width: 15px; height: 15px; stroke-width: 2.4; }
.tick.read { color: var(--accent); }
.bubble.failed { outline: 1.5px solid var(--danger); }
.bubble.failed .meta { color: var(--danger); }
.bubble.deleted { background: transparent; box-shadow: none; border: 1px dashed var(--line); color: var(--dim); font-style: italic; }
.day { align-self: center; margin: var(--s-4) 0 var(--s-2); padding: 4px 12px; border-radius: var(--r-full); background: var(--surface-2); color: var(--dim); font-size: var(--fs-xs); font-weight: 600; }
.dots { display: inline-flex; align-items: center; gap: 4px; height: 20px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--dim); animation: bounce 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }
.jump { position: absolute; right: var(--s-4); bottom: var(--s-4); }

/* ---------- composer ---------- */
.composer { display: flex; justify-content: center; padding: var(--s-2) calc(var(--s-3) + var(--safe-r)) calc(var(--s-2) + var(--safe-b)) calc(var(--s-3) + var(--safe-l)); background: var(--bg); border-top: 1px solid var(--line); }
.composer-inner { display: flex; align-items: flex-end; gap: var(--s-2); width: 100%; }
.composer textarea {
  flex: 1;
  min-height: 44px;
  max-height: 140px;
  padding: 10px 16px;
  resize: none;
  background: var(--surface);
  color: var(--text);
  border: 1.5px solid var(--line);
  border-radius: 22px;
  font-size: 16px;
  line-height: 1.35;
}
.composer textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.composer .send {
  flex: none;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  opacity: 0;
  transform: scale(0.5);
  pointer-events: none;
  transition: transform var(--dur) var(--ease-pop), opacity var(--dur-fast) var(--ease);
}
.composer.has-text .send { opacity: 1; transform: none; pointer-events: auto; }

/* ---------- surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--s-4); }
.request { display: grid; gap: var(--s-3); }
.request .who { display: flex; align-items: center; gap: var(--s-3); }
.request .quote { padding: var(--s-3); border-radius: var(--r-md); background: var(--surface-2); overflow-wrap: anywhere; }
.request .actions { display: flex; gap: var(--s-2); flex-wrap: wrap; }
.request .actions .btn-primary-grow { flex: 1; }
.group { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
.group > * + * { border-top: 1px solid var(--line); }
.cell { display: flex; align-items: center; gap: var(--s-3); min-height: 56px; padding: var(--s-2) var(--s-4); }
.cell .grow { flex: 1; min-width: 0; }
.cell .sub { font-size: var(--fs-sm); color: var(--dim); }
.menu { min-width: 200px; padding: var(--s-1); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--shadow-2); }
.menu button, .menu a { display: flex; align-items: center; gap: var(--s-3); width: 100%; min-height: 40px; padding: 0 var(--s-3); background: none; border: 0; border-radius: var(--r-sm); text-align: left; text-decoration: none; color: var(--text); font-size: var(--fs-base); }
.menu .danger { color: var(--danger); }
@media (hover: hover) { .menu button:hover, .menu a:hover { background: var(--surface-2); } }

/* sheet / dialog: use <dialog class="sheet"> (native focus trap, Esc to close) */
dialog.sheet {
  width: 100%;
  max-width: 520px;
  max-height: 90dvh;
  margin: auto auto 0;
  padding: var(--s-2) var(--s-5) calc(var(--s-5) + var(--safe-b));
  border: 0;
  border-radius: 22px 22px 0 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-2);
  overflow-y: auto;
}
dialog.sheet::backdrop { background: var(--scrim); }
dialog.sheet[open] { animation: sheet-in var(--dur-slow) var(--ease); }
dialog.sheet::before { content: ""; display: block; width: 36px; height: 4px; margin: 0 auto var(--s-4); border-radius: 2px; background: var(--line); }
dialog.sheet h2 { margin-bottom: var(--s-3); }
@media (min-width: 700px) {
  dialog.sheet { margin: auto; border-radius: var(--r-lg); padding-bottom: var(--s-5); }
  dialog.sheet[open] { animation: pop-in var(--dur) var(--ease); }
  dialog.sheet::before { display: none; }
}

.toast {
  position: fixed;
  left: 50%;
  top: calc(var(--safe-t) + var(--s-3));
  transform: translateX(-50%);
  z-index: var(--z-toast);
  max-width: min(92vw, 420px);
  padding: 10px var(--s-4);
  border-radius: var(--r-full);
  background: var(--text);
  color: var(--bg);
  font-size: var(--fs-base);
  font-weight: 500;
  box-shadow: var(--shadow-2);
  animation: toast-in var(--dur) var(--ease);
}
.banner { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-3) var(--s-4); border-radius: var(--r-md); background: var(--surface-2); color: var(--text); font-size: var(--fs-base); }
.banner .grow { flex: 1; min-width: 0; }
.banner-warn { background: var(--attention-soft); }
.banner-warn > .icon { color: var(--attention); }
.banner-err { background: var(--danger-soft); }
.banner-err > .icon { color: var(--danger); }

/* ---------- feedback ---------- */
.spinner { width: 20px; height: 20px; border: 2.5px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.7s linear infinite; }
.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--line) 50%, var(--surface-2) 75%); background-size: 300% 100%; animation: shimmer 1.4s linear infinite; border-radius: var(--r-sm); }
.empty { display: grid; justify-items: center; text-align: center; gap: var(--s-3); padding: var(--s-9) var(--s-6); }
.empty p { color: var(--dim); max-width: 28ch; }
.eyes { display: flex; gap: 10px; margin-bottom: var(--s-2); animation: blink 5s infinite; transform-origin: center; }
.eyes i { display: block; width: 30px; height: 30px; border-radius: 50%; background: var(--accent); }
.eyes i + i { background: none; border: 6px solid var(--text); }

/* ---------- motion ---------- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pop-in { from { opacity: 0; transform: translateY(6px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes sheet-in { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -10px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.5; } 30% { transform: translateY(-4px); opacity: 1; } }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -200% 0; } }
@keyframes badge-pop { 0% { transform: scale(0.6); } 60% { transform: scale(1.25); } 100% { transform: scale(1); } }
@keyframes blink { 0%, 92%, 100% { transform: scaleY(1); } 95% { transform: scaleY(0.1); } }
