/* Reusable UI primitives shared by every page. */

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

.btn {
  position: relative;
  border: 0;
  border-radius: var(--r-md);
  padding: 12px 20px;
  color: var(--primary-ink);
  background: linear-gradient(115deg, var(--primary), var(--primary-2));
  font-weight: 600;
  font-size: 14.5px;
  letter-spacing: -0.01em;
  white-space: nowrap;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 9px;
  box-shadow: var(--shadow-sm), var(--glow);
  overflow: hidden;
  transition:
    transform var(--t-fast) var(--ease),
    box-shadow var(--t) var(--ease),
    opacity var(--t-fast) var(--ease);
}

/* Sheen that sweeps across on hover. */
.btn::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    100deg,
    transparent 20%,
    rgba(255, 255, 255, 0.28) 50%,
    transparent 80%
  );
  transform: translateX(-120%);
  transition: transform var(--t-slow) var(--ease);
}

.btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: var(--shadow), var(--glow);
}

.btn:hover:not(:disabled)::after {
  transform: translateX(120%);
}

.btn:active:not(:disabled) {
  transform: translateY(0);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn.secondary {
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  box-shadow: none;
}

.btn.secondary:hover:not(:disabled) {
  background: var(--surface-3);
  border-color: var(--line-strong);
  box-shadow: var(--shadow-sm);
}

.btn.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
  box-shadow: none;
}

.btn.ghost:hover:not(:disabled) {
  background: var(--primary-soft);
  border-color: var(--primary-ring);
  box-shadow: none;
}

.btn.danger {
  background: var(--danger);
  box-shadow: none;
  margin-right: auto;
}

.btn.danger:hover:not(:disabled) {
  box-shadow: var(--shadow-sm);
  filter: brightness(1.06);
}

.btn.block {
  width: 100%;
}

/* Busy state: label dims and a spinner takes over. */
.btn[data-busy="true"] {
  color: transparent;
  pointer-events: none;
}

.btn[data-busy="true"]::before {
  content: "";
  position: absolute;
  width: 17px;
  height: 17px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.btn.secondary[data-busy="true"]::before,
.btn.ghost[data-busy="true"]::before {
  border-color: var(--line-strong);
  border-top-color: var(--text);
}

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

.icon-btn {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text-2);
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: var(--r-md);
  font-size: 16px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition:
    background var(--t-fast) var(--ease),
    color var(--t-fast) var(--ease),
    border-color var(--t-fast) var(--ease),
    transform var(--t-fast) var(--ease);
}

.icon-btn:hover {
  background: var(--primary-soft);
  border-color: var(--primary-ring);
  color: var(--text);
  transform: translateY(-1px);
}

.icon-btn:active {
  transform: translateY(0);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

/* The moon/sun swap inside the theme toggle. */
.theme-toggle .sun {
  display: none;
}

:root[data-theme="light"] .theme-toggle .sun {
  display: block;
}

:root[data-theme="light"] .theme-toggle .moon {
  display: none;
}

/* --- Form fields ------------------------------------------------------- */

.field {
  display: grid;
  gap: 7px;
  margin: 16px 0;
  min-width: 0;
}

.field > label,
.field-label {
  font-weight: 600;
  font-size: 13px;
  color: var(--text-2);
}

.field input,
.field select,
.field textarea,
.search {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 12px 14px;
  color: var(--text);
  outline: 0;
  transition:
    border-color var(--t-fast) var(--ease),
    box-shadow var(--t-fast) var(--ease),
    background var(--t-fast) var(--ease);
}

.field textarea {
  resize: vertical;
  min-height: 72px;
}

.field input::placeholder,
.search::placeholder {
  color: var(--muted);
  opacity: 0.75;
}

.field input:hover,
.field select:hover,
.field textarea:hover,
.search:hover {
  border-color: var(--line-strong);
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.search:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-soft);
  background: var(--surface);
}

.field select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) calc(50% + 1px),
    calc(100% - 13px) calc(50% + 1px);
  background-size: 5px 5px;
  background-repeat: no-repeat;
  padding-right: 36px;
}

.field .hint {
  font-size: 12.5px;
  color: var(--muted);
}

.field .hint.error {
  color: var(--danger);
}

.input-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.input-row input {
  min-width: 0;
  flex: 1;
}

.input-row .icon-btn,
.input-row .btn {
  flex: none;
}

/* Password input with trailing reveal/copy buttons layered inside. */
.secret-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.secret-wrap input {
  padding-right: 84px;
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
}

.secret-tools {
  position: absolute;
  right: 6px;
  display: flex;
  gap: 2px;
}

.secret-tools button {
  border: 0;
  background: transparent;
  color: var(--muted);
  width: 32px;
  height: 32px;
  border-radius: var(--r-sm);
  display: grid;
  place-items: center;
  transition:
    background var(--t-fast) var(--ease),
    color var(--t-fast) var(--ease);
}

