/* Shared components: buttons, fields, chips, cards, dialogs, menus, toasts, banners, bubbles, spinners. */

/* ---- Buttons ---------------------------------------------------------------------------------------------- */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--raised);
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  transition: background-color .15s var(--ease), border-color .15s var(--ease), color .15s var(--ease),
    transform .15s var(--ease), box-shadow .15s var(--ease), opacity .15s;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { text-decoration: none; border-color: color-mix(in srgb, var(--ink) 22%, var(--line)); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; }
/* 44 px hit areas for small visual buttons */
.btn::after, .icon-btn::after, .chip::after {
  content: '';
  position: absolute;
  inset: min(0px, calc((100% - 44px) / 2)) min(0px, calc((100% - 44px) / 2));
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn-primary:hover { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 88%, var(--ink)); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
:root[data-theme="dark"] .btn-danger { color: #0d0d10; }
@media (prefers-color-scheme: dark) { :root[data-theme="auto"] .btn-danger { color: #0d0d10; } }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--ink-soft); border-color: transparent; }
.btn-quiet { background: var(--ink-softer); border-color: transparent; }
.btn-quiet:hover { background: var(--ink-soft); border-color: transparent; }
.btn-sm { min-height: 32px; padding: 0 12px; font-size: 14px; }
.btn-lg { min-height: 48px; padding: 0 22px; font-size: 16px; }
.btn-block { width: 100%; }

.icon-btn {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  color: var(--ink);
  transition: background-color .15s var(--ease), color .15s;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover { background: var(--ink-soft); }
.icon-btn:disabled { opacity: .4; }

.link-btn {
  position: relative;
  color: var(--accent);
  font-weight: 600;
  padding: 2px 0;
  border-radius: 4px;
}
.link-btn:hover { text-decoration: underline; text-underline-offset: 3px; }

/* Button whose visible label comes from data-label (so a bar's textContent stays its message; aria-label names it). */
.btn[data-label]::before { content: attr(data-label); }

/* ---- Fields ----------------------------------------------------------------------------------------------- */
.field {
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.4;
  transition: border-color .15s, box-shadow .15s;
}
.field::placeholder { color: color-mix(in srgb, var(--mute) 80%, transparent); }
.field:focus { border-color: var(--accent); box-shadow: var(--ring); }
.field:disabled { opacity: .6; }
.field-label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.field-hint { font-size: 13px; color: var(--mute); margin-top: 6px; }
.field-error { font-size: 14px; color: var(--danger); margin-top: 8px; min-height: 0; }
.field-error:empty { display: none; }
.code-field { font-family: var(--mono); font-size: 24px; letter-spacing: .35em; text-align: center; padding-left: calc(14px + .35em); }

.counter { font-size: 12px; color: var(--mute); font-variant-numeric: tabular-nums; }
.counter[data-over="true"] { color: var(--danger); font-weight: 600; }

/* ---- Chips ------------------------------------------------------------------------------------------------ */
.chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--raised);
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  transition: border-color .15s, background-color .15s, transform .15s var(--ease);
}
.chip:hover { border-color: var(--accent-line); background: var(--accent-soft); }
.chip:active { transform: scale(.98); }

/* ---- Tags ------------------------------------------------------------------------------------------------- */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--ink-soft);
  color: var(--mute);
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
}
.tag .icon { width: 13px; height: 13px; stroke-width: 2; }
.tag[data-tone="accent"] { background: var(--accent-soft); color: var(--accent); }
.tag[data-tone="danger"] { background: var(--danger-soft); color: var(--danger); }
.tag[data-tone="ok"] { background: var(--ok-soft); color: var(--ok); }

/* ---- Cards (home lists) ------------------------------------------------------------------------------------ */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}
.card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 156px;
  padding: 18px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: var(--raised);
  color: var(--ink);
  text-decoration: none;
  transition: transform .2s var(--ease), box-shadow .2s var(--ease), border-color .2s;
}
.card:hover {
  text-decoration: none;
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  border-color: color-mix(in srgb, var(--ink) 14%, var(--line));
}
.card-emoji {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: var(--surface);
  font-size: 26px;
  line-height: 1;
}
.card-title {
  font-size: 16px;
  font-weight: 650;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.card-desc {
  font-size: 14px;
  line-height: 1.45;
  color: var(--mute);
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.card-meta {
  margin-top: auto;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 10px;
  font-size: 13px;
  color: var(--mute);
}
.card-meta .views { display: inline-flex; align-items: center; gap: 5px; font-variant-numeric: tabular-nums; }
.card-meta .views .icon { width: 15px; height: 15px; }
.card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.card.skeleton { pointer-events: none; }
.skeleton-bar {
  height: 12px;
  border-radius: 6px;
  background: var(--ink-soft);
  animation: fx-pulse 1.4s ease-in-out infinite;
}
.card.skeleton .card-emoji { animation: fx-pulse 1.4s ease-in-out infinite; color: transparent; }

/* ---- Dialogs ---------------------------------------------------------------------------------------------- */
dialog.dialog {
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--raised);
  color: var(--ink);
  box-shadow: 0 24px 80px rgba(0, 0, 0, .28);
  overflow: auto;
  overscroll-behavior: contain;
}
dialog.dialog::backdrop {
  background: rgba(10, 10, 14, .42);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
dialog.dialog[open] { animation: fx-dialog-in .22s var(--ease); }
.dialog-body { padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.dialog-title { font-size: 20px; font-weight: 700; line-height: 1.25; letter-spacing: -0.01em; }
.dialog-text { color: var(--mute); font-size: 15px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.dialog-close { margin: -6px -8px 0 0; color: var(--mute); }
.dialog-note {
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--ink);
  font-size: 14px;
}
.dialog-links { display: flex; gap: 16px; flex-wrap: wrap; font-size: 14px; }

@media (max-width: 599px) {
  dialog.dialog {
    width: 100vw;
    max-width: 100vw;
    margin: auto 0 0;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    border-bottom: 0;
    max-height: calc(100dvh - 24px);
    padding-bottom: var(--safe-bottom);
  }
  dialog.dialog[open] { animation: fx-sheet-in .26s var(--ease); }
  .dialog-actions .btn { flex: 1 1 auto; }
}

/* ---- Radios / switches ------------------------------------------------------------------------------------ */
.choice {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: border-color .15s, background-color .15s;
}
.choice:hover { background: var(--ink-softer); }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice input { margin: 3px 0 0; accent-color: var(--accent); width: 18px; height: 18px; flex: none; }
.choice-title { font-weight: 600; font-size: 15px; }
.choice-sub { font-size: 13px; color: var(--mute); }
.choices { display: flex; flex-direction: column; gap: 8px; }
.choices.compact .choice { padding: 9px 12px; }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; }
.switch {
  position: relative;
  flex: none;
  width: 44px;
  height: 26px;
  margin: 0;
  border-radius: 999px;
  background: var(--line);
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  transition: background-color .2s var(--ease);
}
.switch::before {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
  transition: transform .2s var(--ease);
}
.switch:checked { background: var(--accent); }
.switch:checked::before { transform: translateX(18px); }
.switch:disabled { opacity: .45; cursor: default; }
.switch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 999px; }

/* ---- Menus and popovers ----------------------------------------------------------------------------------- */
.menu, .popover {
  position: fixed;
  z-index: 60;
  min-width: 220px;
  max-width: min(340px, calc(100vw - 16px));
  max-height: calc(100dvh - 24px);
  overflow: auto;
  padding: 6px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--raised);
  color: var(--ink);
  box-shadow: var(--shadow);
  animation: fx-pop-in .14s var(--ease);
}
.popover { padding: 0; width: 360px; max-width: calc(100vw - 16px); }
.menu-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border-radius: 9px;
  color: var(--ink);
  font-size: 15px;
  text-align: left;
  text-decoration: none;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--ink-soft); text-decoration: none; outline: none; }
