/* Shared building blocks: cards, buttons, fields, chips. Screen-specific parts are in screens.css. */

.notice {
  margin: var(--space-4) 0;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  background: var(--color-notice-bg);
  color: var(--color-notice-text);
  font-weight: 700;
}

.form-error {
  margin: var(--space-4) 0;
  padding: var(--space-3) var(--space-4);
  border: var(--border-width) solid var(--color-danger);
  border-radius: var(--radius);
  background: var(--color-error-bg);
  color: var(--color-error-text);
}

.form-error p {
  margin: 0;
}

.form-error-title {
  font-weight: 700;
}

.card {
  margin: var(--space-4) 0;
  padding: var(--space-2) var(--space-4) var(--space-4);
  border-radius: var(--radius-card);
  background: var(--color-surface);
  box-shadow: var(--shadow-card);
}

.card h2 {
  margin-top: var(--space-3);
}

.card-leaf {
  background: var(--color-soft);
  box-shadow: none;
}

.card-title-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

/* Full-width and tall: easy to hit with a thumb. */
.button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  width: 100%;
  min-height: var(--control-height);
  margin: var(--tap-gap) 0;
  padding: var(--space-2) var(--space-4);
  border: var(--border-width) solid var(--color-primary);
  border-radius: var(--radius);
  font: inherit;
  font-size: var(--font-size-md);
  font-weight: 700;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

.button > .icon {
  flex: none;
  width: 1.25rem;
  height: 1.25rem;
}

.button-primary {
  background: var(--color-primary);
  color: var(--color-primary-contrast);
}

.button-secondary {
  background: var(--color-surface);
  color: var(--color-primary);
}

/* Disabled reads apart by its dashed border and page-colored fill, not only by a lighter color. */
.button:disabled {
  border-style: dashed;
  border-color: var(--color-border);
  background: var(--color-bg);
  color: var(--color-muted);
  font-weight: 400;
  cursor: not-allowed;
}

.button-danger {
  border-color: var(--color-danger);
  background: var(--color-surface);
  color: var(--color-danger);
}

.button-quiet {
  border-color: transparent;
  background: transparent;
  color: var(--color-muted);
  font-weight: 400;
  text-decoration: underline;
}

.button-pair {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--tap-gap);
}

.button-pair .button {
  margin: 0;
}

.field {
  margin: var(--space-4) 0;
}

.field label,
.field-label,
.time label {
  display: block;
  font-weight: 700;
}

.field-hint {
  margin: 0 0 var(--space-2);
  color: var(--color-muted);
}

.field-head {
  display: flex;
  align-items: center;
}

/* A 3rem tap target around a small round "?", kept from stretching the label row. */
.hint-toggle {
  display: grid;
  place-items: center;
  width: var(--control-height);
  height: var(--control-height);
  margin: calc(var(--control-height) / -4) 0 calc(var(--control-height) / -4) -0.5rem;
  padding: 0;
  border: 0;
  background: none;
  color: var(--color-primary);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.hint-toggle > span[aria-hidden] {
  display: grid;
  place-items: center;
  width: 1.125rem;
  height: 1.125rem;
  border: var(--border-width) solid currentColor;
  border-radius: 50%;
  font-size: 0.75rem;
  line-height: 1;
}

.hint-toggle[aria-expanded="true"] > span[aria-hidden] {
  background: var(--color-primary);
  color: var(--color-primary-contrast);
}

.hint-note {
  padding: var(--space-3);
  border-radius: var(--radius);
  background: var(--color-soft);
  font-size: var(--font-size-xs);
}

input[type="text"],
input[type="email"],
input[type="time"],
input[type="date"],
input[type="datetime-local"],
select,
textarea {
  width: 100%;
  min-height: var(--control-height);
  padding: var(--space-2) var(--space-3);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit;
  /* 16px or more stops iOS Safari from zooming into the field on focus. */
  font-size: var(--font-size-md);
}

/* The native arrow hugs the right edge and ignores padding on iOS, so draw our own and place it. */
select {
  appearance: none;
  padding-right: calc(var(--space-4) + 1rem + var(--space-2));
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3.5 6l4.5 4.5L12.5 6' fill='none' stroke='%233a4634' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-position: right var(--space-4) center;
  background-repeat: no-repeat;
  background-size: 1rem;
}

textarea {
  display: block;
  resize: vertical;
}

[aria-invalid="true"] {
  border-color: var(--color-danger);
  border-width: var(--focus-width);
}

/* Native checkboxes kept but drawn as chips, so one tap picks or drops and no script is needed. */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--tap-gap);
  margin: var(--space-3) 0;
  padding: 0;
  border: 0;
}

