/* Components shared by every page: buttons, badges, panels, forms, notices, progress. */

/* ---------- Buttons ---------- */

.btn {
  --btn-bg: var(--sheet);
  --btn-fg: var(--ink);
  --btn-border: var(--line-strong);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 44px;
  padding: 0.55rem 1.1rem;
  border: 1.5px solid var(--btn-border);
  border-radius: var(--radius-s);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-weight: 650;
  font-size: var(--step--1);
  line-height: 1.2;
  text-decoration: none;
  text-align: center;
  text-wrap: balance;
  touch-action: manipulation;
  transition:
    background-color var(--dur-fast) ease,
    border-color var(--dur-fast) ease,
    transform var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-fast) ease;
}

.btn:hover {
  --btn-border: var(--ink-soft);
  text-decoration: none;
}

.btn:active {
  transform: translateY(1px) scale(0.985);
}

.btn[disabled],
.btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn svg {
  width: 1.1em;
  height: 1.1em;
  flex: none;
}

/* Primary: violet with an offset "drafting" shadow. */
.btn--primary {
  --btn-bg: var(--violet);
  --btn-fg: var(--on-accent);
  --btn-border: var(--violet);
  box-shadow: 3px 3px 0 var(--ink);
}

.btn--primary:hover {
  --btn-bg: var(--violet-hover);
  --btn-border: var(--violet-hover);
  box-shadow: 4px 4px 0 var(--ink);
  transform: translate(-1px, -1px);
}

.btn--primary:active {
  box-shadow: 1px 1px 0 var(--ink);
  transform: translate(2px, 2px);
}

@media (prefers-color-scheme: dark) {
  .btn--primary { box-shadow: 3px 3px 0 #000; }
  .btn--primary:hover { box-shadow: 4px 4px 0 #000; }
  .btn--primary:active { box-shadow: 1px 1px 0 #000; }
}

.btn--ghost {
  --btn-bg: transparent;
  --btn-border: transparent;
  color: var(--ink-soft);
}

.btn--ghost:hover {
  --btn-bg: var(--sheet-sunk);
  --btn-border: transparent;
  color: var(--ink);
}

.btn--ai {
  --btn-bg: var(--ai-tint);
  --btn-fg: var(--ai);
  --btn-border: var(--ai-stroke);
}

.btn--ai:hover {
  --btn-border: var(--ai);
}

.btn--lg {
  font-size: var(--step-0);
  padding: 0.8rem 1.5rem;
  min-height: 52px;
}

.btn--sm {
  padding: 0.4rem 0.8rem;
}

.btn.is-busy {
  cursor: progress;
}

.btn.is-busy::after {
  content: "";
  width: 0.9em;
  height: 0.9em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Text-like button (e.g. "Sign out"). */
.link-btn {
  background: none;
  border: 0;
  padding: 0 0.5rem;
  min-height: 44px;
  color: var(--violet-text);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

/* ---------- Badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  padding: 0.12rem 0.5rem;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1.5;
  white-space: nowrap;
}

.badge svg {
  width: 0.95em;
  height: 0.95em;
}

.badge--free { color: var(--ok); background: var(--ok-tint); }
.badge--pro { color: var(--violet-text); background: var(--violet-tint); }
.badge--soon { color: var(--ink-faint); background: var(--sheet-sunk); border-style: dashed; }
.badge--done { color: var(--ok); background: var(--ok-tint); }

/* ---------- Panels ---------- */

/* A sheet pinned to the notebook, with small registration ticks at two corners. */
.sheet {
  position: relative;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  box-shadow: var(--shadow-m);
}

.sheet--ticked::before,
.sheet--ticked::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  border-color: var(--violet);
  border-style: solid;
  pointer-events: none;
}

.sheet--ticked::before {
  top: -6px;
  left: -6px;
  border-width: 2px 0 0 2px;
}

.sheet--ticked::after {
  bottom: -6px;
  right: -6px;
  border-width: 0 2px 2px 0;
}

/* ---------- Notices ---------- */

.notice {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  padding: var(--space-xs) var(--space-s);
  border-radius: var(--radius-s);
  border: 1px solid var(--line);
  background: var(--sheet);
  font-size: var(--step--1);
}

.notice--error { border-color: var(--bad); background: var(--bad-tint); color: var(--bad); }
.notice--ok { border-color: var(--ok); background: var(--ok-tint); color: var(--ok); }
.notice--info { border-color: var(--violet-line); background: var(--violet-tint); }

.notice[hidden] {
  display: none;
}

/* ---------- Forms ---------- */

.field {
  display: grid;
  gap: 0.35rem;
}

.field label {
  font-weight: 650;
  font-size: var(--step--1);
}

.field__hint {
  color: var(--ink-faint);
  font-size: var(--step--2);
  font-family: var(--font-mono);
}

.input {
  width: 100%;
  min-height: 48px;
  padding: 0.6rem 0.8rem;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-s);
  background: var(--sheet);
  color: var(--ink);
  transition: border-color var(--dur-fast) ease, box-shadow var(--dur-fast) ease;
}

.input:hover {
  border-color: var(--ink-faint);
}

.input:focus-visible {
  outline: none;
  border-color: var(--violet);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--violet) 30%, transparent);
}

.input[aria-invalid="true"] {
  border-color: var(--bad);
}

.field__error {
  color: var(--bad);
  font-size: var(--step--1);
  font-weight: 600;
}

/* ---------- Progress bar ---------- */

.progress {
  display: grid;
  gap: 0.4rem;
}

.progress__row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: var(--step--1);
}

.progress__track {
  position: relative;
  height: 10px;
  border-radius: 999px;
  background: var(--sheet-sunk);
  border: 1px solid var(--line);
  overflow: hidden;
}

.progress__fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 100%;
  background:
    repeating-linear-gradient(-45deg, rgb(255 255 255 / 0.18) 0 6px, transparent 6px 12px),
    var(--violet);
  border-radius: inherit;
  transform-origin: left center;
  transform: scaleX(var(--p, 0));
  transition: transform var(--dur-slow) var(--ease-out);
}

/* ---------- In-page confirm (replaces window.confirm) ---------- */

.confirm {
  display: grid;
  gap: var(--space-xs);
  padding: var(--space-s);
  border: 1.5px dashed var(--key-stroke);
  border-radius: var(--radius-m);
  background: var(--key-tint);
}

.confirm__title {
  font-weight: 700;
  margin: 0;
}

.confirm__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* ---------- Loading skeleton ---------- */

.skeleton {
  border-radius: var(--radius-s);
  background: linear-gradient(90deg, var(--sheet-sunk), var(--line), var(--sheet-sunk));
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
  min-height: 1.2em;
}

@keyframes shimmer {
  from { background-position: 100% 0; }
  to { background-position: -100% 0; }
}

/* ---------- Icon helper ---------- */

.icon {
  width: 1.15em;
  height: 1.15em;
  flex: none;
  display: inline-block;
  vertical-align: -0.2em;
}

/* A row of actions under a message (locked, not found, 404). */
.state-card__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}