.secret-tools button:hover {
  background: var(--surface-3);
  color: var(--text);
}

.secret-tools svg {
  width: 17px;
  height: 17px;
}

/* Checkbox / switch */
.check {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-size: 13.5px;
  cursor: pointer;
  user-select: none;
}

.check input {
  appearance: none;
  width: 18px;
  height: 18px;
  flex: none;
  border: 1.5px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  transition:
    background var(--t-fast) var(--ease),
    border-color var(--t-fast) var(--ease);
}

.check input::after {
  content: "";
  width: 9px;
  height: 5px;
  border: 2px solid #fff;
  border-top: 0;
  border-right: 0;
  transform: rotate(-45deg) scale(0.4);
  opacity: 0;
  transition: all var(--t-fast) var(--spring);
}

.check input:checked {
  background: var(--primary);
  border-color: var(--primary);
}

.check input:checked::after {
  opacity: 1;
  transform: rotate(-45deg) scale(1);
}

/* --- Surfaces ---------------------------------------------------------- */

.card {
  position: relative;
  background:
    linear-gradient(160deg, var(--card-sheen), transparent 42%),
    var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 12.5px;
  margin: 20px 0;
}

.divider::before,
.divider::after {
  content: "";
  height: 1px;
  background: var(--line);
  flex: 1;
}

.notice {
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--muted);
  background: var(--primary-soft);
  border: 1px solid var(--primary-ring);
  border-radius: var(--r-md);
  padding: 11px 14px;
}

.notice.warn {
  background: var(--warning-soft);
  border-color: transparent;
  color: var(--text-2);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 4px 9px;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  color: var(--muted);
}

/* --- Strength meter ---------------------------------------------------- */

.strength {
  height: 6px;
  background: var(--surface-3);
  border-radius: var(--r-pill);
  overflow: hidden;
}

.strength i {
  height: 100%;
  display: block;
  width: 0;
  border-radius: inherit;
  background: var(--danger);
  transition:
    width var(--t) var(--ease-out),
    background-color var(--t) var(--ease);
}

.strength i.score-0,
.strength i.score-1 {
  background: var(--danger);
}
.strength i.score-2 {
  background: #f97316;
}
.strength i.score-3 {
  background: var(--warning);
}
.strength i.score-4 {
  background: #84cc16;
}
.strength i.score-5 {
  background: var(--success);
}

/* --- OTP boxes --------------------------------------------------------- */

.otp-boxes {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin: 6px 0;
}

.otp-boxes input {
  width: 52px;
  height: 60px;
  text-align: center;
  font: 600 24px var(--font-mono);
  padding: 0;
  border-radius: var(--r-md);
}

.otp-boxes input:focus {
  transform: translateY(-2px);
}

/* --- Toasts ------------------------------------------------------------ */

.toast-area {
  position: fixed;
  bottom: 22px;
  right: 22px;
  z-index: 200;
  display: grid;
  gap: 10px;
  justify-items: end;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 11px;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--primary);
  padding: 13px 16px;
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  animation: toast-in var(--t) var(--spring) both;
}

.toast[data-leaving="true"] {
  animation: toast-out var(--t-fast) var(--ease) forwards;
}

.toast .dot {
  width: 8px;
  height: 8px;
  flex: none;
  border-radius: 50%;
  background: var(--primary);
}

.toast.success {
  border-left-color: var(--success);
}
.toast.success .dot {
  background: var(--success);
}
.toast.error {
  border-left-color: var(--danger);
}
.toast.error .dot {
  background: var(--danger);
}
.toast.warning {
  border-left-color: var(--warning);
}
.toast.warning .dot {
  background: var(--warning);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(28px) scale(0.96);
  }
}

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateX(28px) scale(0.96);
  }
}

/* --- Modal ------------------------------------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--backdrop);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  visibility: hidden;
  transition:
    opacity var(--t) var(--ease),
    visibility var(--t) var(--ease);
}

.modal[hidden] {
  display: none;
}

.modal.open {
  opacity: 1;
  visibility: visible;
}

.modal-box {
  width: min(640px, 100%);
  max-height: min(92vh, 900px);
  overflow: auto;
  padding: 26px;
  transform: translateY(18px) scale(0.97);
  opacity: 0;
  transition:
    transform var(--t) var(--spring),
    opacity var(--t) var(--ease);
}

.modal.open .modal-box {
  transform: none;
  opacity: 1;
}

.modal-box.narrow {
  width: min(420px, 100%);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
}

.modal-head h2 {
  font-size: 21px;
}

.actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  margin-top: 24px;
  flex-wrap: wrap;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.hidden {
  display: none !important;
}