.chips legend {
  margin-bottom: var(--space-2);
  padding: 0;
  font-weight: 700;
}

/* A hint inside the chip row takes a line of its own. */
.chips-hint {
  flex-basis: 100%;
  margin: 0;
}

.period {
  margin: var(--space-3) 0;
  padding: 0;
  border: 0;
}

.period legend {
  padding: 0;
  font-weight: 700;
}

.export-count {
  margin: var(--space-4) 0 0;
  font-size: var(--font-size-md);
}

.export-count strong {
  margin: 0 var(--space-1);
  font-size: var(--font-size-lg);
}

.chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--control-height);
  padding: 0 var(--space-4);
  border: var(--border-width) solid var(--color-border);
  border-radius: 999px;
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
}

/* The checkbox stays focusable and announced; the chip's fill shows the choice. */
.chip input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.chip:has(input:checked) {
  border-color: var(--color-primary);
  background: var(--color-primary);
  color: var(--color-primary-contrast);
  font-weight: 700;
}

.chip:has(input:focus-visible) {
  outline: var(--focus-width) solid var(--color-focus);
  outline-offset: 2px;
}

.chip-add {
  border-style: dashed;
  background: transparent;
  color: var(--color-link);
  text-decoration: none;
}

.check {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  margin: var(--space-3) 0;
}

.check input {
  flex: none;
  width: 1.5rem;
  height: 1.5rem;
  margin-top: 0.125rem;
  accent-color: var(--color-primary);
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: 0 0 var(--space-3);
  padding: 0;
  list-style: none;
}

.entry-labels {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

.tag,
.entry-label {
  padding: 0 var(--space-3);
  border-radius: 999px;
  background: var(--label-bg, var(--color-tag-bg));
  color: var(--color-text);
  font-size: var(--font-size-sm);
}

.quote {
  margin: var(--space-4) 0;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  background: var(--color-surface);
}

.label-list,
.key-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.title-row {
  display: flex;
  gap: var(--tap-gap);
  align-items: center;
  justify-content: space-between;
}

.button-inline {
  width: auto;
  flex: none;
  margin: 0;
}

.label-count {
  margin: var(--space-2) 0 0;
  color: var(--color-muted);
  text-align: right;
}

.inline-form {
  display: flex;
  gap: var(--tap-gap);
  align-items: center;
  margin-top: var(--space-2);
}

.inline-form .button {
  width: auto;
  flex: none;
}

.secret {
  display: block;
  padding: var(--space-3);
  border-radius: var(--radius);
  background: var(--color-bg);
  font-size: var(--font-size-sm);
  overflow-wrap: anywhere;
  user-select: all;
}

.dialog {
  width: min(100% - 2 * var(--space-4), 32rem);
  padding: var(--space-4);
  border: 0;
  border-radius: var(--radius-card);
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--shadow-card);
}

.dialog :is(h1, h2) {
  margin-top: 0;
}

/* The entry editor brings its page's h1 into the dialog; size it like the other dialog titles. */
.dialog h1 {
  font-size: var(--font-size-lg);
}

.dialog::backdrop {
  background: rgb(31 42 27 / 0.5);
}

[data-copy-status]:empty {
  display: none;
}