.menu-item .icon { color: var(--mute); }
.menu-item[data-tone="danger"], .menu-item[data-tone="danger"] .icon { color: var(--danger); }
.menu-item .menu-sub { display: block; font-size: 12px; color: var(--mute); }
.menu-item[aria-checked="true"]::after {
  content: '';
  margin-left: auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}
.menu-sep { height: 1px; margin: 6px 4px; background: var(--line); }
.menu-label { padding: 8px 10px 4px; font-size: 12px; color: var(--mute); font-weight: 600; overflow-wrap: anywhere; }
.menu-account { padding: 8px 10px; font-size: 13px; color: var(--mute); overflow-wrap: anywhere; }
.menu-account strong { display: block; color: var(--ink); font-size: 14px; font-weight: 600; }
.menu-seg { display: flex; gap: 4px; padding: 2px 6px 6px; }
.menu-seg button {
  position: relative;
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  border-radius: 8px;
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 600;
  color: var(--mute);
}
.menu-seg button .icon { width: 15px; height: 15px; }
.menu-seg button[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

@media (max-width: 599px) {
  .menu.as-sheet, .popover.as-sheet {
    left: 0 !important;
    right: 0 !important;
    top: auto !important;
    bottom: 0 !important;
    width: 100vw;
    max-width: 100vw;
    max-height: 85dvh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    border-bottom: 0;
    padding-bottom: calc(6px + var(--safe-bottom));
    animation: fx-sheet-in .24s var(--ease);
  }
  .popover.as-sheet { padding-bottom: var(--safe-bottom); }
  .menu.as-sheet .menu-item { min-height: 48px; }
}
.sheet-scrim {
  position: fixed;
  inset: 0;
  z-index: 59;
  background: rgba(10, 10, 14, .35);
  animation: fx-fade-in .2s;
}

/* ---- Toasts ----------------------------------------------------------------------------------------------- */
#toasts {
  position: fixed;
  left: 50%;
  top: calc(16px + var(--safe-top));
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: max-content;
  max-width: calc(100vw - 32px);
  transform: translateX(-50%);
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 100%;
  padding: 10px 14px 10px 12px;
  border-radius: 14px;
  background: var(--ink);
  color: var(--bg);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.35;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
  pointer-events: auto;
  animation: fx-toast-in .26s var(--ease);
}
.toast .icon { width: 18px; height: 18px; color: var(--ok); stroke-width: 2.2; }
.toast[data-tone="error"] .icon { color: var(--danger); }
.toast .toast-action {
  margin-left: 4px;
  padding: 4px 8px;
  border-radius: 8px;
  color: var(--bg);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.toast.leaving { animation: fx-toast-out .2s var(--ease) forwards; }
:root[data-theme="dark"] .toast .icon { color: #1d8a4e; }
@media (prefers-color-scheme: dark) { :root[data-theme="auto"] .toast .icon { color: #1d8a4e; } }
:root[data-theme="dark"] .toast[data-tone="error"] .icon { color: #c8372d; }
@media (prefers-color-scheme: dark) { :root[data-theme="auto"] .toast[data-tone="error"] .icon { color: #c8372d; } }

/* ---- Banners ---------------------------------------------------------------------------------------------- */
.bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding: 10px 10px 10px 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--raised);
  color: var(--ink);
  box-shadow: var(--shadow);
  font-size: 14px;
  line-height: 1.4;
  animation: fx-pop-in .2s var(--ease);
}
.bar > .bar-text { flex: 1 1 200px; min-width: 0; overflow-wrap: anywhere; }
.bar > .bar-icon { color: var(--accent); }
.bar[data-tone="warn"] > .bar-icon, .bar[data-tone="error"] > .bar-icon { color: var(--danger); }
.bar .bar-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---- Chat bubbles ----------------------------------------------------------------------------------------- */
.bubble {
  padding: 10px 14px;
  border-radius: 16px;
  background: var(--surface);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.bubble[data-tone="error"] {
  background: var(--danger-soft);
  border: 1px solid color-mix(in srgb, var(--danger) 25%, transparent);
  white-space: normal;
}
.bubble[data-tone="error"] .bubble-text { color: var(--ink); }
.bubble .btn { margin-top: 10px; }

/* ---- Spinner ---------------------------------------------------------------------------------------------- */
.spinner {
  flex: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--accent) 22%, transparent);
  border-top-color: var(--accent);
  animation: fx-spin .8s linear infinite;
}
.spinner-lg { width: 22px; height: 22px; border-width: 2.5px; }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; border-color: var(--accent); }
  .pulse-when-reduced { animation: fx-pulse 1.6s ease-in-out infinite; }
}

/* ---- Animations ------------------------------------------------------------------------------------------- */
@keyframes fx-spin { to { transform: rotate(360deg); } }
@keyframes fx-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }
@keyframes fx-fade-in { from { opacity: 0; } }
@keyframes fx-pop-in { from { opacity: 0; transform: translateY(-4px) scale(.98); } }
@keyframes fx-dialog-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes fx-sheet-in { from { transform: translateY(100%); } }
@keyframes fx-toast-in { from { opacity: 0; transform: translateY(-10px) scale(.97); } }
@keyframes fx-toast-out { to { opacity: 0; transform: translateY(-8px) scale(.97); } }
@keyframes fx-rise { from { opacity: 0; transform: translateY(6px); } }
.plain-fieldset > legend { float: left; width: 100%; padding: 0; }
.plain-fieldset > legend + * { clear: both; }
.signin-content { display: flex; flex-direction: column; gap: 16px; }
.signin-form, .report-form, .rename-form { display: flex; flex-direction: column; gap: 10px; }
.signin-form .field-label, .rename-form .field-label { margin-bottom: -2px; }
.signin-form .btn-block { margin-top: 4px; }
.dialog-links .link-btn:disabled { color: var(--mute); cursor: default; text-decoration: none; }
.field:focus-visible { outline: none; }
.link-btn::after { content: ''; position: absolute; inset: -12px -4px; }