/* The label and the check share one cell, so the button keeps its size while the check plays. */
.copy-button {
  display: grid;
  place-items: center;
}

.copy-label,
.copy-check {
  grid-area: 1 / 1;
}

.copy-check {
  visibility: hidden;
  fill: none;
  stroke: currentColor;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.copy-button.is-copied .copy-label {
  visibility: hidden;
}

.copy-button.is-copied .copy-check {
  visibility: visible;
}

/* Only for those who have not asked the OS to reduce motion. */
@media (prefers-reduced-motion: no-preference) {
  .copy-button.is-copied .copy-check {
    stroke-dasharray: 22;
    stroke-dashoffset: 22;
    animation: draw-check 0.35s ease-out forwards;
  }

  @keyframes draw-check {
    to {
      stroke-dashoffset: 0;
    }
  }
}

.endpoints dt {
  margin-top: var(--space-3);
  font-weight: 700;
}

.endpoints dd {
  margin: 0;
}

.icon {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* The passkey and push status lines are filled by JS; empty, they would only add a gap. */
[data-passkey-status]:empty,
[data-push-status]:empty {
  display: none;
}

.legal-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-2) var(--space-6);
  margin-block-start: var(--space-8);
  font-size: var(--font-size-xs);
}

.legal-links a {
  color: var(--color-muted);
}

/* Two-press danger button (ConfirmButton, public/js/confirm.js). */
.confirm-button {
  display: grid;
  place-items: center;
  overflow: hidden;
  transition:
    background-color 200ms ease,
    color 200ms ease;
}

.confirm-face {
  grid-area: 1 / 1;
  transition:
    opacity 200ms ease,
    translate 200ms ease;
}

.confirm-again {
  opacity: 0;
  translate: 0 0.5rem;
}

.confirm-button[data-confirming] {
  background: var(--color-danger);
  color: var(--color-danger-contrast);
}

.confirm-button[data-confirming] .confirm-face {
  opacity: 0;
  translate: 0 -0.5rem;
}

.confirm-button[data-confirming] .confirm-again {
  opacity: 1;
  translate: 0 0;
}

@media (prefers-reduced-motion: reduce) {
  .confirm-button,
  .confirm-face {
    transition: none;
  }
}

/* Label colors: each class sets the pair, so .tag, .entry-label and .swatch read the same. */
.label-green {
  --label-bg: var(--color-label-green-bg);
  --label-dot: var(--color-label-green);
}

.label-blue {
  --label-bg: var(--color-label-blue-bg);
  --label-dot: var(--color-label-blue);
}

.label-yellow {
  --label-bg: var(--color-label-yellow-bg);
  --label-dot: var(--color-label-yellow);
}

.label-pink {
  --label-bg: var(--color-label-pink-bg);
  --label-dot: var(--color-label-pink);
}

.label-purple {
  --label-bg: var(--color-label-purple-bg);
  --label-dot: var(--color-label-purple);
}

.label-orange {
  --label-bg: var(--color-label-orange-bg);
  --label-dot: var(--color-label-orange);
}

.label-gray {
  --label-bg: var(--color-label-gray-bg);
  --label-dot: var(--color-label-gray);
}

.label-brown {
  --label-bg: var(--color-label-brown-bg);
  --label-dot: var(--color-label-brown);
}

/* The ring keeps the dot visible on a filled (picked) chip as well as on the page. */
.swatch {
  display: inline-block;
  flex: none;
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 50%;
  background: var(--label-dot);
  box-shadow: 0 0 0 2px var(--color-surface);
}

.label-edit {
  display: flex;
  flex-wrap: wrap;
  gap: var(--tap-gap);
  align-items: center;
}

.label-edit input[type="text"] {
  flex: 1 1 10rem;
  width: auto;
}

.label-edit select {
  flex: 1 1 6rem;
  width: auto;
}

.label-edit .button {
  width: auto;
  flex: none;
}
